This commit is contained in:
xiaozhiyong
2023-02-09 15:51:21 +08:00
commit 08196dbf68
82 changed files with 4443 additions and 0 deletions

12
src/store/getters.js Normal file
View File

@@ -0,0 +1,12 @@
const getters = {
sidebar: (state) => state.app.sidebar,
device: (state) => state.app.device,
// token: state => state.user.token,
avatar: (state) => state.user.avatar,
name: (state) => state.user.name,
auth: (state) => state.user.auth,
company_type: (state) => state.user.companyType,
company_id: (state) => state.user.companyId,
permission_routes: (state) => state.permission.routes,
};
export default getters;

21
src/store/index.js Normal file
View File

@@ -0,0 +1,21 @@
import Vue from 'vue'
import Vuex from 'vuex'
import getters from './getters'
import app from './modules/app'
import permission from './modules/permission'
import settings from './modules/settings'
import user from './modules/user'
Vue.use(Vuex)
const store = new Vuex.Store({
modules: {
app,
permission,
settings,
user
},
getters
})
export default store

48
src/store/modules/app.js Normal file
View File

@@ -0,0 +1,48 @@
import Cookies from 'js-cookie'
const state = {
sidebar: {
opened: Cookies.get('sidebarStatus') ? !!+Cookies.get('sidebarStatus') : true,
withoutAnimation: false
},
device: 'desktop'
}
const mutations = {
TOGGLE_SIDEBAR: state => {
state.sidebar.opened = !state.sidebar.opened
state.sidebar.withoutAnimation = false
if (state.sidebar.opened) {
Cookies.set('sidebarStatus', 1)
} else {
Cookies.set('sidebarStatus', 0)
}
},
CLOSE_SIDEBAR: (state, withoutAnimation) => {
Cookies.set('sidebarStatus', 0)
state.sidebar.opened = false
state.sidebar.withoutAnimation = withoutAnimation
},
TOGGLE_DEVICE: (state, device) => {
state.device = device
}
}
const actions = {
toggleSideBar({ commit }) {
commit('TOGGLE_SIDEBAR')
},
closeSideBar({ commit }, { withoutAnimation }) {
commit('CLOSE_SIDEBAR', withoutAnimation)
},
toggleDevice({ commit }, device) {
commit('TOGGLE_DEVICE', device)
}
}
export default {
namespaced: true,
state,
mutations,
actions
}

View File

@@ -0,0 +1,49 @@
import { constantRoutes } from "@/router";
function hasPermission(roles, route) {
if (route.meta && route.meta.roles) {
return roles.some((role) => route.meta.roles.includes(role));
} else {
return true;
}
}
export function filterAsyncRoutes(routes, roles) {
const res = [];
routes.forEach((route) => {
const tmp = { ...route };
if (hasPermission(roles, tmp)) {
if (tmp.children) {
tmp.children = filterAsyncRoutes(tmp.children, roles);
}
res.push(tmp);
}
});
return res;
}
const state = {
routes: [],
addRoutes: [],
};
const mutations = {
SET_ROUTES: (state, routes) => {
state.addRoutes = routes;
state.routes = constantRoutes.concat(routes);
},
};
const actions = {
generateRoutes({ commit }, realRouter) {
commit("SET_ROUTES", realRouter);
},
};
export default {
namespaced: true,
state,
mutations,
actions,
};

View File

@@ -0,0 +1,32 @@
import defaultSettings from '@/settings'
const { showSettings, fixedHeader, sidebarLogo } = defaultSettings
const state = {
showSettings: showSettings,
fixedHeader: fixedHeader,
sidebarLogo: sidebarLogo
}
const mutations = {
CHANGE_SETTING: (state, { key, value }) => {
// eslint-disable-next-line no-prototype-builtins
if (state.hasOwnProperty(key)) {
state[key] = value
}
}
}
const actions = {
changeSetting({ commit }, data) {
commit('CHANGE_SETTING', data)
}
}
export default {
namespaced: true,
state,
mutations,
actions
}

40
src/store/modules/user.js Normal file
View File

@@ -0,0 +1,40 @@
const getDefaultState = () => {
return {
name: "admin",
avatar: "",
auth: null,
companyType: 0,
companyId: "",
};
};
const state = getDefaultState();
const mutations = {
SET_NAME: (state, name) => {
state.name = name;
},
SET_AUTH: (state, auth) => {
state.auth = auth;
},
SET_COMPANYTYPE: (state, data) => {
//chainParentMark 1总公司 0分公司
state.companyType = data.chainParentMark;
state.companyId = data.userCompany;
},
};
const actions = {
info({ commit }, data) {
commit("SET_AUTH", data.authList);
commit("SET_NAME", data.name);
commit("SET_COMPANYTYPE", data);
},
};
export default {
namespaced: true,
state,
mutations,
actions,
};