ruoyi-plus-soybean/src/components/custom/workflow-category-select.vue

58 lines
1.4 KiB
Vue
Raw Normal View History

2025-05-22 22:56:59 +08:00
<script setup lang="tsx">
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';
import { isNull } from '@/utils/common';
2025-05-22 22:56:59 +08:00
defineOptions({ name: 'WorkflowCategorySelect' });
interface Props {
[key: string]: any;
}
defineProps<Props>();
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();
/** 转换为strid可能是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-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
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>