chore: 更新分类逻辑

This commit is contained in:
dap 2024-10-30 15:04:12 +08:00
parent 0c7a8f1eb0
commit b9edb5d493
3 changed files with 18 additions and 5 deletions

View File

@ -3,7 +3,7 @@ import { computed, ref } from 'vue';
import { useVbenModal } from '@vben/common-ui'; import { useVbenModal } from '@vben/common-ui';
import { $t } from '@vben/locales'; import { $t } from '@vben/locales';
import { cloneDeep, listToTree } from '@vben/utils'; import { cloneDeep, getPopupContainer, listToTree } from '@vben/utils';
import { useVbenForm } from '#/adapter/form'; import { useVbenForm } from '#/adapter/form';
import { import {
@ -59,6 +59,7 @@ async function setupCategorySelect() {
treeLine: { showLeafIcon: false }, treeLine: { showLeafIcon: false },
fieldNames: { label: 'categoryName', value: 'id' }, fieldNames: { label: 'categoryName', value: 'id' },
treeDefaultExpandAll: true, treeDefaultExpandAll: true,
getPopupContainer,
}, },
}, },
]); ]);
@ -74,13 +75,19 @@ const [BasicModal, modalApi] = useVbenModal({
} }
modalApi.modalLoading(true); modalApi.modalLoading(true);
const { id } = modalApi.getData() as { id?: number | string }; const { id, parentId } = modalApi.getData() as {
id?: number | string;
parentId?: number | string;
};
isUpdate.value = !!id; isUpdate.value = !!id;
if (isUpdate.value && id) { if (isUpdate.value && id) {
const record = await categoryInfo(id); const record = await categoryInfo(id);
await formApi.setValues(record); await formApi.setValues(record);
} }
if (parentId) {
await formApi.setValues({ parentId });
}
await setupCategorySelect(); await setupCategorySelect();
modalApi.modalLoading(false); modalApi.modalLoading(false);

View File

@ -33,7 +33,7 @@ export const columns: VxeGridProps['columns'] = [
fixed: 'right', fixed: 'right',
slots: { default: 'action' }, slots: { default: 'action' },
title: '操作', title: '操作',
width: 180, width: 200,
}, },
]; ];

View File

@ -70,8 +70,8 @@ const [CategoryModal, modalApi] = useVbenModal({
connectedComponent: categoryModal, connectedComponent: categoryModal,
}); });
function handleAdd() { function handleAdd(row?: Recordable<any>) {
modalApi.setData({}); modalApi.setData({ parentId: row?.id });
modalApi.open(); modalApi.open();
} }
@ -122,6 +122,12 @@ function collapseAll() {
> >
{{ $t('pages.common.edit') }} {{ $t('pages.common.edit') }}
</ghost-button> </ghost-button>
<ghost-button
v-access:code="['workflow:category:edit']"
@click.stop="handleAdd(row)"
>
{{ $t('pages.common.add') }}
</ghost-button>
<Popconfirm <Popconfirm
:get-popup-container="getPopupContainer" :get-popup-container="getPopupContainer"
placement="left" placement="left"