Files
certd/packages/ui/certd-client/src/components/plugins/common/remote-select.vue
T

68 lines
1.3 KiB
Vue
Raw Normal View History

2024-09-27 02:15:41 +08:00
<script setup lang="ts">
import { ComponentPropsType, doRequest } from "/@/components/plugins/lib";
import { ref, watch } from "vue";
const props = defineProps<
{
watches: string[];
} & ComponentPropsType
>();
const emit = defineEmits<{
"update:value": any;
}>();
const optionsRef = ref([]);
const getOptions = async () => {
return await doRequest({
type: props.type,
typeName: props.typeName,
action: props.action,
input: props.form
});
};
2024-09-30 18:00:51 +08:00
const filterOption = (input: string, option: any) => {
return option.label.toLowerCase().indexOf(input.toLowerCase()) >= 0 || String(option.value).toLowerCase().indexOf(input.toLowerCase());
};
let isFirst = true;
async function onClick() {
if (!isFirst) {
return;
}
isFirst = false;
optionsRef.value = await getOptions();
}
2024-09-27 02:15:41 +08:00
watch(
() => {
const values = [];
for (const item of props.watches) {
values.push(props.form[item]);
}
return {
form: props.form,
watched: values
};
},
async () => {
optionsRef.value = await getOptions();
2024-09-30 18:00:51 +08:00
}
2024-09-27 02:15:41 +08:00
);
</script>
<template>
2024-09-30 18:00:51 +08:00
<a-select
class="remote-select"
show-search
:filter-option="filterOption"
:options="optionsRef"
:value="value"
@click="onClick"
@update:value="emit('update:value', $event)"
/>
2024-09-27 02:15:41 +08:00
</template>
<style lang="less"></style>