BatchForm.vue
3.57 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
<template>
<el-dialog title="批量新增" :close-on-click-modal="false" :close-on-press-escape="false"
:visible.sync="visible" lock-scroll class="NCC-dialog NCC-dialog_center" width="600px">
<el-form ref="dataForm" :model="dataForm" :rules="dataRule" label-width="80px"
label-position="top" v-loading="formLoading">
<!-- <el-form-item label="绑定表格" prop="bindTable">-->
<!-- <el-input v-model="dataForm.bindTable" placeholder="输入绑定表格" />-->
<!-- </el-form-item>-->
<!-- <el-form-item label="表格描述" prop="bindTableName">-->
<!-- <el-input v-model="dataForm.bindTableName" placeholder="绑定表格描述" />-->
<!-- </el-form-item>-->
<div class="json-demo">
<pre>
// 示例
[
{
"fullName":"名称",
"enCode":"fullName"
}
]
</pre>
</div>
<el-form-item label="字段Json" prop="columnJson">
<div class="formCodeEditor">
<NCCCodeEditor :options="options" v-model="content" ref="CodeEditor" />
</div>
</el-form-item>
</el-form>
<span slot="footer" class="dialog-footer">
<el-button @click="visible = false">{{$t('common.cancelButton')}}</el-button>
<el-button type="primary" :loading="btnLoading" @click="dataFormSubmit()">
{{$t('common.confirmButton')}}</el-button>
</span>
</el-dialog>
</template>
<script>
import { batchCreateColumn } from '@/api/system/columnAuthorize'
import NCCCodeEditor from '@/components/NCCEditor/monaco'
export default {
components: { NCCCodeEditor },
data() {
return {
options: {
readOnly: false,
language: 'json'
},
visible: false,
formLoading: false,
btnLoading: false,
content: '',
dataForm: {
moduleId: '',
bindTable: '',
bindTableName: '',
columnJson: []
},
dataRule: {}
}
},
methods: {
init(moduleId) {
this.dataForm.moduleId = moduleId
this.visible = true
this.formLoading = true
this.$nextTick(() => {
this.content = ''
this.$refs['dataForm'].resetFields()
this.$refs.CodeEditor.changeEditor({
value: '',
options: this.options
})
this.formLoading = false
})
},
dataFormSubmit() {
this.$refs['dataForm'].validate((valid) => {
if (valid) {
const rtnData = this.content
if (!rtnData) return this.$message.warning('请输入字段JSON')
const fixedRtnData = rtnData.replace(/("\w+":)(?=[},])/g, '$1null')
const jsonData = JSON.parse(fixedRtnData)
this.dataForm.columnJson = jsonData
this.btnLoading = true
batchCreateColumn(this.dataForm).then(res => {
this.$message({
message: res.msg,
type: 'success',
duration: 1500,
onClose: () => {
this.visible = false
this.btnLoading = false
this.content = ''
this.$emit('refreshDataList')
}
})
}).catch(() => { this.btnLoading = false })
}
})
}
}
}
</script>
<style lang="scss" scoped>
.formCodeEditor {
width: 100%;
height: 260px;
margin: 0;
padding: 0;
border: 1px solid #c0c4cc;
overflow: hidden;
}
.json-demo {
width: 100%;
background: #f4f4f5;
border-radius: 4px;
color: #909399;
padding-top: 10px;
pre {
margin-left: -40px;
font-size: 12px;
}
}
</style>