diff --git a/.DS_Store b/.DS_Store index 5008ddf..816e1f9 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/src/router/guard.ts b/src/router/guard.ts index 8464a85..f19c7af 100644 --- a/src/router/guard.ts +++ b/src/router/guard.ts @@ -70,7 +70,7 @@ const compareTag = async () => { } /** 免登录白名单 */ -const whiteList = ['/login', '/social/callback', '/pwdExpired'] +const whiteList = ['/login', '/pwdExpired'] /** 是否已经生成过路由表 */ let hasRouteFlag = false @@ -93,7 +93,7 @@ export const setupRouterGuard = (router: Router) => { if (!hasRouteFlag) { try { await userStore.getInfo() - if (userStore.userInfo.pwdExpired && to.path !== '/pwdExpired') { + if (!userStore.pwdExpiredShow && to.path !== '/pwdExpired') { Message.warning('密码已过期,请修改密码') next('/pwdExpired') } diff --git a/src/router/route.ts b/src/router/route.ts index abe0021..dde18ec 100644 --- a/src/router/route.ts +++ b/src/router/route.ts @@ -389,11 +389,7 @@ export const systemRoutes: RouteRecordRaw[] = [ } ], }, - { - path: '/social/callback', - component: () => import('@/views/login/social/index.vue'), - meta: { hidden: true }, - }, + { path: '/pwdExpired', component: () => import('@/views/login/pwdExpired/index.vue'), diff --git a/src/stores/modules/user.ts b/src/stores/modules/user.ts index ef75739..ac20f3c 100644 --- a/src/stores/modules/user.ts +++ b/src/stores/modules/user.ts @@ -4,18 +4,18 @@ import { resetRouter } from '@/router' import { type AccountLoginReq, AuthTypeConstants, - type EmailLoginReq, + type PhoneLoginReq, type UserDetail, type DeptDetail, type RoleDetail, type UserInfo, accountLogin as accountLoginApi, - emailLogin as emailLoginApi, + getUserInfo as getUserInfoApi, logout as logoutApi, phoneLogin as phoneLoginApi, - socialLogin as socialLoginApi, + } from '@/apis' import { clearToken, getToken, setToken } from '@/utils/auth' import { resetHasRouteFlag } from '@/router/guard' @@ -64,17 +64,12 @@ const storeSetup = () => { // 登录 const accountLogin = async (req: AccountLoginReq) => { const res = await accountLoginApi({ ...req }) - setToken(res.data.tokenValue) - token.value = res.data.tokenValue - } - - // 邮箱登录 - const emailLogin = async (req: EmailLoginReq) => { - const res = await emailLoginApi({ ...req, clientId: import.meta.env.VITE_CLIENT_ID, authType: AuthTypeConstants.EMAIL }) setToken(res.data.token) token.value = res.data.token } + + // 手机号登录 const phoneLogin = async (req: PhoneLoginReq) => { const res = await phoneLoginApi({ ...req, clientId: import.meta.env.VITE_CLIENT_ID, authType: AuthTypeConstants.PHONE }) @@ -82,12 +77,7 @@ const storeSetup = () => { token.value = res.data.token } - // 三方账号登录 - const socialLogin = async (source: string, req: any) => { - const res = await socialLoginApi({ ...req, source, clientId: import.meta.env.VITE_CLIENT_ID, authType: AuthTypeConstants.SOCIAL }) - setToken(res.data.token) - token.value = res.data.token - } + // 退出登录回调 const logoutCallBack = async () => { @@ -172,9 +162,7 @@ const storeSetup = () => { permissions, pwdExpiredShow, accountLogin, - emailLogin, phoneLogin, - socialLogin, logout, logoutCallBack, getInfo, diff --git a/src/utils/encrypt.ts b/src/utils/encrypt.ts index 1d7433b..33d1b81 100644 --- a/src/utils/encrypt.ts +++ b/src/utils/encrypt.ts @@ -26,9 +26,17 @@ export function encryptByRsa(txt: string) { return encryptor.encrypt(txt) // 对数据进行加密 } -const defaultKeyWork = 'XwKsGlMcdPMEhR1B' - -export function encryptByAes(word, keyWord = defaultKeyWork) { +/** + * AES加密 + * @param word 要加密的密码 + * @param account 账号,用于生成加密密钥 + * @returns 加密后的字符串 + */ +export function encryptByAes(word: string, account: string) { + // 对账号做md5计算,然后取8-24位作为密钥(16个字符) + const accountMd5 = md5(account).toString() + const keyWord = accountMd5.substring(8, 24) // 取8-24位(索引8-23,共16位) + const key = CryptoJS.enc.Utf8.parse(keyWord) const arcs = CryptoJS.enc.Utf8.parse(word) const encrypted = CryptoJS.AES.encrypt(arcs, key, { diff --git a/src/views/login/components/account/index.vue b/src/views/login/components/account/index.vue index 0089603..f7b8f7b 100644 --- a/src/views/login/components/account/index.vue +++ b/src/views/login/components/account/index.vue @@ -33,7 +33,7 @@ import { type FormInstance, Message } from '@arco-design/web-vue' import { useStorage } from '@vueuse/core' import { getImageCaptcha } from '@/apis/common' import { useTabsStore, useUserStore } from '@/stores' -import { encryptByRsa } from '@/utils/encrypt' +import { encryptByAes } from '@/utils/encrypt' const loginConfig = useStorage('login-config', { rememberMe: true, @@ -101,7 +101,7 @@ const handleLogin = async () => { loading.value = true await userStore.accountLogin({ account: form.account, - password: 'Csq+AVwlEzX3r5vfxL7d/g==', + password: encryptByAes(form.password, form.account), }) tabsStore.reset() const { redirect, ...othersQuery } = router.currentRoute.value.query diff --git a/src/views/login/index.vue b/src/views/login/index.vue index ee4afa0..99862f9 100644 --- a/src/views/login/index.vue +++ b/src/views/login/index.vue @@ -14,9 +14,7 @@
- - -
@@ -60,9 +45,7 @@ -
- 其他登录方式 -
-
账号/手机号登录
-
邮箱登录
- - - - - - -
-
@@ -94,8 +64,6 @@ import { computed, ref } from 'vue' import Background from './components/background/index.vue' import AccountLogin from './components/account/index.vue' import PhoneLogin from './components/phone/index.vue' -import EmailLogin from './components/email/index.vue' -import { socialAuth } from '@/apis/auth' import { useAppStore } from '@/stores' import { useDevice } from '@/hooks' @@ -106,19 +74,7 @@ const appStore = useAppStore() const title = computed(() => appStore.getTitle()) const logo = computed(() => appStore.getLogo()) -const isEmailLogin = ref(false) const activeTab = ref('1') - -// 切换登录模式 -const toggleLoginMode = () => { - isEmailLogin.value = !isEmailLogin.value -} - -// 第三方登录授权 -const onOauth = async (source: string) => { - const { data } = await socialAuth(source) - window.location.href = data.authorizeUrl -}