74 lines
1.8 KiB
JavaScript
74 lines
1.8 KiB
JavaScript
import Vue from 'vue'
|
|
import Vuex from 'vuex'
|
|
import perState from 'vuex-persistedstate'
|
|
import http from '../common/axios'
|
|
import * as modules from "../common/modules";
|
|
|
|
Vue.use(Vuex)
|
|
const store = new Vuex.Store({
|
|
state: {
|
|
openUser: {},
|
|
apps: [],
|
|
module: ""
|
|
},
|
|
mutations: {
|
|
setApps(state, apps) {
|
|
state.apps = apps
|
|
},
|
|
setModule(state, mod) {
|
|
state.module = mod
|
|
},
|
|
logout(state) {
|
|
state.openUser = {}
|
|
state.user = {}
|
|
},
|
|
setOpenUser(state, user) {
|
|
state.openUser = user
|
|
},
|
|
bindAccount(state, params) {
|
|
//具备解决二次登录,绑定手机,token等问题
|
|
// http.post("/admin/user/cpBindByPhone", params, {
|
|
http.post("/auth/wechatcp/token", {customerLogin: 1, ...params}, {
|
|
headers: {
|
|
Authorization: "Basic d2VjaGF0OndlY2hhdA=="
|
|
},
|
|
withoutToken: true
|
|
}).then(res => {
|
|
if (res?.access_token) {
|
|
params?.then(res)
|
|
} else alert(res)
|
|
}).catch(err => alert(err))
|
|
}
|
|
},
|
|
actions: {
|
|
getUserInfo(state, code) {
|
|
if (code) {
|
|
return http.post("/app/wxcp/portal/getUserInfo", null, {
|
|
params: {code}, withoutToken: true
|
|
}).then(res => {
|
|
if (res?.code == 0) {
|
|
state.commit("setOpenUser", res.data)
|
|
}
|
|
})
|
|
} else {
|
|
return http.post("/app/wxcp/wxuser/getUserInfoByToken")
|
|
.then(res => {
|
|
if (res?.code == 0) {
|
|
state.commit("setOpenUser", res.data)
|
|
}
|
|
})
|
|
}
|
|
},
|
|
},
|
|
modules,
|
|
plugins: [perState({
|
|
storage: {
|
|
getItem: key => uni.getStorageSync(key),
|
|
setItem: (key, value) => uni.setStorageSync(key, value),
|
|
removeItem: key => uni.removeStorageSync(key)
|
|
}
|
|
})]
|
|
})
|
|
|
|
export default store
|