ScriptSelectItem.vue
3.14 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
<template>
<div class="flex">
<div>
<Select
v-bind="$attrs"
placeholder="请选择脚本"
@change="handleChange"
v-model:value="scriptId"
style="width: 305px"
show-search
:options="selectOptions"
:filter-option="handleSearch"
allowClear
/>
</div>
<div>
<span
@click="handleBusinessModal(BusinessConvertScriptTextEnum.BUSINESS_ADD_TEXT)"
class="ml-2"
style="color: #409eff; cursor: pointer"
size="small"
>新建转换脚本</span
>
</div>
</div>
<a-button
@click="handleBusinessModal(BusinessConvertScriptTextEnum.BUSINESS_TEST_TEXT)"
class="mt-4"
type="primary"
>测试脚本</a-button
>
<ConverScriptModal @register="registerModal" @success="handleSuccess" />
</template>
<script lang="ts" setup name="ScriptSelectItem">
import { ref, Ref, onMounted } from 'vue';
import { SelectTypes } from 'ant-design-vue/es/select';
import { Select } from 'ant-design-vue';
import {
BusinessConvertScriptTextEnum,
ScriptTypeEnum,
} from '/@/views/rule/script/TcpConversionScript/config';
import { getScriptManageMeList } from '/@/api/scriptmanage/scriptManager';
import { useModal } from '/@/components/Modal';
import { useMessage } from '/@/hooks/web/useMessage';
import { ConverScriptModal } from '/@/views/rule/script/TcpConversionScript/components';
const props = defineProps({
scriptType: {
type: String,
default: ScriptTypeEnum.TRANSPORT_TCP_AUTH,
},
modelValue: {
type: String,
default: '',
},
});
const emits = defineEmits(['update:modelValue', 'change']);
const { createMessage } = useMessage();
const selectOptions: Ref<SelectTypes['options']> = ref([]);
//如果是空字符串,placeholder没提示文字
const scriptId = ref<any>(null);
onMounted(() => {
getSelectOptions();
});
const getSelectOptions = async () => {
selectOptions.value = await getAllScriptType(props.scriptType);
};
const getAllScriptType = async (type) => {
const rest = await getScriptManageMeList({ scriptType: type });
return rest.map((m) => ({ label: m.name, value: m.id }));
};
const handleSearch = (inputValue: string, option: Record<'label' | 'value', string>) => {
return option.label.includes(inputValue);
};
const [registerModal, { openModal }] = useModal();
// 业务弹窗
const handleBusinessModal = (text) => {
const modalParams = {
text,
record:
text !== BusinessConvertScriptTextEnum.BUSINESS_ADD_TEXT ? { id: scriptId.value } : null,
scriptType: props.scriptType,
};
if (!scriptId.value) return createMessage.error('请先选择对应脚本');
openModal(true, modalParams);
};
const handleSuccess = () => {
getSelectOptions();
};
const handleChange = (value) => {
emits('update:modelValue', value);
emits('change', value);
};
const setValue = (value) => {
scriptId.value = value;
};
defineExpose({
setValue,
});
</script>