From e40932827105b2114935961a098b08a4c8455d81 Mon Sep 17 00:00:00 2001 From: aixianling Date: Fri, 10 Jun 2022 16:46:03 +0800 Subject: [PATCH] =?UTF-8?q?vuex=E6=A8=A1=E5=9D=97=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/common/axios.js | 5 +++-- src/common/modules.js | 9 ++++++--- src/pages/login.vue | 3 +-- src/store/index.js | 21 --------------------- 4 files changed, 10 insertions(+), 28 deletions(-) diff --git a/src/common/axios.js b/src/common/axios.js index b65f1cc6..b090380b 100644 --- a/src/common/axios.js +++ b/src/common/axios.js @@ -3,7 +3,7 @@ import instance from './http' instance.interceptors.request.use(config => { store.commit('initWaterMarker') - config.baseURL = "/lan" + if (/\/node\//.test(config.url)) { config.baseURL = '/ns' } else if (/AppCountryAlbum/.test(location.pathname) || config.module == 'AppCountryAlbum') { @@ -16,7 +16,8 @@ instance.interceptors.request.use(config => { config.url = config.url.replace(/(app|auth|admin)\//, "api/") } else if (sessionStorage.getItem("prj") == "saas") { config.baseURL = '/online' - } + } else config.baseURL = "/lan" + console.log(config) return config }, err => { console.error(err) diff --git a/src/common/modules.js b/src/common/modules.js index e6aefdf2..bbafe976 100644 --- a/src/common/modules.js +++ b/src/common/modules.js @@ -1,6 +1,9 @@ import http from "./http"; import Vue from "vue"; +/** + * 用户登录信息 + */ export const user = { state: () => ({}), mutations: { @@ -16,13 +19,13 @@ export const user = { return http.post("/admin/user/detail-phone", null, config).then(res => { if (res?.code == 0) { commit('setUser', res.data) - return Promise.all([dispatch('getGridInfo')]) + return Promise.all([dispatch('getGridInfo', config)]) } }) }, - getGridInfo({commit}) { + getGridInfo({commit}, config) { //获取登录着网格员信息 - return http.post("/app/appgirdmemberinfo/checkLogOnUser").then(res => { + return http.post("/app/appgirdmemberinfo/checkLogOnUser", null, config).then(res => { if (res?.data) { let {girdId, girdMemberId, girdName, checkType: girdCheckType, appGirdInfo: gridInfo} = res.data return commit("setUser", {girdId, girdMemberId, girdName, girdCheckType, gridInfo}) diff --git a/src/pages/login.vue b/src/pages/login.vue index 6c1ed547..026cc30c 100644 --- a/src/pages/login.vue +++ b/src/pages/login.vue @@ -66,8 +66,7 @@ export default { }) }, handleLogout() { - this.logout() - this.$http.delete("/auth/token/logout") + this.$http.delete("/auth/token/logout").finally(() => this.logout()) } }, onShow() { diff --git a/src/store/index.js b/src/store/index.js index cabf098b..e748ba8e 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -46,19 +46,6 @@ const store = new Vuex.Store({ } else alert(res) }).catch(err => alert(err)) }, - setDicts(state, payload) { - if (payload) { - payload.map(p => { - if (state.dicts.some(d => d.key == p.key)) { - const index = state.dicts.findIndex(d => d.key == p.key) - state.dicts.splice(index, 1) - state.dicts.push(p) - } else { - state.dicts.push(p) - } - }) - } - }, redirectCode(state, url = location.href) { let REDIRECT_URI = encodeURIComponent(url), corpid = state.config.corpid @@ -286,14 +273,6 @@ const store = new Vuex.Store({ }) }, }, - getters: { - getDict: state => key => { - if (key && state.dicts.length > 0) { - return state.dicts.find(e => e.key == key) - } - return null - } - }, modules: {user, waterMarker}, plugins: [perState({ storage: {