BusinessObjCopyDialog.vue
9.22 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
<template>
<el-dialog
width="65%"
title="建模复制"
:visible="dialogVisible"
:before-close="handleClose"
:destroy-on-close="true"
append-to-body
:close-on-click-modal="false"
>
<form v-form data-vv-scope="saveCopyForm">
<table class="form-table" cellspacing="0" cellpadding="0" border="0">
<tbody>
<tr>
<th width="140px" class="text-center">模型描述</th>
<th width="140px" class="text-center">模型别名</th>
<th width="140px" class="text-center">所属分类</th>
<th width="140px" class="is-required text-center">新模型描述</th>
<th width="140px" class="is-required text-center">新模型别名</th>
<th width="140px" class="is-required text-center">新所属分类</th>
</tr>
<tr>
<th width="140px" class="text-center">{{ boDef.description }}</th>
<th width="140px" class="text-center">{{ boDef.alias }}</th>
<th width="140px" class="text-center">{{ boDef.categoryName }}</th>
<th width="140px" class="text-center">
<ht-input
v-model="boDef.newDescription"
placeholder="请输入新模型描述"
:validate="{required: true}"
:maxlength="50"
:showWordLimit="true"
></ht-input>
</th>
<th width="140px" class="text-center">
<ht-input
v-model="boDef.newAlias"
placeholder="请输入新模型别名"
autocomplete="off"
v-pinyin="boDef.newDescription"
validate="required: true|regex:^[a-zA-Z][a-zA-Z0-9_]*$,只能输入字母、数字、下划线,且以字母开头"
:maxlength="50"
:showWordLimit="true"
></ht-input>
</th>
<th width="140px" class="text-center">
<EipSysTypeSelector
placeholder="请选择分类"
cat-id="9"
v-model="boDef.newCategoryName"
:sys-type-id.sync="boDef.newCategoryId"
:validate="{required: true}"
/>
</th>
</tr>
</tbody>
</table>
<el-table
:data="boEnts"
style="margin-top: 20px;"
row-key="id"
border
default-expand-all
:tree-props="{children: 'childEnts'}"
>
<el-table-column prop="desc" label="实体描述"> </el-table-column>
<el-table-column prop="name" label="实体名称"> </el-table-column>
<el-table-column prop="newDesc" label="新实体描述">
<template slot-scope="{row}">
<ht-input
v-model="row.newDesc"
placeholder="请输入新实体描述"
:validate="{required: true}"
@input="chineseFormat(row.newDesc, row)"
:maxlength="50"
:showWordLimit="true"
></ht-input>
</template>
</el-table-column>
<el-table-column prop="newName" label="新实体名称"
><template slot-scope="{row}">
<ht-input
v-model="row.newName"
placeholder="请输入新实体名称"
:validate="{
required: true,
regex: {
exp: '^[a-zA-Z][a-zA-Z0-9_]{0,28}$',
message:
'只能输入字母、数字、下划线,且以字母开头,长度不能超过28'
}
}"
:maxlength="28"
:showWordLimit="true"
></ht-input>
</template>
</el-table-column>
</el-table>
</form>
<div slot="footer" class="dialog-footer">
<el-button @click="handleClose">{{ $t('eip.common.cancel') }}</el-button>
<el-button type="primary" @click="saveCopy">{{
$t('eip.common.save')
}}</el-button>
</div>
</el-dialog>
</template>
<script>
import EipSysTypeSelector from '@/components/selector/EipSysTypeSelector.vue'
import form from '@/api/form.js'
import req from '@/request.js'
export default {
components: {EipSysTypeSelector},
data() {
return {
defId: '',
boDef: {
alias: '',
description: '',
categoryName: '',
newAlias: '',
newDescription: '',
newCategoryId: '',
newCategoryName: ''
},
boEnts: [],
dialogVisible: false
}
},
mounted() {
this.$validator = this.$root.$validator
},
methods: {
chineseFormat(desc, row) {
setTimeout(function() {
req
.request({
url: `${window.context.uc}/base/tools/v1/getPinyin`,
method: 'GET',
params: {chinese: desc, type: 0}
})
.then(res => {
if (res.data.state) {
row.newName = res.data.value
}
})
}, 500)
},
showDialog(defId) {
this.defId = defId
form.getEntData(defId, resp => {
this.boDef = {
alias: resp.data.alias,
description: resp.data.description,
categoryName: resp.data.categoryName,
newAlias: '',
newDescription: '',
newCategoryId: '',
newCategoryName: ''
}
this.boEnts = []
if (resp.data && resp.data.boEnt) {
this.handleEnt([resp.data.boEnt])
}
this.dialogVisible = true
})
},
handleEnt(boEnt) {
boEnt.forEach(e => {
let newE = {
id: e.id,
name: e.name,
desc: e.desc,
newName: '',
newDesc: ''
}
if (e.childEnts) {
newE.childEnts = []
e.childEnts.forEach(sub => {
let newSub = {
id: sub.id,
name: sub.name,
desc: sub.desc,
newName: '',
newDesc: ''
}
if (sub.childEnts) {
newSub.childEnts = []
sub.childEnts.forEach(sun => {
let newSun = {
id: sun.id,
name: sun.name,
desc: sun.desc,
newName: '',
newDesc: ''
}
newSub.childEnts.push(newSun)
})
}
newE.childEnts.push(newSub)
})
}
this.boEnts.push(newE)
})
},
handleClose() {
this.dialogVisible = false
},
saveCopy() {
let param = JSON.parse(JSON.stringify(this.boDef))
let entsMap = this.nest2tile(this.boEnts)
if (!entsMap) {
return
}
param.entsMap = entsMap
let dataList = _.cloneDeep(param)
delete dataList.description
delete dataList.categoryName
for (let item in dataList.entsMap) {
if (dataList.entsMap[item].id) {
delete dataList.entsMap[item].id
}
if (dataList.entsMap[item].name) {
delete dataList.entsMap[item].name
}
if (dataList.entsMap[item].desc) {
delete dataList.entsMap[item].desc
}
if (dataList.entsMap[item].childEnts) {
delete dataList.entsMap[item].childEnts
}
}
this.$validator.validateAll('saveCopyForm').then(result => {
if (result) {
form.saveBoCopy(dataList).then(resp => {
if (resp.data && resp.data.state) {
this.$message.success(resp.data.message || '操作成功')
this.handleClose()
this.$emit('onConfirm', null)
}
})
} else {
let arr = this.$validator.errors.items.filter(
item => item.scope == 'saveCopyForm'
)
this.$message({
showClose: true,
message: `有${arr.length}个字段未通过校验,请正确填写表单内容。`,
type: 'warning'
})
}
})
},
nest2tile(ents) {
let result = {},
newNameSet = new Set()
for (let i = 0; i < ents.length; i++) {
const e = ents[i]
if (newNameSet.has(e.newName)) {
this.$message.warning(`存在重名的实体名称:${e.newName}`)
return null
}
result[e.name] = e
newNameSet.add(e.newName)
//子表
if (e.childEnts) {
for (let j = 0; j < e.childEnts.length; j++) {
const sub = e.childEnts[j]
if (newNameSet.has(sub.newName)) {
this.$message.warning(`存在重名的实体名称:${sub.newName}`)
return null
}
result[sub.name] = sub
newNameSet.add(sub.newName)
//孙表
if (sub.childEnts) {
for (let g = 0; g < sub.childEnts.length; g++) {
const sun = sub.childEnts[g]
if (newNameSet.has(sun.newName)) {
this.$message.warning(`存在重名的实体名称:${sun.newName}`)
return null
}
result[sun.name] = sun
newNameSet.add(sun.newName)
}
}
}
}
}
return result
}
}
}
</script>
<style scoped>
.text-center {
text-align: center;
}
</style>