فهرست منبع

优化公众号登录逻辑

shaogen1995 8 ماه پیش
والد
کامیت
7696c9960d

+ 2 - 2
展示端/src/components/AuthRoute.tsx

@@ -17,8 +17,8 @@ export default function AuthRoute({ path, component: Com, ...rest }: AtahType) {
       render={() => {
         if (hasToken()) return <Com />
         else {
-          MessageFu.info('请先登录!')
-          return <Redirect to={`/login${window.location.hash.includes('exhi') ? '?exhi=1' : ''}`} />
+          MessageFu.info('未登录或登录失效')
+          return <Redirect to={`/login${window.location.href.includes('exhi') ? '/2' : '/1'}`} />
         }
       }}
     />

+ 1 - 1
展示端/src/components/RouterOrder.tsx

@@ -105,7 +105,7 @@ function RouterOrder() {
         <Switch>
           <Route path='/' component={homeFlag === '课堂' ? A1home : B1exhibit} exact={true} />
           <Route path='/exhi' component={B1exhibit} exact={true} />
-          <Route path='/login' component={Login} exact={true} />
+          <Route path='/login/:key' component={Login} exact={true} />
           {routerArr.map(v => (
             <AuthRoute key={v.id} path={v.path} exact={v.exact} component={v.Com} />
           ))}

+ 1 - 1
展示端/src/pages/B4form/index.tsx

@@ -152,7 +152,7 @@ function B4form() {
                 <Form.Item
                   label='姓名'
                   name={`name${item.id}`}
-                  rules={[{ required: true, message: '请输入负责人姓名!' }]}
+                  rules={[{ required: true, message: '请输姓名!' }]}
                   getValueFromEvent={e => e.target.value.replace(/\s+/g, '')}
                 >
                   <Input placeholder='请输入内容,不超过6个字' maxLength={6} />

+ 13 - 13
展示端/src/pages/Z1login/index.tsx

@@ -2,24 +2,26 @@ import React, { useCallback, useEffect, useState } from 'react'
 import styles from './index.module.scss'
 import TopCom from '@/components/TopCom'
 import { Button } from 'antd'
-import { toHomeFu } from '@/utils/history'
+import history, { toHomeFu } from '@/utils/history'
 import { setTokenInfo } from '@/utils/storage'
 import { MessageFu } from '@/utils/message'
+import { useParams } from 'react-router-dom'
 function Z1login() {
+  // 获取地址栏参数 1:课程 2:展馆
+  const urlObjTemp: any = useParams()
+
   // 获取用户openID(微信授权)
   const getUserCode = useCallback(() => {
-    window.location.href = 'http://192.168.20.55:3001/#/login?code=xxxx'
+    console.log(123, urlObjTemp.key)
+
+    // window.location.href = 'http://192.168.20.55:3001/#/login?code=xxxx'
     //此处的ID是在文档的开发-基本配置里面
     // let appid = 'wx3d4f2e0cfc3b8e54'
-    // let url = `https://sit-hqbooking.4dage.com/#/login${
-    //   window.location.href.includes('exhi') ? '?exhi=1' : ''
-    // }`
+    // let url = `https://sit-hqbooking.4dage.com/web/#/login${urlObjTemp.key}`
     // window.location.href = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${encodeURIComponent(
     //   url
     // )}&response_type=code&scope=SCOPE&state=STATE#wechat_redirect`
-
-    setTime(Date.now())
-  }, [])
+  }, [urlObjTemp.key])
 
   // 获取地址栏参数的方法
   const getQueryCode = useCallback((name: string) => {
@@ -42,8 +44,6 @@ function Z1login() {
     return r[2]
   }, [])
 
-  const [time, setTime] = useState(0)
-
   useEffect(() => {
     let code = getQueryCode('code')
     console.log('-----------', code)
@@ -52,13 +52,13 @@ function Z1login() {
       // 用户信息存到本地
       setTokenInfo({
         token:
-          'eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJvakpPdDZBc1MyTUhKSUFLMWtqSV9FTllyRnIwIiwibG9naW5UeXBlIjoid3giLCJpZCI6MSwidXNlck5hbWUiOiJvakpPdDZBc1MyTUhKSUFLMWtqSV9FTllyRnIwIiwiZXhwIjoxNzM0NDE2MDc1LCJyb2xlS2V5cyI6WyJ3ZWJfdXNlciJdLCJpYXQiOjE3MzQzMjk2NzUsImp0aSI6IjI5MjNlZmZhLWNjNDctNGExMy05Y2ZlLTZiMjA5ZjU3N2Y4OSJ9.8yAERk2x_H5jU3WilD9X1hXTTNkRdiBQGvgI7LVZNRg'
+          'eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJvakpPdDZBc1MyTUhKSUFLMWtqSV9FTllyRnIwIiwibG9naW5UeXBlIjoid3giLCJpZCI6MSwidXNlck5hbWUiOiJvakpPdDZBc1MyTUhKSUFLMWtqSV9FTllyRnIwIiwiZXhwIjoxNzM0NjU3NjgyLCJyb2xlS2V5cyI6WyJ3ZWJfdXNlciJdLCJpYXQiOjE3MzQ1NzEyODIsImp0aSI6IjBkOTNlZTBkLTI0NjAtNDliZi1iM2Y2LTdjY2ZjNzMwNjVlMSJ9.01BrenscrgsUxvM6z6GFap0d78qnnmAVQuW1VTA_3mI'
       })
       // 跳到首页
       MessageFu.success('登录成功!')
-      toHomeFu()
+      history.replace(urlObjTemp.key === '1' ? '/' : '/exhi')
     }
-  }, [getQueryCode, time])
+  }, [getQueryCode, urlObjTemp.key])
 
   return (
     <div className={styles.Z1login}>

+ 3 - 3
展示端/src/utils/http.ts

@@ -60,10 +60,10 @@ http.interceptors.response.use(
     }
     if (response.data.code === 5001 || response.data.code === 5002) {
       removeTokenInfo()
-      history.push('/login')
+      history.push(`/login${window.location.href.includes('exhi') ? '/2' : '/1'}`)
       clearTimeout(timeId)
       timeId = window.setTimeout(() => {
-        MessageFu.warning('登录失效!')
+        MessageFu.info('未登录或登录失效')
       }, 200)
     } else if (response.data.code === 0) {
       // MessageFu.success(response.data.msg);
@@ -89,7 +89,7 @@ http.interceptors.response.use(
           // 没有权限
           if (err.response.data.code === 5003) {
             removeTokenInfo()
-            history.push('/login')
+            history.push(`/login${window.location.href.includes('exhi') ? '/2' : '/1'}`)
           }
         } else MessageFu.error('响应错误,请联系管理员!')
       }