yanghao před 3 týdny
rodič
revize
91e07253d6
3 změnil soubory, kde provedl 49 přidání a 11 odebrání
  1. 9 0
      src/api/login/index.ts
  2. 36 2
      src/permission.ts
  3. 4 9
      src/views/Home/Index.vue

+ 9 - 0
src/api/login/index.ts

@@ -22,6 +22,15 @@ export const login = (data: UserLoginVO) => {
   })
 }
 
+// 门户用户登录
+export const portalLogin = (data: any) => {
+  return request.post({
+    url: 'system/auth/portal/login',
+    headers: { 'portal-secret': '71ba46d3-3dd4-5232-9b7e-75765b36897f' },
+    data
+  })
+}
+
 export const dingTalkLogin = (data: { code: string; type: number; state: number }) => {
   return request.post({ url: '/system/auth/h5SocialLogin', data, headers: { 'tenant-id': 1 } })
 }

+ 36 - 2
src/permission.ts

@@ -8,6 +8,9 @@ import { usePageLoading } from '@/hooks/web/usePageLoading'
 import { useDictStoreWithOut } from '@/store/modules/dict'
 import { useUserStoreWithOut } from '@/store/modules/user'
 import { usePermissionStoreWithOut } from '@/store/modules/permission'
+import * as LoginApi from '@/api/login'
+import * as authUtil from '@/utils/auth'
+import { deleteUserCache } from '@/hooks/web/useCache'
 
 const { start, done } = useNProgress()
 
@@ -62,6 +65,17 @@ router.beforeEach(async (to, from, next) => {
   loadStart()
   if (getAccessToken()) {
     if (to.path === '/login') {
+      next({ path: '/' })
+    } else if (to.fullPath.includes('portalLogin')) {
+      const userStore = useUserStoreWithOut()
+      await userStore.loginOut()
+      // await getTenantId()
+      const res = await LoginApi.portalLogin({
+        username: to.query.username
+      })
+
+      authUtil.setToken(res)
+
       next({ path: '/' })
     } else {
       const dictStore = useDictStoreWithOut()
@@ -92,8 +106,28 @@ router.beforeEach(async (to, from, next) => {
       }
     }
   } else {
-    if (whiteList.indexOf(to.path) !== -1) {
-      next()
+    authUtil.removeToken()
+    deleteUserCache()
+    useUserStoreWithOut().resetState()
+    if (to.query.username) {
+      // await getTenantId()
+      const res = await LoginApi.portalLogin({
+        username: to.query.username
+      })
+
+      authUtil.setToken(res)
+
+      next({ path: '/index' })
+    } else if (whiteList.indexOf(to.path) !== -1) {
+      const code = to.query.code
+      if (code) {
+        // await getTenantId()
+        const res = await LoginApi.socialLogin('20', typeof code === 'string' ? code : '', '22')
+        authUtil.setToken(res)
+        next({ path: 'index' })
+      } else {
+        next() // 正常导航
+      }
     } else {
       next(`/login?redirect=${to.fullPath}`) // 否则全部重定向到登录页
     }

+ 4 - 9
src/views/Home/Index.vue

@@ -112,15 +112,10 @@ const progressItems: ProgressItem[] = [
 ]
 
 const donutData = [
-  { name: '完工', value: 54, color: '#f35e5c' },
-  { name: '闲置', value: 28, color: '#8dd46c' },
-  { name: '施工', value: 5, color: '#5578d4' },
-  { name: '对接', value: 7, color: '#8f7cff' },
-  { name: '待修缮', value: 0, color: '#f2c04e' },
-  { name: '待分布', value: 2, color: '#4cc2c8' },
-  { name: '现场待命', value: 2, color: '#f08ac7' },
-  { name: '待管', value: 2, color: '#5fb96f' },
-  { name: '待建', value: 0, color: '#607ad8' }
+  { name: '进行中', value: 54, color: '#f35e5c' },
+  { name: '结题', value: 28, color: '#8dd46c' },
+  { name: '终止', value: 5, color: '#5578d4' },
+  { name: '延期', value: 7, color: '#8f7cff' }
 ]
 
 const expertSeries = [