weaver_trunk_cli/pc4mobx/hrm/public/valhalla/stores/top.js

139 lines
2.3 KiB
JavaScript
Raw Normal View History

2023-03-14 09:11:54 +08:00
import {
observable,
action,
computed,
} from 'mobx';
import {
Button,
} from 'antd';
export default class TopStore {
2024-12-11 15:32:14 +08:00
constructor(root) {
this.root = root;
2023-03-14 09:11:54 +08:00
}
2024-12-11 15:32:14 +08:00
2023-03-14 09:11:54 +08:00
get topProps() {
return {
showDropIcon: true,
iconBgcolor: '#217346',
icon: <i className='icon-coms-hrm'/>,
}
}
2024-12-11 15:32:14 +08:00
hideMenu = [];
@observable title = '';
2023-03-14 09:11:54 +08:00
@observable tConf = [];
@observable rConf = [];
@computed get loading() {
2024-12-11 15:32:14 +08:00
return this.root.topLoading;
}
@action init = (config) => {
Object.keys(config).forEach(key => {
this[key] = config[key];
})
2023-03-14 09:11:54 +08:00
}
@action fetchRightMenu = (params = {}) => {
this.api(params).then(datas => {
const {
2024-12-11 15:32:14 +08:00
btnMenu = [],
rightMenus,
2023-03-14 09:11:54 +08:00
} = datas;
const {
tConf,
rConf
2024-12-11 15:32:14 +08:00
} = this.convertDatasToTopRightConf(rightMenus || btnMenu);
2023-03-14 09:11:54 +08:00
this.tConf = tConf;
this.rConf = rConf;
})
}
@computed get buttons() {
const buttons = this.tConf.map((item, index) => {
const {
menuFun,
menuName
} = item;
const state = this.getRightMenuState(index);
return (
2024-12-11 15:32:14 +08:00
<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@eluqhn@${index}`}
2023-03-14 09:11:54 +08:00
type="primary"
disabled={state}
2024-12-11 15:32:14 +08:00
onClick={() => this.root[menuFun]()}
2023-03-14 09:11:54 +08:00
>
{menuName}
</Button>
)
});
2024-12-11 15:32:14 +08:00
if (this.root.otherTopButtons) {
return [...this.root.otherTopButtons, ...buttons];
2023-03-14 09:11:54 +08:00
} else {
return buttons;
}
}
@computed get dropMenuDatas() {
return this.rConf.map((item, index) => {
const {
menuFun,
menuName,
menuIcon
} = item;
const state = this.getRightMenuState(index);
return {
key: menuFun,
disabled: state,
icon: <i className={`${menuIcon}`} />,
content: menuName,
2024-12-11 15:32:14 +08:00
onClick: () => this.root[menuFun]()
2023-03-14 09:11:54 +08:00
}
});
}
getRightMenuState = (index) => {
const {
rightMenuStates
2024-12-11 15:32:14 +08:00
} = this.root;
2023-03-14 09:11:54 +08:00
2024-12-11 15:32:14 +08:00
if (rightMenuStates && (index <= rightMenuStates.length - 1) ) {
2023-03-14 09:11:54 +08:00
return rightMenuStates[index];
2024-12-11 15:32:14 +08:00
}else{
2023-03-14 09:11:54 +08:00
return false
}
}
convertDatasToTopRightConf = (datas) => {
2024-12-11 15:32:14 +08:00
const tmp = datas.filter(data => !this.hideMenu.includes(data.menuFun))
2023-03-14 09:11:54 +08:00
let tConf, rConf;
2024-12-11 15:32:14 +08:00
tConf = tmp.filter(data => {
2023-03-14 09:11:54 +08:00
const {
isTop,
isBatch
} = data;
if (isTop === '1') {
return true;
}
if (isBatch === '1') {
return true;
}
})
2024-12-11 15:32:14 +08:00
rConf = tmp;
2023-03-14 09:11:54 +08:00
return {
tConf,
rConf
}
}
2024-12-11 15:32:14 +08:00
2023-03-14 09:11:54 +08:00
}