浏览代码

更新逻辑

lex 2 年之前
父节点
当前提交
232308628a

+ 8 - 0
src/router/routes-student.ts

@@ -152,6 +152,14 @@ export default [
         }
         }
       },
       },
       {
       {
+        path: '/home-layout-center',
+        name: 'home-layout-center',
+        component: () => import('@/student/home-layout-orchestra/home-layout-center'),
+        meta: {
+          title: '登录酷乐秀'
+        }
+      },
+      {
         path: '/home-login',
         path: '/home-login',
         name: 'home-login',
         name: 'home-login',
         component: () => import('@/student/home-layout-orchestra/login'),
         component: () => import('@/student/home-layout-orchestra/login'),

+ 56 - 12
src/student/home-layout-orchestra/auth-login.tsx

@@ -12,7 +12,7 @@ import iconStudent from '@common/images/icon_student.png'
 import logo from '@common/images/logo.png'
 import logo from '@common/images/logo.png'
 import ColPopup from '@/components/col-popup'
 import ColPopup from '@/components/col-popup'
 import InviteCode from './invite-code'
 import InviteCode from './invite-code'
-import { state } from '@/state'
+import { setLogin, state } from '@/state'
 import request from '@/student/home-layout-orchestra/request-home'
 import request from '@/student/home-layout-orchestra/request-home'
 
 
 export default defineComponent({
 export default defineComponent({
@@ -28,14 +28,20 @@ export default defineComponent({
     removeAuth()
     removeAuth()
 
 
     listenerMessage('webViewOnResume', () => {
     listenerMessage('webViewOnResume', () => {
-      promisefiyPostMessage({ api: 'getUserAccount' }).then((res: any) => {
-        const content = res.content
-        state.orchestraInfo.token = content.token
-        state.orchestraInfo.phone = content.phone
-        state.orchestraInfo.nickname = content.nickname
-        state.orchestraInfo.avatar = content.avatar
-        state.orchestraInfo.unionId = content.unionId || 0
-      })
+      promisefiyPostMessage({ api: 'getUserAccount' }).then(
+        async (res: any) => {
+          const content = res.content
+          state.orchestraInfo.token = content.token
+          state.orchestraInfo.phone = content.phone
+          state.orchestraInfo.nickname = content.nickname
+          state.orchestraInfo.avatar = content.avatar
+          state.orchestraInfo.unionId = content.unionId || 0
+          this.username = state.orchestraInfo.phone
+          if (content.unionId && this.$route.path === '/home-auth') {
+            this.getUserInfo()
+          }
+        }
+      )
     })
     })
   },
   },
   unmounted() {
   unmounted() {
@@ -52,13 +58,47 @@ export default defineComponent({
         Toast('授权成功')
         Toast('授权成功')
       }, 100)
       }, 100)
       setTimeout(() => {
       setTimeout(() => {
+        this.getUserInfo()
         // this.$router.push('/home')
         // this.$router.push('/home')
-        window.location.href = location.origin + location.pathname + '#/home'
+        // window.location.href = location.origin + location.pathname + '#/home'
         // setTimeout(() => {
         // setTimeout(() => {
-        window.location.reload()
+        // window.location.reload()
         // }, 100)
         // }, 100)
       }, 1000)
       }, 1000)
     },
     },
+    async getUserInfo() {
+      try {
+        const res = await request.post('/api-auth/smsLogin', {
+          requestType: 'form',
+          data: {
+            clientId: 'student',
+            clientSecret: 'student',
+            phone: state.orchestraInfo.phone,
+            token: state.orchestraInfo.token,
+            isSurportRegister: true
+          }
+        })
+        const { authentication } = res.data
+        setAuth(authentication.token_type + ' ' + authentication.access_token)
+        promisefiyPostMessage({
+          api: 'setCache',
+          content: {
+            key: 'h5-colexiu-token',
+            value: authentication.token_type + ' ' + authentication.access_token
+          }
+        })
+        const userCash = await request.get(
+          '/api-student/student/queryUserInfo',
+          {
+            initRequest: true // 初始化接口
+          }
+        )
+        setLogin(userCash.data)
+        this.$router.push('/home')
+      } catch {
+        //
+      }
+    },
     async onLogin() {
     async onLogin() {
       try {
       try {
         const res = await request.post('/api-auth/smsLogin', {
         const res = await request.post('/api-auth/smsLogin', {
@@ -92,7 +132,11 @@ export default defineComponent({
       <div class={styles.login}>
       <div class={styles.login}>
         <div class={styles.container}>
         <div class={styles.container}>
           <div class={[styles.userInfo, styles.loginCenter]}>
           <div class={[styles.userInfo, styles.loginCenter]}>
-            <Image src={iconStudent} class={styles.img} />
+            <Image
+              src={state.orchestraInfo.avatar || iconStudent}
+              class={styles.img}
+              fit="cover"
+            />
 
 
             <p class={styles.name}>{state.orchestraInfo.name}</p>
             <p class={styles.name}>{state.orchestraInfo.name}</p>
           </div>
           </div>

+ 5 - 2
src/student/home-layout-orchestra/auth.tsx

@@ -1,7 +1,7 @@
 import { defineComponent } from 'vue'
 import { defineComponent } from 'vue'
 import styles from './index.module.less'
 import styles from './index.module.less'
 import { state, setLogin, setLogout, setLoginError } from '@/state'
 import { state, setLogin, setLogout, setLoginError } from '@/state'
-import { browser } from '@/helpers/utils'
+import { browser, removeAuth } from '@/helpers/utils'
 import { setAuth } from './utils'
 import { setAuth } from './utils'
 import { RouterView } from 'vue-router'
 import { RouterView } from 'vue-router'
 
 
@@ -28,12 +28,16 @@ export default defineComponent({
         state.user.status === 'login' ||
         state.user.status === 'login' ||
         this.$route.path === '/home-auth' ||
         this.$route.path === '/home-auth' ||
         this.$route.path === '/home-login' ||
         this.$route.path === '/home-login' ||
+        this.$route.path === '/home-layout-center' ||
         (this as any).isExternal
         (this as any).isExternal
       )
       )
     }
     }
   },
   },
   mounted() {
   mounted() {
     !this.isExternal && this.setAuth()
     !this.isExternal && this.setAuth()
+    if (!state.orchestraInfo.unionId) {
+      removeAuth()
+    }
   },
   },
   methods: {
   methods: {
     async setAuth() {
     async setAuth() {
@@ -45,7 +49,6 @@ export default defineComponent({
       if (this.loading) {
       if (this.loading) {
         return
         return
       }
       }
-      console.log('state.user', state.user)
       if (state.user.status === 'init' || state.user.status === 'error') {
       if (state.user.status === 'init' || state.user.status === 'error') {
         this.loading = true
         this.loading = true
 
 

+ 51 - 0
src/student/home-layout-orchestra/home-layout-center.tsx

@@ -0,0 +1,51 @@
+import { promisefiyPostMessage } from '@/helpers/native-message'
+import { setAuth } from '@/helpers/utils'
+import { setLogin, state } from '@/state'
+import { defineComponent } from 'vue'
+import request from './request-home'
+
+export default defineComponent({
+  name: 'home-layout-center',
+  mounted() {
+    this.getUserInfo()
+  },
+  methods: {
+    async getUserInfo() {
+      try {
+        const res = await request.post('/api-auth/smsLogin', {
+          requestType: 'form',
+          data: {
+            clientId: 'student',
+            clientSecret: 'student',
+            phone: state.orchestraInfo.phone,
+            token: state.orchestraInfo.token,
+            isSurportRegister: true
+          }
+        })
+        const { authentication } = res.data
+        setAuth(authentication.token_type + ' ' + authentication.access_token)
+        promisefiyPostMessage({
+          api: 'setCache',
+          content: {
+            key: 'h5-colexiu-token',
+            value: authentication.token_type + ' ' + authentication.access_token
+          }
+        })
+        const userCash = await request.get(
+          '/api-student/student/queryUserInfo',
+          {
+            initRequest: true // 初始化接口
+          }
+        )
+        setLogin(userCash.data)
+        this.$router.push('/home')
+      } catch {
+        //
+      }
+    }
+  },
+  render() {
+    
+    return () => 
+  }
+})

+ 4 - 1
src/student/home-layout-orchestra/request-home.ts

@@ -1,7 +1,7 @@
 import { extend } from 'umi-request'
 import { extend } from 'umi-request'
 import cleanDeep from 'clean-deep'
 import cleanDeep from 'clean-deep'
 import { browser, openLoading, closeLoading } from '@/helpers/utils'
 import { browser, openLoading, closeLoading } from '@/helpers/utils'
-import { setLogout, setLoginError } from './state-orchestra'
+import { setLogout, setLoginError } from '@/state'
 import { postMessage } from '@/helpers/native-message'
 import { postMessage } from '@/helpers/native-message'
 import { Toast } from 'vant'
 import { Toast } from 'vant'
 
 
@@ -101,6 +101,9 @@ request.interceptors.response.use(
       const browserInfo = browser()
       const browserInfo = browser()
       if (data.code === 403) {
       if (data.code === 403) {
         msg += '403'
         msg += '403'
+        setLogout()
+        window.location.href = window.location.origin + window.location.pathname + '#/home-layout-center'
+        // window.location.reload()
         // if (browserInfo.isApp) {
         // if (browserInfo.isApp) {
         //   postMessage({
         //   postMessage({
         //     api: 'login'
         //     api: 'login'

+ 20 - 7
src/student/home/index.tsx

@@ -21,7 +21,7 @@ import {
   removeListenerMessage
   removeListenerMessage
 } from '@/helpers/native-message'
 } from '@/helpers/native-message'
 import { browser } from '@/helpers/utils'
 import { browser } from '@/helpers/utils'
-import { state } from '@/state'
+import { setLogout, state } from '@/state'
 import event from './event'
 import event from './event'
 
 
 export default defineComponent({
 export default defineComponent({
@@ -74,13 +74,26 @@ export default defineComponent({
     listenerMessage('webViewOnResume', () => {
     listenerMessage('webViewOnResume', () => {
       promisefiyPostMessage({ api: 'getUserAccount' }).then((res: any) => {
       promisefiyPostMessage({ api: 'getUserAccount' }).then((res: any) => {
         const content = res.content
         const content = res.content
-        // state.orchestraInfo.token = content.token
-        // state.orchestraInfo.phone = content.phone
-        // state.orchestraInfo.nickname = content.nickname
-        // state.orchestraInfo.avatar = content.avatar
-        // state.orchestraInfo.unionId = content.unionId || 0
+        // console.log(state.orchestraInfo, 'state.orchestraInfo')
+        // console.log(content, 'content')
         if (content.phone !== state.orchestraInfo.phone) {
         if (content.phone !== state.orchestraInfo.phone) {
-          window.location.reload()
+          // 判断是否已经有关联编号
+          if (content.unionId) {
+            window.location.reload()
+          } else {
+            state.orchestraInfo.token = content.token
+            state.orchestraInfo.phone = content.phone
+            state.orchestraInfo.nickname = content.nickname
+            state.orchestraInfo.avatar = content.avatar
+            state.orchestraInfo.unionId = content.unionId || 0
+            // 13310106048
+            // 15088666723
+            setLogout()
+            // window.location.reload()
+            this.$router.push({
+              path: '/home-auth'
+            })
+          }
         }
         }
       })
       })
     })
     })

+ 2 - 2
src/student/main.ts

@@ -14,8 +14,8 @@ import { browser, setAuth } from '@/helpers/utils'
 
 
 const app = createApp(App)
 const app = createApp(App)
 
 
-// import Vconsole from 'vconsole'
-// const vconsole = new Vconsole()
+import Vconsole from 'vconsole'
+const vconsole = new Vconsole()
 postMessage(
 postMessage(
   {
   {
     api: 'getVersion'
     api: 'getVersion'