| 
1
 | 
 
 | 
-<template>
 | 
| 
2
 | 
 
 | 
-  <div>
 | 
| 
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
 | 
 
 | 
-      >
 | 
| 
18
 | 
 
 | 
-        <div style="display: flex; align-items: center">
 | 
| 
19
 | 
 
 | 
-          <div>
 | 
| 
20
 | 
 
 | 
-            <Select
 | 
| 
21
 | 
 
 | 
-              @change="handleAuthChange"
 | 
| 
22
 | 
 
 | 
-              placeholder="请选择"
 | 
| 
23
 | 
 
 | 
-              v-model:value="scriptForm.authScriptId"
 | 
| 
24
 | 
 
 | 
-              style="width: 305px"
 | 
| 
25
 | 
 
 | 
-              show-search
 | 
| 
26
 | 
 
 | 
-              :options="selectAuthOptions"
 | 
| 
27
 | 
 
 | 
-              :filter-option="handleAuthSearch"
 | 
| 
28
 | 
 
 | 
-              allowClear
 | 
| 
29
 | 
 
 | 
-            />
 | 
| 
30
 | 
 
 | 
-          </div>
 | 
| 
31
 | 
 
 | 
-          <div>
 | 
| 
32
 | 
 
 | 
-            <span
 | 
| 
33
 | 
 
 | 
-              @click="handleCreateOrEditAuth('add')"
 | 
| 
34
 | 
 
 | 
-              class="ml-2"
 | 
| 
35
 | 
 
 | 
-              style="color: #409eff; cursor: pointer"
 | 
| 
36
 | 
 
 | 
-              size="small"
 | 
| 
37
 | 
 
 | 
-              >新建转换脚本</span
 | 
| 
38
 | 
 
 | 
-            >
 | 
| 
39
 | 
 
 | 
-          </div>
 | 
| 
40
 | 
 
 | 
-        </div>
 | 
| 
41
 | 
 
 | 
-        <a-button @click="handleCreateOrEditAuth('test')" class="mt-4" type="primary"
 | 
| 
42
 | 
 
 | 
-          >测试脚本</a-button
 | 
| 
43
 | 
 
 | 
-        >
 | 
| 
44
 | 
 
 | 
-      </a-form-item>
 | 
| 
45
 | 
 
 | 
-      <a-form-item
 | 
| 
46
 | 
 
 | 
-        label="上行脚本"
 | 
| 
47
 | 
 
 | 
-        name="'params'"
 | 
| 
48
 | 
 
 | 
-        :rules="[{ required: true, message: '请选择上行脚本' }]"
 | 
| 
49
 | 
 
 | 
-      >
 | 
| 
50
 | 
 
 | 
-        <div style="display: flex; align-items: center">
 | 
| 
51
 | 
 
 | 
-          <div>
 | 
| 
52
 | 
 
 | 
-            <Select
 | 
| 
53
 | 
 
 | 
-              @change="handleUpChange"
 | 
| 
54
 | 
 
 | 
-              placeholder="请选择"
 | 
| 
55
 | 
 
 | 
-              v-model:value="scriptForm.upScriptId"
 | 
| 
56
 | 
 
 | 
-              style="width: 305px"
 | 
| 
57
 | 
 
 | 
-              show-search
 | 
| 
58
 | 
 
 | 
-              :options="selectUpOptions"
 | 
| 
59
 | 
 
 | 
-              :filter-option="handleSearch"
 | 
| 
60
 | 
 
 | 
-              allowClear
 | 
| 
61
 | 
 
 | 
-            />
 | 
| 
62
 | 
 
 | 
-          </div>
 | 
| 
63
 | 
 
 | 
-          <div>
 | 
| 
64
 | 
 
 | 
-            <span
 | 
| 
65
 | 
 
 | 
-              @click="handleCreateOrEdit('add')"
 | 
| 
66
 | 
 
 | 
-              class="ml-2"
 | 
| 
67
 | 
 
 | 
-              style="color: #409eff; cursor: pointer"
 | 
| 
68
 | 
 
 | 
-              size="small"
 | 
| 
69
 | 
 
 | 
-              >新建转换脚本</span
 | 
| 
70
 | 
 
 | 
-            >
 | 
| 
71
 | 
 
 | 
-          </div>
 | 
| 
72
 | 
 
 | 
-        </div>
 | 
| 
73
 | 
 
 | 
-        <a-button @click="handleCreateOrEdit('test')" class="mt-4" type="primary"
 | 
| 
74
 | 
 
 | 
-          >测试脚本</a-button
 | 
| 
75
 | 
 
 | 
-        >
 | 
| 
76
 | 
 
 | 
-      </a-form-item>
 | 
| 
77
 | 
 
 | 
-    </a-form>
 | 
| 
78
 | 
 
 | 
-    <ConverScriptModal @register="registerModal" @success="handleSuccess" />
 | 
| 
79
 | 
 
 | 
-    <ConverScriptModal @register="registerAuthModal" @success="handleAuthSuccess" />
 | 
| 
80
 | 
 
 | 
-  </div>
 | 
| 
81
 | 
 
 | 
-</template>
 | 
| 
82
 | 
 
 | 
-<script lang="ts" setup name="index">
 | 
| 
83
 | 
 
 | 
-  import { ref, Ref, onMounted, reactive } from 'vue';
 | 
| 
84
 | 
 
 | 
-  import { SelectTypes } from 'ant-design-vue/es/select';
 | 
| 
85
 | 
 
 | 
-  import { Select } from 'ant-design-vue';
 | 
| 
86
 | 
 
 | 
-  import { useModal } from '/@/components/Modal';
 | 
| 
87
 | 
 
 | 
-  import { getScriptManageMeList } from '/@/api/scriptmanage/scriptManager';
 | 
| 
88
 | 
 
 | 
-  import ConverScriptModal from '/@/views/scriptmanage/converscript/ConverScriptModal.vue';
 | 
| 
89
 | 
 
 | 
-  import { useMessage } from '/@/hooks/web/useMessage';
 | 
| 
90
 | 
 
 | 
-
 | 
| 
91
 | 
 
 | 
-  const props = defineProps({
 | 
| 
92
 | 
 
 | 
-    deviceTypeStr: { type: String, default: '' },
 | 
| 
93
 | 
 
 | 
-  });
 | 
| 
94
 | 
 
 | 
-
 | 
| 
95
 | 
 
 | 
-  const scriptForm = reactive({
 | 
| 
96
 | 
 
 | 
-    authScriptId: '',
 | 
| 
97
 | 
 
 | 
-    upScriptId: '',
 | 
| 
98
 | 
 
 | 
-  });
 | 
| 
99
 | 
 
 | 
-  const selectUpOptions: Ref<SelectTypes['options']> = ref([]);
 | 
| 
100
 | 
 
 | 
-
 | 
| 
101
 | 
 
 | 
-  const selectAuthOptions: Ref<SelectTypes['options']> = ref([]);
 | 
| 
102
 | 
 
 | 
-
 | 
| 
103
 | 
 
 | 
-  const { createMessage } = useMessage();
 | 
| 
104
 | 
 
 | 
-
 | 
| 
105
 | 
 
 | 
-  const upScriptIdStr = ref('');
 | 
| 
106
 | 
 
 | 
-
 | 
| 
107
 | 
 
 | 
-  const authScriptIdStr = ref('');
 | 
| 
108
 | 
 
 | 
-
 | 
| 
109
 | 
 
 | 
-  onMounted(async () => {
 | 
| 
110
 | 
 
 | 
-    selectUpOptions.value = await getAllScriptType('TRANSPORT_TCP_UP');
 | 
| 
111
 | 
 
 | 
-    selectAuthOptions.value = await getAllScriptType('TRANSPORT_TCP_AUTH');
 | 
| 
112
 | 
 
 | 
-  });
 | 
| 
113
 | 
 
 | 
-
 | 
| 
114
 | 
 
 | 
-  const getAllScriptType = async (type) => {
 | 
| 
115
 | 
 
 | 
-    const rest = await getScriptManageMeList({ scriptType: type });
 | 
| 
116
 | 
 
 | 
-    return rest.map((m) => ({ label: m.name, value: m.id }));
 | 
| 
117
 | 
 
 | 
-  };
 | 
| 
118
 | 
 
 | 
-
 | 
| 
119
 | 
 
 | 
-  const handleSuccess = async ({ res, text }) => {
 | 
| 
120
 | 
 
 | 
-    if (text !== 'test') {
 | 
| 
121
 | 
 
 | 
-      const rest = await getAllScriptType('TRANSPORT_TCP_UP');
 | 
| 
122
 | 
 
 | 
-      selectUpOptions.value = rest;
 | 
| 
123
 | 
 
 | 
-      scriptForm.upScriptId = res?.id;
 | 
| 
124
 | 
 
 | 
-      upScriptIdStr.value = res?.id;
 | 
| 
125
 | 
 
 | 
-    }
 | 
| 
126
 | 
 
 | 
-  };
 | 
| 
127
 | 
 
 | 
-
 | 
| 
128
 | 
 
 | 
-  const handleAuthSuccess = async ({ res, text }) => {
 | 
| 
129
 | 
 
 | 
-    if (text !== 'test') {
 | 
| 
130
 | 
 
 | 
-      const rest = await getAllScriptType('TRANSPORT_TCP_AUTH');
 | 
| 
131
 | 
 
 | 
-      selectAuthOptions.value = rest;
 | 
| 
132
 | 
 
 | 
-      scriptForm.authScriptId = res?.id;
 | 
| 
133
 | 
 
 | 
-      authScriptIdStr.value = res?.id;
 | 
| 
134
 | 
 
 | 
-    }
 | 
| 
135
 | 
 
 | 
-  };
 | 
| 
136
 | 
 
 | 
-
 | 
| 
137
 | 
 
 | 
-  const handleUpChange = (v) => {
 | 
| 
138
 | 
 
 | 
-    upScriptIdStr.value = v;
 | 
| 
139
 | 
 
 | 
-    scriptForm.upScriptId = v;
 | 
| 
140
 | 
 
 | 
-  };
 | 
| 
141
 | 
 
 | 
-
 | 
| 
142
 | 
 
 | 
-  const handleAuthChange = (v) => {
 | 
| 
143
 | 
 
 | 
-    authScriptIdStr.value = v;
 | 
| 
144
 | 
 
 | 
-    scriptForm.authScriptId = v;
 | 
| 
145
 | 
 
 | 
-  };
 | 
| 
146
 | 
 
 | 
-
 | 
| 
147
 | 
 
 | 
-  const [registerModal, { openModal }] = useModal();
 | 
| 
148
 | 
 
 | 
-
 | 
| 
149
 | 
 
 | 
-  const [registerAuthModal, { openModal: openAuthModel }] = useModal();
 | 
| 
150
 | 
 
 | 
-
 | 
| 
151
 | 
 
 | 
-  //TODO: 待优化
 | 
| 
152
 | 
 
 | 
-
 | 
| 
153
 | 
 
 | 
-  const handleCreateOrEditAuth = (c) => {
 | 
| 
154
 | 
 
 | 
-    if (c === 'add') {
 | 
| 
155
 | 
 
 | 
-      openAuthModel(true, {
 | 
| 
156
 | 
 
 | 
-        isUpdate: true,
 | 
| 
157
 | 
 
 | 
-        isView: false,
 | 
| 
158
 | 
 
 | 
-        isTest: false,
 | 
| 
159
 | 
 
 | 
-        isText: 'confirm',
 | 
| 
160
 | 
 
 | 
-        isTitle: 'add',
 | 
| 
161
 | 
 
 | 
-      });
 | 
| 
162
 | 
 
 | 
-    } else {
 | 
| 
163
 | 
 
 | 
-      if (!authScriptIdStr.value) return createMessage.error('请先选择对应脚本');
 | 
| 
164
 | 
 
 | 
-      openAuthModel(true, {
 | 
| 
165
 | 
 
 | 
-        isUpdate: false,
 | 
| 
166
 | 
 
 | 
-        isTest: true,
 | 
| 
167
 | 
 
 | 
-        record: authScriptIdStr.value,
 | 
| 
168
 | 
 
 | 
-        isText: 'test',
 | 
| 
169
 | 
 
 | 
-        isTitle: 'test',
 | 
| 
170
 | 
 
 | 
-      });
 | 
| 
171
 | 
 
 | 
-    }
 | 
| 
172
 | 
 
 | 
-  };
 | 
| 
173
 | 
 
 | 
-
 | 
| 
174
 | 
 
 | 
-  const handleCreateOrEdit = (c) => {
 | 
| 
175
 | 
 
 | 
-    if (c === 'add') {
 | 
| 
176
 | 
 
 | 
-      openModal(true, {
 | 
| 
177
 | 
 
 | 
-        isUpdate: true,
 | 
| 
178
 | 
 
 | 
-        isView: false,
 | 
| 
179
 | 
 
 | 
-        isTest: false,
 | 
| 
180
 | 
 
 | 
-        isText: 'confirm',
 | 
| 
181
 | 
 
 | 
-        isTitle: 'add',
 | 
| 
182
 | 
 
 | 
-      });
 | 
| 
183
 | 
 
 | 
-    } else {
 | 
| 
184
 | 
 
 | 
-      if (!upScriptIdStr.value) return createMessage.error('请先选择对应脚本');
 | 
| 
185
 | 
 
 | 
-      openModal(true, {
 | 
| 
186
 | 
 
 | 
-        isUpdate: false,
 | 
| 
187
 | 
 
 | 
-        isTest: true,
 | 
| 
188
 | 
 
 | 
-        record: upScriptIdStr.value,
 | 
| 
189
 | 
 
 | 
-        isText: 'test',
 | 
| 
190
 | 
 
 | 
-        isTitle: 'test',
 | 
| 
191
 | 
 
 | 
-      });
 | 
| 
192
 | 
 
 | 
-    }
 | 
| 
193
 | 
 
 | 
-  };
 | 
| 
194
 | 
 
 | 
-
 | 
| 
195
 | 
 
 | 
-  const getFormData = async () => {
 | 
| 
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
 | 
 
 | 
-    }
 | 
| 
211
 | 
 
 | 
-    return {
 | 
| 
212
 | 
 
 | 
-      ...scriptForm,
 | 
| 
213
 | 
 
 | 
-      type: 'TCP',
 | 
| 
214
 | 
 
 | 
-    };
 | 
| 
215
 | 
 
 | 
-  };
 | 
| 
216
 | 
 
 | 
-
 | 
| 
217
 | 
 
 | 
-  const resetFormData = () => {
 | 
| 
218
 | 
 
 | 
-    // resetFields();
 | 
| 
219
 | 
 
 | 
-  };
 | 
| 
220
 | 
 
 | 
-
 | 
| 
221
 | 
 
 | 
-  const setFormData = (v) => {
 | 
| 
222
 | 
 
 | 
-    scriptForm.authScriptId = v?.authScriptId;
 | 
| 
223
 | 
 
 | 
-    scriptForm.upScriptId = v?.upScriptId;
 | 
| 
224
 | 
 
 | 
-    // setFieldsValue(v);
 | 
| 
225
 | 
 
 | 
-    upScriptIdStr.value = v?.upScriptId;
 | 
| 
226
 | 
 
 | 
-    authScriptIdStr.value = v?.authScriptId;
 | 
| 
227
 | 
 
 | 
-  };
 | 
| 
228
 | 
 
 | 
-
 | 
| 
229
 | 
 
 | 
-  const handleSearch = (inputValue: string, option: Record<'label' | 'value', string>) => {
 | 
| 
230
 | 
 
 | 
-    return option.label.includes(inputValue);
 | 
| 
231
 | 
 
 | 
-  };
 | 
| 
232
 | 
 
 | 
-
 | 
| 
233
 | 
 
 | 
-  const handleAuthSearch = (inputValue: string, option: Record<'label' | 'value', string>) => {
 | 
| 
234
 | 
 
 | 
-    return option.label.includes(inputValue);
 | 
| 
235
 | 
 
 | 
-  };
 | 
| 
236
 | 
 
 | 
-
 | 
| 
237
 | 
 
 | 
-  defineExpose({
 | 
| 
238
 | 
 
 | 
-    getFormData,
 | 
| 
239
 | 
 
 | 
-    resetFormData,
 | 
| 
240
 | 
 
 | 
-    setFormData,
 | 
| 
241
 | 
 
 | 
-  });
 | 
| 
242
 | 
 
 | 
-</script>
 | 
| 
243
 | 
 
 | 
-<style lang="less" scoped></style> | 
| 
 
 | 
1
 | 
+<template>
 | 
| 
 
 | 
2
 | 
+  <div>
 | 
| 
 
 | 
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
 | 
+      >
 | 
| 
 
 | 
18
 | 
+        <div style="display: flex; align-items: center">
 | 
| 
 
 | 
19
 | 
+          <div>
 | 
| 
 
 | 
20
 | 
+            <Select
 | 
| 
 
 | 
21
 | 
+              @change="handleAuthChange"
 | 
| 
 
 | 
22
 | 
+              placeholder="请选择"
 | 
| 
 
 | 
23
 | 
+              v-model:value="scriptForm.authScriptId"
 | 
| 
 
 | 
24
 | 
+              style="width: 305px"
 | 
| 
 
 | 
25
 | 
+              show-search
 | 
| 
 
 | 
26
 | 
+              :options="selectAuthOptions"
 | 
| 
 
 | 
27
 | 
+              :filter-option="handleAuthSearch"
 | 
| 
 
 | 
28
 | 
+              allowClear
 | 
| 
 
 | 
29
 | 
+            />
 | 
| 
 
 | 
30
 | 
+          </div>
 | 
| 
 
 | 
31
 | 
+          <div>
 | 
| 
 
 | 
32
 | 
+            <span
 | 
| 
 
 | 
33
 | 
+              @click="handleCreateOrEditAuth('add')"
 | 
| 
 
 | 
34
 | 
+              class="ml-2"
 | 
| 
 
 | 
35
 | 
+              style="color: #409eff; cursor: pointer"
 | 
| 
 
 | 
36
 | 
+              size="small"
 | 
| 
 
 | 
37
 | 
+              >新建转换脚本</span
 | 
| 
 
 | 
38
 | 
+            >
 | 
| 
 
 | 
39
 | 
+          </div>
 | 
| 
 
 | 
40
 | 
+        </div>
 | 
| 
 
 | 
41
 | 
+        <a-button @click="handleCreateOrEditAuth('test')" class="mt-4" type="primary"
 | 
| 
 
 | 
42
 | 
+          >测试脚本</a-button
 | 
| 
 
 | 
43
 | 
+        >
 | 
| 
 
 | 
44
 | 
+      </a-form-item>
 | 
| 
 
 | 
45
 | 
+      <a-form-item
 | 
| 
 
 | 
46
 | 
+        label="上行脚本"
 | 
| 
 
 | 
47
 | 
+        name="'params'"
 | 
| 
 
 | 
48
 | 
+        :rules="[{ required: true, message: '请选择上行脚本' }]"
 | 
| 
 
 | 
49
 | 
+      >
 | 
| 
 
 | 
50
 | 
+        <div style="display: flex; align-items: center">
 | 
| 
 
 | 
51
 | 
+          <div>
 | 
| 
 
 | 
52
 | 
+            <Select
 | 
| 
 
 | 
53
 | 
+              @change="handleUpChange"
 | 
| 
 
 | 
54
 | 
+              placeholder="请选择"
 | 
| 
 
 | 
55
 | 
+              v-model:value="scriptForm.upScriptId"
 | 
| 
 
 | 
56
 | 
+              style="width: 305px"
 | 
| 
 
 | 
57
 | 
+              show-search
 | 
| 
 
 | 
58
 | 
+              :options="selectUpOptions"
 | 
| 
 
 | 
59
 | 
+              :filter-option="handleSearch"
 | 
| 
 
 | 
60
 | 
+              allowClear
 | 
| 
 
 | 
61
 | 
+            />
 | 
| 
 
 | 
62
 | 
+          </div>
 | 
| 
 
 | 
63
 | 
+          <div>
 | 
| 
 
 | 
64
 | 
+            <span
 | 
| 
 
 | 
65
 | 
+              @click="handleCreateOrEdit('add')"
 | 
| 
 
 | 
66
 | 
+              class="ml-2"
 | 
| 
 
 | 
67
 | 
+              style="color: #409eff; cursor: pointer"
 | 
| 
 
 | 
68
 | 
+              size="small"
 | 
| 
 
 | 
69
 | 
+              >新建转换脚本</span
 | 
| 
 
 | 
70
 | 
+            >
 | 
| 
 
 | 
71
 | 
+          </div>
 | 
| 
 
 | 
72
 | 
+        </div>
 | 
| 
 
 | 
73
 | 
+        <a-button @click="handleCreateOrEdit('test')" class="mt-4" type="primary"
 | 
| 
 
 | 
74
 | 
+          >测试脚本</a-button
 | 
| 
 
 | 
75
 | 
+        >
 | 
| 
 
 | 
76
 | 
+      </a-form-item>
 | 
| 
 
 | 
77
 | 
+    </a-form>
 | 
| 
 
 | 
78
 | 
+    <ConverScriptModal @register="registerModal" @success="handleSuccess" />
 | 
| 
 
 | 
79
 | 
+    <ConverScriptModal @register="registerAuthModal" @success="handleAuthSuccess" />
 | 
| 
 
 | 
80
 | 
+  </div>
 | 
| 
 
 | 
81
 | 
+</template>
 | 
| 
 
 | 
82
 | 
+<script lang="ts" setup name="index">
 | 
| 
 
 | 
83
 | 
+  import { ref, Ref, onMounted, reactive } from 'vue';
 | 
| 
 
 | 
84
 | 
+  import { SelectTypes } from 'ant-design-vue/es/select';
 | 
| 
 
 | 
85
 | 
+  import { Select } from 'ant-design-vue';
 | 
| 
 
 | 
86
 | 
+  import { useModal } from '/@/components/Modal';
 | 
| 
 
 | 
87
 | 
+  import { getScriptManageMeList } from '/@/api/scriptmanage/scriptManager';
 | 
| 
 
 | 
88
 | 
+  import ConverScriptModal from '/@/views/rule/script/TcpConversionScript/ConverScriptModal.vue';
 | 
| 
 
 | 
89
 | 
+  import { useMessage } from '/@/hooks/web/useMessage';
 | 
| 
 
 | 
90
 | 
+
 | 
| 
 
 | 
91
 | 
+  const props = defineProps({
 | 
| 
 
 | 
92
 | 
+    deviceTypeStr: { type: String, default: '' },
 | 
| 
 
 | 
93
 | 
+  });
 | 
| 
 
 | 
94
 | 
+
 | 
| 
 
 | 
95
 | 
+  const scriptForm = reactive({
 | 
| 
 
 | 
96
 | 
+    authScriptId: '',
 | 
| 
 
 | 
97
 | 
+    upScriptId: '',
 | 
| 
 
 | 
98
 | 
+  });
 | 
| 
 
 | 
99
 | 
+  const selectUpOptions: Ref<SelectTypes['options']> = ref([]);
 | 
| 
 
 | 
100
 | 
+
 | 
| 
 
 | 
101
 | 
+  const selectAuthOptions: Ref<SelectTypes['options']> = ref([]);
 | 
| 
 
 | 
102
 | 
+
 | 
| 
 
 | 
103
 | 
+  const { createMessage } = useMessage();
 | 
| 
 
 | 
104
 | 
+
 | 
| 
 
 | 
105
 | 
+  const upScriptIdStr = ref('');
 | 
| 
 
 | 
106
 | 
+
 | 
| 
 
 | 
107
 | 
+  const authScriptIdStr = ref('');
 | 
| 
 
 | 
108
 | 
+
 | 
| 
 
 | 
109
 | 
+  onMounted(async () => {
 | 
| 
 
 | 
110
 | 
+    selectUpOptions.value = await getAllScriptType('TRANSPORT_TCP_UP');
 | 
| 
 
 | 
111
 | 
+    selectAuthOptions.value = await getAllScriptType('TRANSPORT_TCP_AUTH');
 | 
| 
 
 | 
112
 | 
+  });
 | 
| 
 
 | 
113
 | 
+
 | 
| 
 
 | 
114
 | 
+  const getAllScriptType = async (type) => {
 | 
| 
 
 | 
115
 | 
+    const rest = await getScriptManageMeList({ scriptType: type });
 | 
| 
 
 | 
116
 | 
+    return rest.map((m) => ({ label: m.name, value: m.id }));
 | 
| 
 
 | 
117
 | 
+  };
 | 
| 
 
 | 
118
 | 
+
 | 
| 
 
 | 
119
 | 
+  const handleSuccess = async ({ res, text }) => {
 | 
| 
 
 | 
120
 | 
+    if (text !== 'test') {
 | 
| 
 
 | 
121
 | 
+      const rest = await getAllScriptType('TRANSPORT_TCP_UP');
 | 
| 
 
 | 
122
 | 
+      selectUpOptions.value = rest;
 | 
| 
 
 | 
123
 | 
+      scriptForm.upScriptId = res?.id;
 | 
| 
 
 | 
124
 | 
+      upScriptIdStr.value = res?.id;
 | 
| 
 
 | 
125
 | 
+    }
 | 
| 
 
 | 
126
 | 
+  };
 | 
| 
 
 | 
127
 | 
+
 | 
| 
 
 | 
128
 | 
+  const handleAuthSuccess = async ({ res, text }) => {
 | 
| 
 
 | 
129
 | 
+    if (text !== 'test') {
 | 
| 
 
 | 
130
 | 
+      const rest = await getAllScriptType('TRANSPORT_TCP_AUTH');
 | 
| 
 
 | 
131
 | 
+      selectAuthOptions.value = rest;
 | 
| 
 
 | 
132
 | 
+      scriptForm.authScriptId = res?.id;
 | 
| 
 
 | 
133
 | 
+      authScriptIdStr.value = res?.id;
 | 
| 
 
 | 
134
 | 
+    }
 | 
| 
 
 | 
135
 | 
+  };
 | 
| 
 
 | 
136
 | 
+
 | 
| 
 
 | 
137
 | 
+  const handleUpChange = (v) => {
 | 
| 
 
 | 
138
 | 
+    upScriptIdStr.value = v;
 | 
| 
 
 | 
139
 | 
+    scriptForm.upScriptId = v;
 | 
| 
 
 | 
140
 | 
+  };
 | 
| 
 
 | 
141
 | 
+
 | 
| 
 
 | 
142
 | 
+  const handleAuthChange = (v) => {
 | 
| 
 
 | 
143
 | 
+    authScriptIdStr.value = v;
 | 
| 
 
 | 
144
 | 
+    scriptForm.authScriptId = v;
 | 
| 
 
 | 
145
 | 
+  };
 | 
| 
 
 | 
146
 | 
+
 | 
| 
 
 | 
147
 | 
+  const [registerModal, { openModal }] = useModal();
 | 
| 
 
 | 
148
 | 
+
 | 
| 
 
 | 
149
 | 
+  const [registerAuthModal, { openModal: openAuthModel }] = useModal();
 | 
| 
 
 | 
150
 | 
+
 | 
| 
 
 | 
151
 | 
+  //TODO: 待优化
 | 
| 
 
 | 
152
 | 
+
 | 
| 
 
 | 
153
 | 
+  const handleCreateOrEditAuth = (c) => {
 | 
| 
 
 | 
154
 | 
+    if (c === 'add') {
 | 
| 
 
 | 
155
 | 
+      openAuthModel(true, {
 | 
| 
 
 | 
156
 | 
+        isUpdate: true,
 | 
| 
 
 | 
157
 | 
+        isView: false,
 | 
| 
 
 | 
158
 | 
+        isTest: false,
 | 
| 
 
 | 
159
 | 
+        isText: 'confirm',
 | 
| 
 
 | 
160
 | 
+        isTitle: 'add',
 | 
| 
 
 | 
161
 | 
+      });
 | 
| 
 
 | 
162
 | 
+    } else {
 | 
| 
 
 | 
163
 | 
+      if (!authScriptIdStr.value) return createMessage.error('请先选择对应脚本');
 | 
| 
 
 | 
164
 | 
+      openAuthModel(true, {
 | 
| 
 
 | 
165
 | 
+        isUpdate: false,
 | 
| 
 
 | 
166
 | 
+        isTest: true,
 | 
| 
 
 | 
167
 | 
+        record: authScriptIdStr.value,
 | 
| 
 
 | 
168
 | 
+        isText: 'test',
 | 
| 
 
 | 
169
 | 
+        isTitle: 'test',
 | 
| 
 
 | 
170
 | 
+      });
 | 
| 
 
 | 
171
 | 
+    }
 | 
| 
 
 | 
172
 | 
+  };
 | 
| 
 
 | 
173
 | 
+
 | 
| 
 
 | 
174
 | 
+  const handleCreateOrEdit = (c) => {
 | 
| 
 
 | 
175
 | 
+    if (c === 'add') {
 | 
| 
 
 | 
176
 | 
+      openModal(true, {
 | 
| 
 
 | 
177
 | 
+        isUpdate: true,
 | 
| 
 
 | 
178
 | 
+        isView: false,
 | 
| 
 
 | 
179
 | 
+        isTest: false,
 | 
| 
 
 | 
180
 | 
+        isText: 'confirm',
 | 
| 
 
 | 
181
 | 
+        isTitle: 'add',
 | 
| 
 
 | 
182
 | 
+      });
 | 
| 
 
 | 
183
 | 
+    } else {
 | 
| 
 
 | 
184
 | 
+      if (!upScriptIdStr.value) return createMessage.error('请先选择对应脚本');
 | 
| 
 
 | 
185
 | 
+      openModal(true, {
 | 
| 
 
 | 
186
 | 
+        isUpdate: false,
 | 
| 
 
 | 
187
 | 
+        isTest: true,
 | 
| 
 
 | 
188
 | 
+        record: upScriptIdStr.value,
 | 
| 
 
 | 
189
 | 
+        isText: 'test',
 | 
| 
 
 | 
190
 | 
+        isTitle: 'test',
 | 
| 
 
 | 
191
 | 
+      });
 | 
| 
 
 | 
192
 | 
+    }
 | 
| 
 
 | 
193
 | 
+  };
 | 
| 
 
 | 
194
 | 
+
 | 
| 
 
 | 
195
 | 
+  const getFormData = async () => {
 | 
| 
 
 | 
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
 | 
+    }
 | 
| 
 
 | 
211
 | 
+    return {
 | 
| 
 
 | 
212
 | 
+      ...scriptForm,
 | 
| 
 
 | 
213
 | 
+      type: 'TCP',
 | 
| 
 
 | 
214
 | 
+    };
 | 
| 
 
 | 
215
 | 
+  };
 | 
| 
 
 | 
216
 | 
+
 | 
| 
 
 | 
217
 | 
+  const resetFormData = () => {
 | 
| 
 
 | 
218
 | 
+    // resetFields();
 | 
| 
 
 | 
219
 | 
+  };
 | 
| 
 
 | 
220
 | 
+
 | 
| 
 
 | 
221
 | 
+  const setFormData = (v) => {
 | 
| 
 
 | 
222
 | 
+    scriptForm.authScriptId = v?.authScriptId;
 | 
| 
 
 | 
223
 | 
+    scriptForm.upScriptId = v?.upScriptId;
 | 
| 
 
 | 
224
 | 
+    // setFieldsValue(v);
 | 
| 
 
 | 
225
 | 
+    upScriptIdStr.value = v?.upScriptId;
 | 
| 
 
 | 
226
 | 
+    authScriptIdStr.value = v?.authScriptId;
 | 
| 
 
 | 
227
 | 
+  };
 | 
| 
 
 | 
228
 | 
+
 | 
| 
 
 | 
229
 | 
+  const handleSearch = (inputValue: string, option: Record<'label' | 'value', string>) => {
 | 
| 
 
 | 
230
 | 
+    return option.label.includes(inputValue);
 | 
| 
 
 | 
231
 | 
+  };
 | 
| 
 
 | 
232
 | 
+
 | 
| 
 
 | 
233
 | 
+  const handleAuthSearch = (inputValue: string, option: Record<'label' | 'value', string>) => {
 | 
| 
 
 | 
234
 | 
+    return option.label.includes(inputValue);
 | 
| 
 
 | 
235
 | 
+  };
 | 
| 
 
 | 
236
 | 
+
 | 
| 
 
 | 
237
 | 
+  defineExpose({
 | 
| 
 
 | 
238
 | 
+    getFormData,
 | 
| 
 
 | 
239
 | 
+    resetFormData,
 | 
| 
 
 | 
240
 | 
+    setFormData,
 | 
| 
 
 | 
241
 | 
+  });
 | 
| 
 
 | 
242
 | 
+</script>
 | 
| 
 
 | 
243
 | 
+<style lang="less" scoped></style> | 
...
 | 
...
 | 
 |