index.vue
6.11 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
<template>
<div>
<BasicForm :showResetButton="false" :showSubmitButton="false" @register="register">
<template #authScriptId="{ model, field }">
<div style="display: flex; align-items: center">
<div>
<Select
@change="handleAuthChange"
placeholder="请选择"
v-model:value="model[field]"
style="width: 305px"
show-search
:options="selectAuthOptions"
:filter-option="handleAuthSearch"
allowClear
/>
</div>
<div>
<span
@click="handleCreateOrEditAuth('add')"
class="ml-2"
style="color: #409eff; cursor: pointer"
size="small"
>新建转换脚本</span
>
</div>
</div>
<a-button @click="handleCreateOrEditAuth('test')" class="mt-4" type="primary"
>测试脚本</a-button
>
</template>
<template #upScriptId="{ model, field }">
<div style="display: flex; align-items: center">
<div>
<Select
@change="handleUpChange"
placeholder="请选择"
v-model:value="model[field]"
style="width: 305px"
show-search
:options="selectUpOptions"
:filter-option="handleSearch"
allowClear
/>
</div>
<div>
<span
@click="handleCreateOrEdit('add')"
class="ml-2"
style="color: #409eff; cursor: pointer"
size="small"
>新建转换脚本</span
>
</div>
</div>
<a-button @click="handleCreateOrEdit('test')" class="mt-4" type="primary"
>测试脚本</a-button
>
</template>
</BasicForm>
<ConverScriptModal @register="registerModal" @success="handleSuccess" />
<ConverScriptModal @register="registerAuthModal" @success="handleAuthSuccess" />
</div>
</template>
<script lang="ts" setup name="index">
import { ref, Ref, onMounted } from 'vue';
import { BasicForm, useForm } from '/@/components/Form';
import { tcpSchemas } from './config';
import { SelectTypes } from 'ant-design-vue/es/select';
import { Select } from 'ant-design-vue';
import { useModal } from '/@/components/Modal';
import { getScriptManageMeList } from '/@/api/scriptmanage/scriptManager';
import ConverScriptModal from '/@/views/scriptmanage/converscript/ConverScriptModal.vue';
import { useMessage } from '/@/hooks/web/useMessage';
const selectUpOptions: Ref<SelectTypes['options']> = ref([]);
const selectAuthOptions: Ref<SelectTypes['options']> = ref([]);
const { createMessage } = useMessage();
const upScriptIdStr = ref('');
const authScriptIdStr = ref('');
onMounted(async () => {
selectUpOptions.value = await getAllScriptType('TRANSPORT_TCP_UP');
selectAuthOptions.value = await getAllScriptType('TRANSPORT_TCP_AUTH');
});
const getAllScriptType = async (type) => {
const rest = await getScriptManageMeList({ scriptType: type });
return rest.map((m) => ({ label: m.name, value: m.id }));
};
const handleSuccess = async ({ res, text }) => {
if (text !== 'test') {
const rest = await getAllScriptType('TRANSPORT_TCP_UP');
selectUpOptions.value = rest;
setFieldsValue({ upScriptId: res?.id });
upScriptIdStr.value = res?.id;
}
};
const handleAuthSuccess = async ({ res, text }) => {
if (text !== 'test') {
const rest = await getAllScriptType('TRANSPORT_TCP_AUTH');
selectAuthOptions.value = rest;
setFieldsValue({ authScriptId: res?.id });
authScriptIdStr.value = res?.id;
}
};
const [register, { validate, resetFields, setFieldsValue }] = useForm({
labelWidth: 180,
schemas: tcpSchemas,
actionColOptions: {
span: 14,
},
});
const handleUpChange = (v) => (upScriptIdStr.value = v);
const handleAuthChange = (v) => (authScriptIdStr.value = v);
const [registerModal, { openModal }] = useModal();
const [registerAuthModal, { openModal: openAuthModel }] = useModal();
//TODO: 待优化
const handleCreateOrEditAuth = (c) => {
if (c === 'add') {
openAuthModel(true, {
isUpdate: true,
isView: false,
isTest: false,
isText: 'confirm',
isTitle: 'add',
});
} else {
if (!authScriptIdStr.value) return createMessage.error('请先选择对应脚本');
openAuthModel(true, {
isUpdate: false,
isTest: true,
record: authScriptIdStr.value,
isText: 'test',
isTitle: 'test',
});
}
};
const handleCreateOrEdit = (c) => {
if (c === 'add') {
openModal(true, {
isUpdate: true,
isView: false,
isTest: false,
isText: 'confirm',
isTitle: 'add',
});
} else {
if (!upScriptIdStr.value) return createMessage.error('请先选择对应脚本');
openModal(true, {
isUpdate: false,
isTest: true,
record: upScriptIdStr.value,
isText: 'test',
isTitle: 'test',
});
}
};
const getFormData = async () => {
const values = await validate();
if (!values) return;
return {
...values,
type: 'TCP',
};
};
const resetFormData = () => {
resetFields();
};
const setFormData = (v) => {
setFieldsValue(v);
upScriptIdStr.value = v?.upScriptId;
authScriptIdStr.value = v?.authScriptId;
};
const handleSearch = (inputValue: string, option: Record<'label' | 'value', string>) => {
return option.label.includes(inputValue);
};
const handleAuthSearch = (inputValue: string, option: Record<'label' | 'value', string>) => {
return option.label.includes(inputValue);
};
defineExpose({
getFormData,
resetFormData,
setFormData,
});
</script>
<style lang="less" scoped></style>