You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
xy-frontend/src/store/index.js

97 lines
2.8 KiB
JavaScript

2 years ago
import Vue from "vue";
import Vuex from "vuex";
2 years ago
import cacheModule from "./cache";
2 years ago
Vue.use(Vuex);
export default new Vuex.Store({
state: {
//用户登录token 存储
token: "",
userName: "",
1 year ago
uid: "",
2 years ago
role: "",
currentData: "",
channelId: "",
termId: "",
protocol: "",
cmdId: "",
channelIdList: [],
2 years ago
isRenderTab: true,
2 years ago
},
getters: {
token: (state) => state.token,
userName: (state) => state.userName,
role: (state) => state.role,
1 year ago
menuPermission: (state) => state.resources,
2 years ago
},
mutations: {
//点击获取的左侧列表
currentData(state, currentData) {
state.currentData = currentData;
console.log("保存起来currentData", state.currentData);
localStorage.setItem("currentData", JSON.stringify(currentData));
},
channelId(state, channelId) {
state.channelId = channelId;
console.log("channelId", state.channelId);
localStorage.setItem("channelId", JSON.stringify(channelId));
},
termId(state, termId) {
state.termId = termId;
console.log("termId", state.termId);
localStorage.setItem("termId", JSON.stringify(termId));
},
protocol(state, protocol) {
state.protocol = protocol;
console.log("protocol", state.protocol);
localStorage.setItem("protocol", JSON.stringify(protocol));
},
cmdId(state, cmdId) {
state.cmdId = cmdId;
console.log("protocol", state.cmdId);
localStorage.setItem("protocol", JSON.stringify(cmdId));
},
channelIdList(state, channelIdList) {
state.channelIdList = channelIdList;
console.log("channelIdList", state.channelIdList);
localStorage.setItem("channelIdList", JSON.stringify(channelIdList));
},
SET_TOKEN(state, token) {
state.token = token;
localStorage.setItem("token", state.token);
},
SET_USERINFO(state, val) {
state.userName = val.userName;
1 year ago
state.uid = val.uid;
2 years ago
state.role = val.role;
1 year ago
if (val.role !== 0) {
state.resources = val.resources;
const menuArr = val.resources
.filter((item) => item.key.includes("/"))
.sort((a, b) => a.id - b.id);
const btnArr = val.resources
.filter((item) => item.key.includes("Btn"))
.sort((a, b) => a.id - b.id);
localStorage.setItem("menuPermission", JSON.stringify(menuArr));
localStorage.setItem("btnPermission", JSON.stringify(btnArr));
}
2 years ago
localStorage.setItem("userName", state.userName);
1 year ago
localStorage.setItem("uid", state.uid);
2 years ago
localStorage.setItem("role", state.role);
},
//退出清除locastorge
REMOVE_INFO(state) {
localStorage.clear();
},
2 years ago
setIsRenderTab(state, data) {
state.isRenderTab = data;
},
2 years ago
},
actions: {},
2 years ago
modules: { cache: cacheModule },
2 years ago
});