2025-05-22 22:56:59 +08:00
|
|
|
|
<script setup lang="tsx">
|
2025-05-27 22:41:48 +08:00
|
|
|
|
import { computed, useAttrs } from 'vue';
|
2025-05-22 22:56:59 +08:00
|
|
|
|
import type { TreeSelectProps } from 'naive-ui';
|
|
|
|
|
import { useLoading } from '@sa/hooks';
|
|
|
|
|
import { fetchGetCategoryTree } from '@/service/api/workflow';
|
2025-05-27 22:41:48 +08:00
|
|
|
|
import { isNull } from '@/utils/common';
|
2025-05-22 22:56:59 +08:00
|
|
|
|
|
|
|
|
|
defineOptions({ name: 'WorkflowCategorySelect' });
|
|
|
|
|
|
|
|
|
|
interface Props {
|
|
|
|
|
[key: string]: any;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
defineProps<Props>();
|
|
|
|
|
|
2025-05-27 22:41:48 +08:00
|
|
|
|
const rawValue = defineModel<CommonType.IdType | null>('value', { required: false });
|
2025-05-22 22:56:59 +08:00
|
|
|
|
const options = defineModel<Api.Common.CommonTreeRecord>('options', { required: false, default: [] });
|
|
|
|
|
|
|
|
|
|
const attrs: TreeSelectProps = useAttrs();
|
|
|
|
|
const { loading, startLoading, endLoading } = useLoading();
|
|
|
|
|
|
2025-05-27 22:41:48 +08:00
|
|
|
|
/** 转换为str,id可能是number类型或者String类型,导致回显失败 */
|
2025-05-29 10:34:00 +08:00
|
|
|
|
const strValue = computed({
|
|
|
|
|
get() {
|
|
|
|
|
return isNull(rawValue.value) ? null : rawValue.value?.toString();
|
|
|
|
|
},
|
|
|
|
|
set(val) {
|
|
|
|
|
rawValue.value = val;
|
|
|
|
|
}
|
2025-05-27 22:41:48 +08:00
|
|
|
|
});
|
|
|
|
|
|
2025-05-22 22:56:59 +08:00
|
|
|
|
async function getCategoryList() {
|
|
|
|
|
startLoading();
|
|
|
|
|
const { error, data } = await fetchGetCategoryTree();
|
|
|
|
|
if (error) return;
|
|
|
|
|
options.value = data;
|
|
|
|
|
endLoading();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getCategoryList();
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<template>
|
|
|
|
|
<NTreeSelect
|
2025-05-27 22:41:48 +08:00
|
|
|
|
v-model:value="strValue"
|
2025-05-22 22:56:59 +08:00
|
|
|
|
filterable
|
|
|
|
|
class="h-full"
|
|
|
|
|
:loading="loading"
|
|
|
|
|
key-field="id"
|
|
|
|
|
label-field="label"
|
|
|
|
|
:options="options as []"
|
|
|
|
|
:default-expanded-keys="[0]"
|
|
|
|
|
v-bind="attrs"
|
|
|
|
|
/>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<style scoped></style>
|