diff --git a/core/app.js b/core/app.js index 8a4aa2b..af19ebd 100644 --- a/core/app.js +++ b/core/app.js @@ -158,7 +158,7 @@ export const setCartTabBadge = () => { * 验证是否已登录 */ export const checkLogin = () => { - return !!store.getters.userId + return !!store.getters.accountId } /** diff --git a/pages/login/components/main.vue b/pages/login/components/main.vue index 02a5f5a..1f739e7 100644 --- a/pages/login/components/main.vue +++ b/pages/login/components/main.vue @@ -56,6 +56,9 @@ import * as LoginApi from '@/api/login' import * as Verify from '@/utils/verify' + // 校验登录 + import { checkLogin, showError } from '@/core/app' + export default { components: { // nothing @@ -110,7 +113,6 @@ this.utchk2=true this.utchk1=false; } - let bb = this.$md5("123456") }, // 判断是否阅读了政策协议 readpri(e){ @@ -209,7 +211,7 @@ delta: Number(delta || 1) }) } else { - this.$navTo('pages/index/index') + this.$navTo('pages/user/index') } }, diff --git a/pages/login/index.vue b/pages/login/index.vue index c2b41c2..37985f1 100644 --- a/pages/login/index.vue +++ b/pages/login/index.vue @@ -10,6 +10,8 @@ import MpWeixin from './components/mp-weixin' import SettingKeyEnum from '@/common/enum/setting/Key' import SettingModel from '@/common/model/Setting' + + export default { components: { diff --git a/store/getters.js b/store/getters.js index d27e783..a224799 100644 --- a/store/getters.js +++ b/store/getters.js @@ -1,6 +1,7 @@ const getters = { token: state => state.user.token, userId: state => state.user.userId, + accountId: state => state.user.accountId, platform: state => state.app.platform } diff --git a/store/modules/user.js b/store/modules/user.js index 591a2e4..7fc875e 100644 --- a/store/modules/user.js +++ b/store/modules/user.js @@ -1,17 +1,17 @@ -import { ACCESS_TOKEN, USER_ID } from '@/store/mutation-types' +import { ACCESS_TOKEN, ACCOUNT_ID } from '@/store/mutation-types' import storage from '@/utils/storage' import * as LoginApi from '@/api/login' // 登陆成功后执行 -const loginSuccess = (commit, { token, accountId }) => { +const loginSuccess = (commit, { token, user }) => { // 过期时间30天 const expiryTime = 30 * 86400 // 保存tokne和userId到缓存 - storage.set(USER_ID, accountId, expiryTime) + storage.set(ACCOUNT_ID, user.accountId, expiryTime) storage.set(ACCESS_TOKEN, token, expiryTime) // 记录到store全局变量 commit('SET_TOKEN', token) - commit('SET_USER_ID', accountId) + commit('SET_ACCOUNT_ID', user.accountId) } const user = { @@ -26,9 +26,12 @@ const user = { SET_TOKEN: (state, value) => { state.token = value }, - SET_USER_ID: (state, value) => { - state.userId = value - } + // SET_USER_ID: (state, value) => { + // state.userId = value + // }, + SET_ACCOUNT_ID:(state,value)=>{ + state.accountId = value + } }, actions: { @@ -78,13 +81,13 @@ const user = { Logout({ commit }, data) { const store = this return new Promise((resolve, reject) => { - if (store.getters.userId > 0) { + if (store.getters.accountId > 0) { // 删除缓存中的tokne和userId - storage.remove(USER_ID) + storage.remove(ACCOUNT_ID) storage.remove(ACCESS_TOKEN) // 记录到store全局变量 commit('SET_TOKEN', '') - commit('SET_USER_ID', null) + commit('SET_ACCOUNT_ID', null) resolve() } }) diff --git a/store/mutation-types.js b/store/mutation-types.js index 4f0572f..0ef803d 100644 --- a/store/mutation-types.js +++ b/store/mutation-types.js @@ -1,3 +1,4 @@ export const ACCESS_TOKEN = 'AccessToken' export const USER_ID = 'userId' export const PLATFORM = 'platform' +export const ACCOUNT_ID = 'accountId' \ No newline at end of file