基于vue3.0和element-plus的组件库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

105 lines
2.6 KiB

import { createStore as create } from 'vuex';
import { Styles, Size } from '../config';
import { getByCodes, getMenus, logout } from '../api/public';
import { mapping } from '../api/role';
export class State {
dict = {
active_status: {
A: '启用',
B: '禁用',
},
};
roles = {};
menus = [];
roleRefresh = true;
style = Styles.plain;
size = Size.normal;
}
export class Actions {
getDictMap = ({ state, commit }, codes) => {
if (codes == null) {
return;
}
const arr: Array<any> = [];
for (let i = 0; i < codes.length; i++) {
const code = codes[i];
state.dict[code] || arr.push(code);
}
if (arr.length == 0) {
return;
}
getByCodes({ codes: arr.join() }).then((rsp: any) => {
if (rsp) {
for (let i = 0; i < arr.length; i++) {
const key = arr[i];
const dict = {};
if (rsp[key]) {
rsp[key].forEach((item) => {
dict[item.code] = item.name;
});
}
commit('updateDict', [key, dict]);
}
}
});
};
getRoleMap = ({ state, commit }) => {
state.roleRefresh &&
mapping().then((rsp) => {
commit('updateState', ['roles', rsp]);
commit('updateState', ['roleRefresh', false]);
});
};
getMenus = ({ state, commit }) => {
getMenus().then((rsp) => commit('updateState', ['menus', rsp]));
};
}
export class Mutations {
updateState = (state, param) => {
state[param[0]] = param[1];
};
initSize = (state, param) => {
const size = state.size;
const head = parseInt(size.headHeight);
const mainPad = parseInt(size.mainPad);
const searchRow = parseInt(size.searchRowHeight);
const searchRowPad = parseInt(size.searchRowPad);
const headRightWidth = parseInt(size.headRightWidth);
if (param) {
size.height = param[0];
size.width = param[1];
}
size.mainHeight = Math.floor(size.height - head) + 'px';
size.tableHeight = size.height - 2 * (mainPad + searchRowPad) - 3 - searchRow - head;
size.pTableHeight = size.tableHeight - size.pageHeight;
size.headLeftWidth = size.width - headRightWidth - 10 + 'px';
};
updateDict = (state, param) => {
state.dict[param[0]] = param[1];
};
}
export class Getters {
menuIconSize = (state) => {
return state.size.menuIconSize;
};
}
export interface StoreOptions {
state?: State;
getters?: Getters;
actions?;
mutations?: Mutations;
modules?;
plugins?;
strict?: boolean;
devtools?: boolean;
}
export const createStore = (options) => {
return create(options);
};