|
|
|
import Setting from "@/setting";
|
|
|
|
import util from "@/libs/util";
|
|
|
|
import { post, get, del, put } from "@/plugins/requests/index.js";
|
|
|
|
import api from "@/api";
|
|
|
|
/**
|
|
|
|
* 用户信息
|
|
|
|
* */
|
|
|
|
export default {
|
|
|
|
namespaced: true,
|
|
|
|
state: {
|
|
|
|
activeTab: "/station/list", // 当前激活菜单
|
|
|
|
title: '',
|
|
|
|
logoUrl: '',
|
|
|
|
avatar: "https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png",
|
|
|
|
userId: '',
|
|
|
|
studentId: '',
|
|
|
|
userName: '',
|
|
|
|
customerName: '',
|
|
|
|
schoolId: '',
|
|
|
|
roleId: '',
|
|
|
|
dataTime: '',
|
|
|
|
logView: false // 是否查询过日志状态,如果有,则不再调接口
|
|
|
|
},
|
|
|
|
mutations: {
|
|
|
|
SET_INFO: (state, info) => {
|
|
|
|
if (info.avatar) state.avatar = info.avatar;
|
|
|
|
state.userId = info.userId;
|
|
|
|
state.studentId = info.studentId;
|
|
|
|
state.schoolId = info.schoolId;
|
|
|
|
state.userName = info.userName;
|
|
|
|
state.roleId = info.roleId;
|
|
|
|
state.dataTime = info.dataTime;
|
|
|
|
},
|
|
|
|
SET_TITLE: (state, title) => {
|
|
|
|
state.title = title;
|
|
|
|
},
|
|
|
|
SET_LOGO_URL: (state, logoUrl) => {
|
|
|
|
state.logoUrl = logoUrl;
|
|
|
|
},
|
|
|
|
SET_AVATAR: (state, avatar) => {
|
|
|
|
state.avatar = avatar;
|
|
|
|
},
|
|
|
|
SET_USERNAME: (state, userName) => {
|
|
|
|
state.userName = userName;
|
|
|
|
},
|
|
|
|
SET_CUSTOMERNAME: (state, customerName) => {
|
|
|
|
state.customerName = customerName;
|
|
|
|
},
|
|
|
|
SET_ACTIVE_TAB: (state, activeTab) => {
|
|
|
|
state.activeTab = activeTab;
|
|
|
|
},
|
|
|
|
SET_LOG: (state) => {
|
|
|
|
state.logView = true
|
|
|
|
},
|
|
|
|
},
|
|
|
|
actions: {
|
|
|
|
login({ state, commit }, userInfo) {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
post(api.logins, userInfo).then(res => {
|
|
|
|
if (res.status == 200) {
|
|
|
|
let { data } = res;
|
|
|
|
// 生成路由权限
|
|
|
|
// 每个系统都是用这套角色权限代码的,后端也是基本一样,除了个别字段可能会不一样
|
|
|
|
// 总体来说就两个步骤: 1是生成能够访问的路由的数组集合,2是生成能看到的按钮的数组集合
|
|
|
|
//res.message.listValue && Setting.dynamicRoute && addRoutes(res.message.listValue)
|
|
|
|
util.local.set(Setting.tokenKey, data.token, Setting.tokenExpires);
|
|
|
|
util.successMsg("登录成功");
|
|
|
|
// console.log(data, "登录保存的数据");
|
|
|
|
commit("SET_INFO", data);
|
|
|
|
resolve();
|
|
|
|
} else {
|
|
|
|
util.errorMsg(res.message);
|
|
|
|
reject(res);
|
|
|
|
}
|
|
|
|
}).catch(error => {
|
|
|
|
reject(error);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
logout({ commit, state, dispatch }) {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
util.local.remove(Setting.storeKey);
|
|
|
|
util.local.remove(Setting.tokenKey);
|
|
|
|
location.reload();
|
|
|
|
resolve();
|
|
|
|
});
|
|
|
|
},
|
|
|
|
setInfo({ state, commit }, info) {
|
|
|
|
commit("SET_INFO", info);
|
|
|
|
},
|
|
|
|
setTitle({ state, commit }, title) {
|
|
|
|
commit("SET_TITLE", title);
|
|
|
|
},
|
|
|
|
setLogoUrl({ state, commit }, logoUrl) {
|
|
|
|
commit("SET_LOGO_URL", logoUrl);
|
|
|
|
},
|
|
|
|
setAvatar({ state, commit }, avatar) {
|
|
|
|
commit("SET_AVATAR", avatar);
|
|
|
|
},
|
|
|
|
setUserName({ state, commit }, userName) {
|
|
|
|
commit("SET_USERNAME", userName);
|
|
|
|
},
|
|
|
|
setActiveTab({ state, commit }, activeTab) {
|
|
|
|
commit("SET_ACTIVE_TAB", activeTab);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|