| 
1
 | 
1
 | 
 <template>
 | 
| 
2
 | 
2
 | 
   <div>
 | 
| 
3
 | 
 
 | 
-    <BasicForm :showResetButton="false" :showSubmitButton="false" @register="register">
 | 
| 
4
 | 
 
 | 
-      <template #authScriptId="{ model, field }">
 | 
| 
 
 | 
3
 | 
+    <a-form
 | 
| 
 
 | 
4
 | 
+      ref="formRef"
 | 
| 
 
 | 
5
 | 
+      :model="scriptForm"
 | 
| 
 
 | 
6
 | 
+      name="basic"
 | 
| 
 
 | 
7
 | 
+      :label-col="{ span: 4 }"
 | 
| 
 
 | 
8
 | 
+      :wrapper-col="{ span: 16 }"
 | 
| 
 
 | 
9
 | 
+      style="margin-left: 2.4rem"
 | 
| 
 
 | 
10
 | 
+      autocomplete="off"
 | 
| 
 
 | 
11
 | 
+    >
 | 
| 
 
 | 
12
 | 
+      <a-form-item
 | 
| 
 
 | 
13
 | 
+        v-if="deviceTypeStr !== 'SENSOR'"
 | 
| 
 
 | 
14
 | 
+        label="鉴权脚本"
 | 
| 
 
 | 
15
 | 
+        name="'params'"
 | 
| 
 
 | 
16
 | 
+        :rules="[{ required: true, message: '请选择鉴权脚本' }]"
 | 
| 
 
 | 
17
 | 
+      >
 | 
| 
5
 | 
18
 | 
         <div style="display: flex; align-items: center">
 | 
| 
6
 | 
19
 | 
           <div>
 | 
| 
7
 | 
20
 | 
             <Select
 | 
| 
8
 | 
21
 | 
               @change="handleAuthChange"
 | 
| 
9
 | 
22
 | 
               placeholder="请选择"
 | 
| 
10
 | 
 
 | 
-              v-model:value="model[field]"
 | 
| 
 
 | 
23
 | 
+              v-model:value="scriptForm.authScriptId"
 | 
| 
11
 | 
24
 | 
               style="width: 305px"
 | 
| 
12
 | 
25
 | 
               show-search
 | 
| 
13
 | 
26
 | 
               :options="selectAuthOptions"
 | 
| 
...
 | 
...
 | 
@@ -28,14 +41,18 @@ | 
| 
28
 | 
41
 | 
         <a-button @click="handleCreateOrEditAuth('test')" class="mt-4" type="primary"
 | 
| 
29
 | 
42
 | 
           >测试脚本</a-button
 | 
| 
30
 | 
43
 | 
         >
 | 
| 
31
 | 
 
 | 
-      </template>
 | 
| 
32
 | 
 
 | 
-      <template #upScriptId="{ model, field }">
 | 
| 
 
 | 
44
 | 
+      </a-form-item>
 | 
| 
 
 | 
45
 | 
+      <a-form-item
 | 
| 
 
 | 
46
 | 
+        label="上行脚本"
 | 
| 
 
 | 
47
 | 
+        name="'params'"
 | 
| 
 
 | 
48
 | 
+        :rules="[{ required: true, message: '请选择上行脚本' }]"
 | 
| 
 
 | 
49
 | 
+      >
 | 
| 
33
 | 
50
 | 
         <div style="display: flex; align-items: center">
 | 
| 
34
 | 
51
 | 
           <div>
 | 
| 
35
 | 
52
 | 
             <Select
 | 
| 
36
 | 
53
 | 
               @change="handleUpChange"
 | 
| 
37
 | 
54
 | 
               placeholder="请选择"
 | 
| 
38
 | 
 
 | 
-              v-model:value="model[field]"
 | 
| 
 
 | 
55
 | 
+              v-model:value="scriptForm.upScriptId"
 | 
| 
39
 | 
56
 | 
               style="width: 305px"
 | 
| 
40
 | 
57
 | 
               show-search
 | 
| 
41
 | 
58
 | 
               :options="selectUpOptions"
 | 
| 
...
 | 
...
 | 
@@ -56,16 +73,14 @@ | 
| 
56
 | 
73
 | 
         <a-button @click="handleCreateOrEdit('test')" class="mt-4" type="primary"
 | 
| 
57
 | 
74
 | 
           >测试脚本</a-button
 | 
| 
58
 | 
75
 | 
         >
 | 
| 
59
 | 
 
 | 
-      </template>
 | 
| 
60
 | 
 
 | 
-    </BasicForm>
 | 
| 
 
 | 
76
 | 
+      </a-form-item>
 | 
| 
 
 | 
77
 | 
+    </a-form>
 | 
| 
61
 | 
78
 | 
     <ConverScriptModal @register="registerModal" @success="handleSuccess" />
 | 
| 
62
 | 
79
 | 
     <ConverScriptModal @register="registerAuthModal" @success="handleAuthSuccess" />
 | 
| 
63
 | 
80
 | 
   </div>
 | 
| 
64
 | 
81
 | 
 </template>
 | 
| 
65
 | 
82
 | 
 <script lang="ts" setup name="index">
 | 
| 
66
 | 
 
 | 
-  import { ref, Ref, onMounted } from 'vue';
 | 
| 
67
 | 
 
 | 
-  import { BasicForm, useForm } from '/@/components/Form';
 | 
| 
68
 | 
 
 | 
-  import { tcpSchemas } from './config';
 | 
| 
 
 | 
83
 | 
+  import { ref, Ref, onMounted, reactive } from 'vue';
 | 
| 
69
 | 
84
 | 
   import { SelectTypes } from 'ant-design-vue/es/select';
 | 
| 
70
 | 
85
 | 
   import { Select } from 'ant-design-vue';
 | 
| 
71
 | 
86
 | 
   import { useModal } from '/@/components/Modal';
 | 
| 
...
 | 
...
 | 
@@ -73,6 +88,14 @@ | 
| 
73
 | 
88
 | 
   import ConverScriptModal from '/@/views/scriptmanage/converscript/ConverScriptModal.vue';
 | 
| 
74
 | 
89
 | 
   import { useMessage } from '/@/hooks/web/useMessage';
 | 
| 
75
 | 
90
 | 
 
 | 
| 
 
 | 
91
 | 
+  const props = defineProps({
 | 
| 
 
 | 
92
 | 
+    deviceTypeStr: { type: String, default: '' },
 | 
| 
 
 | 
93
 | 
+  });
 | 
| 
 
 | 
94
 | 
+
 | 
| 
 
 | 
95
 | 
+  const scriptForm = reactive({
 | 
| 
 
 | 
96
 | 
+    authScriptId: '',
 | 
| 
 
 | 
97
 | 
+    upScriptId: '',
 | 
| 
 
 | 
98
 | 
+  });
 | 
| 
76
 | 
99
 | 
   const selectUpOptions: Ref<SelectTypes['options']> = ref([]);
 | 
| 
77
 | 
100
 | 
 
 | 
| 
78
 | 
101
 | 
   const selectAuthOptions: Ref<SelectTypes['options']> = ref([]);
 | 
| 
...
 | 
...
 | 
@@ -97,7 +120,7 @@ | 
| 
97
 | 
120
 | 
     if (text !== 'test') {
 | 
| 
98
 | 
121
 | 
       const rest = await getAllScriptType('TRANSPORT_TCP_UP');
 | 
| 
99
 | 
122
 | 
       selectUpOptions.value = rest;
 | 
| 
100
 | 
 
 | 
-      setFieldsValue({ upScriptId: res?.id });
 | 
| 
 
 | 
123
 | 
+      scriptForm.upScriptId = res?.id;
 | 
| 
101
 | 
124
 | 
       upScriptIdStr.value = res?.id;
 | 
| 
102
 | 
125
 | 
     }
 | 
| 
103
 | 
126
 | 
   };
 | 
| 
...
 | 
...
 | 
@@ -106,22 +129,20 @@ | 
| 
106
 | 
129
 | 
     if (text !== 'test') {
 | 
| 
107
 | 
130
 | 
       const rest = await getAllScriptType('TRANSPORT_TCP_AUTH');
 | 
| 
108
 | 
131
 | 
       selectAuthOptions.value = rest;
 | 
| 
109
 | 
 
 | 
-      setFieldsValue({ authScriptId: res?.id });
 | 
| 
 
 | 
132
 | 
+      scriptForm.authScriptId = res?.id;
 | 
| 
110
 | 
133
 | 
       authScriptIdStr.value = res?.id;
 | 
| 
111
 | 
134
 | 
     }
 | 
| 
112
 | 
135
 | 
   };
 | 
| 
113
 | 
136
 | 
 
 | 
| 
114
 | 
 
 | 
-  const [register, { validate, resetFields, setFieldsValue }] = useForm({
 | 
| 
115
 | 
 
 | 
-    labelWidth: 180,
 | 
| 
116
 | 
 
 | 
-    schemas: tcpSchemas,
 | 
| 
117
 | 
 
 | 
-    actionColOptions: {
 | 
| 
118
 | 
 
 | 
-      span: 14,
 | 
| 
119
 | 
 
 | 
-    },
 | 
| 
120
 | 
 
 | 
-  });
 | 
| 
121
 | 
 
 | 
-
 | 
| 
122
 | 
 
 | 
-  const handleUpChange = (v) => (upScriptIdStr.value = v);
 | 
| 
 
 | 
137
 | 
+  const handleUpChange = (v) => {
 | 
| 
 
 | 
138
 | 
+    upScriptIdStr.value = v;
 | 
| 
 
 | 
139
 | 
+    scriptForm.upScriptId = v;
 | 
| 
 
 | 
140
 | 
+  };
 | 
| 
123
 | 
141
 | 
 
 | 
| 
124
 | 
 
 | 
-  const handleAuthChange = (v) => (authScriptIdStr.value = v);
 | 
| 
 
 | 
142
 | 
+  const handleAuthChange = (v) => {
 | 
| 
 
 | 
143
 | 
+    authScriptIdStr.value = v;
 | 
| 
 
 | 
144
 | 
+    scriptForm.authScriptId = v;
 | 
| 
 
 | 
145
 | 
+  };
 | 
| 
125
 | 
146
 | 
 
 | 
| 
126
 | 
147
 | 
   const [registerModal, { openModal }] = useModal();
 | 
| 
127
 | 
148
 | 
 
 | 
| 
...
 | 
...
 | 
@@ -172,20 +193,35 @@ | 
| 
172
 | 
193
 | 
   };
 | 
| 
173
 | 
194
 | 
 
 | 
| 
174
 | 
195
 | 
   const getFormData = async () => {
 | 
| 
175
 | 
 
 | 
-    const values = await validate();
 | 
| 
176
 | 
 
 | 
-    if (!values) return;
 | 
| 
 
 | 
196
 | 
+    if (props.deviceTypeStr === 'SENSOR') {
 | 
| 
 
 | 
197
 | 
+      if (!scriptForm.upScriptId) {
 | 
| 
 
 | 
198
 | 
+        createMessage.error('请先选择对应脚本');
 | 
| 
 
 | 
199
 | 
+        throw new Error('请先选择对应脚本');
 | 
| 
 
 | 
200
 | 
+      }
 | 
| 
 
 | 
201
 | 
+    } else {
 | 
| 
 
 | 
202
 | 
+      if (!scriptForm.authScriptId) {
 | 
| 
 
 | 
203
 | 
+        createMessage.error('请先选择对应脚本');
 | 
| 
 
 | 
204
 | 
+        throw new Error('请先选择对应脚本');
 | 
| 
 
 | 
205
 | 
+      }
 | 
| 
 
 | 
206
 | 
+      if (!scriptForm.upScriptId) {
 | 
| 
 
 | 
207
 | 
+        createMessage.error('请先选择对应脚本');
 | 
| 
 
 | 
208
 | 
+        throw new Error('请先选择对应脚本');
 | 
| 
 
 | 
209
 | 
+      }
 | 
| 
 
 | 
210
 | 
+    }
 | 
| 
177
 | 
211
 | 
     return {
 | 
| 
178
 | 
 
 | 
-      ...values,
 | 
| 
 
 | 
212
 | 
+      ...scriptForm,
 | 
| 
179
 | 
213
 | 
       type: 'TCP',
 | 
| 
180
 | 
214
 | 
     };
 | 
| 
181
 | 
215
 | 
   };
 | 
| 
182
 | 
216
 | 
 
 | 
| 
183
 | 
217
 | 
   const resetFormData = () => {
 | 
| 
184
 | 
 
 | 
-    resetFields();
 | 
| 
 
 | 
218
 | 
+    // resetFields();
 | 
| 
185
 | 
219
 | 
   };
 | 
| 
186
 | 
220
 | 
 
 | 
| 
187
 | 
221
 | 
   const setFormData = (v) => {
 | 
| 
188
 | 
 
 | 
-    setFieldsValue(v);
 | 
| 
 
 | 
222
 | 
+    scriptForm.authScriptId = v?.authScriptId;
 | 
| 
 
 | 
223
 | 
+    scriptForm.upScriptId = v?.upScriptId;
 | 
| 
 
 | 
224
 | 
+    // setFieldsValue(v);
 | 
| 
189
 | 
225
 | 
     upScriptIdStr.value = v?.upScriptId;
 | 
| 
190
 | 
226
 | 
     authScriptIdStr.value = v?.authScriptId;
 | 
| 
191
 | 
227
 | 
   };
 | 
...
 | 
...
 | 
 |