Bladeren bron

feat: 增加授权跳转功能

lanjianrong 3 jaren geleden
bovenliggende
commit
d7ce2618e6

BIN
src/assets/img/svg_cycling.png


BIN
src/assets/img/svg_wrong.png


+ 6 - 6
src/pages/Login/index.tsx

@@ -47,13 +47,13 @@ const NormalLoginForm: React.FC<iLoginProps> = () => {
     }
   }
 
-  const setVisible = (label: boolean) => {
-    setState({ ...state, visible: label })
-  }
+  // const setVisible = (label: boolean) => {
+  //   setState({ ...state, visible: label })
+  // }
 
-  const handleForgetPsw = () => {
-    setState({ ...state, visible: !state.visible })
-  }
+  // const handleForgetPsw = () => {
+  //   setState({ ...state, visible: !state.visible })
+  // }
 
   return (
     <Form

+ 51 - 0
src/pages/PreAuth/index.less

@@ -0,0 +1,51 @@
+.pre-auth-container {
+  display: flex;
+  flex-direction: column;
+  align-items: center;
+  justify-content: center;
+  width: 100%;
+  height: 100%;
+  background-color: #f5f5f5;
+  .pre-auth-progress {
+    display: flex;
+    flex-direction: column;
+    width: 600px;
+    height: 8px;
+    margin-top: 48px;
+    background: #d3d9e5;
+    border-radius: 77px 77px 77px 77px;
+    .pre-auth-loading {
+      height: 8px;
+      background: #4582fc;
+      border-radius: 52px 52px 52px 52px;
+      animation: process 1s linear forwards;
+    }
+  }
+  .pre-auth-status {
+    margin-top: 16px;
+    font-size: 16px;
+    font-weight: 400;
+    line-height: 21px;
+    color: rgba(0, 0, 0, 0.6);
+    .link {
+      margin-left: 2px;
+      color: #4582fc;
+      cursor: pointer;
+    }
+  }
+}
+
+@keyframes process {
+  0% {
+    width: 0;
+  }
+  20% {
+    width: 20%;
+  }
+  40% {
+    width: 30%;
+  }
+  60% { width: 60%; }
+  80% { width: 80%; }
+  100% { width: 100%; }
+}

+ 61 - 0
src/pages/PreAuth/index.tsx

@@ -0,0 +1,61 @@
+import { userStore } from '@/store/mobx'
+import { apiExternalAuthLogin } from '@/utils/common/api'
+import consts from '@/utils/consts'
+import history from '@/utils/history'
+import React, { useState, useEffect } from 'react'
+import cycling from '../../assets/img/svg_cycling.png'
+import wrong from '../../assets/img/svg_wrong.png'
+import './index.less'
+
+enum authStatus {
+  success = 0,
+  fail = 1,
+  wait = 2
+}
+const PreAuth = () => {
+  const [ status, setStatus ] = useState(authStatus.wait)
+  useEffect(() => {
+    const token = window.location.search.split('=')[1]
+    async function authLogin() {
+      const { code = -1, data } = await apiExternalAuthLogin(token)
+      if (code === consts.RET_CODE.SUCCESS) {
+        setStatus(authStatus.success)
+        userStore.updateUserInfo(data)
+        userStore.getProjectInfo()
+        setTimeout(() => {
+          history.replace('/console/dashboard')
+        }, 250)
+      } else {
+        setStatus(authStatus.fail)
+      }
+    }
+    authLogin()
+  }, [])
+
+  return (
+    <div className='pre-auth-container'>
+      <img src={status === authStatus.fail ? wrong : cycling} alt="" />
+      {
+        status === authStatus.wait ? <div className='pre-auth-progress'>
+          <div className='pre-auth-loading' />
+        </div> : null
+      }
+
+      <div className='pre-auth-status'>
+        {
+          status === authStatus.wait ? <span>
+            正在进入...
+          </span> : null
+        }
+        {
+          status === authStatus.fail ? <><span>请返回计量支付并</span>
+            <span className='link' onClick={() => window.location.href= 'http://127.0.0.1:7002/dashboard'}>重新进入</span></> : null
+        }
+
+
+      </div>
+    </div>
+  )
+}
+
+export default PreAuth

+ 7 - 0
src/router/routes.ts

@@ -15,6 +15,13 @@ export const routeConfig: RouteModel[] = [
     }
   },
   {
+    path: '/auth',
+    component: AsyncModuleLoader(() => import('@/pages/PreAuth')),
+    meta: {
+      title: '正在授权'
+    }
+  },
+  {
     path: '/console',
     component: AsyncModuleLoader(() => import('@/layout/NavSide')),
     auth: [ 'USER', 'ADMIN' ],

+ 9 - 1
src/utils/common/api.ts

@@ -1,5 +1,4 @@
 import { iFile } from "@/types/file"
-import consts from "../consts"
 import request from "./request"
 
 /**
@@ -102,3 +101,12 @@ export async function apiContractSection(bidsectionId: string, treeType: number)
   const { data } = await request.get('/api/contract/section/not', { bidsectionId, treeType })
   return data
 }
+
+/**
+ * 计量-授权登录
+ * @param token 令牌
+ */
+export async function apiExternalAuthLogin(token: string) {
+  const { data } = await request.post('/api/external/jl/auth/login', { token })
+  return data
+}