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