PortalDataSensitiveManager.vue
16.5 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
<template>
<div class="fullheight">
<ht-table
@load="loadData"
:data="data"
:pageResult="pageResult"
:selection="true"
quick-search-props="dataSourceAlias,tableName"
:show-export="false"
:show-custom-column="false"
ref="htTable"
@row-click="rowClick"
@selection-change="handleSelectionChange"
>
<template v-slot:toolbar>
<!-- <el-button-group> -->
<el-button size="small" @click="showDialog()" icon="el-icon-plus" type="primary">添加</el-button>
<ht-delete-button style="margin-left:10;" url="${portal}/portal/portalDataSensitive/v1/remove" :htTable="$refs.htTable" :disabled="isDisabled">删除</ht-delete-button>
<!-- </el-button-group> -->
</template>
<template>
<ht-table-column type="index" width="50" align="center" label="序号" />
<ht-table-column prop="tableName" label="表名" :sortable="true" :show-overflow-tooltip="true">
<template v-slot="{row}">
<el-link type="primary" @click="showDialog(row.id)" title="查看详情">{{row.tableName}}</el-link>
</template>
</ht-table-column>
<ht-table-column prop="reulesRemark" label="脱敏规则说明" :sortable="true" :show-overflow-tooltip="true">
</ht-table-column>
</template>
</ht-table>
<el-dialog
width="1240px"
title="表字段脱敏处理"
class="sp-manager__dialog"
:visible="dialogVisible"
:before-close="beforeCloseDialog"
:close-on-click-modal="false"
>
<el-form v-if="dialogVisible" v-form data-vv-scope="portalDataSensitiveForm" @submit.native.prevent>
<ht-form-item label="表名">
<template slot="label">
<el-tooltip
content="数据库表名,小写,如果是建模生成的实体则为w_ + 实体名称 如: w_userinfo"
>
<i class="property-tip icon-question" />
</el-tooltip>
<span>表名</span>
</template>
<ht-input v-model="portalDataSensitive.tableName" validate="required|alpha_dash" :maxlength="20"
show-word-limit/>
<span style="color:red">注:表名为已经存在数据库中的表名,表名不存在配置无法生效</span>
</ht-form-item>
<ht-form-item label="脱敏规则">
<el-table :data="desensitizationRulesArr" style="width: 100%">
<el-table-column prop="fieldName" label width="230">
<template slot="header">
<el-button
type="primary"
size="mini"
icon="el-icon-plus"
circle
@click="addField"
title="添加"
></el-button><span class="is-required">字段</span>
<el-tooltip content="数据库表的字段,忽略大小写,如果是建模生成的则为F_ + 字段名称,如: F_mobile" placement="right">
<i class="icon-question" style="margin-right: 8px" />
</el-tooltip>
</template>
<template slot-scope="scope">
<ht-input
v-model="scope.row.fieldName"
autocomplete="off"
validate="required"
placeholder="字段"
:maxlength="20"
show-word-limit
></ht-input>
</template>
</el-table-column>
<el-table-column prop="fieldName" label width="230">
<template slot="header">
<span class="is-required">掩码处理方式</span>
</template>
<template slot-scope="scope">
<ht-select v-model="scope.row.calType"
autocomplete="off"
validate="required"
:options="[{key:'1',value:'掩码规则'},{key:'2',value:'自定义'}]"
placeholder="请选择"></ht-select>
</template>
</el-table-column>
<el-table-column prop="rules" label width="350" >
<template slot="header">
<span class="is-required">掩码规则</span>
<el-tooltip content="掩码规则,将该字段的开始位置到结束位置的根据填字符替换" placement="right">
<i class="icon-question" style="margin-right: 8px" />
</el-tooltip>
</template>
<template slot-scope="scope">
<el-form :inline="true" class="demo-form-inline" style="margin-top:13px" v-show="scope.row.calType=='1'">
<el-form-item>
<el-tooltip content="掩码开始位置" placement="top">
<ht-input
type="number"
v-model="scope.row.rules.startPosition"
autocomplete="off"
:min=1
:validate="{required:true,between:[1,scope.row.rules.endPosition],}"
placeholder="开始位置"
></ht-input>
</el-tooltip>
</el-form-item>
<el-form-item>
<el-tooltip content="掩码结束位置" placement="top">
<ht-input
type="number"
v-model="scope.row.rules.endPosition"
autocomplete="off"
:min=1
validate="required"
placeholder="结束位置"
></ht-input>
</el-tooltip>
</el-form-item>
<el-form-item>
<el-tooltip content="掩码填充符" placement="top">
<ht-select v-model="scope.row.rules.pad"
autocomplete="off"
:options="[{key:'*',value:'*'},{key:'_',value:'_'},{key:'.',value:'.'},{key:'#',value:'#'}]"
placeholder="填充字符默认为*" />
</el-tooltip>
</el-form-item>
</el-form>
</template>
</el-table-column>
<el-table-column prop="groovyScript" label width="130">
<template slot="header">
<span class="is-required">自定义脚本</span>
<el-tooltip content="自定义脚本处理当前字段的掩码规则如:com.hotent.base.util.StringUtil.wordMask(F_sjhm, 1, 5, '#') F_sjhm为字段名" placement="right">
<i class="icon-question" style="margin-right: 8px" />
</el-tooltip>
</template>
<template slot-scope="scope">
<div v-show="scope.row.calType=='2'">
<ht-input style="width: 100%" type="textarea" v-model="scope.row.groovyScript" ></ht-input>
</div>
</template>
</el-table-column>
<el-table-column prop="rights" label width="230">
<template slot="header">
<span>白名单</span>
</template>
<template v-slot="{ row, $index }">
<el-table :data="row.rights">
<el-table-column prop="title">
<template slot="header">
<el-button
type="primary"
size="mini"
icon="el-icon-plus"
@click="showAuthDialog(row.rights,$index)"
>选择</el-button
>
</template>
</el-table-column>
<el-table-column prop="name" label="授权给">
</el-table-column>
<el-table-column width="50">
<template slot-scope="scope">
<el-button
type="text"
@click="row.rights.remove(row.rights[scope.$index])"
>删除</el-button>
</template>
</el-table-column>
</el-table>
</template>
</el-table-column>
<el-table-column label="操作" width="80">
<template v-slot="{ $index }">
<el-button
type="danger"
icon="el-icon-delete"
circle
@click="desensitizationRulesArr.remove(desensitizationRulesArr[$index])"
></el-button>
</template>
</el-table-column>
</el-table>
</ht-form-item>
<ht-form-item label="脱敏说明">
<ht-input type="textarea" v-model="portalDataSensitive.reulesRemark" validate="required" :show-word-limit="true" :maxlength="200" style="width:100%"/>
</ht-form-item>
</el-form>
<div slot="footer" style="text-align: right">
<!-- <ht-submit-button-->
<!-- url="${portal}/portal/portalDataSensitive/v1/save"-->
<!-- :model="saveData"-->
<!-- scope-name="portalDataSensitiveForm"-->
<!-- :is-submit="isSubmit"-->
<!-- @before-save-data="beforeSaveData"-->
<!-- @after-save-data="afterSaveData"-->
<!-- >{{$t("eip.common.save")}}</ht-submit-button>-->
<el-button @click="beforeCloseDialog">{{$t("eip.common.cancel")}}</el-button>
<el-button @click="save" type="primary">{{$t("eip.common.save")}}</el-button>
</div>
</el-dialog>
<!-- 选择对话框 -->
<eip-auth-dialog
ref="eipAuthDialog"
name="eipAuthDialog"
@onConfirm="dialogOnConfirm"
append-to-body
/>
</div>
</template>
<script>
const eipAuthDialog = () => import("@/components/dialog/EipAuthDialog.vue");
import utils from "@/hotent-ui-util.js"
import deepmerge from "deepmerge";
export default {
components: {
eipAuthDialog
},
data() {
return {
isDisabled:true,
dialogVisible: false,
data: [],
isSubmit:true,
currentIndex:0,
pageResult: {
page: 1,
pageSize: 50,
total: 0
},
portalDataSensitive: {dataSourceAlias:"local"},
desensitizationRulesArr:[],
saveData:{},
selectedList: []
};
},
watch: {
selectedList:{
handler(val){
this.isDisabled = val.length < 1 ? true : false
},
deep:true
}
},
mounted() {
this.$validator = this.$root.$validator;
},
methods: {
handleSelectionChange(selection) {
this.selectedList = selection
},
rowClick(row, column, event){
this.$refs.htTable.$refs.htTable.toggleRowSelection(row);
},
addField() {
let obj = {
"fieldName": "",
"rules": {
"pad": "*"
},
"groovyScript": "",
"rights": []
};
this.$nextTick(()=>{
this.desensitizationRulesArr.push(obj);
});
},
async beforeSaveData() {
this.saveData = deepmerge({}, this.portalDataSensitive, {
clone: true
});
this.isSubmit = true;
if(!this.saveData.tableName){
this.$message.warning("表名必填");
this.isSubmit = false;
return
}
if(this.desensitizationRulesArr.length == 0){
this.$message.warning("脱敏规则必填");
this.isSubmit = false;
return
}
if(!this.saveData.reulesRemark){
this.$message.warning("脱敏说明必填");
this.isSubmit = false;
return
}
try {
this.desensitizationRulesArr.forEach(item=>{
if(!item.fieldName){
this.$message.warning("掩码字段必填");
this.isSubmit = false;
throw('')
}
if(!item.calType){
this.$message.warning("掩码方式必填");
this.isSubmit = false;
throw('')
}
if(item.calType==2 && !item.groovyScript ){
this.$message.warning("掩码方式为自定义时,脚本必填");
this.isSubmit = false;
throw('')
}
if(item.rules.endPosition < item.rules.startPosition){
this.$message.warning(`掩码结束${item.rules.endPosition}不能小于掩码开始${item.rules.startPosition}`);
this.isSubmit = false;
throw('')
}
if(item.calType==1 && !item.rules.pad ){
this.$message.warning("掩码方式为掩码规则时,填充符必填");
this.isSubmit = false;
throw('')
}
item.rights = JSON.stringify(item.rights);
item.rules = JSON.stringify(item.rules);
});
} catch(e) {
console.log('e: ', e)
}
this.saveData.desensitizationRules = JSON.stringify(this.desensitizationRulesArr);
},
showAuthDialog(rightsArr,currentIndex) {
this.currentIndex = currentIndex;
let conf = {
right: [],
permissionList: [
{ type: "everyone", title: "所有人" },
{ type: "user", title: "用户" },
{ type: "org", title: "组织" },
{ type: "pos", title: "岗位" },
{ type: "role", title: "角色" }
]
};
conf.right = rightsArr||[];
this.$refs.eipAuthDialog.showDialog(conf);
},
dialogOnConfirm(data, name) {
if (name == "eipAuthDialog") {
this.desensitizationRulesArr[this.currentIndex].rights = data;
}
},
showDialog(id) {
if (id) {
this.$http.get("${portal}/portal/portalDataSensitive/v1/getJson?id="+`${id}`).then(resp => {
this.portalDataSensitive = resp.data;
this.desensitizationRulesArr = JSON.parse(this.portalDataSensitive.desensitizationRules);
this.desensitizationRulesArr.forEach(element => {
element.rules = JSON.parse(element.rules);
element.rights = JSON.parse(element.rights);
});
this.dialogVisible = true;
}, error => {
reject(error);
})
} else {
this.dialogVisible = true;
}
},
beforeCloseDialog() {
this.portalDataSensitive = {dataSourceAlias:"local",calType:"1"};
this.desensitizationRulesArr = [];
this.dialogVisible = false;
},
loadData(param, cb) {
this.$http.post("${portal}/portal/portalDataSensitive/v1/listJson", param).then(resp => {
let response = resp.data;
this.data = response.rows;
this.pageResult = {
page: response.page,
pageSize: response.pageSize,
total: response.total
};
}, error => {
reject(error);
}).finally(() => cb());
},
afterSaveData(resp) {
setTimeout(() => {
if (resp.data.state) {
this.$message.success(resp.data.message);
}
this.beforeCloseDialog();
this.$refs.htTable.load();
}, 500);
},
save() {
this.beforeSaveData();
if(!this.isSubmit){
return
}
utils.validateForm(this, 'portalDataSensitiveForm').then(r => {
if (this.saveData.id) {
this.$http.post(`${window.context.portal}/portal/portalDataSensitive/v1/save`, this.saveData).then(resp => {
this.afterSaveData(resp);
})
}else {
this.$http.get(`${window.context.portal}/portal/portalDataSensitive/v1/getByTableName/${this.saveData.tableName}`).then(resp => {
if (resp.data) {
this.$confirm("已存在表为【"+this.saveData.tableName+"】的配置,是否覆盖?").then(() => {
this.saveData.id = resp.data.id;
this.$http.post(`${window.context.portal}/portal/portalDataSensitive/v1/save`, this.saveData).then(resp => {
this.afterSaveData(resp);
})
}).catch(() => {
this.beforeCloseDialog();
})
}else {
this.$http.post(`${window.context.portal}/portal/portalDataSensitive/v1/save`, this.saveData).then(resp => {
this.afterSaveData(resp);
})
}
})
}
})
}
}
};
</script>
<style lang="scss" scoped>
.sp-manager__dialog /deep/ > .el-dialog > .el-dialog__body {
height: calc(100% - 170px);
}
.sp-manager__dialog /deep/ .demo-form-inline .el-input-number--small{
width: 106px;
}
.sp-manager__dialog /deep/ .demo-form-inline .el-input--small{
width: 106px;
}
.sp-manager__dialog /deep/ .demo-form-inline .el-form-item{
margin-right:0px;
}
.demo-form-inline{
display: flex;
div{
width: 110px;
}
}
</style>