Browse Source

gjus cache

lex 2 years ago
parent
commit
5c9475f0cb

+ 29 - 1
src/student/home-layout-orchestra/auth-login.tsx

@@ -2,7 +2,12 @@ import { defineComponent } from 'vue'
 import { Button, Image, Toast } from 'vant'
 import { Button, Image, Toast } from 'vant'
 import { removeAuth, setAuth } from './utils'
 import { removeAuth, setAuth } from './utils'
 import styles from './index.module.less'
 import styles from './index.module.less'
-import { postMessage } from '@/helpers/native-message'
+import {
+  listenerMessage,
+  postMessage,
+  promisefiyPostMessage,
+  removeListenerMessage
+} from '@/helpers/native-message'
 import iconStudent from '@common/images/icon_student.png'
 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'
@@ -21,6 +26,22 @@ export default defineComponent({
   mounted() {
   mounted() {
     this.username = state.orchestraInfo.phone
     this.username = state.orchestraInfo.phone
     removeAuth()
     removeAuth()
+
+    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
+      })
+    })
+  },
+  unmounted() {
+    removeListenerMessage('webViewOnResume', () => {
+      //
+    })
   },
   },
   methods: {
   methods: {
     onLoginSuccess() {
     onLoginSuccess() {
@@ -53,6 +74,13 @@ export default defineComponent({
 
 
         const { authentication } = res.data
         const { authentication } = res.data
         setAuth(authentication.token_type + ' ' + authentication.access_token)
         setAuth(authentication.token_type + ' ' + authentication.access_token)
+        promisefiyPostMessage({
+          api: 'setCache',
+          content: {
+            key: 'h5-colexiu-token',
+            value: authentication.token_type + ' ' + authentication.access_token
+          }
+        })
         this.onLoginSuccess()
         this.onLoginSuccess()
       } catch {
       } catch {
         //
         //

+ 9 - 0
src/student/home-layout-orchestra/auth.tsx

@@ -7,6 +7,7 @@ import { RouterView } from 'vue-router'
 
 
 import request from './request-home'
 import request from './request-home'
 import ColResult from '@/components/col-result'
 import ColResult from '@/components/col-result'
+import { promisefiyPostMessage } from '@/helpers/native-message'
 
 
 const browserInfo = browser()
 const browserInfo = browser()
 export default defineComponent({
 export default defineComponent({
@@ -65,6 +66,14 @@ export default defineComponent({
             setAuth(
             setAuth(
               authentication.token_type + ' ' + authentication.access_token
               authentication.token_type + ' ' + authentication.access_token
             )
             )
+            promisefiyPostMessage({
+              api: 'setCache',
+              content: {
+                key: 'h5-colexiu-token',
+                value:
+                  authentication.token_type + ' ' + authentication.access_token
+              }
+            })
           }
           }
 
 
           const res = await request.get('/api-student/student/queryUserInfo', {
           const res = await request.get('/api-student/student/queryUserInfo', {

+ 7 - 1
src/student/home-layout-orchestra/login.tsx

@@ -60,7 +60,13 @@ export default defineComponent({
 
 
         const { authentication } = res.data
         const { authentication } = res.data
         setAuth(authentication.token_type + ' ' + authentication.access_token)
         setAuth(authentication.token_type + ' ' + authentication.access_token)
-
+        postMessage({
+          api: 'setCache',
+          content: {
+            key: 'h5-colexiu-token',
+            value: authentication.token_type + ' ' + authentication.access_token
+          }
+        })
         const userCash = await request.get(
         const userCash = await request.get(
           '/api-student/student/queryUserInfo',
           '/api-student/student/queryUserInfo',
           {
           {

+ 2 - 2
src/student/main.ts

@@ -4,7 +4,7 @@ import dayjs from 'dayjs'
 import 'dayjs/locale/zh-cn'
 import 'dayjs/locale/zh-cn'
 import router from '../router/index-student'
 import router from '../router/index-student'
 import vueFilter from '@/helpers/vueFilter'
 import vueFilter from '@/helpers/vueFilter'
-import { postMessage, promisefiyPostMessage } from '@/helpers/native-message'
+import { listenerMessage, postMessage, promisefiyPostMessage } from '@/helpers/native-message'
 
 
 import 'normalize.css'
 import 'normalize.css'
 
 
@@ -58,7 +58,7 @@ if (browser().isOrchestraStudent) {
   promisefiyPostMessage({ api: 'getCache', content: { key: 'h5-colexiu-token' } }).then((res: any) => {
   promisefiyPostMessage({ api: 'getCache', content: { key: 'h5-colexiu-token' } }).then((res: any) => {
     const content = res.content
     const content = res.content
     if (content.value) {
     if (content.value) {
-      setAuth('bearer ' + content.value)
+      setAuth(content.value)
     }
     }
   })
   })
 }
 }