trunk/pc4mobx/organization/stores/columnPermission.js

247 lines
6.8 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import * as mobx from "mobx";
import { action, computed, extendObservable, observable } from "mobx";
import { WeaTableNew } from "comsMobx";
import { message } from "antd";
import { WeaHelpfulTip } from "ecCom";
import { isEmpty } from "lodash";
import { i18n } from "../public/i18n";
import * as Api from "../apis/columnPermission";
const { TableStore } = WeaTableNew;
const toJS = mobx.toJS;
export class ColumnPermission {
@observable tableStore = new TableStore();
@observable columnsPermissionData = [];
@observable selectedKey = "0";
@observable authorized = true;
@observable loading = true;
@observable tabOneRelatedData = {
datas: [], //datas受控
columns: [],
loading: true
};
@observable tabTwoRelatedData = {
datas: [], //datas受控
columns: [],
loading: true,
selectedData: {}, //selectedData受控
authorized: false
};
@computed get checkedItems() {
const data = isEmpty(this.columnsPermissionData) ? toJS(this.tableStore.datas) : this.columnsPermissionData;
return this.arrColumnsToJson(data);
}
@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() {
Api.hasRight().then(res => {
let { code, data, msg } = res;
const { hasRight } = data;
if (code === 200) {
this.setRight(hasRight);
} else {
message.error(msg);
}
}).catch(error => {
message.error(error);
});
}
loadTabOneRelatedData() {
this.tabOneRelatedData.loading = true;
Promise.all(
[
Api.getTable()
]
).then(([res]) => {
if (res.code === 200) {
res.data.datas && this.tableStore.getDatas(res.data.datas, 1);
} else {
message.warning(res.msg);
}
}).catch(error => {
message.error(error);
});
}
loadTabTwoRelatedData() {
this.tabTwoRelatedData.loading = true;
Promise.all(
[
Api.getTableEdit()
]
).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) => {
if (c.key === "itemurl") {
c.title = <span>
<span>{c.title}</span>
<span style={{ marginLeft: 10 }}>
<WeaHelpfulTip
ecId={`${this && this.props && this.props.ecId || ""}_WeaHelpfulTip@4vdvfp@${index}`}
title="自定义页面链接地址可以为外网地址http://www.baidu.com
也可以是内部地址,如:/test.jsp可以带上参数传参像这样/test.jsp?a=1&b=2
也可以写占位符{#id}传人员id像这样/test.jsp?a=1&b={#id}&mypara2={#id}
即使不写占位符默认也会收到1个固定的参数hrmResourceID=人员id"/>
</span>
</span>;
} else if (c.key === "itemnum") {
c.title = <span>
<span>{c.title}</span>
<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字样。"/>
</span>
</span>;
}
});
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 = {
...toJS(this.checkedItems)
};
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);
// }
}).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,
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);
}
}).catch(error => {
message.error(error);
});
}
arrColumnsToJson(arr, rows) {
let jsonColumn = {};
arr.map((item, index) => {
for (let key in item) {
jsonColumn[key + "_" + index] = item[key];
}
});
return jsonColumn;
}
arrToJson(arr, rows) {
let json = {};
const _rows = isEmpty(arr) ? [] : rows;
_rows && _rows.map(index => {
arr[index].isused = "1";
});
arr.map((item, index) => {
if (!item.isused) item.isused = "0";
for (let key in item) {
json[key + "_" + index] = item[key];
}
});
return json;
}
verify(arr) {
for (let i = 0; i < arr.length; i++) {
if (!arr[i].itemname || !arr[i].itemurl) {
const temp = i18n.message.requiredInfoIsNotFull().replace("{param}", i + 1);
message.warning(temp);
return false;
}
}
return true;
}
setRight(right) {
this.authorized = right;
}
setSelectedKey(key) {
this.selectedKey = key;
}
setColumnsPermissionData(list) {
this.columnsPermissionData = list;
}
}