2024-09-27 02:15:41 +08:00
|
|
|
<script setup lang="ts">
|
|
|
|
|
import { ComponentPropsType, doRequest } from "/@/components/plugins/lib";
|
|
|
|
|
import { ref, watch } from "vue";
|
|
|
|
|
|
2024-10-07 03:21:16 +08:00
|
|
|
defineOptions({
|
|
|
|
|
name: "RemoteSelect"
|
|
|
|
|
});
|
|
|
|
|
|
2024-09-27 02:15:41 +08:00
|
|
|
const props = defineProps<
|
|
|
|
|
{
|
|
|
|
|
watches: string[];
|
|
|
|
|
} & ComponentPropsType
|
|
|
|
|
>();
|
|
|
|
|
|
|
|
|
|
const emit = defineEmits<{
|
|
|
|
|
"update:value": any;
|
|
|
|
|
}>();
|
|
|
|
|
|
|
|
|
|
const optionsRef = ref([]);
|
2024-10-03 01:29:12 +08:00
|
|
|
const message = ref("");
|
2024-09-27 02:15:41 +08:00
|
|
|
const getOptions = async () => {
|
2024-10-03 01:29:12 +08:00
|
|
|
return await doRequest(
|
|
|
|
|
{
|
|
|
|
|
type: props.type,
|
|
|
|
|
typeName: props.typeName,
|
|
|
|
|
action: props.action,
|
|
|
|
|
input: props.form
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
onError(err) {
|
|
|
|
|
message.value = err.message;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
);
|
2024-09-27 02:15:41 +08:00
|
|
|
};
|
|
|
|
|
|
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-10-03 01:29:12 +08:00
|
|
|
<div>
|
|
|
|
|
<a-select
|
2024-10-07 03:21:16 +08:00
|
|
|
class="remote-select"
|
|
|
|
|
show-search
|
|
|
|
|
:filter-option="filterOption"
|
|
|
|
|
:options="optionsRef"
|
|
|
|
|
:value="value"
|
|
|
|
|
@click="onClick"
|
|
|
|
|
@update:value="emit('update:value', $event)"
|
|
|
|
|
/>
|
2024-10-03 01:29:12 +08:00
|
|
|
<div class="helper">
|
|
|
|
|
{{ message }}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2024-09-27 02:15:41 +08:00
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<style lang="less"></style>
|