SubImportMergeDialog.vue
2.78 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
<template>
<el-dialog title="子表导入数据合并编辑器" :visible.sync="dialogVisible" width="600px" :append-to-body="true" :close-on-click-modal="false">
<div v-if="dialogVisible">
<codemirror v-model="funcExp" :options="cmOptions" class="code" id="singleText"></codemirror>
<p class="help-tag">
在编辑器中可以编写JS代码,实现子表导入时原有数据和导入数据的合并处理逻辑。
需要定义一个JS方法,该方法有两个入参,第一个入参为原有数据(类型为数组),
第二个参数为导入的数据(类型为数组),该方法需要返回一个新的数组。示例代码如下:
</p>
<pre>
function(rows, importRows){
//TODO 数据合并的逻辑处理,例如简单的合并两个数组
const newRows = rows.concat(importRows);
return newRows;
}
</pre>
</div>
<span slot="footer" class="dialog-footer">
<el-button @click="dialogVisible=false">取消</el-button>
<el-button type="primary" @click="sure">确定</el-button>
</span>
</el-dialog>
</template>
<script>
import { codemirror } from "vue-codemirror";
const Base64 = require("js-base64").Base64;
export default {
name: "sub-import-merge-dialog",
components: {
codemirror,
},
props: ["expression"],
data() {
return {
funcExp: null,
dialogVisible: false,
cmOptions: {
showCursorWhenSelecting: true,
value: "",
mode: "javascript",
readOnly: false,
smartIndent: true,
tabSize: 2,
theme: "base16-light",
lineNumbers: true,
line: true,
autofocus: true,
inputStyle: "textarea",
},
};
},
watch: {
dialogVisible: {
handler: function (newVal) {
if (newVal) {
if (this.expression) {
try {
this.funcExp = Base64.decode(this.expression);
} catch (err) {}
}
} else {
this.funcExp = null;
}
},
immediate: true,
},
},
methods: {
// 打开对话框
open() {
this.dialogVisible = true;
},
// 点击确定按钮
sure() {
const expInBase64 = Base64.encode(this.funcExp);
this.$emit("updateExpression", expInBase64);
this.dialogVisible = false;
},
},
};
</script>
<style lang="scss" scoped>
@import "@/assets/css/element-variables.scss";
@import "@/assets/css/form-editor.scss";
.help-tag {
display: block;
margin-top: 20px;
padding: 10px;
border: 1px solid #faecd8;
background: #fdf6ec;
color: #e6a23c;
border-radius: 5px;
font-size: 13px;
line-height: 19px;
}
.code >>> .CodeMirror {
font-family: monospace;
height: 200px !important;
color: black;
direction: ltr;
}
</style>