mirror of
https://github.com/m-xlsea/ruoyi-plus-soybean.git
synced 2025-09-24 07:49:47 +08:00
feat: 更新工作流分类选择组件,修复值回显问题并优化添加数据操作
This commit is contained in:
@ -1,8 +1,9 @@
|
||||
<script setup lang="tsx">
|
||||
import { useAttrs } from 'vue';
|
||||
import { computed, useAttrs } from 'vue';
|
||||
import type { TreeSelectProps } from 'naive-ui';
|
||||
import { useLoading } from '@sa/hooks';
|
||||
import { fetchGetCategoryTree } from '@/service/api/workflow';
|
||||
import { isNull } from '@/utils/common';
|
||||
|
||||
defineOptions({ name: 'WorkflowCategorySelect' });
|
||||
|
||||
@ -12,12 +13,17 @@ interface Props {
|
||||
|
||||
defineProps<Props>();
|
||||
|
||||
const value = defineModel<CommonType.IdType | null>('value', { required: false });
|
||||
const rawValue = defineModel<CommonType.IdType | null>('value', { required: false });
|
||||
const options = defineModel<Api.Common.CommonTreeRecord>('options', { required: false, default: [] });
|
||||
|
||||
const attrs: TreeSelectProps = useAttrs();
|
||||
const { loading, startLoading, endLoading } = useLoading();
|
||||
|
||||
/** 转换为str,id可能是number类型或者String类型,导致回显失败 */
|
||||
const strValue = computed(() => {
|
||||
return isNull(rawValue.value) ? null : rawValue.value?.toString();
|
||||
});
|
||||
|
||||
async function getCategoryList() {
|
||||
startLoading();
|
||||
const { error, data } = await fetchGetCategoryTree();
|
||||
@ -31,7 +37,7 @@ getCategoryList();
|
||||
|
||||
<template>
|
||||
<NTreeSelect
|
||||
v-model:value="value"
|
||||
v-model:value="strValue"
|
||||
filterable
|
||||
class="h-full"
|
||||
:loading="loading"
|
||||
|
@ -143,6 +143,10 @@ async function addInRow(row: TableDataWithIndex<Api.Workflow.WorkflowCategory>)
|
||||
handleAdd();
|
||||
}
|
||||
|
||||
async function handleAddDataOperate() {
|
||||
editingData.value = null;
|
||||
handleAdd();
|
||||
}
|
||||
function handleExport() {
|
||||
download('/workflow/category/export', searchParams, `流程分类_#[[${new Date().getTime()}]]#.xlsx`);
|
||||
}
|
||||
@ -159,7 +163,7 @@ function handleExport() {
|
||||
:show-add="hasAuth('workflow:category:add')"
|
||||
:show-delete="false"
|
||||
:show-export="false"
|
||||
@add="handleAdd"
|
||||
@add="handleAddDataOperate"
|
||||
@export="handleExport"
|
||||
@refresh="getData"
|
||||
>
|
||||
|
@ -43,7 +43,7 @@ const model: Model = reactive(createDefaultModel());
|
||||
|
||||
function createDefaultModel(): Model {
|
||||
return {
|
||||
parentId: null,
|
||||
parentId: props.rowData?.categoryId,
|
||||
categoryName: '',
|
||||
orderNum: 0
|
||||
};
|
||||
@ -60,7 +60,6 @@ const rules: Record<RuleKey, App.Global.FormRule> = {
|
||||
function handleUpdateModelWhenEdit() {
|
||||
if (props.operateType === 'add') {
|
||||
Object.assign(model, createDefaultModel());
|
||||
model.parentId = props.rowData?.categoryId || 0;
|
||||
return;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user