Showing
1 changed file
with
40 additions
and
4 deletions
... | ... | @@ -14,7 +14,12 @@ |
14 | 14 | :rules="[{ required: true, message: ifAdd ? '请输入脚本名称' : '请输入参数' }]" |
15 | 15 | > |
16 | 16 | <a-input v-if="ifAdd" v-model:value="scriptForm.name" placeholder="请输入脚本名称" /> |
17 | - <a-input v-else v-model:value="scriptForm.params" placeholder="请输入参数" /> | |
17 | + <a-input | |
18 | + @change="handleInputChange" | |
19 | + v-else | |
20 | + v-model:value="scriptForm.params" | |
21 | + placeholder="请输入参数" | |
22 | + /> | |
18 | 23 | </a-form-item> |
19 | 24 | <a-form-item |
20 | 25 | label="上报数据类型" |
... | ... | @@ -25,6 +30,15 @@ |
25 | 30 | <a-radio-group v-model:value="scriptForm.dataType" :options="typeOptions" /> |
26 | 31 | </a-space> |
27 | 32 | </a-form-item> |
33 | + <a-form-item | |
34 | + label="保存原始数据" | |
35 | + name="saveOriginalData" | |
36 | + :rules="[{ required: true, message: '请选择保存原始数据' }]" | |
37 | + > | |
38 | + <a-space direction="vertical"> | |
39 | + <a-radio-group v-model:value="scriptForm.saveOriginalData" :options="originalOptions" /> | |
40 | + </a-space> | |
41 | + </a-form-item> | |
28 | 42 | <a-form-item label="脚本内容" :name="ifAdd ? 'convertJs' : 'script'"> |
29 | 43 | <Card title="脚本内容" :bodyStyle="{ padding: 0, height: '280px' }"> |
30 | 44 | <template #extra> |
... | ... | @@ -74,7 +88,8 @@ |
74 | 88 | import { useMessage } from '/@/hooks/web/useMessage'; |
75 | 89 | import { findDictItemByCode } from '/@/api/system/dict'; |
76 | 90 | import { QuestionCircleOutlined } from '@ant-design/icons-vue'; |
77 | - import { defaultTitle, defaultScriptContent } from './config.data'; | |
91 | + import { defaultTitle } from './config.data'; | |
92 | + import { nextTick } from 'process'; | |
78 | 93 | |
79 | 94 | defineEmits(['register']); |
80 | 95 | const props = defineProps({ |
... | ... | @@ -88,11 +103,13 @@ |
88 | 103 | params: '', |
89 | 104 | output: '', |
90 | 105 | dataType: 'HEX', |
106 | + saveOriginalData: 'false', | |
91 | 107 | }); |
92 | 108 | const reportTypeOptions = reactive({ |
93 | 109 | typeOptions: [], |
110 | + originalOptions: [], | |
94 | 111 | }); |
95 | - const { typeOptions } = toRefs(reportTypeOptions); | |
112 | + const { typeOptions, originalOptions } = toRefs(reportTypeOptions); | |
96 | 113 | const { createMessage } = useMessage(); |
97 | 114 | const { clipboardRef, copiedRef } = useCopyToClipboard(); |
98 | 115 | const aceEditor = ref(); |
... | ... | @@ -101,10 +118,17 @@ |
101 | 118 | const res: any = await findDictItemByCode({ |
102 | 119 | dictCode: 'report_data_type', |
103 | 120 | }); |
121 | + const resOriginal: any = await findDictItemByCode({ | |
122 | + dictCode: 'original_data', | |
123 | + }); | |
104 | 124 | reportTypeOptions.typeOptions = res.map((m) => { |
105 | 125 | return { label: m.itemText, value: m.itemValue }; |
106 | 126 | }); |
127 | + reportTypeOptions.originalOptions = resOriginal.map((m) => { | |
128 | + return { label: m.itemText, value: m.itemValue }; | |
129 | + }); | |
107 | 130 | scriptForm.dataType = 'HEX'; |
131 | + scriptForm.saveOriginalData = 'false'; | |
108 | 132 | }); |
109 | 133 | // 初始化编辑器 |
110 | 134 | const initEditor = (jsScript?: string) => { |
... | ... | @@ -121,7 +145,7 @@ |
121 | 145 | enableBasicAutocompletion: true, |
122 | 146 | enableLiveAutocompletion: true, |
123 | 147 | }); |
124 | - aceEditor.value.setValue(jsScript ?? defaultScriptContent); | |
148 | + aceEditor.value.setValue(jsScript); | |
125 | 149 | beautify(aceEditor.value.session); |
126 | 150 | scriptForm.convertJs = aceEditor.value.getValue(); |
127 | 151 | }; |
... | ... | @@ -154,16 +178,28 @@ |
154 | 178 | } |
155 | 179 | } |
156 | 180 | if (!value) return; |
181 | + if (scriptForm.params) { | |
182 | + const trimParams = scriptForm.params.replace(/\s*/g, ''); | |
183 | + Reflect.set(value, 'params', trimParams); | |
184 | + } | |
157 | 185 | return { |
158 | 186 | ...value, |
159 | 187 | ...{ convertJs: props.ifAdd ? scriptForm.convertJs : null }, |
160 | 188 | ...{ script: !props.ifAdd ? scriptForm.script : null }, |
189 | + ...{ saveOriginalData: scriptForm.saveOriginalData === 'false' ? false : true }, | |
161 | 190 | }; |
162 | 191 | }; |
192 | + const handleInputChange = (e) => { | |
193 | + const trimParams = e.target.value.replace(/\s*/g, ''); | |
194 | + Reflect.set(scriptForm, 'params', trimParams); | |
195 | + }; | |
163 | 196 | const setFormData = (v) => { |
164 | 197 | for (let i in scriptForm) { |
165 | 198 | Reflect.set(scriptForm, i, v[i]); |
166 | 199 | } |
200 | + nextTick(() => { | |
201 | + scriptForm.saveOriginalData = v.saveOriginalData === false ? 'false' : 'true'; | |
202 | + }); | |
167 | 203 | aceEditor.value.setValue(v.convertJs); |
168 | 204 | handleFormat(); |
169 | 205 | }; | ... | ... |