From af2b1eb25f17bace718ca0de3db8a87c0b5c8ac5 Mon Sep 17 00:00:00 2001 From: xingyu Date: Wed, 3 Aug 2022 17:23:12 +0800 Subject: [PATCH] fix: bugs --- .../src/components/DictTag/src/DictTag.vue | 2 +- yudao-ui-admin-vue3/src/router/index.ts | 3 +++ yudao-ui-admin-vue3/src/store/modules/user.ts | 3 --- .../src/views/Login/components/LoginForm.vue | 20 +++------------- .../src/views/Login/components/MobileForm.vue | 24 ++++++------------- .../infra/codegen/components/Preview.vue | 2 +- .../src/views/infra/fileList/index.vue | 18 +++++++++++++- 7 files changed, 32 insertions(+), 40 deletions(-) diff --git a/yudao-ui-admin-vue3/src/components/DictTag/src/DictTag.vue b/yudao-ui-admin-vue3/src/components/DictTag/src/DictTag.vue index 0ad3ec69a..5bbb9104c 100644 --- a/yudao-ui-admin-vue3/src/components/DictTag/src/DictTag.vue +++ b/yudao-ui-admin-vue3/src/components/DictTag/src/DictTag.vue @@ -8,7 +8,7 @@ const props = defineProps({ required: true }, value: { - type: [String, Number] as PropType, + type: [String, Number, Boolean] as PropType, required: true } }) diff --git a/yudao-ui-admin-vue3/src/router/index.ts b/yudao-ui-admin-vue3/src/router/index.ts index ccdcbdeb0..6cdec5ee1 100644 --- a/yudao-ui-admin-vue3/src/router/index.ts +++ b/yudao-ui-admin-vue3/src/router/index.ts @@ -11,6 +11,7 @@ import { useDictStoreWithOut } from '@/store/modules/dict' import { useUserStoreWithOut } from '@/store/modules/user' import { listSimpleDictDataApi } from '@/api/system/dict/dict.data' import { isRelogin } from '@/config/axios' +import { getInfoApi } from '@/api/login' const { start, done } = useNProgress() @@ -52,6 +53,8 @@ router.beforeEach(async (to, from, next) => { } if (userStore.getRoles.length === 0) { isRelogin.show = true + const res = await getInfoApi() + await userStore.setUserInfoAction(res) isRelogin.show = false // 后端过滤菜单 await permissionStore.generateRoutes() diff --git a/yudao-ui-admin-vue3/src/store/modules/user.ts b/yudao-ui-admin-vue3/src/store/modules/user.ts index f107ef33c..a8aa17de8 100644 --- a/yudao-ui-admin-vue3/src/store/modules/user.ts +++ b/yudao-ui-admin-vue3/src/store/modules/user.ts @@ -27,9 +27,6 @@ export const useUserStore = defineStore({ nickname: '' } }), - persist: { - enabled: true - }, getters: { getPermissions(): string[] { return this.permissions diff --git a/yudao-ui-admin-vue3/src/views/Login/components/LoginForm.vue b/yudao-ui-admin-vue3/src/views/Login/components/LoginForm.vue index ae27f4603..1f713e525 100644 --- a/yudao-ui-admin-vue3/src/views/Login/components/LoginForm.vue +++ b/yudao-ui-admin-vue3/src/views/Login/components/LoginForm.vue @@ -21,19 +21,17 @@ import { getPassword, getTenantName } from '@/utils/auth' -import { useUserStore } from '@/store/modules/user' import { usePermissionStore } from '@/store/modules/permission' import { useRouter } from 'vue-router' import { useI18n } from '@/hooks/web/useI18n' import { required } from '@/utils/formRules' import { Icon } from '@/components/Icon' import { LoginStateEnum, useLoginState, useFormValid } from './useLogin' -import type { RouteLocationNormalizedLoaded, RouteRecordRaw } from 'vue-router' +import type { RouteLocationNormalizedLoaded } from 'vue-router' import { Verify } from '@/components/Verifition' -const { currentRoute, addRoute, push } = useRouter() +const { currentRoute, push } = useRouter() const permissionStore = usePermissionStore() -const userStore = useUserStore() const formLogin = ref() const { validForm } = useFormValid(formLogin) const { setLoginState, getLoginState } = useLoginState() @@ -111,23 +109,11 @@ const handleLogin = async (params) => { loginData.loginForm.captchaVerification = params.captchaVerification const res = await LoginApi.loginApi(loginData.loginForm) setToken(res) - const userInfo = await LoginApi.getInfoApi() - await userStore.setUserInfoAction(userInfo) - await getRoutes() - loginLoading.value = false -} - -// 获取路由 -const getRoutes = async () => { - // 后端过滤菜单 - await permissionStore.generateRoutes() - permissionStore.getAddRouters.forEach((route) => { - addRoute(route as RouteRecordRaw) // 动态添加可访问路由表 - }) if (!redirect.value) { redirect.value = '/' } push({ path: redirect.value || permissionStore.addRouters[0].path }) + loginLoading.value = false } // 社交登录 diff --git a/yudao-ui-admin-vue3/src/views/Login/components/MobileForm.vue b/yudao-ui-admin-vue3/src/views/Login/components/MobileForm.vue index 0ffd9d6dc..9768a7f7a 100644 --- a/yudao-ui-admin-vue3/src/views/Login/components/MobileForm.vue +++ b/yudao-ui-admin-vue3/src/views/Login/components/MobileForm.vue @@ -5,13 +5,12 @@ import LoginFormTitle from './LoginFormTitle.vue' import { ElForm, ElFormItem, ElInput, ElRow, ElCol, ElMessage } from 'element-plus' import { useI18n } from '@/hooks/web/useI18n' import { required } from '@/utils/formRules' -import { getTenantIdByNameApi, sendSmsCodeApi, smsLoginApi, getInfoApi } from '@/api/login' +import { getTenantIdByNameApi, sendSmsCodeApi, smsLoginApi } from '@/api/login' import { useCache } from '@/hooks/web/useCache' import { usePermissionStore } from '@/store/modules/permission' import { useRouter } from 'vue-router' import { setToken } from '@/utils/auth' -import { useUserStore } from '@/store/modules/user' -import type { RouteLocationNormalizedLoaded, RouteRecordRaw } from 'vue-router' +import type { RouteLocationNormalizedLoaded } from 'vue-router' import { useLoginState, LoginStateEnum, useFormValid } from './useLogin' const formSmsLogin = ref() const { validForm } = useFormValid(formSmsLogin) @@ -21,9 +20,8 @@ const iconHouse = useIcon({ icon: 'ep:house' }) const iconCellphone = useIcon({ icon: 'ep:cellphone' }) const iconCircleCheck = useIcon({ icon: 'ep:circle-check' }) const { wsCache } = useCache() -const userStore = useUserStore() const permissionStore = usePermissionStore() -const { currentRoute, addRoute, push } = useRouter() +const { currentRoute, push } = useRouter() const loginLoading = ref(false) const { t } = useI18n() @@ -102,24 +100,16 @@ const signIn = async () => { await smsLoginApi(smsVO.loginSms) .then(async (res) => { setToken(res?.token) - const userInfo = await getInfoApi() - await userStore.setUserInfoAction(userInfo) - getRoutes() + if (!redirect.value) { + redirect.value = '/' + } + push({ path: redirect.value || permissionStore.addRouters[0].path }) }) .catch(() => {}) .finally(() => { loginLoading.value = false }) } -// 获取路由 -const getRoutes = async () => { - // 后端过滤菜单 - await permissionStore.generateRoutes() - permissionStore.getAddRouters.forEach((route) => { - addRoute(route as RouteRecordRaw) // 动态添加可访问路由表 - }) - push({ path: redirect.value || permissionStore.addRouters[0].path }) -}