ScriptEdit.vue
6.37 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
<template>
<el-container>
<ht-sidebar-dialog
width="450px"
:title="title"
:visible.sync="dialogVisible"
:before-close="handleClose"
append-to-body
class="add_edit_type"
>
<el-form :model="formData" data-vv-scope="templateForm">
<ht-form-item label="名称" label-width="100px">
<ht-input
v-model="formData.name"
:validate="{ required: true }"
:maxlength="50"
:showWordLimit="true"
/>
<el-tooltip class="item" effect="dark" placement="top-end">
<div slot="content">
<span>人员脚本用于流程设计中节点事件设置</span>
</div>
<i class="el-icon-question"></i>
</el-tooltip>
</ht-form-item>
<ht-form-item label="脚本" class="is-required" label-width="100px">
<div style="height: 35px;width: 100%;position: relative;float: left;margin-bottom: 15px;">
<el-tooltip
class="item"
effect="dark"
:content="text"
placement="top-end"
>
<el-button @click="executeScript" style="position: absolute;top: 1px">测试脚本</el-button>
</el-tooltip>
</div>
<codemirror
ref="script"
v-model="formData.script"
:options="cmOptions"
class="mycode"
style="width: 99%;height:100%;position: relative;float: left"
></codemirror>
</ht-form-item>
<ht-form-item label="脚本分类" class="is-required" label-width="100px">
<el-tooltip
class="item"
effect="dark"
:content="typeDesc"
placement="top-end"
style="width: 290px;"
>
<el-select
v-model="formData.category"
filterable
allow-create
default-first-option
placeholder="请选择脚本分类">
<el-option
v-for="item in options"
:key="item"
:label="item"
:value="item">
</el-option>
</el-select>
</el-tooltip>
</ht-form-item>
<ht-form-item label="数据源" label-width="100px">
<ht-select
class="ht"
v-model="formData.dsName"
:validate="{ required: true }"
:options="dataSourcesInBean"
:props="{ key: 'alias', value: 'name' }"
/>
</ht-form-item>
<ht-form-item label="备注" label-width="100px">
<ht-input
v-model="formData.memo" :showWordLimit="true" :maxlength="200"
/>
</ht-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button @click="handleClose">取 消</el-button>
<ht-submit-button
:url="saveUrl()"
:model="formData"
:is-submit="isSubmit"
scope-name="templateForm"
@before-save-data="beforeSaveData()"
@after-save-data="afterSaveData"
>保存</ht-submit-button
>
</div>
</ht-sidebar-dialog>
</el-container>
</template>
<script>
import flow from "@/api/flow.js";
import req from "@/request.js";
export default {
props: ["editData"],
data() {
return {
categoryList: [{ key: "系统脚本", value: "系统脚本" }],
dialogVisible: false,
title: "",
isSubmit: false,
formData: {
category: "",
memo: "",
name: "",
script: ""
},
text:"请根据方法所需类型参数进行传参,避免执行失败",
typeDesc:"可在下拉框输入新分类,保存后可自动新增分类选项",
options: [],
cmOptions: {
value: "",
mode: "groovy",
readOnly: false,
smartIndent: true,
tabSize: 2,
theme: "base16-light",
lineNumbers: true,
line: true
},
dataSourcesInBean: [], //数据源池
};
},
methods: {
handleClose() {
this.dialogVisible = false;
this.formData = {
category: "",
memo: "",
name: "",
script: ""
};
},
saveUrl() {
return window.context.bpmRunTime + "/runtime/script/v1/save";
},
beforeSaveData() {
if(!this.formData.script || this.formData.script == ""){
this.$message({message:"脚本未填写",type:"warning"});
return false;
}
if(!this.formData.category || this.formData.category == ""){
this.$message({message:"脚本分类不能为空",type:"warning"});
return false;
}
this.isSubmit = true;
},
afterSaveData() {
this.handleClose();
this.$emit("loadList");
},
handleOpen() {
this.dialogVisible = true;
this.title = this.editData.title;
if (this.editData.data) {
this.formData = this.editData.data;
};
this.getScriptType();
},
//执行脚本
executeScript() {
flow.executeScript(this.formData.script).then(resp => {
if (resp.data.state) {
this.$message({ message: resp.data.message, type: "success" });
}
});
},
//获取常用脚本分类
getScriptType(){
flow.getScriptType().then(resp=>{
this.options=resp.data
})
}
},
mounted() {
const this_ = this;
//获取数据源池
req
.get(window.context.portal + "/sys/sysDataSource/v1/getDataSources")
.then(function (data) {
this_.dataSourcesInBean = data.data;
});
},
};
</script>
<style lang="scss" scoped>
//侧边弹窗
.add_edit_type {
::v-deep {
.el-dialog__body {
padding: 0;
padding-top: 10px;
padding-right: 20px;
}
}
}
::v-deep{
.el-form-item__content{
.ht-form-inputs__inline {
width: 290px;
}
}
}
.right-dialog {
::v-deep{
.el-dialog {
right: 10px !important;
}
}
}
</style>