standardDialog.vue
11 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
<template>
<el-dialog v-model="visible" :title="title" width="900" modal-class="standard-modal">
<el-form :rules="formRules" :model="form" ref="formEl">
<el-row>
<el-col :span="12" style="padding-right:10px">
<el-form-item label="元数据标准名称" prop="standardName">
<el-input v-model="form.standardName" placeholder="请输入" maxlength="50"/>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="标准编号" prop="standardCode">
<el-input v-model="form.standardCode" placeholder="请输入" maxlength="20"/>
</el-form-item>
</el-col>
<el-col :span="4" style="padding-right:10px">
<el-form-item label="排序" prop="orderNum">
<el-input v-model="form.orderNum" placeholder="请输入" type="number" maxlength="2"/>
</el-form-item>
</el-col>
<el-col :span="8" style="padding-right:10px">
<el-form-item label="发布单位" prop="publishingUnitCode">
<el-select v-model="form.publishingUnitCode" placeholder="请选择" size="small">
<el-option v-for="item in publishUnitOptions" :label="item.label" :value="item.value" :key="item.value"></el-option>
</el-select>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="上级标准" prop="parentGuid">
<!-- <el-tree-select
v-model="form.parentGuid"
:data="standardOptions"
:props="standardProps"
node-key="guid"
:expandOnNodeClick="false"
placeholder="请选择"
/> -->
<el-cascader
v-model="form.parentGuid"
:options="standardOptions"
:props="standardProps"
:show-all-levels="false"
style="width:100%"
clearable
@change="parentGuidChange"
/>
</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item label="描述" prop="description">
<el-input v-model="form.description" placeholder="请输入" type="textarea"/>
</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item label="自定义字段选择" v-if="form.fieldRQVOS && form.fieldRQVOS.length">
<div class="table-form">
<div class="table-form-wrapper" v-for="item,index in form.fieldRQVOS" :key="index">
<div class="table-form-item">
<el-select v-model="item.fileNameCode" style="width:160px" size="small" clearable>
<el-option v-for="item in fieldOptions" :label="item.label" :value="item.value" :key="item.value"></el-option>
</el-select>
</div>
<div class="table-form-item">
<el-select v-model="item.isNotnull" style="width: 96px" size="small" placeholder="是否必填" clearable>
<el-option v-for="item in isBooleanOptions" :label="item.label" :value="item.value" :key="item.value"></el-option>
</el-select>
</div>
<div class="table-form-item">
<el-select v-model="item.isDisplay" style="width:96px" size="small" placeholder="是否展示" clearable>
<el-option v-for="item in isBooleanOptions" :label="item.label" :value="item.value" :key="item.value"></el-option>
</el-select>
</div>
<div class="table-form-item">
<el-select v-model="item.inputTypeCode" style="width:130px" size="small" clearable @change="v => inputTypeChange(v, item)">
<el-option v-for="item in inputOptions" :label="item.label" :value="item.value" :key="item.value"></el-option>
</el-select>
</div>
<div class="table-form-item">
<el-select v-if="item.inputTypeCode == 2" v-model="item.dataTypeCode" style="width:220px" size="small" filterable clearable>
<el-option v-for="item in allDictOptions" :label="item.dictTypeName" :value="item.dictTypeName" :key="item.guid"></el-option>
</el-select>
<el-input v-else-if="item.inputTypeCode == 3" v-model="item.validateExpression" placeholder="请输入"></el-input>
</div>
<div class="table-form-operation">
<el-icon color="#4fa1a4" @click="() => addTableItem(index)">
<CirclePlus />
</el-icon>
<el-icon color="#F56C6C" @click="() => deleteTableItem(index)"><Delete /></el-icon>
</div>
</div>
</div>
</el-form-item>
</el-col>
</el-row>
</el-form>
<template #footer>
<el-button @click="visible = false" :disabled="confirmLoading">取消</el-button>
<el-button type="primary" @click="confirm" :loading="confirmLoading">确认</el-button>
</template>
</el-dialog>
</template>
<script setup lang="ts">
import { watch } from 'vue'
import { Search, CirclePlus, Delete } from '@element-plus/icons-vue'
import { saveMetaStandard, deleteMetaStandard, updateMetaStandard, getMetaStandardDetail } from '@/api/modules/dataMetaService'
import {
getParamsList, getDictAllList
} from '@/api/modules/dataAsset'
import { ElMessage } from "element-plus";
const { proxy } = getCurrentInstance() as any;
const props = defineProps({
modelValue: Boolean,
standardOptions: {
type: Array,
default: () => ([])
},
type: {
type: String,
default: 'add'
},
guid: {
type: String,
default: ''
}
})
const emit = defineEmits(['update:modelValue', 'success', 'confirm']);
const visible = computed({
get() {
return props.modelValue;
},
set(val) {
emit('update:modelValue', val);
}
})
const title = computed(() => {
return props.type === 'add' ? '新建元标准' : '编辑元标准'
})
/**
* 配置项列表
*/
const publishUnitOptions = ref([])
const standardProps = {
label: 'standardName',
value: 'guid',
checkStrictly: true,
emitPath: false
}
const fieldOptions = ref([])
const isBooleanOptions = [
{ label: '是', value: 'Y' },
{ label: '否', value: 'N' },
]
const inputOptions = ref([])
const allDictOptions = ref([])
/**表单 */
const formEl = ref()
const formTpl = {
standardName: '',
standardCode: '',
orderNum: '',
publishingUnitCode: '',
parentGuid: '',
description: '',
fieldRQVOS: []
}
const form = ref({...formTpl})
const formRules = {
standardName: { required: true, message: '请填写元数据标准名称' },
orderNum: { required: true, message: '请填写排序' },
publishingUnitCode: { required: true, message: '请选择发布的单位' }
}
function parentGuidChange (val) {
console.log(val)
if (!val) {
form.value.fieldRQVOS = []
return
}
const isFirst = props.standardOptions.find(item => item.guid === val)
if (isFirst) {
form.value.fieldRQVOS = [{...tableFormTpl}]
}
}
const tableFormTpl = {
fileNameCode: '',
isNotnull: 'Y',
isDisplay: 'N',
inputTypeCode: '',
dataTypeCode: null,
validateExpression: null
}
function addTableItem (index) {
const tableObj = { ...tableFormTpl }
form.value.fieldRQVOS.splice(index + 1, 0, tableObj)
}
function deleteTableItem (index) {
form.value.fieldRQVOS.splice(index, 1)
}
function inputTypeChange (val, item) {
console.log(val)
if (val == 2) {
// 下拉框
item.validateExpression = null
} else if (val == 3) {
item.dataTypeCode = null
} else {
item.validateExpression = null
item.dataTypeCode = null
}
}
function getDetail () {
getMetaStandardDetail(props.guid).then((res:any) => {
if (res.code === proxy.$passCode) {
const data = res.data
data.fieldRQVOS = data.fieldRSVOS
form.value = { ...data }
}
})
}
const confirmLoading = ref(false)
function confirm () {
formEl.value.validate(valid => {
if (!valid) return
let body = { ...form.value }
console.log(body)
delete body.fieldRSVOS
// return
const request = props.type === 'add' ? saveMetaStandard : updateMetaStandard
confirmLoading.value = true
request(body).then((res:any) => {
if (res.code === proxy.$passCode) {
ElMessage.success('操作成功')
emit('success')
visible.value = false
return
}
ElMessage.error(res.msg)
}).finally(() => confirmLoading.value = false)
})
}
watch(
() => visible.value,
(v) => {
if (!v) return
if (props.type === 'edit') {
getDetail()
}
}
)
onBeforeMount(() => {
getParamsList({ dictType: '发布单位' }).then((res:any) => {
if (res.code === proxy.$passCode) {
const data = res.data || []
publishUnitOptions.value = data
}
})
getParamsList({ dictType: '字段名代码' }).then((res:any) => {
if (res.code === proxy.$passCode) {
const data = res.data || []
fieldOptions.value = data
}
})
getParamsList({ dictType: '输入框类型' }).then((res:any) => {
if (res.code === proxy.$passCode) {
const data = res.data || []
inputOptions.value = data
}
})
getDictAllList().then((res:any) => {
if (res.code === proxy.$passCode) {
const data = res.data || []
allDictOptions.value = data
}
})
})
</script>
<style lang="scss">
.standard-modal {
.el-form-item {
flex-direction: column;
.el-form-item__label {
justify-content: flex-start;
}
}
.el-dialog__footer {
padding: 10px;
}
.table-form-wrapper {
display: flex;
margin-bottom: 5px;
.table-form-item {
padding-right: 10px;
}
.table-form-operation {
flex: 0 0 70px;
padding-left: 6px;
}
}
}
</style>