diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..7a73a41 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,2 @@ +{ +} \ No newline at end of file diff --git a/src/api/interceptor.ts b/src/api/interceptor.ts index 1d8214f..6e436c9 100644 --- a/src/api/interceptor.ts +++ b/src/api/interceptor.ts @@ -40,7 +40,7 @@ axios.interceptors.response.use( (response: AxiosResponse) => { const res = response.data; // if the custom code is not 20000, it is judged as an error. - if (res.code !== 20000) { + if (res.code !== 200) { Message.error({ content: res.msg || 'Error', duration: 5 * 1000, diff --git a/src/api/user.ts b/src/api/user.ts index 5b47019..f0c82c0 100644 --- a/src/api/user.ts +++ b/src/api/user.ts @@ -9,21 +9,51 @@ export interface LoginData { uuid: string; } +export interface RegisterData { + username: string; + password: string; + email: string; + code: string; + uuid: string; + inviteCode: string; +} + export interface LoginRes { token: string; } + +export interface CaptchaData { + captchaEnabled: boolean; + img: string; + uuid: string; +} + export function login(data: LoginData) { return axios.post('/login', data); } +export function register(data: RegisterData) { + return axios.post('/register', data); +} + export function logout() { - return axios.post('/api/user/logout'); + return axios.post('/logout'); } export function getUserInfo() { - return axios.post('/api/user/info'); + return axios.get('/getInfo'); } export function getMenuList() { return axios.post('/api/user/menu'); } + +// 获取验证码 +export function getCodeImg() { + return axios.get('/captchaImage2'); +} + +// 获取邮箱验证码 +export function getEmailCode(email: string) { + return axios.get(`/captchaMail?email=${email}`); +} diff --git a/src/components/navbar/index.vue b/src/components/navbar/index.vue index e37b697..e1ad612 100644 --- a/src/components/navbar/index.vue +++ b/src/components/navbar/index.vue @@ -23,7 +23,7 @@
    -
  • + +
  • @@ -108,7 +108,7 @@ -
  • + -->
  • - avatar + avatar + + + + + + {{ $t('login.form.login') }} - @@ -73,25 +94,40 @@ import { useUserStore } from '@/store'; import useLoading from '@/hooks/loading'; import type { LoginData } from '@/api/user'; + import { getCodeImg } from '@/api/user'; const router = useRouter(); const { t } = useI18n(); const errorMessage = ref(''); const { loading, setLoading } = useLoading(); const userStore = useUserStore(); + const codeUrl = ref(""); + // 验证码开关 + const captchaEnabled = ref(true); const loginConfig = useStorage('login-config', { - rememberPassword: true, - username: 'admin', // 演示默认值 - password: 'admin', // demo default value + rememberPassword: false, + username: '', + password: '', + code: '', + uuid: '' }); const userInfo = reactive({ username: loginConfig.value.username, password: loginConfig.value.password, - code: '111', - uuid: '222' + code: '', + uuid: '' }); + const getCode = async () => { + const res = await getCodeImg(); + captchaEnabled.value = res.data.captchaEnabled === undefined ? true : res.data.captchaEnabled; + if (captchaEnabled.value) { + codeUrl.value = `data:image/gif;base64,${res.data.img}`; + userInfo.uuid = res.data.uuid; + } + }; + const handleSubmit = async ({ errors, values, @@ -114,12 +150,13 @@ Message.success(t('login.form.login.success')); const { rememberPassword } = loginConfig.value; const { username, password } = values; - // 实际生产环境需要进行加密存储。 - // The actual production environment requires encrypted storage. loginConfig.value.username = rememberPassword ? username : ''; loginConfig.value.password = rememberPassword ? password : ''; } catch (err) { errorMessage.value = (err as Error).message; + if (captchaEnabled.value) { + getCode(); + } } finally { setLoading(false); } @@ -128,9 +165,16 @@ const setRememberPassword = (value: boolean) => { loginConfig.value.rememberPassword = value; }; + + getCode(); + + \ No newline at end of file diff --git a/src/views/login/index.vue b/src/views/login/index.vue index 7ad5b01..b32b36b 100644 --- a/src/views/login/index.vue +++ b/src/views/login/index.vue @@ -5,12 +5,13 @@ alt="logo" src="//p3-armor.byteimg.com/tos-cn-i-49unhts6dw/dfdba5317c0c20ce20e64fac803d52bc.svg~tplv-49unhts6dw-image.image" /> -
    Arco Design Pro
    +
    Api2Gpt
    - + +