TCPDescription.vue
3.28 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
<script lang="ts" setup>
import { Button, Tag } from 'ant-design-vue';
import { h, onMounted, ref, unref, Ref } from 'vue';
import { DeviceRecord } from '/@/api/device/model/deviceModel';
import { getScriptManageMeList } from '/@/api/scriptmanage/scriptManager';
import { Description, useDescription } from '/@/components/Description';
import { useModal } from '/@/components/Modal';
import { ConverScriptModal } from '/@/views/rule/script/TcpConversionScript/components';
import { SelectTypes } from 'ant-design-vue/es/select';
import { BusinessConvertScriptTextEnum } from '/@/views/rule/script/TcpConversionScript/config';
const props = defineProps<{
record: DeviceRecord['profileData']['transportConfiguration'];
}>();
const authScriptIdStr = ref('');
const upScriptIdStr = ref('');
const selectUpOptions: Ref<SelectTypes['options']> = ref([]);
const selectAuthOptions: Ref<SelectTypes['options']> = ref([]);
onMounted(async () => {
selectUpOptions.value = await getAllScriptType('TRANSPORT_TCP_UP');
selectAuthOptions.value = await getAllScriptType('TRANSPORT_TCP_AUTH');
setDescProps({
data: Object.assign(props.record),
});
});
const getAllScriptType = async (type) => {
const rest = await getScriptManageMeList({ scriptType: type });
return rest.map((m) => ({ label: m.name, value: m.id }));
};
const findScriptUpName = (scriptId) => {
upScriptIdStr.value = scriptId;
return selectUpOptions.value?.find((it) => it.value === scriptId)?.label;
};
const findScriptAuthName = (scriptId) => {
authScriptIdStr.value = scriptId;
return selectAuthOptions.value?.find((it) => it.value === scriptId)?.label;
};
const [register, { setDescProps }] = useDescription({
layout: 'vertical',
column: 2,
data: props.record,
schema: [
{
field: 'type',
label: '接入协议',
span: 2,
},
{
field: 'authScriptId',
label: '鉴权脚本',
render: (value: string) => {
return (
value &&
h('div', [
h(Tag, { color: 'blue' }, () => findScriptAuthName(value)),
h(Button, { type: 'link', onClick: handleTestAuthScript }, () => '测试脚本'),
])
);
},
},
{
field: 'upScriptId',
label: '上行脚本',
render: (value: string) => {
return (
value &&
h('div', [
h(Tag, { color: 'blue' }, () => findScriptUpName(value)),
h(Button, { type: 'link', onClick: handleTestUpScript }, () => '测试脚本'),
])
);
},
},
],
});
const [registerModal, { openModal }] = useModal();
const handleTestAuthScript = () => {
const modalParams = {
text: BusinessConvertScriptTextEnum.BUSINESS_TEST_TEXT,
record: { id: unref(authScriptIdStr) },
};
openModal(true, modalParams);
};
const handleTestUpScript = () => {
const modalParams = {
text: BusinessConvertScriptTextEnum.BUSINESS_TEST_TEXT,
record: { id: unref(upScriptIdStr) },
};
openModal(true, modalParams);
};
</script>
<template>
<section>
<Description @register="register" />
<ConverScriptModal @register="registerModal" />
</section>
</template>