|
@@ -21,6 +21,10 @@ module.exports = app => {
|
|
|
constructor(ctx) {
|
|
|
super(ctx);
|
|
|
this.tableName = 'sub_project_permission';
|
|
|
+ this._definePermission();
|
|
|
+ }
|
|
|
+
|
|
|
+ _definePermission() {
|
|
|
this.PermissionConst = {
|
|
|
budget: {
|
|
|
view: { title: '查看', value: 1 },
|
|
@@ -34,8 +38,63 @@ module.exports = app => {
|
|
|
},
|
|
|
manage: {
|
|
|
rela: { title: '关联标段', value: 1 },
|
|
|
- }
|
|
|
+ },
|
|
|
+ info: {
|
|
|
+ view: { title: '查看', value: 1},
|
|
|
+ edit: { title: '编辑', value: 2 },
|
|
|
+ },
|
|
|
+ datacollect: {
|
|
|
+ view: { title: '查看', value: 1},
|
|
|
+ },
|
|
|
+ contract: {
|
|
|
+ edit: { title: '编辑节点', value: 1 },
|
|
|
+ add: { title: '添加合同', value: 2 },
|
|
|
+ node: { title: '授权查看本节点合同', value: 3 },
|
|
|
+ unit: { title: '授权查看本单位合同', value: 4 },
|
|
|
+
|
|
|
+ },
|
|
|
+ fund_trans: {
|
|
|
+ view: { title: '查看', value: 1 },
|
|
|
+ add: { title: '新建划拨', value: 2 },
|
|
|
+ att: { title: '上传附件', value: 3 },
|
|
|
+ },
|
|
|
+ fund_pay: {
|
|
|
+ view: { title: '查看', value: 1 },
|
|
|
+ att: { title: '上传附件', value: 3 },
|
|
|
+ },
|
|
|
};
|
|
|
+ this.PermissionBlock = [
|
|
|
+ { key: 'datacollect', name: '决策大屏', field: 'datacollect_permission' },
|
|
|
+ { key: 'info', name: '项目概况', field: 'info_permission' },
|
|
|
+ { key: 'contract', name: '合同管理', field: 'contract_permission', hint: ['1、编辑节点:编辑合同管理内页树结构', '2、添加合同:允许添加合同', '3、授权查看本节点合同:授权节点下查看所有人上传的合同', '4、授权查看本单位合同:授权节点下查看本单位人员添加的所有合同'] },
|
|
|
+ { key: 'file', name: '资料归集', field: 'file_permission' },
|
|
|
+ { key: 'budget', name: '动态投资', field: 'budget_permission' },
|
|
|
+ {
|
|
|
+ key: 'financial', name: '资金监管', children: [
|
|
|
+ { key: 'fund_trans', name: '资金划拨', field: 'fund_trans_permission' },
|
|
|
+ { key: 'fund_pay', name: '资金支付', field: 'fund_pay_permission' },
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ ];
|
|
|
+ for (const p of this.PermissionBlock) {
|
|
|
+ if (p.children) {
|
|
|
+ for (const c of p.children) {
|
|
|
+ c.permission = [];
|
|
|
+ const pConst = this.PermissionConst[c.key];
|
|
|
+ if (!pConst) continue;
|
|
|
+ for (const prop in pConst) {
|
|
|
+ c.permission.push({ key: prop, ...pConst[prop]});
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ p.permission = [];
|
|
|
+ const pConst = this.PermissionConst[p.key];
|
|
|
+ if (!pConst) continue;
|
|
|
+ for (const prop in pConst) {
|
|
|
+ p.permission.push({ key: prop, ...pConst[prop]});
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
get adminPermission () {
|
|
@@ -144,6 +203,53 @@ module.exports = app => {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ async _addUser(subProject, data) {
|
|
|
+ const ids = data instanceof Array ? data : [data];
|
|
|
+ const exists = await this.getAllDataByCondition({ where: { spid: subProject.id, uid: ids } });
|
|
|
+ if (exists.length > 0) throw '请勿重复选择账号';
|
|
|
+
|
|
|
+ const insertData = ids.map(x => {
|
|
|
+ return { id: this.uuid.v4(), spid: subProject.id, pid: subProject.project_id, uid: x };
|
|
|
+ });
|
|
|
+ await this.db.insert(this.tableName, insertData);
|
|
|
+ return insertData;
|
|
|
+ }
|
|
|
+
|
|
|
+ async _delUser(subProject, data) {
|
|
|
+ const ids = data instanceof Array ? data : [data];
|
|
|
+ const permissions = await this.getAllDataByCondition({ where: { spid: subProject.id, uid: ids } });
|
|
|
+ await this.db.delete(this.tableName, { id: permissions.map(x => { return x.id; }) });
|
|
|
+ return data;
|
|
|
+ }
|
|
|
+
|
|
|
+ async _updateUserPermission(data) {
|
|
|
+ const datas = data instanceof Array ? data : [data];
|
|
|
+ const updateData = [];
|
|
|
+ datas.forEach(x => {
|
|
|
+ const ud = { id: x.id };
|
|
|
+ for (const p of this.PermissionBlock) {
|
|
|
+ if (p.children) {
|
|
|
+ for (const c of p.children) {
|
|
|
+ if (data[c.field] !== undefined) ud[c.field] = x[c.field] || '';
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (data[p.field] !== undefined) ud[p.field] = x[p.field] || '';
|
|
|
+ }
|
|
|
+ }
|
|
|
+ updateData.push(ud);
|
|
|
+ });
|
|
|
+ await this.db.updateRows(this.tableName, updateData);
|
|
|
+ return updateData;
|
|
|
+ }
|
|
|
+
|
|
|
+ async updatePermission(subProject, data) {
|
|
|
+ const result = {};
|
|
|
+ if (data.add) result.add = await this._addUser(subProject, data.add);
|
|
|
+ if (data.del) result.del = await this._delUser(subProject, data.del);
|
|
|
+ if (data.update) result.update = await this._updateUserPermission(data.update);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
async getFilingType(subProjectId) {
|
|
|
const permissionConst = {}, prefix = 'f';
|
|
|
for (const p in this.PermissionConst.file) {
|