productSpaceEdit.vue
18.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
<template>
<div class="container_wrap full" v-loading="fullscreenLoading">
<div class="content_main">
<ContentWrap id="id-baseInfo" title="逻辑空间信息" description="" :isExpand="baseInfoExpand" :expand-swicth="true"
class="mb16" @expand="(v) => baseInfoExpand = v">
<Form ref="baseInfoFormRef" :itemList="baseInfoFormItems" formId="base-info-form" :rules="baseInfoFormRules"
col="col3" />
<el-tabs v-model="activeTabName" class="param-tabs">
<el-tab-pane label="成员权限" name="member">
<Table ref="memberTableRef" :tableInfo="memberTableInfo" class="fiveRow-table" />
<div class="row-add-btn">
<el-button link @click="addMember" :icon="CirclePlus" v-preReClick>添加</el-button>
</div>
</el-tab-pane>
<el-tab-pane label="策略配置" name="strategy">
<StrategyTable ref="strategyTableRef" :value="detailInfo.policyRSVOS || []"
:operatorOptionList="operatorOptionList" :actionOptionsList="actionOptionsList"
:constraintOptionsList="constraintOptionsList"></StrategyTable>
</el-tab-pane>
</el-tabs>
</ContentWrap>
<!-- 可信空间需要显示 -->
<!-- <ContentWrap id="id-approveInfo" title="流程审批" expandSwicth style="margin-top: 15px" :isExpand="expandApprove"
@expand="(v) => expandApprove = v">
<ApprovalProcess ref="approvalProcessRef" v-if="deploymentId" :deploymentId="deploymentId"
:processInstanceId="processInstanceId">
</ApprovalProcess>
</ContentWrap> -->
</div>
<div class="bottom_tool_wrap">
<el-button @click="cancel">取消</el-button>
<el-button v-show="detailInfo.bizApproveState !== 'Y' && detailInfo.bizApproveState !== 'C' && detailInfo.bizApproveState !== 'R'" @click="save" v-preReClick>保存草稿</el-button>
<el-button type="primary" @click="submit" v-preReClick>提交</el-button>
</div>
</div>
</template>
<script lang="ts" setup name="productSpaceEdit">
import { CirclePlus } from "@element-plus/icons-vue";
import { getCamundaDeploymentId } from "@/api/modules/workFlowService";
import {
getParamsList
} from "@/api/modules/queryService";
import {
getActionPolicyList,
getConstraintPolicyList,
getContractTenantListExcludeSelf
} from "@/api/modules/dataSmartContract"
import useUserStore from "@/store/modules/user";
import useDataProductSpaceStore from "@/store/modules/productSpace";
import { useValidator } from '@/hooks/useValidator';
import { TableColumnWidth } from "@/utils/enum";
import { scrollLastRowToView } from "@/utils/common";
import StrategyTable from "../data_smart_contract/components/strategyTable.vue";
import { getLogicSpaceDetail, saveLogicSpace, updateLogicSpace, updateLogicSpaceMember } from "@/api/modules/dataAsset";
const { required } = useValidator();
const { proxy } = getCurrentInstance() as any;
const userStore = useUserStore();
const productSpaceStore = useDataProductSpaceStore();
const route = useRoute();
const router = useRouter();
const userData = JSON.parse(localStorage.userData);
const fullPath = route.fullPath;
const detailInfo: any = ref({});
const fullscreenLoading = ref(false);
const baseInfoExpand = ref(true);
const expandApprove = ref(true);
/** 约束运算符字典下拉 */
const operatorOptionList: any = ref([]);
/** 约束行为下拉列表 */
const constraintOptionsList: any = ref([]);
/** 策略操作行为下拉列表 */
const actionOptionsList: any = ref([]);
/** 页签当前活跃的有成员权限和策略配置 */
const activeTabName = ref('member');
const deploymentId = ref('');
const processInstanceId = ref('');
/** 策略表格组件引用 */
const strategyTableRef = ref();
const baseInfoFormRef = ref();
const domainDictList: any = ref([]);
const baseInfoFormItems = ref([
{
label: '逻辑空间名称',
type: 'input',
placeholder: '请输入',
field: 'spaceName',
maxlength: 50,
default: '',
clearable: true,
required: true
},
{
label: '所属领域',
type: 'select',
placeholder: '请选择',
field: 'domain',
default: '003',
options: domainDictList.value,
props: {
value: 'value',
label: 'label',
children: 'children'
},
required: true,
filterable: true,
clearable: true,
visible: true
},
{
label: '创建企业',
type: 'input',
placeholder: '请输入',
field: 'tenantName',
default: userData.tenantName,
required: true,
disabled: true
},
{
label: '是否开启',
type: 'switch',
field: 'isActivate',
default: 'Y',
placeholder: '请选择',
activeValue: 'Y',
inactiveValue: 'N',
required: true,
switchWidth: 32,
},
{
label: '逻辑空间描述',
type: 'textarea',
placeholder: '该逻辑空间主要为医疗机构的数据产品,限制了数据产品以及只有进行查看操作。参与方为某某医药企业、某某医疗机构以及运营方。',
field: 'spaceDescription',
default: '',
block: true,
maxlength: 500,
clearable: true,
required: true,
},
])
const baseInfoFormRules = ref({
spaceName: [required('请输入逻辑空间名称')],
domain: [required('请选择所属领域')],
spaceDescription: [required('请输入逻辑空间描述')]
})
const cancel = () => {
proxy.$openMessageBox("当前页面尚未保存,确定放弃修改吗?", () => {
userStore.setTabbar(userStore.tabbar.filter((tab: any) => tab.fullPath !== fullPath));
router.push({
name: 'productSpaceManage'
});
}, () => {
proxy.$ElMessage.info("已取消");
});
}
const memberTenantList: any = ref([]);
const roleTypeList: any = ref([{
value: '1',
label: '数据使用方'
}, {
value: '2',
label: '数据提供方'
}]);
/** 对表格组件的引用 */
const memberTableRef = ref();
/** 成员权限表格 */
const memberTableData: any = ref([]);
/** 成员权限表格 */
const memberTableInfo = ref({
id: "input-params-table",
height: '214px',
fields: [
{ label: "序号", type: "index", width: TableColumnWidth.INDEX, align: "center" },
{ label: "成员名称", field: "memberGuid", width: 200, required: true, columClass: 'edit-colum', type: 'edit' },
{ label: "角色类型", field: "characterType", width: 160, required: true, columClass: 'edit-colum', type: 'edit' },
{ label: "描述", field: "description", width: 300, required: false, columClass: 'edit-colum', type: 'edit' },
],
editInfo: {
memberGuid: {
label: '',
type: 'select',
field: 'memberGuid',
default: '',
options: memberTenantList.value,
props: {
label: 'tenantName',
value: 'guid'
},
placeholder: '请选择',
clearable: true,
filterable: true
},
characterType: {
label: '',
type: 'select',
field: 'characterType',
default: '',
options: roleTypeList.value,
props: {
label: 'label',
value: 'value'
},
placeholder: '请选择',
clearable: true,
filterable: true
},
description: {
label: '',
type: 'input',
field: 'description',
default: '',
maxlength: 200,
placeholder: '请输入',
clearable: true,
}
},
STATUS: 'edit',
data: memberTableData.value,
showPage: false,
actionInfo: {
show: true,
label: "操作",
type: "btn",
width: 60,
fixed: 'right',
btns: [
{
label: "删除", value: "remove", click: (scope) => {
let index = scope.$index;
proxy.$openMessageBox("此操作将永久删除, 是否继续?", () => {
memberTableData.value.splice(index, 1);
memberTableInfo.value.data = memberTableData.value;
proxy.$ElMessage.success('参数删除成功');
}, () => {
proxy.$ElMessage.info("已取消");
});
}
},
]
},
loading: false
});
/** 给表格添加一行入参定义。 */
const addMember = () => {
memberTableData.value.push({ memberGuid: '', roleType: '', description: '' });
memberTableInfo.value.data = memberTableData.value;
nextTick(() => {
scrollLastRowToView(memberTableRef.value?.tableRef, memberTableData.value.length);
})
}
// 检查数据是否被修改
const checkIfModified = (formInline: any, policyRQVOS: any[]) => {
// 检查formInline中的字段
for (let key in formInline) {
if (formInline[key] !== detailInfo.value[key]) {
return true;
}
}
// 检查policyRQVOS
const originalPolicies = detailInfo.value?.policyRSVOS || [];
if (policyRQVOS.length !== originalPolicies.length) {
return true;
}
for (let i = 0; i < policyRQVOS.length; i++) {
const current = policyRQVOS[i];
const original = originalPolicies[i];
if (!original) {
return true;
}
// 比较策略数据的每个字段
for (let key in current) {
if (key !== 'childIndex' && key !== 'index' && key !== 'orderNum' && current[key] !== original[key]) {
return true;
}
}
}
// // 检查成员权限数据
// const currentMembers = memberTableInfo.value.data || [];
// const originalMembers = detailInfo.value?.permissionRSVOS || [];
// if (currentMembers.length !== originalMembers.length) {
// return true;
// }
// for (let i = 0; i < currentMembers.length; i++) {
// const current = currentMembers[i];
// const original = originalMembers[i];
// if (!original) {
// return true;
// }
// // 比较成员数据的每个字段
// for (let key in current) {
// if (current[key] !== original[key]) {
// return true;
// }
// }
// }
return false;
};
const save = () => {
// 保存不检验。
let formInline = baseInfoFormRef.value.formInline;
let params = { ...formInline };
if (!params.spaceName) {
proxy.$ElMessage.error('逻辑空间名称不能为空');
return;
}
params.permissionRQVOS = memberTableInfo.value.data || [];
params.policyRQVOS = strategyTableRef.value.strategyData?.map((d, index) => {
return Object.assign({}, d, { orderNum: index + 1 })
});
params.tenantGuid = userData.tenantGuid;
fullscreenLoading.value = true;
if (route.query.guid) {
params.guid = route.query.guid;
updateLogicSpace(params).then((res: any) => {
fullscreenLoading.value = false;
if (res?.code == proxy.$passCode) {
proxy.$ElMessage.success('编辑保存成功');
userStore.setTabbar(userStore.tabbar.filter((tab: any) => tab.fullPath !== fullPath));
router.push({
name: 'productSpaceManage'
});
productSpaceStore.setIsRefresh(true);
} else {
res?.msg && proxy.$ElMessage.error(res.msg);
}
})
} else {
saveLogicSpace(params).then((res: any) => {
fullscreenLoading.value = false;
if (res?.code == proxy.$passCode) {
proxy.$ElMessage.success('保存成功');
userStore.setTabbar(userStore.tabbar.filter((tab: any) => tab.fullPath !== fullPath));
router.push({
name: 'productSpaceManage'
});
productSpaceStore.setIsRefresh(true);
} else {
res?.msg && proxy.$ElMessage.error(res.msg);
}
})
}
}
const submit = () => {
baseInfoFormRef.value?.ruleFormRef?.validate().then((valid, errorItem) => {
if (valid) {
let formInline = baseInfoFormRef.value.formInline;
// for循环判断相同成员不能重复添加相同的角色类型,且每行数据的成员guid和角色类型不能出现为空的,若为空则提示。
for (let data of memberTableData.value) {
if (!data.memberGuid || !data.characterType) {
proxy.$ElMessage.error('成员名称和角色类型请填写完整');
activeTabName.value = 'member';
return;
}
let isExist = memberTableData.value.find((item: any) => data !== item && item.memberGuid == data.memberGuid && item.characterType == data.characterType);
if (isExist) {
proxy.$ElMessage.error('相同成员不能重复添加相同的角色类型');
activeTabName.value = 'member';
return;
}
}
let validate = strategyTableRef.value?.validateValue();
if (!validate) {
activeTabName.value = 'strategy';
return;
}
let params = { ...formInline };
params.permissionRQVOS = memberTableInfo.value.data || [];
params.policyRQVOS = strategyTableRef.value.strategyData?.map((d, index) => {
return Object.assign({}, d, { orderNum: index + 1 })
});
params.immediateApprove = true;
params.tenantGuid = userData.tenantGuid;
fullscreenLoading.value = true;
if (route.query.guid) {
params.guid = route.query.guid;
/** 需要判断是审批通过之后的编辑,若是只改成员信息,则不需要提交审批,只需要调用编辑即可。 */
if (detailInfo.value.bizApproveState != 'Y' || checkIfModified(formInline, params.policyRQVOS)) {
updateLogicSpace(params).then((res: any) => {
fullscreenLoading.value = false;
if (res?.code == proxy.$passCode) {
proxy.$ElMessage.success('编辑提交审批成功');
userStore.setTabbar(userStore.tabbar.filter((tab: any) => tab.fullPath !== fullPath));
router.push({
name: 'productSpaceManage'
});
productSpaceStore.setIsRefresh(true);
} else {
res?.msg && proxy.$ElMessage.error(res.msg);
}
})
} else {
// 未修改过基础信息,只修改成员,或者任何修改都没有时,直接调用提交成员
updateLogicSpaceMember(params).then((res: any) => {
fullscreenLoading.value = false;
if (res?.code == proxy.$passCode) {
proxy.$ElMessage.success('编辑提交成功');
userStore.setTabbar(userStore.tabbar.filter((tab: any) => tab.fullPath !== fullPath));
router.push({
name: 'productSpaceManage'
});
productSpaceStore.setIsRefresh(true);
} else {
res?.msg && proxy.$ElMessage.error(res.msg);
}
}).catch(() => {
fullscreenLoading.value = false;
});
}
} else {
saveLogicSpace(params).then((res: any) => {
fullscreenLoading.value = false;
if (res?.code == proxy.$passCode) {
proxy.$ElMessage.success('提交审批成功');
userStore.setTabbar(userStore.tabbar.filter((tab: any) => tab.fullPath !== fullPath));
router.push({
name: 'productSpaceManage'
});
productSpaceStore.setIsRefresh(true);
} else {
res?.msg && proxy.$ElMessage.error(res.msg);
}
})
}
} else {
var obj = Object.keys(errorItem);
baseInfoFormRef.value.ruleFormRef.scrollToField(obj[0]);
}
})
}
onActivated(() => {
let tab: any = userStore.tabbar.find((tab: any) => tab.fullPath == fullPath);
let name = route.query.name;
if (tab) {
tab.meta.title = route.query.guid ? `编辑-${name}` : '新增逻辑空间';
}
document.title = tab.meta.title;
})
onBeforeMount(() => {
// 可信空间需要
// getCamundaDeploymentId('10034', userData.tenantGuid, userData.staffGuid).then((res: any) => {
// if (res.code == proxy.$passCode) {
// deploymentId.value = res.data;
// } else {
// proxy.$ElMessage.error(res.msg);
// }
// })
if (route.query.guid) {
fullscreenLoading.value = true;
getLogicSpaceDetail({ guid: route.query.guid }).then((res: any) => {
fullscreenLoading.value = false;
if (res?.code == proxy.$passCode) {
detailInfo.value = res.data || {};
baseInfoFormItems.value.forEach((item: any) => {
item.default = detailInfo.value[item.field] || '';
})
memberTableData.value = detailInfo.value?.permissionRSVOS || [];
memberTableInfo.value.data = memberTableData.value;
strategyTableRef.value.strategyData = detailInfo.value?.policyRSVOS || [];
} else {
res?.msg && proxy.$ElMessage.error(res?.msg);
}
})
}
getParamsList({ dictType: '领域' }).then((res: any) => {
if (res?.code == proxy.$passCode) {
domainDictList.value = res.data || [];
let itemIndex = baseInfoFormItems.value.findIndex(item => item.field == 'domain');
let item = baseInfoFormItems.value[itemIndex];
item && (item.options = domainDictList.value);
} else {
res?.msg && proxy.$ElMessage.error(res?.msg);
}
});
getParamsList({ dictType: '约束运算符' }).then((res: any) => {
if (res?.code == proxy.$passCode) {
const data = res.data || [];
operatorOptionList.value = data;
} else {
res?.msg && proxy.$ElMessage.error(res?.msg);
}
})
getActionPolicyList().then((res: any) => {
if (res?.code == proxy.$passCode) {
const data = res.data || [];
actionOptionsList.value = data;
} else {
res?.msg && proxy.$ElMessage.error(res?.msg);
}
})
getConstraintPolicyList().then((res: any) => {
if (res?.code == proxy.$passCode) {
const data = res.data || [];
constraintOptionsList.value = data;
} else {
res?.msg && proxy.$ElMessage.error(res?.msg);
}
})
/** 获取可选择的成员下拉列表 */
getContractTenantListExcludeSelf().then((res: any) => {
if (res?.code == proxy.$passCode) {
memberTenantList.value = res.data || [];
memberTableInfo.value.editInfo.memberGuid.options = memberTenantList.value;
} else {
res?.msg && proxy.$ElMessage.error(res.msg);
}
})
})
</script>
<style lang="scss" scoped>
.content_main {
height: calc(100% - 40px);
padding: 16px;
overflow: hidden auto;
position: sticky;
}
.bottom_tool_wrap {
height: 40px;
padding: 0 16px;
border-top: 1px solid #d9d9d9;
display: flex;
justify-content: center;
align-items: center;
}
.row-add-btn {
.el-button--default {
padding: 4px 0px;
margin-top: 4px;
}
:deep(.el-icon) {
width: 16px;
height: 16px;
svg {
width: 16px;
height: 16px;
}
}
}
:deep(.el-tabs) {
margin-top: 0px;
.el-tabs__header {
margin-bottom: 8px;
}
.el-tabs__item {
height: 32px;
&:nth-child(2) {
padding-left: 16px;
}
}
}
</style>