基于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.

84 lines
1.9 KiB

2 years ago
import { createStore as create } from 'vuex';
2 years ago
import { Styles, Size } from '../config';
import { getByCodes, getInfo } from '../api/public';
2 years ago
2 years ago
export class State {
dict = {
active_status: {
A: '启用',
B: '禁用',
},
};
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]);
}
}
});
};
}
export class Mutations {
updateState = (state, param) => {
state[param[0]] = param[1];
};
initSize = (state, height) => {
const size = state.size;
const head = parseInt(size.headHeight);
const mainPad = parseInt(size.mainPad);
const searchRow = parseInt(size.searchRowHeight);
const searchRowPad = parseInt(size.searchRowPad);
if (height) {
size.height = height;
} else {
height = size.height;
}
size.mainHeight = Math.floor(height - head) + 'px';
1 year ago
size.tableHeight = height - 2 * (mainPad + searchRowPad) - 3 - searchRow - head;
2 years ago
size.pTableHeight = size.tableHeight - size.pageHeight;
};
updateDict = (state, param) => {
state.dict[param[0]] = param[1];
};
}
export interface StoreOptions {
state?: State;
getters?;
actions?;
mutations?: Mutations;
modules?;
plugins?;
strict?: boolean;
devtools?: boolean;
}
2 years ago
export const createStore = (options) => {
return create(options);
};