vuex模块化

This commit is contained in:
aixianling
2022-06-10 16:46:03 +08:00
parent a85a2b5bfe
commit e409328271
4 changed files with 10 additions and 28 deletions

View File

@@ -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)

View File

@@ -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})

View File

@@ -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() {

View File

@@ -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: {