提交代码
This commit is contained in:
43
src/store/getters.js
Normal file
43
src/store/getters.js
Normal file
@ -0,0 +1,43 @@
|
||||
//起到一个快捷访问的作用
|
||||
|
||||
import {
|
||||
generateColors
|
||||
} from '@/utils/theme';
|
||||
import {
|
||||
MAIN_COLOR
|
||||
} from '@/constant';
|
||||
import {
|
||||
getItem
|
||||
} from '@/utils/storage';
|
||||
const getters = {
|
||||
token: (state) => state.user.token,
|
||||
activeId: (state) => state.user.activeId,
|
||||
deptId: (state) => state.user.deptId,
|
||||
deptList: (state) => state.user.deptList,
|
||||
menuList: (state) => state.user.menuList,
|
||||
userName: (state) => state.user.userName,
|
||||
userInfo: (state) => state.user.userInfo,
|
||||
routeReady: (state) => state.permission.routeReady,
|
||||
keepLiiveRoute: (state) => state.user.keepLiiveRoute,
|
||||
/** 如果retuen true 表示用户信息已存在 */
|
||||
hashUserInfo: (state) => {
|
||||
return JSON.stringify(state.user.userInfo) !== '{}';
|
||||
},
|
||||
cssVar: (state) => {
|
||||
return {
|
||||
...state.theme.variables,
|
||||
...generateColors(getItem(MAIN_COLOR))
|
||||
};
|
||||
},
|
||||
sidebarOpened: (state) => state.app.sidebarOpened,
|
||||
mainColor: (state) => state.theme.mainColor,
|
||||
tagsViewList: (state) => state.app.tagsViewList,
|
||||
bdmap: (state) => state.bdmap,
|
||||
leftShows: (state) => state.display.leftShows,
|
||||
rightShows: (state) => state.display.rightShows,
|
||||
tsgzTimeFlsg: (state) => state.display.tsgzTimeFlsg,
|
||||
tourInfo: (state) => state.display.tourInfo,
|
||||
tourSign: (state) => state.display.tourSign
|
||||
};
|
||||
|
||||
export default getters;
|
27
src/store/index.js
Normal file
27
src/store/index.js
Normal file
@ -0,0 +1,27 @@
|
||||
import { createStore } from 'vuex';
|
||||
import user from './modules/user';
|
||||
import app from './modules/app';
|
||||
import theme from './modules/theme';
|
||||
import sysDict from './modules/sysDict';
|
||||
import permission from './modules/permission';
|
||||
import display from './modules/display';
|
||||
|
||||
import getters from './getters';
|
||||
|
||||
export default createStore({
|
||||
// state: {
|
||||
// },
|
||||
// mutations: {
|
||||
// },
|
||||
// actions: {
|
||||
// },
|
||||
getters,
|
||||
modules: {
|
||||
user,
|
||||
app,
|
||||
theme,
|
||||
sysDict,
|
||||
permission,
|
||||
display
|
||||
}
|
||||
});
|
50
src/store/modules/app.js
Normal file
50
src/store/modules/app.js
Normal file
@ -0,0 +1,50 @@
|
||||
import { getItem, setItem } from "@/utils/storage";
|
||||
import { TAGS_VIEW } from "@/constant/index.js";
|
||||
export default {
|
||||
namespaced: true,
|
||||
state: () => ({
|
||||
sidebarOpened: true,
|
||||
tagsViewList: getItem(TAGS_VIEW) || []
|
||||
}),
|
||||
mutations: {
|
||||
triggerSidebarOpened(state) {
|
||||
state.sidebarOpened = !state.sidebarOpened;
|
||||
},
|
||||
|
||||
//添加tags
|
||||
addTagsViewList(state, tag) {
|
||||
const isFind = state.tagsViewList.find((item) => {
|
||||
return item.path === tag.path;
|
||||
});
|
||||
//处理重复
|
||||
if (!isFind) {
|
||||
state.tagsViewList.push(tag);
|
||||
setItem(TAGS_VIEW, state.tagsViewList);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* 删除 tag
|
||||
*/
|
||||
removeTagsView(state, payload) {
|
||||
const tagsViewList = state.tagsViewList;
|
||||
if (payload.type == "index") {
|
||||
tagsViewList.splice(payload.index, 1);
|
||||
} else {
|
||||
tagsViewList.splice(tagsViewList.indexOf(payload.data), 1);
|
||||
}
|
||||
setItem(TAGS_VIEW, tagsViewList);
|
||||
},
|
||||
/**
|
||||
* 清空 tag
|
||||
*/
|
||||
clearTag(state, menu) {
|
||||
if (menu != null) {
|
||||
state.tagsViewList = [menu]
|
||||
} else {
|
||||
state.tagsViewList = []
|
||||
}
|
||||
setItem(TAGS_VIEW, state.tagsViewList);
|
||||
}
|
||||
}
|
||||
};
|
14
src/store/modules/bdmap.js
Normal file
14
src/store/modules/bdmap.js
Normal file
@ -0,0 +1,14 @@
|
||||
export default {
|
||||
namespaced: true,
|
||||
state: () => ({
|
||||
bdmap: null
|
||||
}),
|
||||
mutations: {
|
||||
setMap(state, map) {
|
||||
state.bdmap = map;
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
|
||||
}
|
||||
};
|
76
src/store/modules/display.js
Normal file
76
src/store/modules/display.js
Normal file
@ -0,0 +1,76 @@
|
||||
export default {
|
||||
namespaced: true,
|
||||
state: () => ({
|
||||
leftShows: 1,
|
||||
rightShows: 1,
|
||||
tsgzTimeFlsg: 0,
|
||||
closesp: 2,
|
||||
spkind: 1,
|
||||
videohk: 2,
|
||||
tourInfo: {},
|
||||
tourSign: 2,
|
||||
countTimes1: [],
|
||||
countTimes2: [],
|
||||
countTimes3: [],
|
||||
countTimes4: [],
|
||||
customFlag: 1,
|
||||
rangeTime: [],
|
||||
xzhh: '',
|
||||
dynamicPoint: '1', // '1'点位, '2'热力, '3'方格
|
||||
distinguishKind: '3', // '1' 巡逻;'2' 重点人员, '3'警情
|
||||
xfqOrg: {}
|
||||
}),
|
||||
mutations: {
|
||||
SET_ORGCODE(state, view) {
|
||||
state.xfqOrg = view
|
||||
},
|
||||
SET_LEFT_SHOWS(state, view) {
|
||||
state.leftShows = view
|
||||
},
|
||||
SET_RIGHT_SHOWS(state, view) {
|
||||
state.rightShows = view
|
||||
},
|
||||
SET_TSGZ_TIMEFLAG(state, view) {
|
||||
state.tsgzTimeFlsg = view
|
||||
},
|
||||
SET_CLOSESP(state, view) {
|
||||
state.closesp = view
|
||||
},
|
||||
SET_SPKIND(state, view) {
|
||||
state.spkind = view
|
||||
},
|
||||
SET_TOURSIGN(state, view) {
|
||||
state.tourSign = view
|
||||
},
|
||||
SET_TOURINFO(state, view) {
|
||||
state.tourInfo = view
|
||||
},
|
||||
SET_COUNTTIMES1(state, view) {
|
||||
state.countTimes1 = view
|
||||
},
|
||||
SET_COUNTTIMES2(state, view) {
|
||||
state.countTimes2 = view
|
||||
},
|
||||
SET_COUNTTIMES3(state, view) {
|
||||
state.countTimes3 = view
|
||||
},
|
||||
SET_COUNTTIMES4(state, view) {
|
||||
state.countTimes4 = view
|
||||
},
|
||||
SET_CUSTOMFLAG(state, view) {
|
||||
state.customFlag = view
|
||||
},
|
||||
SET_RANGETIME(state, view) {
|
||||
state.rangeTime = view
|
||||
},
|
||||
SET_XZHH(state, view) {
|
||||
state.xzhh = view
|
||||
},
|
||||
SET_DYNAMIC_POINT(state, view) {
|
||||
state.dynamicPoint = view
|
||||
},
|
||||
SET_DINSTINGUISH_KIND(state, view) {
|
||||
state.distinguishKind = view
|
||||
}
|
||||
}
|
||||
}
|
66
src/store/modules/permission.js
Normal file
66
src/store/modules/permission.js
Normal file
@ -0,0 +1,66 @@
|
||||
// 专门处理权限路由的模块
|
||||
import {
|
||||
publicRoutes,
|
||||
privateRoutes
|
||||
} from '@/router'
|
||||
|
||||
function filter(data, menus) {
|
||||
var newData = data.filter(x => menus ?.includes(x.name))
|
||||
newData.forEach(x => x.children && (x.children = filter(x.children, menus)))
|
||||
return newData
|
||||
}
|
||||
export default {
|
||||
namespaced: true,
|
||||
state: {
|
||||
// 路由表:初始拥有静态路由权限
|
||||
routes: [],
|
||||
routeReady: 0
|
||||
},
|
||||
mutations: {
|
||||
/**
|
||||
* 增加路由
|
||||
*/
|
||||
setRoutes(state, newRoutes) {
|
||||
// 永远在静态路由的基础上增加新路由
|
||||
state.routes = [...publicRoutes, ...newRoutes]
|
||||
},
|
||||
setRouteReady(state, num) {
|
||||
state.routeReady = state.routeReady + num;
|
||||
},
|
||||
resetrouteReady(state) {
|
||||
state.routeReady = 0
|
||||
},
|
||||
deleteRouter(state) {
|
||||
state.routes = []
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
/**
|
||||
* 根据权限筛选路由
|
||||
*/
|
||||
filterRoutes(context, menus) {
|
||||
let routes = []
|
||||
// 路由权限匹配
|
||||
// menus.forEach(key => {
|
||||
// // 权限名 与 路由的 name 匹配
|
||||
// routes.push(...privateRoutes.filter(item => item.name === key))
|
||||
// })
|
||||
|
||||
/**
|
||||
* 树结构数据条件过滤
|
||||
* js 指定删除数组(树结构数据)
|
||||
*/
|
||||
//测试比对
|
||||
routes = filter(privateRoutes, menus)
|
||||
// 最后添加 不匹配路由进入 404
|
||||
routes.push({
|
||||
path: '/:catchAll(.*)',
|
||||
redirect: '/404'
|
||||
})
|
||||
context.commit('setRoutes', routes);
|
||||
context.commit('setRouteReady', 1);
|
||||
// context.commit('setRouteReady', true);
|
||||
return routes
|
||||
}
|
||||
}
|
||||
}
|
69
src/store/modules/sysDict.js
Normal file
69
src/store/modules/sysDict.js
Normal file
@ -0,0 +1,69 @@
|
||||
import { getAllSysDict } from "@/api/sysDict";
|
||||
import { setItem, getItem, removeAllItem } from "@/utils/storage";
|
||||
import router from "@/router";
|
||||
export default {
|
||||
namespaced: true,
|
||||
state: () => ({
|
||||
userInfo: {}
|
||||
}),
|
||||
mutations: {
|
||||
setToken(state, token) {
|
||||
state.token = token;
|
||||
setItem(TOKEN, token);
|
||||
},
|
||||
setUserInfo(state, userInfo) {
|
||||
state.userInfo = userInfo;
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
/*
|
||||
*登录请求动作
|
||||
*/
|
||||
login(ctx, userInfo) {
|
||||
const { username, password } = userInfo;
|
||||
return new Promise((resolve, reject) => {
|
||||
login({
|
||||
username,
|
||||
password: md5(password)
|
||||
})
|
||||
.then((data) => {
|
||||
this.commit("user/setToken", data.token);
|
||||
// 保存登录时间
|
||||
setTimeStamp();
|
||||
resolve();
|
||||
})
|
||||
.catch((err) => {
|
||||
reject(err);
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
/*
|
||||
* 获取用户信息
|
||||
*/
|
||||
async getUserInfo(ctx) {
|
||||
const res = await getUserInfo();
|
||||
this.commit("user/setUserInfo", res);
|
||||
return res;
|
||||
},
|
||||
|
||||
/*
|
||||
* 退出登录
|
||||
*/
|
||||
async logout(ctx) {
|
||||
this.commit("user/setToken", "");
|
||||
this.commit("user/setUserInfo", {});
|
||||
removeAllItem();
|
||||
// 待补充 清理权限相关的配置
|
||||
router.push("/login");
|
||||
},
|
||||
|
||||
/*
|
||||
* 获取 分页查询字典信息
|
||||
*/
|
||||
async getAllSysDict(ctx, params) {
|
||||
const res = await getAllSysDict();
|
||||
return res;
|
||||
}
|
||||
}
|
||||
};
|
19
src/store/modules/theme.js
Normal file
19
src/store/modules/theme.js
Normal file
@ -0,0 +1,19 @@
|
||||
import { MAIN_COLOR, DEFAULT_COLOR } from '@/constant';
|
||||
import { setItem, getItem } from '@/utils/storage';
|
||||
import variables from '@/styles/variables.scss';
|
||||
|
||||
export default {
|
||||
namespaced: true,
|
||||
state: () => ({
|
||||
mainColor: getItem(MAIN_COLOR) || DEFAULT_COLOR,
|
||||
variables: variables
|
||||
}),
|
||||
mutations: {
|
||||
setMainColor(state, newColor) {
|
||||
state.mainColor = newColor;
|
||||
state.variables.menuBg = newColor;
|
||||
setItem(MAIN_COLOR, newColor);
|
||||
}
|
||||
},
|
||||
actions: {}
|
||||
};
|
246
src/store/modules/user.js
Normal file
246
src/store/modules/user.js
Normal file
@ -0,0 +1,246 @@
|
||||
import {
|
||||
login,
|
||||
getUserInfo,
|
||||
getKaptcha,
|
||||
refreshToken,
|
||||
loginOut
|
||||
} from "@/api/sys";
|
||||
import {
|
||||
unifiedLogin
|
||||
} from "@/api/user-manage";
|
||||
import Base64 from "base-64";
|
||||
import {
|
||||
setItem,
|
||||
getItem,
|
||||
removeAllItem
|
||||
} from "@/utils/storage";
|
||||
import {
|
||||
TOKEN
|
||||
} from "@/constant";
|
||||
import router, {
|
||||
resetRouter
|
||||
} from "@/router";
|
||||
import {
|
||||
setTimeStamp
|
||||
} from "@/utils/auth";
|
||||
import {
|
||||
TAGS_VIEW
|
||||
} from "@/constant/index.js";
|
||||
export default {
|
||||
namespaced: true,
|
||||
state: () => ({
|
||||
token: getItem(TOKEN) || "", // 先从localStorage里面取
|
||||
userInfo: {},
|
||||
deptList: [],
|
||||
deptId: "",
|
||||
menuList: [],
|
||||
isReady: 0,
|
||||
userName: getItem("USERNAME") || "",
|
||||
keepLiiveRoute: [], //需要缓存的路由
|
||||
activeId:'',//警组点击的唯一标识
|
||||
}),
|
||||
mutations: {
|
||||
setToken(state, token) {
|
||||
state.token = token;
|
||||
setItem(TOKEN, token);
|
||||
},
|
||||
setActiveId(state, activeId) {
|
||||
state.activeId = activeId;
|
||||
},
|
||||
setUserName(state, userName) {
|
||||
state.userName = userName;
|
||||
},
|
||||
setDeptList(state, deptList) {
|
||||
state.deptList = deptList;
|
||||
},
|
||||
setIsReady(state, deptList) {
|
||||
state.isReady++;
|
||||
},
|
||||
setMenuList(state, menuList) {
|
||||
state.menuList = menuList;
|
||||
},
|
||||
setUserInfo(state, userInfo) {
|
||||
state.userInfo = userInfo;
|
||||
},
|
||||
//保存当前deptId
|
||||
setDeptId(state, deptId) {
|
||||
state.deptId = deptId;
|
||||
setItem("deptId", deptId);
|
||||
},
|
||||
//保存路由
|
||||
setKeepLiiveRoute(state, val) {
|
||||
// state.keepLiiveRoute.push(val);
|
||||
},
|
||||
//删除缓存路由
|
||||
deleteKeepLiiveRoute(state, val) {
|
||||
// state.keepLiiveRoute = state.keepLiiveRoute.filter((item) => {
|
||||
// return item != val;
|
||||
// });
|
||||
},
|
||||
},
|
||||
actions: {
|
||||
/*
|
||||
*登录请求动作
|
||||
*/
|
||||
login(ctx, userInfo) {
|
||||
const {
|
||||
userName,
|
||||
password,
|
||||
kaptcha
|
||||
} = userInfo;
|
||||
return new Promise((resolve, reject) => {
|
||||
login({
|
||||
userName,
|
||||
password: Base64.encode(password),
|
||||
kaptcha
|
||||
})
|
||||
.then((data) => {
|
||||
if (data.deptList.length === 1) {
|
||||
this.commit("user/setToken", data.jwtToken);
|
||||
this.commit("user/setDeptId", data.deptList);
|
||||
this.commit("user/setUserName", data.userName);
|
||||
setItem('isOatuh', 0)
|
||||
setItem("USERNAME", data.userName);
|
||||
setItem("SFRH", data.sfrh);
|
||||
setItem("USERID", data.userId);
|
||||
setItem("PermissionsInfo", data.permissionsInfo);
|
||||
this.commit("user/setMenuList", data.menuList);
|
||||
setItem("menusPermission", data.menuCodeSet);
|
||||
setItem("idEntityCard", data.idEntityCard);
|
||||
this.commit("user/setUserInfo", {
|
||||
token: data.jwtToken,
|
||||
permission: {
|
||||
buttonPermission: ["removeTest", "viewTest"],
|
||||
menus: data.menuCodeSet
|
||||
},
|
||||
menuList: data.menuList,
|
||||
deptList: data.deptList
|
||||
});
|
||||
}
|
||||
// 保存登录时间
|
||||
setTimeStamp();
|
||||
resolve(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
reject(err);
|
||||
});
|
||||
});
|
||||
},
|
||||
/*
|
||||
*单点登录
|
||||
*/
|
||||
oatuhLogin(ctx, userInfo) {
|
||||
const {
|
||||
token,
|
||||
systemId,
|
||||
} = userInfo;
|
||||
return new Promise((resolve, reject) => {
|
||||
unifiedLogin({
|
||||
token,
|
||||
systemId,
|
||||
})
|
||||
.then((data) => {
|
||||
if (data.deptList.length === 1) {
|
||||
this.commit("user/setToken", data.jwtToken);
|
||||
this.commit("user/setDeptId", data.deptList);
|
||||
this.commit("user/setUserName", data.userName);
|
||||
setItem("USERNAME", data.userName);
|
||||
setItem("SFRH", data.sfrh);
|
||||
setItem("USERID", data.userId);
|
||||
setItem("PermissionsInfo", data.permissionsInfo);
|
||||
this.commit("user/setMenuList", data.menuList);
|
||||
setItem("menusPermission", data.menuCodeSet);
|
||||
setItem('isOatuh', 1)
|
||||
setItem("idEntityCard", data.idEntityCard);
|
||||
this.commit("user/setUserInfo", {
|
||||
token: data.jwtToken,
|
||||
permission: {
|
||||
buttonPermission: ["removeTest", "viewTest"],
|
||||
menus: data.menuCodeSet
|
||||
},
|
||||
menuList: data.menuList,
|
||||
deptList: data.deptList
|
||||
});
|
||||
}
|
||||
// 保存登录时间
|
||||
setTimeStamp();
|
||||
resolve(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
reject(err);
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
refreshToken(ctx, parmas) {
|
||||
return new Promise((resolve, reject) => {
|
||||
refreshToken({
|
||||
deptId: parmas.deptId,
|
||||
authorization: parmas.jwtToken
|
||||
})
|
||||
.then((data) => {
|
||||
this.commit("user/setToken", "");
|
||||
this.commit("user/setToken", data.jwtToken);
|
||||
this.commit("user/setDeptList", data.deptList);
|
||||
this.commit("user/setUserName", data.userName);
|
||||
this.commit("user/setMenuList", data.menuList);
|
||||
this.commit("user/setUserInfo", {
|
||||
token: data.jwtToken,
|
||||
permission: {
|
||||
buttonPermission: ["removeTest", "viewTest"],
|
||||
menus: data.menuCodeSet
|
||||
},
|
||||
menuList: data.menuList,
|
||||
deptList: data.deptList
|
||||
});
|
||||
setItem("menusPermission", data.menuCodeSet);
|
||||
// 保存登录时间
|
||||
setTimeStamp();
|
||||
return resolve(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
reject(err);
|
||||
});
|
||||
});
|
||||
},
|
||||
/*
|
||||
* 获取图形验证码
|
||||
*/
|
||||
async getKaptcha(ctx) {
|
||||
const res = await getKaptcha();
|
||||
return res;
|
||||
},
|
||||
|
||||
/*
|
||||
* 获取用户信息
|
||||
*/
|
||||
async getUserInfo(ctx) {
|
||||
const res = await getUserInfo();
|
||||
this.commit("user/setUserInfo", res);
|
||||
return res;
|
||||
},
|
||||
|
||||
/*
|
||||
* 退出登录
|
||||
*/
|
||||
async logout(ctx) {
|
||||
const res = await loginOut();
|
||||
if (res) {
|
||||
resetRouter();
|
||||
this.commit("user/setToken", "");
|
||||
this.commit("user/setUserName", "admin");
|
||||
this.commit("user/setUserInfo", {});
|
||||
this.commit("permission/resetrouteReady", 0);
|
||||
const isOatuh = getItem('isOatuh')
|
||||
this.commit("permission/deleteRouter");
|
||||
removeAllItem();
|
||||
// 待补充 清理权限相关的配置
|
||||
if (isOatuh) {
|
||||
window.location.href = `http://80.149.27.78:8001/login`;
|
||||
} else {
|
||||
router.push("/login");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
Reference in New Issue
Block a user