From 1d1f6498e97523265d17eb0bbc1b6a740fbf9210 Mon Sep 17 00:00:00 2001 From: weipengfei <2187978347@qq.com> Date: Wed, 22 Nov 2023 15:48:06 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=BC=E5=AE=B9=E4=B8=AD=E5=8F=B0=E7=B3=BB?= =?UTF-8?q?=E7=BB=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App.vue | 54 +++++++++++++++++++++++++++++++++++++------ api/appLet.js | 9 ++++++++ main.js | 6 +++++ pages/index/index.vue | 8 ++++--- 4 files changed, 67 insertions(+), 10 deletions(-) create mode 100644 api/appLet.js diff --git a/App.vue b/App.vue index c8c83de..e4c7283 100644 --- a/App.vue +++ b/App.vue @@ -20,6 +20,9 @@ getUserInfo } from '@/api/user.js'; + import { + parseToken + } from "@/api/appLet.js"; import { HTTP_REQUEST_URL } from './config/app'; @@ -29,6 +32,7 @@ history } from '@/api/public.js' import Routine from './libs/routine.js'; +import { Toast } from "./libs/uniApi"; export default { data() { @@ -93,16 +97,52 @@ key: 'launchFlag' }) - + // 用于调试中台登录 + // parseToken({ + // token: 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJjZXNoaS1taWRkbGUubGloYWluay5jbiIsImF1ZCI6ImNlc2hpLW1pZGRsZS5saWhhaW5rLmNuIiwiaWF0IjoxNzAwNjIwMjUxLCJuYmYiOjE3MDA2MjAyNTEsImV4cCI6MTcwMTIyNTA1MSwiZGF0YSI6eyJ1aWQiOjUsInBob25lIjoiMTc2ODUxNTE2NDMiLCJhdmF0YXIiOiIvcmVzb3VyY2UvaW1hZ2UvYWRtaW5hcGkvZGVmYXVsdC9kZWZhdWx0X2F2YXRhci5wbmciLCJuaWNrbmFtZSI6Ilx1NzUyOFx1NjIzNzE3Njg1MTUxNjQzIn19.sTWAHCScRY9FExwJw1MReHTnRBcK7tYu1AMSia_Sm4M' + // }).then((res)=>{ + // this.$store.commit("LOGIN", { + // 'token': res.data.token, + // 'time': 604800 + // }); + // this.$isResolve() + // }).catch((err)=>{ + // if(err=='签名错误'){ + // this.$store.commit("LOGIN", { + // 'token': option.referrerInfo?.extraData?.uniMP, + // 'time': 604800 + // }); + // }else { + // Toast(err); + // } + // this.$isResolve() + // }) if (option?.referrerInfo?.extraData?.uniMP) { uni.setStorageSync('uniMP', option.referrerInfo?.extraData?.uniMP); - // uni.setStorageSync('APP_token', option.referrerInfo?.extraData?.token); - this.$store.commit("LOGIN", { - 'token': option.referrerInfo?.extraData?.token, - 'time': 604800 - }); - } + // this.$store.commit("LOGIN", { + // 'token': option.referrerInfo?.extraData?.token, + // 'time': 604800 + // }); + parseToken({ + token: option.referrerInfo?.extraData?.token + }).then((res)=>{ + this.$store.commit("LOGIN", { + 'token': res.data.token, + 'time': 604800 + }); + this.$isResolve() + }).catch((err)=>{ + this.$store.commit("LOGIN", { + 'token': option.referrerInfo?.extraData?.uniMP, + 'time': 604800 + }); + console.log('TOKEN解析错误:', err); + this.$isResolve() + }) + }else { + this.$isResolve() + } // #ifdef APP-PLUS // #endif diff --git a/api/appLet.js b/api/appLet.js new file mode 100644 index 0000000..8aa6650 --- /dev/null +++ b/api/appLet.js @@ -0,0 +1,9 @@ +import request from "@/utils/request.js"; + +/** + * 文章详情 + * + */ +export function parseToken(data) { + return request.post('parse/token', data, { noAuth: true }); +} \ No newline at end of file diff --git a/main.js b/main.js index b0e2175..e044deb 100644 --- a/main.js +++ b/main.js @@ -34,6 +34,12 @@ Vue.prototype.$eventHub = new Vue(); Vue.config.productionTip = false Vue.prototype.$bus = new Vue(); +// initRouter() +// 让app的onLaunch先执行,主要是用来进行登录 +Vue.prototype.$onLaunched = new Promise(resolve => { + Vue.prototype.$isResolve = resolve +}) + // #ifdef H5 import { parseQuery diff --git a/pages/index/index.vue b/pages/index/index.vue index e1fe4a6..5ede108 100644 --- a/pages/index/index.vue +++ b/pages/index/index.vue @@ -569,9 +569,10 @@ }) }, - onLoad() { - this.list1() + async onLoad() { this.Fheight = uni.getSystemInfoSync().windowHeight + 'px'; + await this.$onLaunched; + this.list1() }, @@ -588,7 +589,8 @@ }, - onShow() { + async onShow() { + await this.$onLaunched; this.getUserInfo() this.codelist() },