|
|
@@ -25,23 +25,42 @@ export default {
|
|
|
// 推送消息监听改在登录成功后注册,见 utils/appDevice.js setupAppPushMessageListener
|
|
|
|
|
|
// #ifdef H5
|
|
|
- // H5开发环境无法微信授权,使用固定的用户 shish 2020.4.30
|
|
|
+ // H5 开发环境无微信授权:仅补齐 account;不再写入过期硬编码 token(会覆盖登录态并触发 /console/init 500)
|
|
|
+ // 有本地 token 时拉取字典;必须 catch,否则 reject 的普通对象会被 webpack overlay 显示成 [object Object]
|
|
|
if (process.env.NODE_ENV == "development") {
|
|
|
- uni.setStorageSync("token","eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiIsImp0aSI6IjBfNTIifQ.eyJpc3MiOiJodHRwczpcL1wvYXBpLnNob3AuaHpnaGQuY29tIiwiYXVkIjoiaHR0cHM6XC9cL2FwaS5zaG9wLmh6Z2hkLmNvbSIsImp0aSI6IjBfNTIiLCJpYXQiOjE2MTYxNTc2NjQsIm5iZiI6MTYxNjE1NzY2NCwiZXhwIjoxNjI0Nzk3NjY0LCJ1bmlxdWVJZCI6IjUyIiwic291cmNlSWQiOjB9.VzSekbSwSczMWsfdPVdrm3gZ-v9o3p01NbMVNT4nGZ4")
|
|
|
- uni.setStorageSync("account", "0")
|
|
|
- getDictionaries({ token: uni.getStorageSync('token') }).then(res => {
|
|
|
- if (util.isEmpty(res)) {
|
|
|
- return false
|
|
|
+ if (!uni.getStorageSync('account')) {
|
|
|
+ uni.setStorageSync("account", "0")
|
|
|
+ }
|
|
|
+ let h5Token = uni.getStorageSync('token')
|
|
|
+ // 清理历史硬编码/已过期 JWT,避免每次启动都打出 500 并干扰登录态
|
|
|
+ if (h5Token) {
|
|
|
+ try {
|
|
|
+ const payload = JSON.parse(atob(h5Token.split('.')[1] || ''))
|
|
|
+ if (payload.exp && payload.exp * 1000 < Date.now()) {
|
|
|
+ uni.removeStorageSync('token')
|
|
|
+ h5Token = ''
|
|
|
+ }
|
|
|
+ } catch (e) {
|
|
|
+ // 非 JWT 结构时保留原 token,交由接口鉴权
|
|
|
}
|
|
|
- store.commit('setDictionariesInfo', {
|
|
|
- ...res.data.dict,
|
|
|
- ...res.data
|
|
|
+ }
|
|
|
+ if (h5Token) {
|
|
|
+ getDictionaries({ token: h5Token }).then(res => {
|
|
|
+ if (util.isEmpty(res)) {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ store.commit('setDictionariesInfo', {
|
|
|
+ ...res.data.dict,
|
|
|
+ ...res.data
|
|
|
+ })
|
|
|
+ store.commit('setMyShopInfo', {
|
|
|
+ ...res.data.shop,
|
|
|
+ ...res.data
|
|
|
+ })
|
|
|
+ }).catch(err => {
|
|
|
+ console.error('H5 拉取字典失败(token 可能失效,请重新登录)', err && (err.errMsg || err.msg || err.statusCode) || err)
|
|
|
})
|
|
|
- store.commit('setMyShopInfo', {
|
|
|
- ...res.data.shop,
|
|
|
- ...res.data
|
|
|
- })
|
|
|
- })
|
|
|
+ }
|
|
|
}
|
|
|
// #endif
|
|
|
|