From 1bbbdf567b5f5d41df2bf7455284415fffbd9c88 Mon Sep 17 00:00:00 2001 From: zmt Date: Mon, 14 Feb 2022 17:25:54 +0800 Subject: [PATCH] =?UTF-8?q?=E7=B2=BE=E7=AE=80=E4=BB=A3=E7=A0=81&=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nxTemp/store/modules/user.js | 35 ++++++++++++++++++++++++++--------- nxTemp/utils/tools.js | 24 ++++++++++++++++++++++++ pages/index/index.vue | 33 ++++++++++----------------------- pages/login/login.vue | 8 +++++--- 4 files changed, 65 insertions(+), 35 deletions(-) diff --git a/nxTemp/store/modules/user.js b/nxTemp/store/modules/user.js index ab73e1a..b7cf087 100644 --- a/nxTemp/store/modules/user.js +++ b/nxTemp/store/modules/user.js @@ -14,20 +14,17 @@ export const state = { } export const actions = { - async setUserData({ - state, - commit - }, data) { + async setUserData({state,commit}, data) { commit('setStateAttr', { key: 'userInfo', val: data }) - uni.setStorageSync('userInfo', data); + uni.setStorageSync('userInfo', data); + state.token = data.token + uni.setStorageSync('token', data.token); }, // 登录过期 重新登录 - reLogin({ - commit - }, info) { + reLogin({commit}, info) { commit('setStateAttr', { key: 'token', val: '' @@ -37,7 +34,27 @@ export const actions = { router.push({ path: '/pages/login/login' }); - } + }, + //预留,已将token更新整合到setUserData,后面可能有单独更新token的必要 + setUserToken({commit},token){ + commit('setStateAttr', { + key: 'token', + val: token + }) + uni.setStorageSync("token", token); + }, + //清空登录信息 + logoutUser({commit}){ + commit('setStateAttr', { + key: 'token', + val: '' + }) + uni.setStorageSync("token", ''); + uni.setStorageSync("userInfo", ''); + // router.push({ + // path: '/pages/index/index' + // }); + }, } export const mutations = { diff --git a/nxTemp/utils/tools.js b/nxTemp/utils/tools.js index 7a75439..2ced899 100644 --- a/nxTemp/utils/tools.js +++ b/nxTemp/utils/tools.js @@ -31,6 +31,30 @@ export default { }, /** + * @description: 封装弹窗交互 + * @param {String} msg 提示信息 + * @param {Function} succ 点确认执行函数 + * @return {Promise} + */ + showModal(msg,succ){ + let that = this + return new Promise((rs,rj)=>{ + uni.showModal({ + title: '温馨提示', + content: msg, + success: function (res) { + if (res.confirm) { + succ() + rs(true) + } else if (res.cancel) { + that.showNone("已取消") + rj(false) + } + } + }); + }) + }, + /** * @description: 弹窗封装 * @param {String} msg * @return: {*} diff --git a/pages/index/index.vue b/pages/index/index.vue index 1b493aa..36a534d 100644 --- a/pages/index/index.vue +++ b/pages/index/index.vue @@ -4,7 +4,7 @@ -