|
|
@@ -3,11 +3,22 @@ import { mapMutations, mapActions, mapGetters } from "vuex";
|
|
|
// 这个导入在小程序环境中是不需要的,因为小程序环境已经有全局的 setTimeout 函数
|
|
|
// import { setTimeout } from "timers";
|
|
|
import { getUser, wxLoginFn } from "@/utils/auth";
|
|
|
+import {
|
|
|
+ TOKEN_STORAGE_KEY,
|
|
|
+ LEGACY_TOKEN_STORAGE_KEY,
|
|
|
+} from "@/constant/storageKeys";
|
|
|
export default {
|
|
|
// 全端,数据共享,还可以解决页面初始化模板访问不到值得问题
|
|
|
// 有坑 分包里的页面访问不到
|
|
|
globalData: {},
|
|
|
onLaunch () {
|
|
|
+ const legacyToken = uni.getStorageSync(LEGACY_TOKEN_STORAGE_KEY);
|
|
|
+ const currentToken = uni.getStorageSync(TOKEN_STORAGE_KEY);
|
|
|
+ if (!currentToken && legacyToken) {
|
|
|
+ uni.setStorageSync(TOKEN_STORAGE_KEY, legacyToken);
|
|
|
+ uni.removeStorageSync(LEGACY_TOKEN_STORAGE_KEY);
|
|
|
+ }
|
|
|
+
|
|
|
// this.getAllOptions()
|
|
|
// 删除缓存
|
|
|
if (process.env.NODE_ENV == "production") {
|
|
|
@@ -24,7 +35,7 @@ export default {
|
|
|
// H5开发环境无法微信授权,使用固定的用户 shish 2020.4.30
|
|
|
if (process.env.NODE_ENV == "development") {
|
|
|
uni.setStorageSync(
|
|
|
- "token",
|
|
|
+ TOKEN_STORAGE_KEY,
|
|
|
"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiIsImp0aSI6IjBfMTI1NDM0MzEifQ.eyJpc3MiOiJodHRwczpcL1wvYXBpLm1hbGwuaHVhbWwuY29tIiwiYXVkIjoiaHR0cHM6XC9cL2FwaS5tYWxsLmh1YW1sLmNvbSIsImp0aSI6IjBfMTI1NDM0MzEiLCJpYXQiOjE1ODgyMzAwMjgsIm5iZiI6MTU4ODIzMDAyOCwiZXhwIjoxNTk2ODcwMDI4LCJ1bmlxdWVJZCI6IjEyNTQzNDMxIiwic291cmNlSWQiOjB9.Tmw2h9pucpyctvtB--i0dg-zTcVMIJZ1PtnWTLLwEEo"
|
|
|
);
|
|
|
uni.setStorageSync("account", "12358");
|
|
|
@@ -37,7 +48,7 @@ export default {
|
|
|
},
|
|
|
methods: {
|
|
|
isLogin () {
|
|
|
- let token = uni.getStorageSync("token");
|
|
|
+ let token = uni.getStorageSync(TOKEN_STORAGE_KEY);
|
|
|
if (!token) {
|
|
|
uni.reLaunch({
|
|
|
url: "/pages/page/login/index"
|