trunk/pc4mobx/organization/stores/columnPermission.js

247 lines
6.8 KiB
JavaScript
Raw Normal View History

2022-11-08 15:56:34 +08:00
import * as mobx from "mobx";
import { action, computed, extendObservable, observable } from "mobx";
2022-11-09 14:03:32 +08:00
import { WeaTableNew } from "comsMobx";
2022-11-08 15:56:34 +08:00
import { message } from "antd";
import { WeaHelpfulTip } from "ecCom";
import { isEmpty } from "lodash";
import { i18n } from "../public/i18n";
import * as Api from "../apis/columnPermission";
2022-11-09 14:03:32 +08:00
2022-11-08 17:43:26 +08:00
const { TableStore } = WeaTableNew;
2022-11-08 15:56:34 +08:00
2022-11-07 16:35:58 +08:00
const toJS = mobx.toJS;
export class ColumnPermission {
2022-11-08 17:43:26 +08:00
@observable tableStore = new TableStore();
2022-11-09 14:03:32 +08:00
@observable columnsPermissionData = [];
2022-11-08 15:56:34 +08:00
@observable selectedKey = "0";
2022-11-09 14:03:32 +08:00
@observable authorized = true;
2022-11-07 16:35:58 +08:00
@observable loading = true;
@observable tabOneRelatedData = {
2022-11-08 15:56:34 +08:00
datas: [], //datas受控
columns: [],
2022-11-07 16:35:58 +08:00
loading: true
};
@observable tabTwoRelatedData = {
datas: [], //datas受控
columns: [],
loading: true,
selectedData: {}, //selectedData受控
2022-11-08 15:56:34 +08:00
authorized: false
2022-11-07 16:35:58 +08:00
};
@computed get checkedItems() {
2022-11-09 14:03:32 +08:00
const data = isEmpty(this.columnsPermissionData) ? toJS(this.tableStore.datas) : this.columnsPermissionData;
return this.arrColumnsToJson(data);
2022-11-07 16:35:58 +08:00
}
@computed get tabTwoSaveParams() {
let datas = this.tabTwoRelatedData.datas;
let selectedData = this.tabTwoRelatedData.selectedData.isused;
let params = this.arrToJson(toJS(datas), toJS(selectedData));
params.rownum = datas.length;
return params;
}
@action
getRight() {
2022-11-08 15:56:34 +08:00
Api.hasRight().then(res => {
let { code, data, msg } = res;
const { hasRight } = data;
if (code === 200) {
this.setRight(hasRight);
2022-11-07 16:35:58 +08:00
} else {
2022-11-08 15:56:34 +08:00
message.error(msg);
2022-11-07 16:35:58 +08:00
}
}).catch(error => {
message.error(error);
});
}
loadTabOneRelatedData() {
this.tabOneRelatedData.loading = true;
Promise.all(
[
2022-11-08 15:56:34 +08:00
Api.getTable()
2022-11-07 16:35:58 +08:00
]
2022-11-08 17:43:26 +08:00
).then(([res]) => {
if (res.code === 200) {
res.data.datas && this.tableStore.getDatas(res.data.datas, 1);
} else {
message.warning(res.msg);
}
2022-11-07 16:35:58 +08:00
}).catch(error => {
message.error(error);
});
}
loadTabTwoRelatedData() {
this.tabTwoRelatedData.loading = true;
Promise.all(
[
2022-11-08 15:56:34 +08:00
Api.getTableEdit()
2022-11-07 16:35:58 +08:00
]
).then(res => {
res.map((rs, index) => {
if (index == 0) {
let {
api_status,
datas,
columns,
selectedData
} = rs;
if (api_status) {
if (!columns || !datas) {
this.tabTwoRelatedData.authorized = false;
return;
}
this.tabTwoRelatedData.authorized = true;
columns.map((c, index) => {
2022-11-08 15:56:34 +08:00
if (c.key === "itemurl") {
2022-11-07 16:35:58 +08:00
c.title = <span>
<span>{c.title}</span>
2022-11-08 15:56:34 +08:00
<span style={{ marginLeft: 10 }}>
<WeaHelpfulTip
ecId={`${this && this.props && this.props.ecId || ""}_WeaHelpfulTip@4vdvfp@${index}`}
title="自定义页面链接地址可以为外网地址http://www.baidu.com
2022-11-07 16:35:58 +08:00
也可以是内部地址/test.jsp可以带上参数传参像这样/test.jsp?a=1&b=2
也可以写占位符{#id}传人员id像这样/test.jsp?a=1&b={#id}&mypara2={#id}
2022-11-08 15:56:34 +08:00
即使不写占位符默认也会收到1个固定的参数hrmResourceID=人员id"/>
2022-11-07 16:35:58 +08:00
</span>
2022-11-08 15:56:34 +08:00
</span>;
} else if (c.key === "itemnum") {
2022-11-07 16:35:58 +08:00
c.title = <span>
<span>{c.title}</span>
2022-11-08 15:56:34 +08:00
<span style={{ marginLeft: 10 }}>
<WeaHelpfulTip
ecId={`${this && this.props && this.props.ecId || ""}_WeaHelpfulTip@wotuuk@${index}`}
title="填写类的全路径例如com.engine.hrm.cmd.hrmcarditem.GetTabNumDemoCmd,类中包含execute方法返回int型数据
填写不正确的路径并启用对应tab页title将会出现error字样"/>
2022-11-07 16:35:58 +08:00
</span>
2022-11-08 15:56:34 +08:00
</span>;
2022-11-07 16:35:58 +08:00
}
});
extendObservable(this.tabTwoRelatedData, {
datas: datas,
columns: columns
});
selectedData && extendObservable(this.tabTwoRelatedData, {
selectedData: selectedData
});
extendObservable(this.tabTwoRelatedData, {
loading: false
});
} else {
message.error(rs.message);
}
}
});
}).catch(error => {
message.error(error);
});
}
columnPermissionSave() {
let params = {
2022-11-09 14:03:32 +08:00
...toJS(this.checkedItems)
2022-11-08 15:56:34 +08:00
};
2022-11-09 14:03:32 +08:00
Api.cardAccessSave(params).then(res => {
console.log(res);
// let {
// api_status,
// sign
// } = res;
//
// if (api_status) {
// if (sign == "1") {
// res.message && message.success(res.message);
// } else {
// res.message && message.warning(res.message);
// }
// } else {
// message.error(res.message);
// }
2022-11-07 16:35:58 +08:00
}).catch(error => {
message.error(error);
});
}
userDefineCardItemSave() {
if (!this.verify(toJS(this.tabTwoRelatedData.datas))) return;
let params = this.tabTwoSaveParams;
Api.userDefineCardItemSave(params).then(res => {
let {
api_status,
2022-11-08 15:56:34 +08:00
sign
2022-11-07 16:35:58 +08:00
} = res;
if (api_status) {
2022-11-08 15:56:34 +08:00
if (sign == "1") {
2022-11-07 16:35:58 +08:00
res.message && message.success(res.message);
} else {
res.message && message.warning(res.message);
}
} else {
message.error(res.message);
}
}).catch(error => {
message.error(error);
});
}
2022-11-09 14:03:32 +08:00
arrColumnsToJson(arr, rows) {
let jsonColumn = {};
arr.map((item, index) => {
for (let key in item) {
jsonColumn[key + "_" + index] = item[key];
}
});
return jsonColumn;
}
2022-11-07 16:35:58 +08:00
arrToJson(arr, rows) {
let json = {};
const _rows = isEmpty(arr) ? [] : rows;
_rows && _rows.map(index => {
2022-11-08 15:56:34 +08:00
arr[index].isused = "1";
2022-11-07 16:35:58 +08:00
});
arr.map((item, index) => {
2022-11-08 15:56:34 +08:00
if (!item.isused) item.isused = "0";
2022-11-07 16:35:58 +08:00
for (let key in item) {
2022-11-08 15:56:34 +08:00
json[key + "_" + index] = item[key];
2022-11-07 16:35:58 +08:00
}
2022-11-08 15:56:34 +08:00
});
2022-11-07 16:35:58 +08:00
return json;
}
verify(arr) {
for (let i = 0; i < arr.length; i++) {
if (!arr[i].itemname || !arr[i].itemurl) {
2022-11-08 15:56:34 +08:00
const temp = i18n.message.requiredInfoIsNotFull().replace("{param}", i + 1);
2022-11-07 16:35:58 +08:00
message.warning(temp);
return false;
}
}
return true;
}
setRight(right) {
this.authorized = right;
}
setSelectedKey(key) {
this.selectedKey = key;
}
2022-11-09 14:03:32 +08:00
setColumnsPermissionData(list) {
this.columnsPermissionData = list;
2022-11-07 16:35:58 +08:00
}
}