refactor: 重新生成主子表内嵌模式代码预览
parent
7ab66aa363
commit
0cb157a29c
|
@ -62,6 +62,7 @@ export function exportDemo03Student(params: any) {
|
|||
}
|
||||
|
||||
// ==================== 子表(学生课程) ====================
|
||||
|
||||
/** 获得学生课程列表 */
|
||||
export function getDemo03CourseListByStudentId(studentId: number) {
|
||||
return requestClient.get<Demo03StudentApi.Demo03Course[]>(
|
||||
|
@ -70,6 +71,7 @@ export function getDemo03CourseListByStudentId(studentId: number) {
|
|||
}
|
||||
|
||||
// ==================== 子表(学生班级) ====================
|
||||
|
||||
/** 获得学生班级 */
|
||||
export function getDemo03GradeByStudentId(studentId: number) {
|
||||
return requestClient.get<Demo03StudentApi.Demo03Grade>(
|
||||
|
|
|
@ -56,10 +56,7 @@ export function useFormSchema(): VbenFormSchema[] {
|
|||
fieldName: 'description',
|
||||
label: '简介',
|
||||
rules: 'required',
|
||||
component: 'Textarea',
|
||||
componentProps: {
|
||||
placeholder: '请输入简介',
|
||||
},
|
||||
component: 'RichTextarea',
|
||||
},
|
||||
];
|
||||
}
|
||||
|
@ -180,7 +177,8 @@ export function useGridColumns(
|
|||
}
|
||||
|
||||
// ==================== 子表(学生课程) ====================
|
||||
/** 新增/修改列表的字段 */ // TODO @puhui999: ==== 下面空一行;
|
||||
|
||||
/** 新增/修改列表的字段 */
|
||||
export function useDemo03CourseGridEditColumns(
|
||||
onActionClick?: OnActionClickFn<Demo03StudentApi.Demo03Course>,
|
||||
): VxeTableGridOptions<Demo03StudentApi.Demo03Course>['columns'] {
|
||||
|
@ -222,7 +220,8 @@ export function useDemo03CourseGridEditColumns(
|
|||
},
|
||||
];
|
||||
}
|
||||
/** 列表的字段 */ // TODO @puhui999:这里空一行;
|
||||
|
||||
/** 列表的字段 */
|
||||
export function useDemo03CourseGridColumns(): VxeTableGridOptions<Demo03StudentApi.Demo03Course>['columns'] {
|
||||
return [
|
||||
{
|
||||
|
@ -253,7 +252,9 @@ export function useDemo03CourseGridColumns(): VxeTableGridOptions<Demo03StudentA
|
|||
},
|
||||
];
|
||||
}
|
||||
// ==================== 子表(学生班级) ==================== // TODO @puhui999: ==== 前后都空一行;
|
||||
|
||||
// ==================== 子表(学生班级) ====================
|
||||
|
||||
/** 新增/修改的表单 */
|
||||
export function useDemo03GradeFormSchema(): VbenFormSchema[] {
|
||||
return [
|
||||
|
@ -285,6 +286,7 @@ export function useDemo03GradeFormSchema(): VbenFormSchema[] {
|
|||
},
|
||||
];
|
||||
}
|
||||
|
||||
/** 列表的字段 */
|
||||
export function useDemo03GradeGridColumns(): VxeTableGridOptions<Demo03StudentApi.Demo03Grade>['columns'] {
|
||||
return [
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
import type { OnActionClickParams, VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
import type { Demo03StudentApi } from '#/api/infra/demo/demo03/inner';
|
||||
|
||||
import Demo03CourseList from './modules/Demo03CourseList.vue';
|
||||
import Demo03GradeList from './modules/Demo03GradeList.vue';
|
||||
import Demo03CourseList from './modules/demo03-course-list.vue';
|
||||
import Demo03GradeList from './modules/demo03-grade-list.vue';
|
||||
import Form from './modules/form.vue';
|
||||
import { Page, useVbenModal } from '@vben/common-ui';
|
||||
import { Download, Plus } from '@vben/icons';
|
||||
|
@ -30,12 +30,6 @@ function onRefresh() {
|
|||
gridApi.reload();
|
||||
}
|
||||
|
||||
/** 导出表格 */
|
||||
async function onExport() {
|
||||
const data = await exportDemo03Student(await gridApi.formApi.getValues());
|
||||
downloadByData(data, '学生.xls');
|
||||
}
|
||||
|
||||
/** 创建学生 */
|
||||
function onCreate() {
|
||||
formModalApi.setData({}).open();
|
||||
|
@ -65,17 +59,23 @@ async function onDelete(row: Demo03StudentApi.Demo03Student) {
|
|||
}
|
||||
}
|
||||
|
||||
/** 导出表格 */
|
||||
async function onExport() {
|
||||
const data = await exportDemo03Student(await gridApi.formApi.getValues());
|
||||
downloadByData(data, '学生.xls');
|
||||
}
|
||||
|
||||
/** 表格操作按钮的回调函数 */
|
||||
function onActionClick({ code, row }: OnActionClickParams<Demo03StudentApi.Demo03Student>) {
|
||||
switch (code) {
|
||||
case 'delete': {
|
||||
onDelete(row);
|
||||
break;
|
||||
}
|
||||
case 'edit': {
|
||||
onEdit(row);
|
||||
break;
|
||||
}
|
||||
case 'delete': {
|
||||
onDelete(row);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -119,8 +119,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
|||
<Grid table-title="学生列表">
|
||||
<template #expand_content="{ row }">
|
||||
<!-- 子表的表单 -->
|
||||
<!-- TODO @puhui999:【样式优化】1)Tabs 和箭头对齐;2)子 Table 也和箭头对齐 -->
|
||||
<Tabs v-model:active-key="subTabsName">
|
||||
<Tabs v-model:active-key="subTabsName" class="mx-8">
|
||||
<Tabs.TabPane key="demo03Course" tab="学生课程" force-render>
|
||||
<Demo03CourseList :student-id="row?.id" />
|
||||
</Tabs.TabPane>
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
<script lang="ts" setup>
|
||||
// TODO @puhui999:命名使用小写 + 中划线
|
||||
import type { OnActionClickParams } from '#/adapter/vxe-table';
|
||||
import type { Demo03StudentApi } from '#/api/infra/demo/demo03/inner';
|
||||
|
||||
|
@ -14,7 +13,7 @@ import { h, nextTick, watch } from 'vue';
|
|||
import { useDemo03CourseGridEditColumns } from '../data';
|
||||
|
||||
const props = defineProps<{
|
||||
studentId?: any; // 学生编号(主表的关联字段) TODO @puhui999:类型定义,应该是 number?
|
||||
studentId?: number; // 学生编号(主表的关联字段)
|
||||
}>();
|
||||
|
||||
/** 表格操作按钮的回调函数 */
|
||||
|
@ -27,8 +26,7 @@ function onActionClick({ code, row }: OnActionClickParams<Demo03StudentApi.Demo0
|
|||
}
|
||||
}
|
||||
|
||||
// TODO @puhui999:对于当前来说,就 Grid,gridApi,更简洁一点?
|
||||
const [Demo03CourseGrid, demo03CourseGridApi] = useVbenVxeGrid({
|
||||
const [Grid, gridApi] = useVbenVxeGrid({
|
||||
gridOptions: {
|
||||
columns: useDemo03CourseGridEditColumns(onActionClick),
|
||||
border: true,
|
||||
|
@ -47,27 +45,25 @@ const [Demo03CourseGrid, demo03CourseGridApi] = useVbenVxeGrid({
|
|||
},
|
||||
});
|
||||
|
||||
/** 删除学生课程 */
|
||||
const onDelete = async (row: Demo03StudentApi.Demo03Course) => {
|
||||
await demo03CourseGridApi.grid.remove(row);
|
||||
/** 添加学生课程 */
|
||||
const onAdd = async () => {
|
||||
await gridApi.grid.insertAt({} as Demo03StudentApi.Demo03Course, -1);
|
||||
};
|
||||
|
||||
/** 添加学生课程 */
|
||||
// TODO @puhui999:要不改成 onAdd?风格一致?;然后 add 放 delete 前面;
|
||||
const handleAdd = async () => {
|
||||
await demo03CourseGridApi.grid.insertAt({} as Demo03StudentApi.Demo03Course, -1);
|
||||
/** 删除学生课程 */
|
||||
const onDelete = async (row: Demo03StudentApi.Demo03Course) => {
|
||||
await gridApi.grid.remove(row);
|
||||
};
|
||||
|
||||
/** 提供获取表格数据的方法供父组件调用 */
|
||||
defineExpose({
|
||||
getData: (): Demo03StudentApi.Demo03Course[] => {
|
||||
// TODO @puhui999 : 要不简化成这样哈?
|
||||
const data = demo03CourseGridApi.grid.getData() as Demo03StudentApi.Demo03Course[];
|
||||
const removeRecords = demo03CourseGridApi.grid.getRemoveRecords() as Demo03StudentApi.Demo03Course[];
|
||||
const insertRecords = demo03CourseGridApi.grid.getInsertRecords() as Demo03StudentApi.Demo03Course[];
|
||||
const data = gridApi.grid.getData() as Demo03StudentApi.Demo03Course[];
|
||||
const removeRecords = gridApi.grid.getRemoveRecords() as Demo03StudentApi.Demo03Course[];
|
||||
const insertRecords = gridApi.grid.getInsertRecords() as Demo03StudentApi.Demo03Course[];
|
||||
return data
|
||||
.filter(row => !removeRecords.some(removed => removed.id === row.id))
|
||||
.concat(insertRecords.map(row => ({ ...row, id: undefined })));
|
||||
.filter((row) => !removeRecords.some((removed) => removed.id === row.id))
|
||||
.concat(insertRecords.map((row: any) => ({ ...row, id: undefined })));
|
||||
},
|
||||
});
|
||||
|
||||
|
@ -78,25 +74,24 @@ watch(
|
|||
if (!val) {
|
||||
return;
|
||||
}
|
||||
|
||||
await nextTick(); // TODO @puhui999:上面的空行去掉
|
||||
await demo03CourseGridApi.grid.loadData(await getDemo03CourseListByStudentId(props.studentId!));
|
||||
await nextTick();
|
||||
await gridApi.grid.loadData(await getDemo03CourseListByStudentId(props.studentId!));
|
||||
},
|
||||
{ immediate: true },
|
||||
);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Demo03CourseGrid class="mx-4">
|
||||
<Grid class="mx-4">
|
||||
<template #name="{ row }">
|
||||
<Input v-model:value="row.name" />
|
||||
</template>
|
||||
<template #score="{ row }">
|
||||
<Input v-model:value="row.score" />
|
||||
</template>
|
||||
</Demo03CourseGrid>
|
||||
<!-- TODO @puhui999:-mt-4 把距离控制下哈; -->
|
||||
<div class="flex justify-center -mt-4">
|
||||
<Button :icon="h(Plus)" type="primary" ghost @click="handleAdd" v-access:code="['infra:demo03-student:create']">
|
||||
</Grid>
|
||||
<div class="-mt-4 flex justify-center">
|
||||
<Button :icon="h(Plus)" type="primary" ghost @click="onAdd" v-access:code="['infra:demo03-student:create']">
|
||||
{{ $t('ui.actionTitle.create', ['学生课程']) }}
|
||||
</Button>
|
||||
</div>
|
|
@ -9,7 +9,7 @@ import { nextTick, watch } from 'vue';
|
|||
import { useDemo03CourseGridColumns } from '../data';
|
||||
|
||||
const props = defineProps<{
|
||||
studentId?: any; // 学生编号(主表的关联字段) TODO @puhui999:类型定义,应该是 number?
|
||||
studentId?: number; // 学生编号(主表的关联字段)
|
||||
}>();
|
||||
|
||||
const [Grid, gridApi] = useVbenVxeGrid({
|
||||
|
@ -41,8 +41,7 @@ watch(
|
|||
if (!val) {
|
||||
return;
|
||||
}
|
||||
|
||||
await nextTick(); // TODO @puhui999:上面空行去掉?
|
||||
await nextTick();
|
||||
await onRefresh();
|
||||
},
|
||||
{ immediate: true },
|
||||
|
@ -50,8 +49,5 @@ watch(
|
|||
</script>
|
||||
|
||||
<template>
|
||||
<!-- TODO @puhui999:这个边距可以调整下,还是“箭头”那相关的哈 -->
|
||||
<div class="mx-4">
|
||||
<Grid table-title="学生课程列表" />
|
||||
</div>
|
||||
<Grid table-title="学生课程列表" />
|
||||
</template>
|
|
@ -6,10 +6,10 @@ import { nextTick, watch } from 'vue';
|
|||
import { useDemo03GradeFormSchema } from '../data';
|
||||
|
||||
const props = defineProps<{
|
||||
studentId?: any; // 学生编号(主表的关联字段) TODO @puhui999:类型定义,应该是 number?
|
||||
studentId?: number; // 学生编号(主表的关联字段)
|
||||
}>();
|
||||
|
||||
const [Demo03GradeForm, demo03GradeFormApi] = useVbenForm({
|
||||
const [Form, formApi] = useVbenForm({
|
||||
layout: 'horizontal',
|
||||
schema: useDemo03GradeFormSchema(),
|
||||
showDefaultActions: false,
|
||||
|
@ -18,10 +18,10 @@ const [Demo03GradeForm, demo03GradeFormApi] = useVbenForm({
|
|||
/** 暴露出表单校验方法和表单值获取方法 */
|
||||
defineExpose({
|
||||
validate: async () => {
|
||||
const { valid } = await demo03GradeFormApi.validate();
|
||||
const { valid } = await formApi.validate();
|
||||
return valid;
|
||||
},
|
||||
getValues: demo03GradeFormApi.getValues,
|
||||
getValues: formApi.getValues,
|
||||
});
|
||||
|
||||
/** 监听主表的关联字段的变化,加载对应的子表数据 */
|
||||
|
@ -31,13 +31,13 @@ watch(
|
|||
if (!val) {
|
||||
return;
|
||||
}
|
||||
|
||||
await nextTick(); // TODO @puhui999:上面的空行去掉
|
||||
await demo03GradeFormApi.setValues(await getDemo03GradeByStudentId(props.studentId!));
|
||||
await nextTick();
|
||||
await formApi.setValues(await getDemo03GradeByStudentId(props.studentId!));
|
||||
},
|
||||
{ immediate: true },
|
||||
);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Demo03GradeForm class="mx-4" />
|
||||
<Form class="mx-4" />
|
||||
</template>
|
|
@ -9,7 +9,7 @@ import { nextTick, watch } from 'vue';
|
|||
import { useDemo03GradeGridColumns } from '../data';
|
||||
|
||||
const props = defineProps<{
|
||||
studentId?: any; // 学生编号(主表的关联字段) // TODO @puhui999:上面的空行去掉
|
||||
studentId?: number; // 学生编号(主表的关联字段)
|
||||
}>();
|
||||
|
||||
const [Grid, gridApi] = useVbenVxeGrid({
|
||||
|
@ -41,8 +41,7 @@ watch(
|
|||
if (!val) {
|
||||
return;
|
||||
}
|
||||
|
||||
await nextTick(); // TODO @puhui999:上面的空行去掉
|
||||
await nextTick();
|
||||
await onRefresh();
|
||||
},
|
||||
{ immediate: true },
|
||||
|
@ -50,7 +49,5 @@ watch(
|
|||
</script>
|
||||
|
||||
<template>
|
||||
<div class="mx-4">
|
||||
<Grid table-title="学生班级列表" />
|
||||
</div>
|
||||
<Grid table-title="学生班级列表" />
|
||||
</template>
|
|
@ -10,8 +10,8 @@ import { $t } from '#/locales';
|
|||
import { computed, ref } from 'vue';
|
||||
|
||||
import { useFormSchema } from '../data';
|
||||
import Demo03CourseForm from './Demo03CourseForm.vue';
|
||||
import Demo03GradeForm from './Demo03GradeForm.vue';
|
||||
import Demo03CourseForm from './demo03-course-form.vue';
|
||||
import Demo03GradeForm from './demo03-grade-form.vue';
|
||||
|
||||
const emit = defineEmits(['success']);
|
||||
const formData = ref<Demo03StudentApi.Demo03Student>();
|
||||
|
@ -72,9 +72,7 @@ const [Modal, modalApi] = useVbenModal({
|
|||
if (!data) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (data.id) {
|
||||
// 编辑
|
||||
modalApi.lock();
|
||||
try {
|
||||
data = await getDemo03Student(data.id);
|
||||
|
|
Loading…
Reference in New Issue