TemplateEdit.vue
2.06 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
<template>
<el-dialog
title="编辑模板"
:visible="dialogVisible"
:before-close="beforeClose"
:close-on-click-modal="false"
width="60%"
append-to-body
>
<el-form>
<ht-form-item label="别名">
<ht-input v-model="data.alias" :disabled="true" />
</ht-form-item>
<ht-form-item label="模板内容">
<codemirror
ref="mycode"
v-model="data.template"
:options="cmOptions"
class="mycode"
style="width: 100%;height:500px;"
></codemirror>
</ht-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button @click="save" type="primary">保存</el-button>
<el-button @click="close">返回</el-button>
</div>
</el-dialog>
</template>
<script>
import form from '@/api/form.js'
export default {
props: {
id: String
},
data() {
return {
dialogVisible: false,
data: {},
cmOptions: {
value: '',
mode: 'vue',
readOnly: false,
smartIndent: true,
tabSize: 2,
theme: 'base16-light',
lineNumbers: true,
line: true
}
}
},
methods: {
beforeClose() {
this.dialogVisible = false
},
handleOpen() {
this.dialogVisible = true
this.$nextTick(() => {
form.getQueryViewTemplate(this.id).then(response => {
this.data = response
})
})
},
save() {
form.saveQueryViewTemplate(this.id, this.data.template).then(response => {
if (response.state) {
this.$message({message: response.message, type: 'success'})
this.close()
this.$emit('closeViewEdit')
} else {
this.$message.error(response.message)
}
})
},
close() {
this.dialogVisible = false
}
}
}
</script>
<style lang="scss" scoped>
@import '@/assets/css/element-variables.scss';
@import '@/assets/css/form-editor.scss';
.mycode >>> .CodeMirror {
font-family: monospace;
height: 500px !important;
color: black;
direction: ltr;
}
</style>