feat:【antd】【ele】统一 infra 和 system 的代码风格(demo03/erp)

This commit is contained in:
YunaiV
2025-10-01 10:48:23 +08:00
parent 67b39cfe8a
commit 2e2a147815
38 changed files with 222 additions and 261 deletions

View File

@@ -39,7 +39,7 @@ async function handleExport() {
/** 创建示例联系人 */
function handleCreate() {
formModalApi.setData({}).open();
formModalApi.setData(null).open();
}
/** 编辑示例联系人 */

View File

@@ -65,21 +65,20 @@ const [Modal, modalApi] = useVbenModal({
return;
}
// 加载数据
let data = modalApi.getData<Demo01ContactApi.Demo01Contact>();
if (!data) {
const data = modalApi.getData<Demo01ContactApi.Demo01Contact>();
if (!data || !data.id) {
return;
}
if (data.id) {
modalApi.lock();
try {
data = await getDemo01Contact(data.id);
} finally {
modalApi.unlock();
modalApi.lock();
try {
formData.value = await getDemo01Contact(data.id);
// 设置到 values
if (formData.value) {
await formApi.setValues(formData.value);
}
} finally {
modalApi.unlock();
}
// 设置到 values
formData.value = data;
await formApi.setValues(formData.value);
},
});
</script>

View File

@@ -143,7 +143,7 @@ export function useGridColumns(): VxeTableGridOptions<Demo03StudentApi.Demo03Stu
},
{
title: '操作',
width: 200,
width: 280,
fixed: 'right',
slots: { default: 'actions' },
},
@@ -258,7 +258,7 @@ export function useDemo03CourseGridColumns(): VxeTableGridOptions<Demo03StudentA
},
{
title: '操作',
width: 200,
width: 280,
fixed: 'right',
slots: { default: 'actions' },
},
@@ -373,7 +373,7 @@ export function useDemo03GradeGridColumns(): VxeTableGridOptions<Demo03StudentAp
},
{
title: '操作',
width: 200,
width: 280,
fixed: 'right',
slots: { default: 'actions' },
},

View File

@@ -4,7 +4,7 @@ import type { Demo03StudentApi } from '#/api/infra/demo/demo03/erp';
import { ref } from 'vue';
import { Page, useVbenModal } from '@vben/common-ui';
import { confirm, Page, useVbenModal } from '@vben/common-ui';
import { downloadFileFromBlobPart, isEmpty } from '@vben/utils';
import { ElLoading, ElMessage, ElTabPane, ElTabs } from 'element-plus';
@@ -33,13 +33,19 @@ const [FormModal, formModalApi] = useVbenModal({
});
/** 刷新表格 */
function onRefresh() {
function handleRefresh() {
gridApi.query();
}
/** 导出表格 */
async function handleExport() {
const data = await exportDemo03Student(await gridApi.formApi.getValues());
downloadFileFromBlobPart({ fileName: '学生.xls', source: data });
}
/** 创建学生 */
function handleCreate() {
formModalApi.setData({}).open();
formModalApi.setData(null).open();
}
/** 编辑学生 */
@@ -51,12 +57,11 @@ function handleEdit(row: Demo03StudentApi.Demo03Student) {
async function handleDelete(row: Demo03StudentApi.Demo03Student) {
const loadingInstance = ElLoading.service({
text: $t('ui.actionMessage.deleting', [row.id]),
background: 'rgba(0, 0, 0, 0.7)',
});
try {
await deleteDemo03Student(row.id!);
ElMessage.success($t('ui.actionMessage.deleteSuccess', [row.id]));
onRefresh();
handleRefresh();
} finally {
loadingInstance.close();
}
@@ -64,15 +69,15 @@ async function handleDelete(row: Demo03StudentApi.Demo03Student) {
/** 批量删除学生 */
async function handleDeleteBatch() {
await confirm($t('ui.actionMessage.deleteBatchConfirm'));
const loadingInstance = ElLoading.service({
text: $t('ui.actionMessage.deleting'),
background: 'rgba(0, 0, 0, 0.7)',
text: $t('ui.actionMessage.deletingBatch'),
});
try {
await deleteDemo03StudentList(checkedIds.value);
checkedIds.value = [];
ElMessage.success($t('ui.actionMessage.deleteSuccess'));
onRefresh();
handleRefresh();
} finally {
loadingInstance.close();
}
@@ -87,12 +92,6 @@ function handleRowCheckboxChange({
checkedIds.value = records.map((item) => item.id!);
}
/** 导出表格 */
async function handleExport() {
const data = await exportDemo03Student(await gridApi.formApi.getValues());
downloadFileFromBlobPart({ fileName: '学生.xls', source: data });
}
const [Grid, gridApi] = useVbenVxeGrid({
formOptions: {
schema: useGridFormSchema(),
@@ -136,8 +135,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
<template>
<Page auto-content-height>
<FormModal @success="onRefresh" />
<FormModal @success="handleRefresh" />
<div>
<Grid table-title="学生列表">
<template #toolbar-tools>

View File

@@ -44,7 +44,6 @@ const [Modal, modalApi] = useVbenModal({
if (!valid) {
return;
}
modalApi.lock();
// 提交表单
const data = (await formApi.getValues()) as Demo03StudentApi.Demo03Course;
@@ -66,7 +65,6 @@ const [Modal, modalApi] = useVbenModal({
formData.value = undefined;
return;
}
// 加载数据
let data = modalApi.getData<Demo03StudentApi.Demo03Course>();
if (!data) {

View File

@@ -4,7 +4,7 @@ import type { Demo03StudentApi } from '#/api/infra/demo/demo03/erp';
import { nextTick, ref, watch } from 'vue';
import { useVbenModal } from '@vben/common-ui';
import { confirm, useVbenModal } from '@vben/common-ui';
import { isEmpty } from '@vben/utils';
import { ElLoading, ElMessage } from 'element-plus';
@@ -50,12 +50,11 @@ function handleEdit(row: Demo03StudentApi.Demo03Course) {
async function handleDelete(row: Demo03StudentApi.Demo03Course) {
const loadingInstance = ElLoading.service({
text: $t('ui.actionMessage.deleting', [row.id]),
background: 'rgba(0, 0, 0, 0.7)',
});
try {
await deleteDemo03Course(row.id!);
ElMessage.success($t('ui.actionMessage.deleteSuccess', [row.id]));
onRefresh();
await handleRefresh();
} finally {
loadingInstance.close();
}
@@ -63,15 +62,15 @@ async function handleDelete(row: Demo03StudentApi.Demo03Course) {
/** 批量删除学生课程 */
async function handleDeleteBatch() {
await confirm($t('ui.actionMessage.deleteBatchConfirm'));
const loadingInstance = ElLoading.service({
text: $t('ui.actionMessage.deleting'),
background: 'rgba(0, 0, 0, 0.7)',
text: $t('ui.actionMessage.deletingBatch'),
});
try {
await deleteDemo03CourseList(checkedIds.value);
checkedIds.value = [];
ElMessage.success($t('ui.actionMessage.deleteSuccess'));
onRefresh();
await handleRefresh();
} finally {
loadingInstance.close();
}
@@ -127,7 +126,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
});
/** 刷新表格 */
async function onRefresh() {
async function handleRefresh() {
await gridApi.query();
}
@@ -139,20 +138,20 @@ watch(
return;
}
await nextTick();
await onRefresh();
await handleRefresh();
},
{ immediate: true },
);
</script>
<template>
<FormModal @success="onRefresh" />
<FormModal @success="handleRefresh" />
<Grid table-title="学生课程列表">
<template #toolbar-tools>
<TableAction
:actions="[
{
label: $t('ui.actionTitle.create', ['学生']),
label: $t('ui.actionTitle.create', ['学生课程']),
type: 'primary',
icon: ACTION_ICON.ADD,
auth: ['infra:demo03-student:create'],

View File

@@ -44,7 +44,6 @@ const [Modal, modalApi] = useVbenModal({
if (!valid) {
return;
}
modalApi.lock();
// 提交表单
const data = (await formApi.getValues()) as Demo03StudentApi.Demo03Grade;
@@ -66,7 +65,6 @@ const [Modal, modalApi] = useVbenModal({
formData.value = undefined;
return;
}
// 加载数据
let data = modalApi.getData<Demo03StudentApi.Demo03Grade>();
if (!data) {

View File

@@ -4,7 +4,7 @@ import type { Demo03StudentApi } from '#/api/infra/demo/demo03/erp';
import { nextTick, ref, watch } from 'vue';
import { useVbenModal } from '@vben/common-ui';
import { confirm, useVbenModal } from '@vben/common-ui';
import { isEmpty } from '@vben/utils';
import { ElLoading, ElMessage } from 'element-plus';
@@ -50,12 +50,11 @@ function handleEdit(row: Demo03StudentApi.Demo03Grade) {
async function handleDelete(row: Demo03StudentApi.Demo03Grade) {
const loadingInstance = ElLoading.service({
text: $t('ui.actionMessage.deleting', [row.id]),
background: 'rgba(0, 0, 0, 0.7)',
});
try {
await deleteDemo03Grade(row.id!);
ElMessage.success($t('ui.actionMessage.deleteSuccess', [row.id]));
onRefresh();
await handleRefresh();
} finally {
loadingInstance.close();
}
@@ -63,15 +62,15 @@ async function handleDelete(row: Demo03StudentApi.Demo03Grade) {
/** 批量删除学生班级 */
async function handleDeleteBatch() {
await confirm($t('ui.actionMessage.deleteBatchConfirm'));
const loadingInstance = ElLoading.service({
text: $t('ui.actionMessage.deleting'),
background: 'rgba(0, 0, 0, 0.7)',
text: $t('ui.actionMessage.deletingBatch'),
});
try {
await deleteDemo03GradeList(checkedIds.value);
checkedIds.value = [];
ElMessage.success($t('ui.actionMessage.deleteSuccess'));
onRefresh();
await handleRefresh();
} finally {
loadingInstance.close();
}
@@ -127,7 +126,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
});
/** 刷新表格 */
async function onRefresh() {
async function handleRefresh() {
await gridApi.query();
}
@@ -139,20 +138,20 @@ watch(
return;
}
await nextTick();
await onRefresh();
await handleRefresh();
},
{ immediate: true },
);
</script>
<template>
<FormModal @success="onRefresh" />
<FormModal @success="handleRefresh" />
<Grid table-title="学生班级列表">
<template #toolbar-tools>
<TableAction
:actions="[
{
label: $t('ui.actionTitle.create', ['学生']),
label: $t('ui.actionTitle.create', ['学生班级']),
type: 'primary',
icon: ACTION_ICON.ADD,
auth: ['infra:demo03-student:create'],

View File

@@ -65,21 +65,20 @@ const [Modal, modalApi] = useVbenModal({
return;
}
// 加载数据
let data = modalApi.getData<Demo03StudentApi.Demo03Student>();
if (!data) {
const data = modalApi.getData<Demo03StudentApi.Demo03Student>();
if (!data || !data.id) {
return;
}
if (data.id) {
modalApi.lock();
try {
data = await getDemo03Student(data.id);
} finally {
modalApi.unlock();
modalApi.lock();
try {
formData.value = await getDemo03Student(data.id);
// 设置到 values
if (formData.value) {
await formApi.setValues(formData.value);
}
} finally {
modalApi.unlock();
}
// 设置到 values
formData.value = data;
await formApi.setValues(formData.value);
},
});
</script>

View File

@@ -38,7 +38,7 @@ function onRefresh() {
/** 创建学生 */
function handleCreate() {
formModalApi.setData({}).open();
formModalApi.setData(null).open();
}
/** 编辑学生 */
@@ -50,7 +50,6 @@ function handleEdit(row: Demo03StudentApi.Demo03Student) {
async function handleDelete(row: Demo03StudentApi.Demo03Student) {
const loadingInstance = ElLoading.service({
text: $t('ui.actionMessage.deleting', [row.id]),
background: 'rgba(0, 0, 0, 0.7)',
});
try {
await deleteDemo03Student(row.id!);
@@ -65,7 +64,6 @@ async function handleDelete(row: Demo03StudentApi.Demo03Student) {
async function handleDeleteBatch() {
const loadingInstance = ElLoading.service({
text: $t('ui.actionMessage.deleting'),
background: 'rgba(0, 0, 0, 0.7)',
});
try {
await deleteDemo03StudentList(checkedIds.value);

View File

@@ -33,7 +33,7 @@ function onRefresh() {
/** 创建学生 */
function handleCreate() {
formModalApi.setData({}).open();
formModalApi.setData(null).open();
}
/** 编辑学生 */
@@ -45,7 +45,6 @@ function handleEdit(row: Demo03StudentApi.Demo03Student) {
async function handleDelete(row: Demo03StudentApi.Demo03Student) {
const loadingInstance = ElLoading.service({
text: $t('ui.actionMessage.deleting', [row.id]),
background: 'rgba(0, 0, 0, 0.7)',
});
try {
await deleteDemo03Student(row.id!);
@@ -60,7 +59,6 @@ async function handleDelete(row: Demo03StudentApi.Demo03Student) {
async function handleDeleteBatch() {
const loadingInstance = ElLoading.service({
text: $t('ui.actionMessage.deleting'),
background: 'rgba(0, 0, 0, 0.7)',
});
try {
await deleteDemo03StudentList(checkedIds.value);

View File

@@ -89,7 +89,7 @@ const [FormModal, formModalApi] = useVbenModal({
/** 创建示例联系人 */
function handleCreate() {
formModalApi.setData({}).open();
formModalApi.setData(null).open();
}
/** 编辑示例联系人 */
@@ -101,7 +101,6 @@ function handleEdit(row: Demo01ContactApi.Demo01Contact) {
async function handleDelete(row: Demo01ContactApi.Demo01Contact) {
const loadingInstance = ElLoading.service({
text: $t('ui.actionMessage.deleting', [row.id]),
background: 'rgba(0, 0, 0, 0.7)',
});
try {
await deleteDemo01Contact(row.id!);
@@ -116,7 +115,6 @@ async function handleDelete(row: Demo01ContactApi.Demo01Contact) {
async function handleDeleteBatch() {
const loadingInstance = ElLoading.service({
text: $t('ui.actionMessage.deleting'),
background: 'rgba(0, 0, 0, 0.7)',
});
try {
await deleteDemo01ContactList(checkedIds.value);

View File

@@ -76,7 +76,7 @@ const [FormModal, formModalApi] = useVbenModal({
/** 创建示例分类 */
function handleCreate() {
formModalApi.setData({}).open();
formModalApi.setData(null).open();
}
/** 编辑示例分类 */
@@ -93,7 +93,6 @@ function handleAppend(row: Demo02CategoryApi.Demo02Category) {
async function handleDelete(row: Demo02CategoryApi.Demo02Category) {
const loadingInstance = ElLoading.service({
text: $t('ui.actionMessage.deleting', [row.id]),
background: 'rgba(0, 0, 0, 0.7)',
});
try {
await deleteDemo02Category(row.id!);

View File

@@ -101,7 +101,7 @@ const [FormModal, formModalApi] = useVbenModal({
/** 创建学生 */
function handleCreate() {
formModalApi.setData({}).open();
formModalApi.setData(null).open();
}
/** 编辑学生 */
@@ -113,7 +113,6 @@ function handleEdit(row: Demo03StudentApi.Demo03Student) {
async function handleDelete(row: Demo03StudentApi.Demo03Student) {
const loadingInstance = ElLoading.service({
text: $t('ui.actionMessage.deleting', [row.id]),
background: 'rgba(0, 0, 0, 0.7)',
});
try {
await deleteDemo03Student(row.id!);
@@ -128,7 +127,6 @@ async function handleDelete(row: Demo03StudentApi.Demo03Student) {
async function handleDeleteBatch() {
const loadingInstance = ElLoading.service({
text: $t('ui.actionMessage.deleting'),
background: 'rgba(0, 0, 0, 0.7)',
});
try {
await deleteDemo03StudentList(checkedIds.value);

View File

@@ -56,7 +56,6 @@ function handleEdit(row: Demo03StudentApi.Demo03Course) {
async function handleDelete(row: Demo03StudentApi.Demo03Course) {
const loadingInstance = ElLoading.service({
text: $t('ui.actionMessage.deleting', [row.id]),
background: 'rgba(0, 0, 0, 0.7)',
});
try {
await deleteDemo03Course(row.id!);
@@ -71,7 +70,6 @@ async function handleDelete(row: Demo03StudentApi.Demo03Course) {
async function handleDeleteBatch() {
const loadingInstance = ElLoading.service({
text: $t('ui.actionMessage.deleting'),
background: 'rgba(0, 0, 0, 0.7)',
});
try {
await deleteDemo03CourseList(checkedIds.value);

View File

@@ -56,7 +56,6 @@ function handleEdit(row: Demo03StudentApi.Demo03Grade) {
async function handleDelete(row: Demo03StudentApi.Demo03Grade) {
const loadingInstance = ElLoading.service({
text: $t('ui.actionMessage.deleting', [row.id]),
background: 'rgba(0, 0, 0, 0.7)',
});
try {
await deleteDemo03Grade(row.id!);
@@ -71,7 +70,6 @@ async function handleDelete(row: Demo03StudentApi.Demo03Grade) {
async function handleDeleteBatch() {
const loadingInstance = ElLoading.service({
text: $t('ui.actionMessage.deleting'),
background: 'rgba(0, 0, 0, 0.7)',
});
try {
await deleteDemo03GradeList(checkedIds.value);

View File

@@ -97,7 +97,7 @@ const [FormModal, formModalApi] = useVbenModal({
/** 创建学生 */
function handleCreate() {
formModalApi.setData({}).open();
formModalApi.setData(null).open();
}
/** 编辑学生 */
@@ -109,7 +109,6 @@ function handleEdit(row: Demo03StudentApi.Demo03Student) {
async function handleDelete(row: Demo03StudentApi.Demo03Student) {
const loadingInstance = ElLoading.service({
text: $t('ui.actionMessage.deleting', [row.id]),
background: 'rgba(0, 0, 0, 0.7)',
});
try {
await deleteDemo03Student(row.id!);
@@ -124,7 +123,6 @@ async function handleDelete(row: Demo03StudentApi.Demo03Student) {
async function handleDeleteBatch() {
const loadingInstance = ElLoading.service({
text: $t('ui.actionMessage.deleting'),
background: 'rgba(0, 0, 0, 0.7)',
});
try {
await deleteDemo03StudentList(checkedIds.value);

View File

@@ -90,7 +90,7 @@ const [FormModal, formModalApi] = useVbenModal({
/** 创建学生 */
function handleCreate() {
formModalApi.setData({}).open();
formModalApi.setData(null).open();
}
/** 编辑学生 */
@@ -102,7 +102,6 @@ function handleEdit(row: Demo03StudentApi.Demo03Student) {
async function handleDelete(row: Demo03StudentApi.Demo03Student) {
const loadingInstance = ElLoading.service({
text: $t('ui.actionMessage.deleting', [row.id]),
background: 'rgba(0, 0, 0, 0.7)',
});
try {
await deleteDemo03Student(row.id!);
@@ -117,7 +116,6 @@ async function handleDelete(row: Demo03StudentApi.Demo03Student) {
async function handleDeleteBatch() {
const loadingInstance = ElLoading.service({
text: $t('ui.actionMessage.deleting'),
background: 'rgba(0, 0, 0, 0.7)',
});
try {
await deleteDemo03StudentList(checkedIds.value);

View File

@@ -28,7 +28,7 @@ function onRefresh() {
/** 创建分类 */
function handleCreate() {
formModalApi.setData({}).open();
formModalApi.setData(null).open();
}
/** 添加下级分类 */

View File

@@ -29,7 +29,7 @@ function handleRefresh() {
/** 创建菜单 */
function handleCreate() {
formModalApi.setData({}).open();
formModalApi.setData(null).open();
}
/** 添加下级菜单 */