commit
f8bcebb576
|
|
@ -69,6 +69,8 @@ function updateTreeSchema(): void {
|
||||||
treeFormApi.setState({
|
treeFormApi.setState({
|
||||||
schema: useGenerationInfoTreeFormSchema(props.columns),
|
schema: useGenerationInfoTreeFormSchema(props.columns),
|
||||||
});
|
});
|
||||||
|
// 树表信息回显
|
||||||
|
treeFormApi.setValues(props.table as any);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 更新主子表信息表单 schema */
|
/** 更新主子表信息表单 schema */
|
||||||
|
|
@ -76,6 +78,8 @@ function updateSubSchema(): void {
|
||||||
subFormApi.setState({
|
subFormApi.setState({
|
||||||
schema: useGenerationInfoSubTableFormSchema(props.columns, tables.value),
|
schema: useGenerationInfoSubTableFormSchema(props.columns, tables.value),
|
||||||
});
|
});
|
||||||
|
// 主子表信息回显
|
||||||
|
subFormApi.setValues(props.table as any);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 获取合并的表单值 */
|
/** 获取合并的表单值 */
|
||||||
|
|
|
||||||
|
|
@ -86,17 +86,17 @@ const [FormModal, formModalApi] = useVbenModal({
|
||||||
});
|
});
|
||||||
|
|
||||||
/** 创建示例联系人 */
|
/** 创建示例联系人 */
|
||||||
function onCreate() {
|
function handleCreate() {
|
||||||
formModalApi.setData({}).open();
|
formModalApi.setData({}).open();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 编辑示例联系人 */
|
/** 编辑示例联系人 */
|
||||||
function onEdit(row: Demo01ContactApi.Demo01Contact) {
|
function handleEdit(row: Demo01ContactApi.Demo01Contact) {
|
||||||
formModalApi.setData(row).open();
|
formModalApi.setData(row).open();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 删除示例联系人 */
|
/** 删除示例联系人 */
|
||||||
async function onDelete(row: Demo01ContactApi.Demo01Contact) {
|
async function handleDelete(row: Demo01ContactApi.Demo01Contact) {
|
||||||
const hideLoading = message.loading({
|
const hideLoading = message.loading({
|
||||||
content: $t('ui.actionMessage.deleting', [row.id]),
|
content: $t('ui.actionMessage.deleting', [row.id]),
|
||||||
duration: 0,
|
duration: 0,
|
||||||
|
|
@ -115,7 +115,7 @@ async function onDelete(row: Demo01ContactApi.Demo01Contact) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 批量删除示例联系人 */
|
/** 批量删除示例联系人 */
|
||||||
async function onDeleteBatch() {
|
async function handleDeleteBatch() {
|
||||||
const hideLoading = message.loading({
|
const hideLoading = message.loading({
|
||||||
content: $t('ui.actionMessage.deleting'),
|
content: $t('ui.actionMessage.deleting'),
|
||||||
duration: 0,
|
duration: 0,
|
||||||
|
|
@ -173,7 +173,6 @@ onMounted(() => {
|
||||||
class="w-full"
|
class="w-full"
|
||||||
/>
|
/>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<!-- TODO @puhui999:貌似性别的宽度不对;并且选择后,会变哈; -->
|
|
||||||
<Form.Item label="性别" name="sex">
|
<Form.Item label="性别" name="sex">
|
||||||
<Select
|
<Select
|
||||||
v-model:value="queryParams.sex"
|
v-model:value="queryParams.sex"
|
||||||
|
|
@ -181,7 +180,6 @@ onMounted(() => {
|
||||||
allow-clear
|
allow-clear
|
||||||
class="w-full"
|
class="w-full"
|
||||||
>
|
>
|
||||||
<!-- TODO @puhui999:要不咱还是把 getIntDictOptions 还是搞出来?总归方便点~ -->
|
|
||||||
<Select.Option
|
<Select.Option
|
||||||
v-for="dict in getDictOptions(
|
v-for="dict in getDictOptions(
|
||||||
DICT_TYPE.SYSTEM_USER_SEX,
|
DICT_TYPE.SYSTEM_USER_SEX,
|
||||||
|
|
@ -221,7 +219,7 @@ onMounted(() => {
|
||||||
class="ml-2"
|
class="ml-2"
|
||||||
:icon="h(Plus)"
|
:icon="h(Plus)"
|
||||||
type="primary"
|
type="primary"
|
||||||
@click="onCreate"
|
@click="handleCreate"
|
||||||
v-access:code="['infra:demo01-contact:create']"
|
v-access:code="['infra:demo01-contact:create']"
|
||||||
>
|
>
|
||||||
{{ $t('ui.actionTitle.create', ['示例联系人']) }}
|
{{ $t('ui.actionTitle.create', ['示例联系人']) }}
|
||||||
|
|
@ -242,7 +240,7 @@ onMounted(() => {
|
||||||
danger
|
danger
|
||||||
class="ml-2"
|
class="ml-2"
|
||||||
:disabled="isEmpty(checkedIds)"
|
:disabled="isEmpty(checkedIds)"
|
||||||
@click="onDeleteBatch"
|
@click="handleDeleteBatch"
|
||||||
v-access:code="['infra:demo01-contact:delete']"
|
v-access:code="['infra:demo01-contact:delete']"
|
||||||
>
|
>
|
||||||
批量删除
|
批量删除
|
||||||
|
|
@ -282,7 +280,7 @@ onMounted(() => {
|
||||||
<Button
|
<Button
|
||||||
size="small"
|
size="small"
|
||||||
type="link"
|
type="link"
|
||||||
@click="onEdit(row as any)"
|
@click="handleEdit(row as any)"
|
||||||
v-access:code="['infra:demo01-contact:update']"
|
v-access:code="['infra:demo01-contact:update']"
|
||||||
>
|
>
|
||||||
{{ $t('ui.actionTitle.edit') }}
|
{{ $t('ui.actionTitle.edit') }}
|
||||||
|
|
@ -292,7 +290,7 @@ onMounted(() => {
|
||||||
type="link"
|
type="link"
|
||||||
danger
|
danger
|
||||||
class="ml-2"
|
class="ml-2"
|
||||||
@click="onDelete(row as any)"
|
@click="handleDelete(row as any)"
|
||||||
v-access:code="['infra:demo01-contact:delete']"
|
v-access:code="['infra:demo01-contact:delete']"
|
||||||
>
|
>
|
||||||
{{ $t('ui.actionTitle.delete') }}
|
{{ $t('ui.actionTitle.delete') }}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,79 @@
|
||||||
|
/* 来自 @vben/plugins/vxe-table style.css,覆盖 vxe-table 原有的样式定义,使用 vben 的样式主题 */
|
||||||
|
:root {
|
||||||
|
--vxe-ui-font-color: hsl(var(--foreground));
|
||||||
|
--vxe-ui-font-primary-color: hsl(var(--primary));
|
||||||
|
|
||||||
|
/* --vxe-ui-font-lighten-color: #babdc0;
|
||||||
|
--vxe-ui-font-darken-color: #86898e; */
|
||||||
|
--vxe-ui-font-disabled-color: hsl(var(--foreground) / 50%);
|
||||||
|
|
||||||
|
/* base */
|
||||||
|
--vxe-ui-base-popup-border-color: hsl(var(--border));
|
||||||
|
--vxe-ui-input-disabled-color: hsl(var(--border) / 60%);
|
||||||
|
|
||||||
|
/* --vxe-ui-base-popup-box-shadow: 0px 12px 30px 8px rgb(0 0 0 / 50%); */
|
||||||
|
|
||||||
|
/* layout */
|
||||||
|
--vxe-ui-layout-background-color: hsl(var(--background));
|
||||||
|
--vxe-ui-table-resizable-line-color: hsl(var(--heavy));
|
||||||
|
|
||||||
|
/* --vxe-ui-table-fixed-left-scrolling-box-shadow: 8px 0px 10px -5px hsl(var(--accent));
|
||||||
|
--vxe-ui-table-fixed-right-scrolling-box-shadow: -8px 0px 10px -5px hsl(var(--accent)); */
|
||||||
|
|
||||||
|
/* input */
|
||||||
|
--vxe-ui-input-border-color: hsl(var(--border));
|
||||||
|
|
||||||
|
/* --vxe-ui-input-placeholder-color: #8d9095; */
|
||||||
|
|
||||||
|
/* --vxe-ui-input-disabled-background-color: #262727; */
|
||||||
|
|
||||||
|
/* loading */
|
||||||
|
--vxe-ui-loading-background-color: hsl(var(--overlay-content));
|
||||||
|
|
||||||
|
/* table */
|
||||||
|
--vxe-ui-table-header-background-color: hsl(var(--accent));
|
||||||
|
--vxe-ui-table-border-color: hsl(var(--border));
|
||||||
|
--vxe-ui-table-row-hover-background-color: hsl(var(--accent-hover));
|
||||||
|
--vxe-ui-table-row-striped-background-color: hsl(var(--accent) / 60%);
|
||||||
|
--vxe-ui-table-row-hover-striped-background-color: hsl(var(--accent));
|
||||||
|
--vxe-ui-table-row-radio-checked-background-color: hsl(var(--accent));
|
||||||
|
--vxe-ui-table-row-hover-radio-checked-background-color: hsl(
|
||||||
|
var(--accent-hover)
|
||||||
|
);
|
||||||
|
--vxe-ui-table-row-checkbox-checked-background-color: hsl(var(--accent));
|
||||||
|
--vxe-ui-table-row-hover-checkbox-checked-background-color: hsl(
|
||||||
|
var(--accent-hover)
|
||||||
|
);
|
||||||
|
--vxe-ui-table-row-current-background-color: hsl(var(--accent));
|
||||||
|
--vxe-ui-table-row-hover-current-background-color: hsl(var(--accent-hover));
|
||||||
|
--vxe-ui-font-primary-tinge-color: hsl(var(--primary));
|
||||||
|
--vxe-ui-font-primary-lighten-color: hsl(var(--primary) / 60%);
|
||||||
|
--vxe-ui-font-primary-darken-color: hsl(var(--primary));
|
||||||
|
|
||||||
|
/* height: auto !important; */
|
||||||
|
|
||||||
|
/* --vxe-ui-table-fixed-scrolling-box-shadow-color: rgb(0 0 0 / 80%); */
|
||||||
|
}
|
||||||
|
|
||||||
|
.vxe-tools--operate {
|
||||||
|
margin-right: 0.25rem;
|
||||||
|
margin-left: 0.75rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.vxe-table-custom--checkbox-option:hover {
|
||||||
|
background: none !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.vxe-toolbar {
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.vxe-buttons--wrapper:not(:empty),
|
||||||
|
.vxe-tools--operate:not(:empty),
|
||||||
|
.vxe-tools--wrapper:not(:empty) {
|
||||||
|
padding: 0.6em 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.vxe-tools--operate:not(:has(button)) {
|
||||||
|
margin-left: 0;
|
||||||
|
}
|
||||||
|
|
@ -18,6 +18,8 @@ import { $t } from '#/locales';
|
||||||
|
|
||||||
import { useVbenForm } from './form';
|
import { useVbenForm } from './form';
|
||||||
|
|
||||||
|
import '#/adapter/style.css';
|
||||||
|
|
||||||
setupVbenVxeTable({
|
setupVbenVxeTable({
|
||||||
configVxeTable: (vxeUI) => {
|
configVxeTable: (vxeUI) => {
|
||||||
vxeUI.setConfig({
|
vxeUI.setConfig({
|
||||||
|
|
@ -295,4 +297,5 @@ export type OnActionClickParams<T = Recordable<any>> = {
|
||||||
export type OnActionClickFn<T = Recordable<any>> = (
|
export type OnActionClickFn<T = Recordable<any>> = (
|
||||||
params: OnActionClickParams<T>,
|
params: OnActionClickParams<T>,
|
||||||
) => void;
|
) => void;
|
||||||
|
export * from '#/components/table-action';
|
||||||
export type * from '@vben/plugins/vxe-table';
|
export type * from '@vben/plugins/vxe-table';
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ export namespace Demo01ContactApi {
|
||||||
export interface Demo01Contact {
|
export interface Demo01Contact {
|
||||||
id: number; // 编号
|
id: number; // 编号
|
||||||
name?: string; // 名字
|
name?: string; // 名字
|
||||||
sex?: boolean; // 性别
|
sex?: number; // 性别
|
||||||
birthday?: Dayjs | string; // 出生年
|
birthday?: Dayjs | string; // 出生年
|
||||||
description?: string; // 简介
|
description?: string; // 简介
|
||||||
avatar: string; // 头像
|
avatar: string; // 头像
|
||||||
|
|
@ -46,6 +46,13 @@ export function deleteDemo01Contact(id: number) {
|
||||||
return requestClient.delete(`/infra/demo01-contact/delete?id=${id}`);
|
return requestClient.delete(`/infra/demo01-contact/delete?id=${id}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 批量删除示例联系人 */
|
||||||
|
export function deleteDemo01ContactList(ids: number[]) {
|
||||||
|
return requestClient.delete(
|
||||||
|
`/infra/demo01-contact/delete-list?ids=${ids.join(',')}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/** 导出示例联系人 */
|
/** 导出示例联系人 */
|
||||||
export function exportDemo01Contact(params: any) {
|
export function exportDemo01Contact(params: any) {
|
||||||
return requestClient.download('/infra/demo01-contact/export-excel', params);
|
return requestClient.download('/infra/demo01-contact/export-excel', params);
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ export namespace Demo03StudentApi {
|
||||||
/** 查询学生分页 */
|
/** 查询学生分页 */
|
||||||
export function getDemo03StudentPage(params: PageParam) {
|
export function getDemo03StudentPage(params: PageParam) {
|
||||||
return requestClient.get<PageResult<Demo03StudentApi.Demo03Student>>(
|
return requestClient.get<PageResult<Demo03StudentApi.Demo03Student>>(
|
||||||
'/infra/demo03-student/page',
|
'/infra/demo03-student-erp/page',
|
||||||
{ params },
|
{ params },
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -42,28 +42,38 @@ export function getDemo03StudentPage(params: PageParam) {
|
||||||
/** 查询学生详情 */
|
/** 查询学生详情 */
|
||||||
export function getDemo03Student(id: number) {
|
export function getDemo03Student(id: number) {
|
||||||
return requestClient.get<Demo03StudentApi.Demo03Student>(
|
return requestClient.get<Demo03StudentApi.Demo03Student>(
|
||||||
`/infra/demo03-student/get?id=${id}`,
|
`/infra/demo03-student-erp/get?id=${id}`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 新增学生 */
|
/** 新增学生 */
|
||||||
export function createDemo03Student(data: Demo03StudentApi.Demo03Student) {
|
export function createDemo03Student(data: Demo03StudentApi.Demo03Student) {
|
||||||
return requestClient.post('/infra/demo03-student/create', data);
|
return requestClient.post('/infra/demo03-student-erp/create', data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 修改学生 */
|
/** 修改学生 */
|
||||||
export function updateDemo03Student(data: Demo03StudentApi.Demo03Student) {
|
export function updateDemo03Student(data: Demo03StudentApi.Demo03Student) {
|
||||||
return requestClient.put('/infra/demo03-student/update', data);
|
return requestClient.put('/infra/demo03-student-erp/update', data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 删除学生 */
|
/** 删除学生 */
|
||||||
export function deleteDemo03Student(id: number) {
|
export function deleteDemo03Student(id: number) {
|
||||||
return requestClient.delete(`/infra/demo03-student/delete?id=${id}`);
|
return requestClient.delete(`/infra/demo03-student-erp/delete?id=${id}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 批量删除学生 */
|
||||||
|
export function deleteDemo03StudentList(ids: number[]) {
|
||||||
|
return requestClient.delete(
|
||||||
|
`/infra/demo03-student-erp/delete-list?ids=${ids.join(',')}`,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 导出学生 */
|
/** 导出学生 */
|
||||||
export function exportDemo03Student(params: any) {
|
export function exportDemo03Student(params: any) {
|
||||||
return requestClient.download('/infra/demo03-student/export-excel', params);
|
return requestClient.download(
|
||||||
|
'/infra/demo03-student-erp/export-excel',
|
||||||
|
params,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ==================== 子表(学生课程) ====================
|
// ==================== 子表(学生课程) ====================
|
||||||
|
|
@ -71,33 +81,44 @@ export function exportDemo03Student(params: any) {
|
||||||
/** 获得学生课程分页 */
|
/** 获得学生课程分页 */
|
||||||
export function getDemo03CoursePage(params: PageParam) {
|
export function getDemo03CoursePage(params: PageParam) {
|
||||||
return requestClient.get<PageResult<Demo03StudentApi.Demo03Course>>(
|
return requestClient.get<PageResult<Demo03StudentApi.Demo03Course>>(
|
||||||
`/infra/demo03-student/demo03-course/page`,
|
`/infra/demo03-student-erp/demo03-course/page`,
|
||||||
{
|
{ params },
|
||||||
params,
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
/** 新增学生课程 */
|
/** 新增学生课程 */
|
||||||
export function createDemo03Course(data: Demo03StudentApi.Demo03Course) {
|
export function createDemo03Course(data: Demo03StudentApi.Demo03Course) {
|
||||||
return requestClient.post(`/infra/demo03-student/demo03-course/create`, data);
|
return requestClient.post(
|
||||||
|
`/infra/demo03-student-erp/demo03-course/create`,
|
||||||
|
data,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 修改学生课程 */
|
/** 修改学生课程 */
|
||||||
export function updateDemo03Course(data: Demo03StudentApi.Demo03Course) {
|
export function updateDemo03Course(data: Demo03StudentApi.Demo03Course) {
|
||||||
return requestClient.put(`/infra/demo03-student/demo03-course/update`, data);
|
return requestClient.put(
|
||||||
|
`/infra/demo03-student-erp/demo03-course/update`,
|
||||||
|
data,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 删除学生课程 */
|
/** 删除学生课程 */
|
||||||
export function deleteDemo03Course(id: number) {
|
export function deleteDemo03Course(id: number) {
|
||||||
return requestClient.delete(
|
return requestClient.delete(
|
||||||
`/infra/demo03-student/demo03-course/delete?id=${id}`,
|
`/infra/demo03-student-erp/demo03-course/delete?id=${id}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 批量删除学生课程 */
|
||||||
|
export function deleteDemo03CourseList(ids: number[]) {
|
||||||
|
return requestClient.delete(
|
||||||
|
`/infra/demo03-student-erp/demo03-course/delete-list?ids=${ids.join(',')}`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 获得学生课程 */
|
/** 获得学生课程 */
|
||||||
export function getDemo03Course(id: number) {
|
export function getDemo03Course(id: number) {
|
||||||
return requestClient.get<Demo03StudentApi.Demo03Course>(
|
return requestClient.get<Demo03StudentApi.Demo03Course>(
|
||||||
`/infra/demo03-student/demo03-course/get?id=${id}`,
|
`/infra/demo03-student-erp/demo03-course/get?id=${id}`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -106,32 +127,43 @@ export function getDemo03Course(id: number) {
|
||||||
/** 获得学生班级分页 */
|
/** 获得学生班级分页 */
|
||||||
export function getDemo03GradePage(params: PageParam) {
|
export function getDemo03GradePage(params: PageParam) {
|
||||||
return requestClient.get<PageResult<Demo03StudentApi.Demo03Grade>>(
|
return requestClient.get<PageResult<Demo03StudentApi.Demo03Grade>>(
|
||||||
`/infra/demo03-student/demo03-grade/page`,
|
`/infra/demo03-student-erp/demo03-grade/page`,
|
||||||
{
|
{ params },
|
||||||
params,
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
/** 新增学生班级 */
|
/** 新增学生班级 */
|
||||||
export function createDemo03Grade(data: Demo03StudentApi.Demo03Grade) {
|
export function createDemo03Grade(data: Demo03StudentApi.Demo03Grade) {
|
||||||
return requestClient.post(`/infra/demo03-student/demo03-grade/create`, data);
|
return requestClient.post(
|
||||||
|
`/infra/demo03-student-erp/demo03-grade/create`,
|
||||||
|
data,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 修改学生班级 */
|
/** 修改学生班级 */
|
||||||
export function updateDemo03Grade(data: Demo03StudentApi.Demo03Grade) {
|
export function updateDemo03Grade(data: Demo03StudentApi.Demo03Grade) {
|
||||||
return requestClient.put(`/infra/demo03-student/demo03-grade/update`, data);
|
return requestClient.put(
|
||||||
|
`/infra/demo03-student-erp/demo03-grade/update`,
|
||||||
|
data,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 删除学生班级 */
|
/** 删除学生班级 */
|
||||||
export function deleteDemo03Grade(id: number) {
|
export function deleteDemo03Grade(id: number) {
|
||||||
return requestClient.delete(
|
return requestClient.delete(
|
||||||
`/infra/demo03-student/demo03-grade/delete?id=${id}`,
|
`/infra/demo03-student-erp/demo03-grade/delete?id=${id}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 批量删除学生班级 */
|
||||||
|
export function deleteDemo03GradeList(ids: number[]) {
|
||||||
|
return requestClient.delete(
|
||||||
|
`/infra/demo03-student-erp/demo03-grade/delete-list?ids=${ids.join(',')}`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 获得学生班级 */
|
/** 获得学生班级 */
|
||||||
export function getDemo03Grade(id: number) {
|
export function getDemo03Grade(id: number) {
|
||||||
return requestClient.get<Demo03StudentApi.Demo03Grade>(
|
return requestClient.get<Demo03StudentApi.Demo03Grade>(
|
||||||
`/infra/demo03-student/demo03-grade/get?id=${id}`,
|
`/infra/demo03-student-erp/demo03-grade/get?id=${id}`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
import type { Dayjs } from 'dayjs';
|
||||||
|
|
||||||
import type { PageParam, PageResult } from '@vben/request';
|
import type { PageParam, PageResult } from '@vben/request';
|
||||||
|
|
||||||
import { requestClient } from '#/api/request';
|
import { requestClient } from '#/api/request';
|
||||||
|
|
@ -24,7 +26,7 @@ export namespace Demo03StudentApi {
|
||||||
id: number; // 编号
|
id: number; // 编号
|
||||||
name?: string; // 名字
|
name?: string; // 名字
|
||||||
sex?: number; // 性别
|
sex?: number; // 性别
|
||||||
birthday?: Date; // 出生日期
|
birthday?: Dayjs | string; // 出生日期
|
||||||
description?: string; // 简介
|
description?: string; // 简介
|
||||||
demo03courses?: Demo03Course[];
|
demo03courses?: Demo03Course[];
|
||||||
demo03grade?: Demo03Grade;
|
demo03grade?: Demo03Grade;
|
||||||
|
|
@ -34,7 +36,7 @@ export namespace Demo03StudentApi {
|
||||||
/** 查询学生分页 */
|
/** 查询学生分页 */
|
||||||
export function getDemo03StudentPage(params: PageParam) {
|
export function getDemo03StudentPage(params: PageParam) {
|
||||||
return requestClient.get<PageResult<Demo03StudentApi.Demo03Student>>(
|
return requestClient.get<PageResult<Demo03StudentApi.Demo03Student>>(
|
||||||
'/infra/demo03-student/page',
|
'/infra/demo03-student-inner/page',
|
||||||
{ params },
|
{ params },
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -42,28 +44,38 @@ export function getDemo03StudentPage(params: PageParam) {
|
||||||
/** 查询学生详情 */
|
/** 查询学生详情 */
|
||||||
export function getDemo03Student(id: number) {
|
export function getDemo03Student(id: number) {
|
||||||
return requestClient.get<Demo03StudentApi.Demo03Student>(
|
return requestClient.get<Demo03StudentApi.Demo03Student>(
|
||||||
`/infra/demo03-student/get?id=${id}`,
|
`/infra/demo03-student-inner/get?id=${id}`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 新增学生 */
|
/** 新增学生 */
|
||||||
export function createDemo03Student(data: Demo03StudentApi.Demo03Student) {
|
export function createDemo03Student(data: Demo03StudentApi.Demo03Student) {
|
||||||
return requestClient.post('/infra/demo03-student/create', data);
|
return requestClient.post('/infra/demo03-student-inner/create', data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 修改学生 */
|
/** 修改学生 */
|
||||||
export function updateDemo03Student(data: Demo03StudentApi.Demo03Student) {
|
export function updateDemo03Student(data: Demo03StudentApi.Demo03Student) {
|
||||||
return requestClient.put('/infra/demo03-student/update', data);
|
return requestClient.put('/infra/demo03-student-inner/update', data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 删除学生 */
|
/** 删除学生 */
|
||||||
export function deleteDemo03Student(id: number) {
|
export function deleteDemo03Student(id: number) {
|
||||||
return requestClient.delete(`/infra/demo03-student/delete?id=${id}`);
|
return requestClient.delete(`/infra/demo03-student-inner/delete?id=${id}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 批量删除学生 */
|
||||||
|
export function deleteDemo03StudentList(ids: number[]) {
|
||||||
|
return requestClient.delete(
|
||||||
|
`/infra/demo03-student-inner/delete-list?ids=${ids.join(',')}`,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 导出学生 */
|
/** 导出学生 */
|
||||||
export function exportDemo03Student(params: any) {
|
export function exportDemo03Student(params: any) {
|
||||||
return requestClient.download('/infra/demo03-student/export-excel', params);
|
return requestClient.download(
|
||||||
|
'/infra/demo03-student-inner/export-excel',
|
||||||
|
params,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ==================== 子表(学生课程) ====================
|
// ==================== 子表(学生课程) ====================
|
||||||
|
|
@ -71,7 +83,7 @@ export function exportDemo03Student(params: any) {
|
||||||
/** 获得学生课程列表 */
|
/** 获得学生课程列表 */
|
||||||
export function getDemo03CourseListByStudentId(studentId: number) {
|
export function getDemo03CourseListByStudentId(studentId: number) {
|
||||||
return requestClient.get<Demo03StudentApi.Demo03Course[]>(
|
return requestClient.get<Demo03StudentApi.Demo03Course[]>(
|
||||||
`/infra/demo03-student/demo03-course/list-by-student-id?studentId=${studentId}`,
|
`/infra/demo03-student-inner/demo03-course/list-by-student-id?studentId=${studentId}`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -80,6 +92,6 @@ export function getDemo03CourseListByStudentId(studentId: number) {
|
||||||
/** 获得学生班级 */
|
/** 获得学生班级 */
|
||||||
export function getDemo03GradeByStudentId(studentId: number) {
|
export function getDemo03GradeByStudentId(studentId: number) {
|
||||||
return requestClient.get<Demo03StudentApi.Demo03Grade>(
|
return requestClient.get<Demo03StudentApi.Demo03Grade>(
|
||||||
`/infra/demo03-student/demo03-grade/get-by-student-id?studentId=${studentId}`,
|
`/infra/demo03-student-inner/demo03-grade/get-by-student-id?studentId=${studentId}`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ export namespace Demo03StudentApi {
|
||||||
/** 查询学生分页 */
|
/** 查询学生分页 */
|
||||||
export function getDemo03StudentPage(params: PageParam) {
|
export function getDemo03StudentPage(params: PageParam) {
|
||||||
return requestClient.get<PageResult<Demo03StudentApi.Demo03Student>>(
|
return requestClient.get<PageResult<Demo03StudentApi.Demo03Student>>(
|
||||||
'/infra/demo03-student/page',
|
'/infra/demo03-student-normal/page',
|
||||||
{ params },
|
{ params },
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -44,28 +44,38 @@ export function getDemo03StudentPage(params: PageParam) {
|
||||||
/** 查询学生详情 */
|
/** 查询学生详情 */
|
||||||
export function getDemo03Student(id: number) {
|
export function getDemo03Student(id: number) {
|
||||||
return requestClient.get<Demo03StudentApi.Demo03Student>(
|
return requestClient.get<Demo03StudentApi.Demo03Student>(
|
||||||
`/infra/demo03-student/get?id=${id}`,
|
`/infra/demo03-student-normal/get?id=${id}`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 新增学生 */
|
/** 新增学生 */
|
||||||
export function createDemo03Student(data: Demo03StudentApi.Demo03Student) {
|
export function createDemo03Student(data: Demo03StudentApi.Demo03Student) {
|
||||||
return requestClient.post('/infra/demo03-student/create', data);
|
return requestClient.post('/infra/demo03-student-normal/create', data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 修改学生 */
|
/** 修改学生 */
|
||||||
export function updateDemo03Student(data: Demo03StudentApi.Demo03Student) {
|
export function updateDemo03Student(data: Demo03StudentApi.Demo03Student) {
|
||||||
return requestClient.put('/infra/demo03-student/update', data);
|
return requestClient.put('/infra/demo03-student-normal/update', data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 删除学生 */
|
/** 删除学生 */
|
||||||
export function deleteDemo03Student(id: number) {
|
export function deleteDemo03Student(id: number) {
|
||||||
return requestClient.delete(`/infra/demo03-student/delete?id=${id}`);
|
return requestClient.delete(`/infra/demo03-student-normal/delete?id=${id}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 批量删除学生 */
|
||||||
|
export function deleteDemo03StudentList(ids: number[]) {
|
||||||
|
return requestClient.delete(
|
||||||
|
`/infra/demo03-student-normal/delete-list?ids=${ids.join(',')}`,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 导出学生 */
|
/** 导出学生 */
|
||||||
export function exportDemo03Student(params: any) {
|
export function exportDemo03Student(params: any) {
|
||||||
return requestClient.download('/infra/demo03-student/export-excel', params);
|
return requestClient.download(
|
||||||
|
'/infra/demo03-student-normal/export-excel',
|
||||||
|
params,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ==================== 子表(学生课程) ====================
|
// ==================== 子表(学生课程) ====================
|
||||||
|
|
@ -73,7 +83,7 @@ export function exportDemo03Student(params: any) {
|
||||||
/** 获得学生课程列表 */
|
/** 获得学生课程列表 */
|
||||||
export function getDemo03CourseListByStudentId(studentId: number) {
|
export function getDemo03CourseListByStudentId(studentId: number) {
|
||||||
return requestClient.get<Demo03StudentApi.Demo03Course[]>(
|
return requestClient.get<Demo03StudentApi.Demo03Course[]>(
|
||||||
`/infra/demo03-student/demo03-course/list-by-student-id?studentId=${studentId}`,
|
`/infra/demo03-student-normal/demo03-course/list-by-student-id?studentId=${studentId}`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -82,6 +92,6 @@ export function getDemo03CourseListByStudentId(studentId: number) {
|
||||||
/** 获得学生班级 */
|
/** 获得学生班级 */
|
||||||
export function getDemo03GradeByStudentId(studentId: number) {
|
export function getDemo03GradeByStudentId(studentId: number) {
|
||||||
return requestClient.get<Demo03StudentApi.Demo03Grade>(
|
return requestClient.get<Demo03StudentApi.Demo03Grade>(
|
||||||
`/infra/demo03-student/demo03-grade/get-by-student-id?studentId=${studentId}`,
|
`/infra/demo03-student-normal/demo03-grade/get-by-student-id?studentId=${studentId}`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,53 @@
|
||||||
|
<!--
|
||||||
|
参考自 https://github.com/yudaocode/yudao-ui-admin-vue3/blob/master/src/components/ContentWrap/src/ContentWrap.vue
|
||||||
|
保证和 yudao-ui-admin-vue3 功能的一致性
|
||||||
|
-->
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import type { CSSProperties } from 'vue';
|
||||||
|
|
||||||
|
import { ShieldQuestion } from '@vben/icons';
|
||||||
|
|
||||||
|
import { ElCard, ElTooltip } from 'element-plus';
|
||||||
|
|
||||||
|
defineOptions({ name: 'ContentWrap' });
|
||||||
|
|
||||||
|
withDefaults(
|
||||||
|
defineProps<{
|
||||||
|
bodyStyle?: CSSProperties;
|
||||||
|
message?: string;
|
||||||
|
title?: string;
|
||||||
|
}>(),
|
||||||
|
{
|
||||||
|
bodyStyle: () => ({ padding: '10px' }),
|
||||||
|
title: '',
|
||||||
|
message: '',
|
||||||
|
},
|
||||||
|
);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<ElCard :body-style="bodyStyle" :header="title" class="mb-4">
|
||||||
|
<template v-if="title" #header>
|
||||||
|
<div class="flex items-center justify-between">
|
||||||
|
<div class="flex items-center">
|
||||||
|
<span class="text-4 font-[700]">{{ title }}</span>
|
||||||
|
<ElTooltip placement="right">
|
||||||
|
<template #content>
|
||||||
|
<div class="max-w-[200px]">{{ message }}</div>
|
||||||
|
</template>
|
||||||
|
<ShieldQuestion :size="14" class="ml-5px" />
|
||||||
|
</ElTooltip>
|
||||||
|
<div class="pl-20px flex flex-grow">
|
||||||
|
<slot name="header"></slot>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<slot name="extra"></slot>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
<template #default>
|
||||||
|
<slot></slot>
|
||||||
|
</template>
|
||||||
|
</ElCard>
|
||||||
|
</template>
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
export { default as ContentWrap } from './content-wrap.vue';
|
||||||
|
|
@ -0,0 +1,13 @@
|
||||||
|
export const ACTION_ICON = {
|
||||||
|
DOWNLOAD: 'lucide:download',
|
||||||
|
UPLOAD: 'lucide:upload',
|
||||||
|
ADD: 'lucide:plus',
|
||||||
|
EDIT: 'lucide:edit',
|
||||||
|
DELETE: 'lucide:trash',
|
||||||
|
REFRESH: 'lucide:refresh-cw',
|
||||||
|
SEARCH: 'lucide:search',
|
||||||
|
FILTER: 'lucide:filter',
|
||||||
|
MORE: 'lucide:ellipsis-vertical',
|
||||||
|
VIEW: 'lucide:eye',
|
||||||
|
COPY: 'lucide:copy',
|
||||||
|
};
|
||||||
|
|
@ -0,0 +1,4 @@
|
||||||
|
export * from './icons';
|
||||||
|
|
||||||
|
export { default as TableAction } from './table-action.vue';
|
||||||
|
export * from './typing';
|
||||||
|
|
@ -0,0 +1,289 @@
|
||||||
|
<!-- add by 星语:参考 vben2 的方式,增加 TableAction 组件 -->
|
||||||
|
<script setup lang="ts">
|
||||||
|
import type { PropType } from 'vue';
|
||||||
|
|
||||||
|
import type { ActionItem, PopConfirm } from './typing';
|
||||||
|
|
||||||
|
import { computed, toRaw } from 'vue';
|
||||||
|
|
||||||
|
import { useAccess } from '@vben/access';
|
||||||
|
import { IconifyIcon } from '@vben/icons';
|
||||||
|
import { $t } from '@vben/locales';
|
||||||
|
import { isBoolean, isFunction } from '@vben/utils';
|
||||||
|
|
||||||
|
import {
|
||||||
|
ElButton,
|
||||||
|
ElDropdown,
|
||||||
|
ElDropdownItem,
|
||||||
|
ElDropdownMenu,
|
||||||
|
ElPopconfirm,
|
||||||
|
ElSpace,
|
||||||
|
ElTooltip,
|
||||||
|
} from 'element-plus';
|
||||||
|
|
||||||
|
const props = defineProps({
|
||||||
|
actions: {
|
||||||
|
type: Array as PropType<ActionItem[]>,
|
||||||
|
default() {
|
||||||
|
return [];
|
||||||
|
},
|
||||||
|
},
|
||||||
|
dropDownActions: {
|
||||||
|
type: Array as PropType<ActionItem[]>,
|
||||||
|
default() {
|
||||||
|
return [];
|
||||||
|
},
|
||||||
|
},
|
||||||
|
divider: {
|
||||||
|
type: Boolean,
|
||||||
|
default: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const { hasAccessByCodes } = useAccess();
|
||||||
|
|
||||||
|
function isIfShow(action: ActionItem): boolean {
|
||||||
|
const ifShow = action.ifShow;
|
||||||
|
|
||||||
|
let isIfShow = true;
|
||||||
|
|
||||||
|
if (isBoolean(ifShow)) {
|
||||||
|
isIfShow = ifShow;
|
||||||
|
}
|
||||||
|
if (isFunction(ifShow)) {
|
||||||
|
isIfShow = ifShow(action);
|
||||||
|
}
|
||||||
|
return isIfShow;
|
||||||
|
}
|
||||||
|
|
||||||
|
const getActions = computed(() => {
|
||||||
|
return (toRaw(props.actions) || [])
|
||||||
|
.filter((action) => {
|
||||||
|
return (
|
||||||
|
(hasAccessByCodes(action.auth || []) ||
|
||||||
|
(action.auth || []).length === 0) &&
|
||||||
|
isIfShow(action)
|
||||||
|
);
|
||||||
|
})
|
||||||
|
.map((action) => {
|
||||||
|
const { popConfirm } = action;
|
||||||
|
return {
|
||||||
|
type: action.type || 'primary',
|
||||||
|
...action,
|
||||||
|
...popConfirm,
|
||||||
|
onConfirm: popConfirm?.confirm,
|
||||||
|
onCancel: popConfirm?.cancel,
|
||||||
|
enable: !!popConfirm,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
const getDropdownList = computed((): any[] => {
|
||||||
|
return (toRaw(props.dropDownActions) || [])
|
||||||
|
.filter((action) => {
|
||||||
|
return (
|
||||||
|
(hasAccessByCodes(action.auth || []) ||
|
||||||
|
(action.auth || []).length === 0) &&
|
||||||
|
isIfShow(action)
|
||||||
|
);
|
||||||
|
})
|
||||||
|
.map((action, index) => {
|
||||||
|
const { label, popConfirm } = action;
|
||||||
|
return {
|
||||||
|
...action,
|
||||||
|
...popConfirm,
|
||||||
|
onConfirm: popConfirm?.confirm,
|
||||||
|
onCancel: popConfirm?.cancel,
|
||||||
|
text: label,
|
||||||
|
divider:
|
||||||
|
index < props.dropDownActions.length - 1 ? props.divider : false,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
function getPopConfirmProps(attrs: PopConfirm) {
|
||||||
|
const originAttrs: any = attrs;
|
||||||
|
delete originAttrs.icon;
|
||||||
|
if (attrs.confirm && isFunction(attrs.confirm)) {
|
||||||
|
originAttrs.onConfirm = attrs.confirm;
|
||||||
|
delete originAttrs.confirm;
|
||||||
|
}
|
||||||
|
if (attrs.cancel && isFunction(attrs.cancel)) {
|
||||||
|
originAttrs.onCancel = attrs.cancel;
|
||||||
|
delete originAttrs.cancel;
|
||||||
|
}
|
||||||
|
return originAttrs;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getButtonProps(action: ActionItem) {
|
||||||
|
const res = {
|
||||||
|
type: action.type || 'primary',
|
||||||
|
...action,
|
||||||
|
};
|
||||||
|
delete res.icon;
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleMenuClick(command: any) {
|
||||||
|
const action = getDropdownList.value[command];
|
||||||
|
if (action.onClick && isFunction(action.onClick)) {
|
||||||
|
action.onClick();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div class="table-actions">
|
||||||
|
<ElSpace
|
||||||
|
:size="
|
||||||
|
getActions?.some((item: ActionItem) => item.type === 'text') ? 0 : 8
|
||||||
|
"
|
||||||
|
>
|
||||||
|
<template v-for="(action, index) in getActions" :key="index">
|
||||||
|
<ElPopconfirm
|
||||||
|
v-if="action.popConfirm"
|
||||||
|
v-bind="getPopConfirmProps(action.popConfirm)"
|
||||||
|
>
|
||||||
|
<template v-if="action.popConfirm.icon" #icon>
|
||||||
|
<IconifyIcon :icon="action.popConfirm.icon" />
|
||||||
|
</template>
|
||||||
|
<template #reference>
|
||||||
|
<ElTooltip
|
||||||
|
v-if="
|
||||||
|
action.tooltip &&
|
||||||
|
((typeof action.tooltip === 'string' && action.tooltip) ||
|
||||||
|
(typeof action.tooltip === 'object' &&
|
||||||
|
action.tooltip.content))
|
||||||
|
"
|
||||||
|
v-bind="
|
||||||
|
typeof action.tooltip === 'string'
|
||||||
|
? { content: action.tooltip }
|
||||||
|
: { ...action.tooltip }
|
||||||
|
"
|
||||||
|
>
|
||||||
|
<ElButton v-bind="getButtonProps(action)">
|
||||||
|
<template v-if="action.icon">
|
||||||
|
<IconifyIcon :icon="action.icon" class="mr-1" />
|
||||||
|
</template>
|
||||||
|
{{ action.label }}
|
||||||
|
</ElButton>
|
||||||
|
</ElTooltip>
|
||||||
|
<ElButton v-else v-bind="getButtonProps(action)">
|
||||||
|
<template v-if="action.icon">
|
||||||
|
<IconifyIcon :icon="action.icon" class="mr-1" />
|
||||||
|
</template>
|
||||||
|
{{ action.label }}
|
||||||
|
</ElButton>
|
||||||
|
</template>
|
||||||
|
</ElPopconfirm>
|
||||||
|
<ElTooltip
|
||||||
|
v-else-if="
|
||||||
|
action.tooltip &&
|
||||||
|
((typeof action.tooltip === 'string' && action.tooltip) ||
|
||||||
|
(typeof action.tooltip === 'object' && action.tooltip.content))
|
||||||
|
"
|
||||||
|
v-bind="
|
||||||
|
typeof action.tooltip === 'string'
|
||||||
|
? { content: action.tooltip }
|
||||||
|
: { ...action.tooltip }
|
||||||
|
"
|
||||||
|
>
|
||||||
|
<ElButton v-bind="getButtonProps(action)" @click="action.onClick">
|
||||||
|
<template v-if="action.icon">
|
||||||
|
<IconifyIcon :icon="action.icon" class="mr-1" />
|
||||||
|
</template>
|
||||||
|
{{ action.label }}
|
||||||
|
</ElButton>
|
||||||
|
</ElTooltip>
|
||||||
|
<ElButton
|
||||||
|
v-else
|
||||||
|
v-bind="getButtonProps(action)"
|
||||||
|
@click="action.onClick"
|
||||||
|
>
|
||||||
|
<template v-if="action.icon">
|
||||||
|
<IconifyIcon :icon="action.icon" class="mr-1" />
|
||||||
|
</template>
|
||||||
|
{{ action.label }}
|
||||||
|
</ElButton>
|
||||||
|
</template>
|
||||||
|
</ElSpace>
|
||||||
|
|
||||||
|
<ElDropdown v-if="getDropdownList.length > 0" @command="handleMenuClick">
|
||||||
|
<slot name="more">
|
||||||
|
<ElButton :type="getDropdownList[0].type">
|
||||||
|
{{ $t('page.action.more') }}
|
||||||
|
<IconifyIcon icon="lucide:ellipsis-vertical" class="ml-1" />
|
||||||
|
</ElButton>
|
||||||
|
</slot>
|
||||||
|
<template #dropdown>
|
||||||
|
<ElDropdownMenu>
|
||||||
|
<ElDropdownItem
|
||||||
|
v-for="(action, index) in getDropdownList"
|
||||||
|
:key="index"
|
||||||
|
:command="index"
|
||||||
|
:disabled="action.disabled"
|
||||||
|
>
|
||||||
|
<template v-if="action.popConfirm">
|
||||||
|
<ElPopconfirm v-bind="getPopConfirmProps(action.popConfirm)">
|
||||||
|
<template v-if="action.popConfirm.icon" #icon>
|
||||||
|
<IconifyIcon :icon="action.popConfirm.icon" />
|
||||||
|
</template>
|
||||||
|
<template #reference>
|
||||||
|
<div>
|
||||||
|
<IconifyIcon v-if="action.icon" :icon="action.icon" />
|
||||||
|
<span :class="action.icon ? 'ml-1' : ''">
|
||||||
|
{{ action.text }}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</ElPopconfirm>
|
||||||
|
</template>
|
||||||
|
<template v-else>
|
||||||
|
<div>
|
||||||
|
<IconifyIcon v-if="action.icon" :icon="action.icon" />
|
||||||
|
{{ action.label }}
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</ElDropdownItem>
|
||||||
|
</ElDropdownMenu>
|
||||||
|
</template>
|
||||||
|
</ElDropdown>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
<style lang="scss">
|
||||||
|
.table-actions {
|
||||||
|
.el-button--text {
|
||||||
|
padding: 4px;
|
||||||
|
margin-left: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.el-button .iconify + span,
|
||||||
|
.el-button span + .iconify {
|
||||||
|
margin-inline-start: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.iconify {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
width: 1em;
|
||||||
|
height: 1em;
|
||||||
|
font-style: normal;
|
||||||
|
line-height: 0;
|
||||||
|
vertical-align: -0.125em;
|
||||||
|
color: inherit;
|
||||||
|
text-align: center;
|
||||||
|
text-transform: none;
|
||||||
|
text-rendering: optimizelegibility;
|
||||||
|
-webkit-font-smoothing: antialiased;
|
||||||
|
-moz-osx-font-smoothing: grayscale;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.el-popconfirm {
|
||||||
|
.el-popconfirm__action {
|
||||||
|
.el-button {
|
||||||
|
margin-left: 8px !important;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
@ -0,0 +1,36 @@
|
||||||
|
import type { ButtonProps } from 'element-plus';
|
||||||
|
|
||||||
|
export type ButtonType =
|
||||||
|
| 'danger'
|
||||||
|
| 'default'
|
||||||
|
| 'info'
|
||||||
|
| 'primary'
|
||||||
|
| 'success'
|
||||||
|
| 'text'
|
||||||
|
| 'warning';
|
||||||
|
|
||||||
|
export interface PopConfirm {
|
||||||
|
title: string;
|
||||||
|
okText?: string;
|
||||||
|
cancelText?: string;
|
||||||
|
confirm: () => void;
|
||||||
|
cancel?: () => void;
|
||||||
|
icon?: string;
|
||||||
|
disabled?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ActionItem extends Partial<ButtonProps> {
|
||||||
|
onClick?: () => void;
|
||||||
|
type?: ButtonType;
|
||||||
|
label?: string;
|
||||||
|
color?: 'error' | 'success' | 'warning';
|
||||||
|
icon?: string;
|
||||||
|
popConfirm?: PopConfirm;
|
||||||
|
disabled?: boolean;
|
||||||
|
divider?: boolean;
|
||||||
|
// 权限编码控制是否显示
|
||||||
|
auth?: string[];
|
||||||
|
// 业务控制是否显示
|
||||||
|
ifShow?: ((action: ActionItem) => boolean) | boolean;
|
||||||
|
tooltip?: string | { [key: string]: any; content?: string };
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
export { default as TableToolbar } from './table-toolbar.vue';
|
||||||
|
|
@ -0,0 +1,75 @@
|
||||||
|
<!-- add by puhui999:vxe table 工具栏二次封装,提供给 vxe 原生列表使用 -->
|
||||||
|
<script setup lang="ts">
|
||||||
|
import type { VxeToolbarInstance } from '#/adapter/vxe-table';
|
||||||
|
|
||||||
|
import { ref } from 'vue';
|
||||||
|
|
||||||
|
import { useContentMaximize, useRefresh } from '@vben/hooks';
|
||||||
|
import { Expand, MsRefresh, Search, TMinimize } from '@vben/icons';
|
||||||
|
|
||||||
|
import { ElButton, ElTooltip } from 'element-plus';
|
||||||
|
|
||||||
|
import { VxeToolbar } from '#/adapter/vxe-table';
|
||||||
|
|
||||||
|
/** 列表工具栏封装 */
|
||||||
|
defineOptions({ name: 'TableToolbar' });
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
hiddenSearch: boolean;
|
||||||
|
}>();
|
||||||
|
|
||||||
|
const emits = defineEmits(['update:hiddenSearch']);
|
||||||
|
|
||||||
|
const toolbarRef = ref<VxeToolbarInstance>();
|
||||||
|
const { toggleMaximizeAndTabbarHidden, contentIsMaximize } =
|
||||||
|
useContentMaximize();
|
||||||
|
const { refresh } = useRefresh();
|
||||||
|
|
||||||
|
/** 隐藏搜索栏 */
|
||||||
|
function onHiddenSearchBar() {
|
||||||
|
emits('update:hiddenSearch', !props.hiddenSearch);
|
||||||
|
}
|
||||||
|
|
||||||
|
defineExpose({
|
||||||
|
getToolbarRef: () => toolbarRef.value,
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<VxeToolbar ref="toolbarRef" custom>
|
||||||
|
<template #toolPrefix>
|
||||||
|
<slot></slot>
|
||||||
|
<ElTooltip placement="bottom">
|
||||||
|
<template #content>
|
||||||
|
<div class="max-w-[200px]">搜索</div>
|
||||||
|
</template>
|
||||||
|
<ElButton class="ml-2 font-[8px]" circle @click="onHiddenSearchBar">
|
||||||
|
<Search :size="15" />
|
||||||
|
</ElButton>
|
||||||
|
</ElTooltip>
|
||||||
|
<ElTooltip placement="bottom">
|
||||||
|
<template #content>
|
||||||
|
<div class="max-w-[200px]">刷新</div>
|
||||||
|
</template>
|
||||||
|
<ElButton class="ml-2 font-[8px]" circle @click="refresh">
|
||||||
|
<MsRefresh :size="15" />
|
||||||
|
</ElButton>
|
||||||
|
</ElTooltip>
|
||||||
|
<ElTooltip placement="bottom">
|
||||||
|
<template #content>
|
||||||
|
<div class="max-w-[200px]">
|
||||||
|
{{ contentIsMaximize ? '还原' : '全屏' }}
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
<ElButton
|
||||||
|
class="ml-2 font-[8px]"
|
||||||
|
circle
|
||||||
|
@click="toggleMaximizeAndTabbarHidden"
|
||||||
|
>
|
||||||
|
<Expand v-if="!contentIsMaximize" :size="15" />
|
||||||
|
<TMinimize v-else :size="15" />
|
||||||
|
</ElButton>
|
||||||
|
</ElTooltip>
|
||||||
|
</template>
|
||||||
|
</VxeToolbar>
|
||||||
|
</template>
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
export * from './use-table-toolbar';
|
||||||
|
|
@ -0,0 +1,47 @@
|
||||||
|
import type { VxeTableInstance, VxeToolbarInstance } from '#/adapter/vxe-table';
|
||||||
|
import type { TableToolbar } from '#/components/table-toolbar';
|
||||||
|
|
||||||
|
import { ref, watch } from 'vue';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* vxe 原生工具栏挂载封装
|
||||||
|
* 解决每个组件使用 vxe-table 组件时都需要写一遍的问题
|
||||||
|
*/
|
||||||
|
export function useTableToolbar() {
|
||||||
|
const hiddenSearchBar = ref(false); // 隐藏搜索栏
|
||||||
|
const tableToolbarRef = ref<InstanceType<typeof TableToolbar>>();
|
||||||
|
const tableRef = ref<VxeTableInstance>();
|
||||||
|
const isBound = ref<boolean>(false);
|
||||||
|
|
||||||
|
/** 挂载 toolbar 工具栏 */
|
||||||
|
async function bindTableToolbar() {
|
||||||
|
const table = tableRef.value;
|
||||||
|
const tableToolbar = tableToolbarRef.value;
|
||||||
|
if (table && tableToolbar) {
|
||||||
|
// 延迟 1 秒,确保 toolbar 组件已经挂载
|
||||||
|
setTimeout(async () => {
|
||||||
|
const toolbar = tableToolbar.getToolbarRef();
|
||||||
|
if (!toolbar) {
|
||||||
|
console.error('[toolbar 挂载失败] Table toolbar not found');
|
||||||
|
}
|
||||||
|
await table.connect(toolbar as VxeToolbarInstance);
|
||||||
|
isBound.value = true;
|
||||||
|
}, 1000); // 延迟挂载确保 toolbar 正确挂载
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => tableRef.value,
|
||||||
|
async (val) => {
|
||||||
|
if (!val || isBound.value) return;
|
||||||
|
await bindTableToolbar();
|
||||||
|
},
|
||||||
|
{ immediate: true },
|
||||||
|
);
|
||||||
|
|
||||||
|
return {
|
||||||
|
hiddenSearchBar,
|
||||||
|
tableToolbarRef,
|
||||||
|
tableRef,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
@ -23,7 +23,8 @@
|
||||||
"cancel": "Cancel",
|
"cancel": "Cancel",
|
||||||
"confirm": "Confirm",
|
"confirm": "Confirm",
|
||||||
"reset": "Reset",
|
"reset": "Reset",
|
||||||
"search": "Search"
|
"search": "Search",
|
||||||
|
"more": "More"
|
||||||
},
|
},
|
||||||
"tenant": {
|
"tenant": {
|
||||||
"placeholder": "Please select tenant",
|
"placeholder": "Please select tenant",
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,8 @@
|
||||||
"cancel": "取消",
|
"cancel": "取消",
|
||||||
"confirm": "确认",
|
"confirm": "确认",
|
||||||
"reset": "重置",
|
"reset": "重置",
|
||||||
"search": "搜索"
|
"search": "搜索",
|
||||||
|
"more": "更多"
|
||||||
},
|
},
|
||||||
"tenant": {
|
"tenant": {
|
||||||
"placeholder": "请选择租户",
|
"placeholder": "请选择租户",
|
||||||
|
|
|
||||||
|
|
@ -350,7 +350,7 @@ export function useGenerationInfoSubTableFormSchema(
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: '一对一',
|
label: '一对一',
|
||||||
value: 'false',
|
value: false,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -131,11 +131,12 @@ getDetail();
|
||||||
v-for="(step, index) in steps"
|
v-for="(step, index) in steps"
|
||||||
:key="index"
|
:key="index"
|
||||||
:title="step.title"
|
:title="step.title"
|
||||||
|
class="cursor-pointer"
|
||||||
|
@click="() => (currentStep = index)"
|
||||||
/>
|
/>
|
||||||
</ElSteps>
|
</ElSteps>
|
||||||
|
|
||||||
<div class="flex-1 overflow-auto py-4">
|
<div class="flex-1 overflow-auto py-4">
|
||||||
<!-- TODO @puhui999:顶部的导航,应该可以点击哈; -->
|
|
||||||
<!-- 根据当前步骤显示对应的组件 -->
|
<!-- 根据当前步骤显示对应的组件 -->
|
||||||
<BasicInfo
|
<BasicInfo
|
||||||
v-show="currentStep === 0"
|
v-show="currentStep === 0"
|
||||||
|
|
|
||||||
|
|
@ -69,6 +69,8 @@ function updateTreeSchema(): void {
|
||||||
treeFormApi.setState({
|
treeFormApi.setState({
|
||||||
schema: useGenerationInfoTreeFormSchema(props.columns),
|
schema: useGenerationInfoTreeFormSchema(props.columns),
|
||||||
});
|
});
|
||||||
|
// 树表信息回显
|
||||||
|
treeFormApi.setValues(props.table as any);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 更新主子表信息表单 schema */
|
/** 更新主子表信息表单 schema */
|
||||||
|
|
@ -76,6 +78,8 @@ function updateSubSchema(): void {
|
||||||
subFormApi.setState({
|
subFormApi.setState({
|
||||||
schema: useGenerationInfoSubTableFormSchema(props.columns, tables.value),
|
schema: useGenerationInfoSubTableFormSchema(props.columns, tables.value),
|
||||||
});
|
});
|
||||||
|
// 主子表信息回显
|
||||||
|
subFormApi.setValues(props.table as any);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 获取合并的表单值 */
|
/** 获取合并的表单值 */
|
||||||
|
|
|
||||||
|
|
@ -274,7 +274,7 @@ const [Modal, modalApi] = useVbenModal({
|
||||||
class="h-full rounded-md bg-gray-50 !p-0 text-gray-800 dark:bg-gray-800 dark:text-gray-200"
|
class="h-full rounded-md bg-gray-50 !p-0 text-gray-800 dark:bg-gray-800 dark:text-gray-200"
|
||||||
>
|
>
|
||||||
<code
|
<code
|
||||||
v-dompurify-html="codeMap.get(activeKey)"
|
v-html="codeMap.get(activeKey)"
|
||||||
class="code-highlight"
|
class="code-highlight"
|
||||||
></code>
|
></code>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,149 @@
|
||||||
|
import type { VbenFormSchema } from '#/adapter/form';
|
||||||
|
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||||
|
import type { Demo01ContactApi } from '#/api/infra/demo/demo01';
|
||||||
|
|
||||||
|
import { DICT_TYPE, getDictOptions, getRangePickerDefaultProps } from '#/utils';
|
||||||
|
|
||||||
|
/** 新增/修改的表单 */
|
||||||
|
export function useFormSchema(): VbenFormSchema[] {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
fieldName: 'id',
|
||||||
|
component: 'Input',
|
||||||
|
dependencies: {
|
||||||
|
triggerFields: [''],
|
||||||
|
show: () => false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
fieldName: 'name',
|
||||||
|
label: '名字',
|
||||||
|
rules: 'required',
|
||||||
|
component: 'Input',
|
||||||
|
componentProps: {
|
||||||
|
placeholder: '请输入名字',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
fieldName: 'sex',
|
||||||
|
label: '性别',
|
||||||
|
rules: 'required',
|
||||||
|
component: 'RadioGroup',
|
||||||
|
componentProps: {
|
||||||
|
options: getDictOptions(DICT_TYPE.SYSTEM_USER_SEX, 'number'),
|
||||||
|
buttonStyle: 'solid',
|
||||||
|
optionType: 'button',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
fieldName: 'birthday',
|
||||||
|
label: '出生年',
|
||||||
|
rules: 'required',
|
||||||
|
component: 'DatePicker',
|
||||||
|
componentProps: {
|
||||||
|
showTime: true,
|
||||||
|
format: 'YYYY-MM-DD HH:mm:ss',
|
||||||
|
valueFormat: 'x',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
fieldName: 'description',
|
||||||
|
label: '简介',
|
||||||
|
rules: 'required',
|
||||||
|
component: 'RichTextarea',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
fieldName: 'avatar',
|
||||||
|
label: '头像',
|
||||||
|
component: 'ImageUpload',
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 列表的搜索表单 */
|
||||||
|
export function useGridFormSchema(): VbenFormSchema[] {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
fieldName: 'name',
|
||||||
|
label: '名字',
|
||||||
|
component: 'Input',
|
||||||
|
componentProps: {
|
||||||
|
allowClear: true,
|
||||||
|
placeholder: '请输入名字',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
fieldName: 'sex',
|
||||||
|
label: '性别',
|
||||||
|
component: 'Select',
|
||||||
|
componentProps: {
|
||||||
|
allowClear: true,
|
||||||
|
options: getDictOptions(DICT_TYPE.SYSTEM_USER_SEX, 'number'),
|
||||||
|
placeholder: '请选择性别',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
fieldName: 'createTime',
|
||||||
|
label: '创建时间',
|
||||||
|
component: 'RangePicker',
|
||||||
|
componentProps: {
|
||||||
|
...getRangePickerDefaultProps(),
|
||||||
|
allowClear: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 列表的字段 */
|
||||||
|
export function useGridColumns(): VxeTableGridOptions<Demo01ContactApi.Demo01Contact>['columns'] {
|
||||||
|
return [
|
||||||
|
{ type: 'checkbox', width: 40 },
|
||||||
|
{
|
||||||
|
field: 'id',
|
||||||
|
title: '编号',
|
||||||
|
minWidth: 120,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'name',
|
||||||
|
title: '名字',
|
||||||
|
minWidth: 120,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'sex',
|
||||||
|
title: '性别',
|
||||||
|
minWidth: 120,
|
||||||
|
cellRender: {
|
||||||
|
name: 'CellDict',
|
||||||
|
props: { type: DICT_TYPE.SYSTEM_USER_SEX },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'birthday',
|
||||||
|
title: '出生年',
|
||||||
|
minWidth: 120,
|
||||||
|
formatter: 'formatDateTime',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'description',
|
||||||
|
title: '简介',
|
||||||
|
minWidth: 120,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'avatar',
|
||||||
|
title: '头像',
|
||||||
|
minWidth: 120,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'createTime',
|
||||||
|
title: '创建时间',
|
||||||
|
minWidth: 120,
|
||||||
|
formatter: 'formatDateTime',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '操作',
|
||||||
|
width: 200,
|
||||||
|
fixed: 'right',
|
||||||
|
slots: { default: 'actions' },
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,185 @@
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||||
|
import type { Demo01ContactApi } from '#/api/infra/demo/demo01';
|
||||||
|
|
||||||
|
import { ref } from 'vue';
|
||||||
|
|
||||||
|
import { Page, useVbenModal } from '@vben/common-ui';
|
||||||
|
import { downloadFileFromBlobPart, isEmpty } from '@vben/utils';
|
||||||
|
|
||||||
|
import { ElLoading, ElMessage } from 'element-plus';
|
||||||
|
|
||||||
|
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||||
|
import {
|
||||||
|
deleteDemo01Contact,
|
||||||
|
deleteDemo01ContactList,
|
||||||
|
exportDemo01Contact,
|
||||||
|
getDemo01ContactPage,
|
||||||
|
} from '#/api/infra/demo/demo01';
|
||||||
|
import { $t } from '#/locales';
|
||||||
|
|
||||||
|
import { useGridColumns, useGridFormSchema } from './data';
|
||||||
|
import Form from './modules/form.vue';
|
||||||
|
|
||||||
|
const [FormModal, formModalApi] = useVbenModal({
|
||||||
|
connectedComponent: Form,
|
||||||
|
destroyOnClose: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
/** 刷新表格 */
|
||||||
|
function onRefresh() {
|
||||||
|
gridApi.query();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 创建示例联系人 */
|
||||||
|
function handleCreate() {
|
||||||
|
formModalApi.setData({}).open();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 编辑示例联系人 */
|
||||||
|
function handleEdit(row: Demo01ContactApi.Demo01Contact) {
|
||||||
|
formModalApi.setData(row).open();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 删除示例联系人 */
|
||||||
|
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 as number);
|
||||||
|
ElMessage.success($t('ui.actionMessage.deleteSuccess', [row.id]));
|
||||||
|
onRefresh();
|
||||||
|
} finally {
|
||||||
|
loadingInstance.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 批量删除示例联系人 */
|
||||||
|
async function handleDeleteBatch() {
|
||||||
|
const loadingInstance = ElLoading.service({
|
||||||
|
text: $t('ui.actionMessage.deleting'),
|
||||||
|
background: 'rgba(0, 0, 0, 0.7)',
|
||||||
|
});
|
||||||
|
try {
|
||||||
|
await deleteDemo01ContactList(checkedIds.value);
|
||||||
|
ElMessage.success($t('ui.actionMessage.deleteSuccess'));
|
||||||
|
onRefresh();
|
||||||
|
} finally {
|
||||||
|
loadingInstance.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const checkedIds = ref<number[]>([]);
|
||||||
|
function handleRowCheckboxChange({
|
||||||
|
records,
|
||||||
|
}: {
|
||||||
|
records: Demo01ContactApi.Demo01Contact[];
|
||||||
|
}) {
|
||||||
|
checkedIds.value = records.map((item) => item.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 导出表格 */
|
||||||
|
async function handleExport() {
|
||||||
|
const data = await exportDemo01Contact(await gridApi.formApi.getValues());
|
||||||
|
downloadFileFromBlobPart({ fileName: '示例联系人.xls', source: data });
|
||||||
|
}
|
||||||
|
|
||||||
|
const [Grid, gridApi] = useVbenVxeGrid({
|
||||||
|
formOptions: {
|
||||||
|
schema: useGridFormSchema(),
|
||||||
|
},
|
||||||
|
gridOptions: {
|
||||||
|
columns: useGridColumns(),
|
||||||
|
height: 'auto',
|
||||||
|
pagerConfig: {
|
||||||
|
enabled: true,
|
||||||
|
},
|
||||||
|
proxyConfig: {
|
||||||
|
ajax: {
|
||||||
|
query: async ({ page }, formValues) => {
|
||||||
|
return await getDemo01ContactPage({
|
||||||
|
pageNo: page.currentPage,
|
||||||
|
pageSize: page.pageSize,
|
||||||
|
...formValues,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
rowConfig: {
|
||||||
|
keyField: 'id',
|
||||||
|
isHover: true,
|
||||||
|
},
|
||||||
|
toolbarConfig: {
|
||||||
|
refresh: { code: 'query' },
|
||||||
|
search: true,
|
||||||
|
},
|
||||||
|
} as VxeTableGridOptions<Demo01ContactApi.Demo01Contact>,
|
||||||
|
gridEvents: {
|
||||||
|
checkboxAll: handleRowCheckboxChange,
|
||||||
|
checkboxChange: handleRowCheckboxChange,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<Page auto-content-height>
|
||||||
|
<FormModal @success="onRefresh" />
|
||||||
|
|
||||||
|
<Grid table-title="示例联系人列表">
|
||||||
|
<template #toolbar-tools>
|
||||||
|
<TableAction
|
||||||
|
:actions="[
|
||||||
|
{
|
||||||
|
label: $t('ui.actionTitle.create', ['示例联系人']),
|
||||||
|
type: 'primary',
|
||||||
|
icon: ACTION_ICON.ADD,
|
||||||
|
auth: ['infra:demo01-contact:create'],
|
||||||
|
onClick: handleCreate,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: $t('ui.actionTitle.export'),
|
||||||
|
type: 'primary',
|
||||||
|
icon: ACTION_ICON.DOWNLOAD,
|
||||||
|
auth: ['infra:demo01-contact:export'],
|
||||||
|
onClick: handleExport,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: $t('ui.actionTitle.deleteBatch'),
|
||||||
|
type: 'danger',
|
||||||
|
icon: ACTION_ICON.DELETE,
|
||||||
|
disabled: isEmpty(checkedIds),
|
||||||
|
auth: ['infra:demo01-contact:delete'],
|
||||||
|
onClick: handleDeleteBatch,
|
||||||
|
},
|
||||||
|
]"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
<template #actions="{ row }">
|
||||||
|
<TableAction
|
||||||
|
:actions="[
|
||||||
|
{
|
||||||
|
label: $t('common.edit'),
|
||||||
|
type: 'text',
|
||||||
|
icon: ACTION_ICON.EDIT,
|
||||||
|
auth: ['infra:demo01-contact:update'],
|
||||||
|
onClick: handleEdit.bind(null, row),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: $t('common.delete'),
|
||||||
|
type: 'danger',
|
||||||
|
text: true,
|
||||||
|
icon: ACTION_ICON.DELETE,
|
||||||
|
auth: ['infra:demo01-contact:delete'],
|
||||||
|
popConfirm: {
|
||||||
|
title: $t('ui.actionMessage.deleteConfirm', [row.id]),
|
||||||
|
confirm: handleDelete.bind(null, row),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
]"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
</Grid>
|
||||||
|
</Page>
|
||||||
|
</template>
|
||||||
|
|
@ -0,0 +1,91 @@
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import type { Demo01ContactApi } from '#/api/infra/demo/demo01';
|
||||||
|
|
||||||
|
import { computed, ref } from 'vue';
|
||||||
|
|
||||||
|
import { useVbenModal } from '@vben/common-ui';
|
||||||
|
|
||||||
|
import { ElMessage } from 'element-plus';
|
||||||
|
|
||||||
|
import { useVbenForm } from '#/adapter/form';
|
||||||
|
import {
|
||||||
|
createDemo01Contact,
|
||||||
|
getDemo01Contact,
|
||||||
|
updateDemo01Contact,
|
||||||
|
} from '#/api/infra/demo/demo01';
|
||||||
|
import { $t } from '#/locales';
|
||||||
|
|
||||||
|
import { useFormSchema } from '../data';
|
||||||
|
|
||||||
|
const emit = defineEmits(['success']);
|
||||||
|
const formData = ref<Demo01ContactApi.Demo01Contact>();
|
||||||
|
const getTitle = computed(() => {
|
||||||
|
return formData.value?.id
|
||||||
|
? $t('ui.actionTitle.edit', ['示例联系人'])
|
||||||
|
: $t('ui.actionTitle.create', ['示例联系人']);
|
||||||
|
});
|
||||||
|
|
||||||
|
const [Form, formApi] = useVbenForm({
|
||||||
|
commonConfig: {
|
||||||
|
componentProps: {
|
||||||
|
class: 'w-full',
|
||||||
|
},
|
||||||
|
formItemClass: 'col-span-2',
|
||||||
|
labelWidth: 80,
|
||||||
|
},
|
||||||
|
layout: 'horizontal',
|
||||||
|
schema: useFormSchema(),
|
||||||
|
showDefaultActions: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
const [Modal, modalApi] = useVbenModal({
|
||||||
|
async onConfirm() {
|
||||||
|
const { valid } = await formApi.validate();
|
||||||
|
if (!valid) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
modalApi.lock();
|
||||||
|
// 提交表单
|
||||||
|
const data = (await formApi.getValues()) as Demo01ContactApi.Demo01Contact;
|
||||||
|
try {
|
||||||
|
await (formData.value?.id
|
||||||
|
? updateDemo01Contact(data)
|
||||||
|
: createDemo01Contact(data));
|
||||||
|
// 关闭并提示
|
||||||
|
await modalApi.close();
|
||||||
|
emit('success');
|
||||||
|
ElMessage.success($t('ui.actionMessage.operationSuccess'));
|
||||||
|
} finally {
|
||||||
|
modalApi.unlock();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
async onOpenChange(isOpen: boolean) {
|
||||||
|
if (!isOpen) {
|
||||||
|
formData.value = undefined;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 加载数据
|
||||||
|
let data = modalApi.getData<Demo01ContactApi.Demo01Contact>();
|
||||||
|
if (!data) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (data.id) {
|
||||||
|
modalApi.lock();
|
||||||
|
try {
|
||||||
|
data = await getDemo01Contact(data.id);
|
||||||
|
} finally {
|
||||||
|
modalApi.unlock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 设置到 values
|
||||||
|
formData.value = data;
|
||||||
|
await formApi.setValues(formData.value);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<Modal :title="getTitle">
|
||||||
|
<Form class="mx-4" />
|
||||||
|
</Modal>
|
||||||
|
</template>
|
||||||
|
|
@ -0,0 +1,120 @@
|
||||||
|
import type { VbenFormSchema } from '#/adapter/form';
|
||||||
|
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||||
|
import type { Demo02CategoryApi } from '#/api/infra/demo/demo02';
|
||||||
|
|
||||||
|
import { handleTree } from '@vben/utils';
|
||||||
|
|
||||||
|
import { getDemo02CategoryList } from '#/api/infra/demo/demo02';
|
||||||
|
import { getRangePickerDefaultProps } from '#/utils';
|
||||||
|
|
||||||
|
/** 新增/修改的表单 */
|
||||||
|
export function useFormSchema(): VbenFormSchema[] {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
fieldName: 'id',
|
||||||
|
component: 'Input',
|
||||||
|
dependencies: {
|
||||||
|
triggerFields: [''],
|
||||||
|
show: () => false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
fieldName: 'parentId',
|
||||||
|
label: '上级示例分类',
|
||||||
|
component: 'ApiTreeSelect',
|
||||||
|
componentProps: {
|
||||||
|
allowClear: true,
|
||||||
|
api: async () => {
|
||||||
|
const data = await getDemo02CategoryList({});
|
||||||
|
data.unshift({
|
||||||
|
id: 0,
|
||||||
|
name: '顶级示例分类',
|
||||||
|
});
|
||||||
|
return handleTree(data);
|
||||||
|
},
|
||||||
|
labelField: 'name',
|
||||||
|
valueField: 'id',
|
||||||
|
childrenField: 'children',
|
||||||
|
placeholder: '请选择上级示例分类',
|
||||||
|
treeDefaultExpandAll: true,
|
||||||
|
},
|
||||||
|
rules: 'selectRequired',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
fieldName: 'name',
|
||||||
|
label: '名字',
|
||||||
|
rules: 'required',
|
||||||
|
component: 'Input',
|
||||||
|
componentProps: {
|
||||||
|
placeholder: '请输入名字',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 列表的搜索表单 */
|
||||||
|
export function useGridFormSchema(): VbenFormSchema[] {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
fieldName: 'name',
|
||||||
|
label: '名字',
|
||||||
|
component: 'Input',
|
||||||
|
componentProps: {
|
||||||
|
allowClear: true,
|
||||||
|
placeholder: '请输入名字',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
fieldName: 'parentId',
|
||||||
|
label: '父级编号',
|
||||||
|
component: 'Input',
|
||||||
|
componentProps: {
|
||||||
|
allowClear: true,
|
||||||
|
placeholder: '请输入父级编号',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
fieldName: 'createTime',
|
||||||
|
label: '创建时间',
|
||||||
|
component: 'RangePicker',
|
||||||
|
componentProps: {
|
||||||
|
...getRangePickerDefaultProps(),
|
||||||
|
allowClear: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 列表的字段 */
|
||||||
|
export function useGridColumns(): VxeTableGridOptions<Demo02CategoryApi.Demo02Category>['columns'] {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
field: 'id',
|
||||||
|
title: '编号',
|
||||||
|
minWidth: 120,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'name',
|
||||||
|
title: '名字',
|
||||||
|
minWidth: 120,
|
||||||
|
treeNode: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'parentId',
|
||||||
|
title: '父级编号',
|
||||||
|
minWidth: 120,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'createTime',
|
||||||
|
title: '创建时间',
|
||||||
|
minWidth: 120,
|
||||||
|
formatter: 'formatDateTime',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '操作',
|
||||||
|
width: 220,
|
||||||
|
fixed: 'right',
|
||||||
|
slots: { default: 'actions' },
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,176 @@
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||||
|
import type { Demo02CategoryApi } from '#/api/infra/demo/demo02';
|
||||||
|
|
||||||
|
import { ref } from 'vue';
|
||||||
|
|
||||||
|
import { Page, useVbenModal } from '@vben/common-ui';
|
||||||
|
import { downloadFileFromBlobPart } from '@vben/utils';
|
||||||
|
|
||||||
|
import { ElLoading, ElMessage } from 'element-plus';
|
||||||
|
|
||||||
|
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||||
|
import {
|
||||||
|
deleteDemo02Category,
|
||||||
|
exportDemo02Category,
|
||||||
|
getDemo02CategoryList,
|
||||||
|
} from '#/api/infra/demo/demo02';
|
||||||
|
import { $t } from '#/locales';
|
||||||
|
|
||||||
|
import { useGridColumns, useGridFormSchema } from './data';
|
||||||
|
import Form from './modules/form.vue';
|
||||||
|
|
||||||
|
const [FormModal, formModalApi] = useVbenModal({
|
||||||
|
connectedComponent: Form,
|
||||||
|
destroyOnClose: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
/** 切换树形展开/收缩状态 */
|
||||||
|
const isExpanded = ref(true);
|
||||||
|
function toggleExpand() {
|
||||||
|
isExpanded.value = !isExpanded.value;
|
||||||
|
gridApi.grid.setAllTreeExpand(isExpanded.value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 刷新表格 */
|
||||||
|
function onRefresh() {
|
||||||
|
gridApi.query();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 创建示例分类 */
|
||||||
|
function handleCreate() {
|
||||||
|
formModalApi.setData({}).open();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 编辑示例分类 */
|
||||||
|
function handleEdit(row: Demo02CategoryApi.Demo02Category) {
|
||||||
|
formModalApi.setData(row).open();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 新增下级示例分类 */
|
||||||
|
function handleAppend(row: Demo02CategoryApi.Demo02Category) {
|
||||||
|
formModalApi.setData({ parentId: row.id }).open();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 删除示例分类 */
|
||||||
|
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 as number);
|
||||||
|
ElMessage.success($t('ui.actionMessage.deleteSuccess', [row.id]));
|
||||||
|
onRefresh();
|
||||||
|
} finally {
|
||||||
|
loadingInstance.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 导出表格 */
|
||||||
|
async function handleExport() {
|
||||||
|
const data = await exportDemo02Category(await gridApi.formApi.getValues());
|
||||||
|
downloadFileFromBlobPart({ fileName: '示例分类.xls', source: data });
|
||||||
|
}
|
||||||
|
|
||||||
|
const [Grid, gridApi] = useVbenVxeGrid({
|
||||||
|
formOptions: {
|
||||||
|
schema: useGridFormSchema(),
|
||||||
|
},
|
||||||
|
gridOptions: {
|
||||||
|
columns: useGridColumns(),
|
||||||
|
height: 'auto',
|
||||||
|
treeConfig: {
|
||||||
|
parentField: 'parentId',
|
||||||
|
rowField: 'id',
|
||||||
|
transform: true,
|
||||||
|
expandAll: true,
|
||||||
|
reserve: true,
|
||||||
|
},
|
||||||
|
pagerConfig: {
|
||||||
|
enabled: false,
|
||||||
|
},
|
||||||
|
proxyConfig: {
|
||||||
|
ajax: {
|
||||||
|
query: async (_, formValues) => {
|
||||||
|
return await getDemo02CategoryList(formValues);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
rowConfig: {
|
||||||
|
keyField: 'id',
|
||||||
|
isHover: true,
|
||||||
|
},
|
||||||
|
toolbarConfig: {
|
||||||
|
refresh: { code: 'query' },
|
||||||
|
search: true,
|
||||||
|
},
|
||||||
|
} as VxeTableGridOptions<Demo02CategoryApi.Demo02Category>,
|
||||||
|
gridEvents: {},
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<Page auto-content-height>
|
||||||
|
<FormModal @success="onRefresh" />
|
||||||
|
|
||||||
|
<Grid table-title="示例分类列表">
|
||||||
|
<template #toolbar-tools>
|
||||||
|
<TableAction
|
||||||
|
:actions="[
|
||||||
|
{
|
||||||
|
label: isExpanded ? '收缩' : '展开',
|
||||||
|
type: 'primary',
|
||||||
|
onClick: toggleExpand,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: $t('ui.actionTitle.create', ['示例分类']),
|
||||||
|
type: 'primary',
|
||||||
|
icon: ACTION_ICON.ADD,
|
||||||
|
auth: ['infra:demo02-category:create'],
|
||||||
|
onClick: handleCreate,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: $t('ui.actionTitle.export'),
|
||||||
|
type: 'primary',
|
||||||
|
icon: ACTION_ICON.DOWNLOAD,
|
||||||
|
auth: ['infra:demo02-category:export'],
|
||||||
|
onClick: handleExport,
|
||||||
|
},
|
||||||
|
]"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
<template #actions="{ row }">
|
||||||
|
<TableAction
|
||||||
|
:actions="[
|
||||||
|
{
|
||||||
|
label: '新增下级',
|
||||||
|
type: 'text',
|
||||||
|
icon: ACTION_ICON.ADD,
|
||||||
|
auth: ['infra:demo02-category:create'],
|
||||||
|
onClick: handleAppend.bind(null, row),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: $t('common.edit'),
|
||||||
|
type: 'text',
|
||||||
|
icon: ACTION_ICON.EDIT,
|
||||||
|
auth: ['infra:demo02-category:update'],
|
||||||
|
onClick: handleEdit.bind(null, row),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: $t('common.delete'),
|
||||||
|
type: 'danger',
|
||||||
|
text: true,
|
||||||
|
icon: ACTION_ICON.DELETE,
|
||||||
|
auth: ['infra:demo02-category:delete'],
|
||||||
|
popConfirm: {
|
||||||
|
title: $t('ui.actionMessage.deleteConfirm', [row.id]),
|
||||||
|
confirm: handleDelete.bind(null, row),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
]"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
</Grid>
|
||||||
|
</Page>
|
||||||
|
</template>
|
||||||
|
|
@ -0,0 +1,92 @@
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import type { Demo02CategoryApi } from '#/api/infra/demo/demo02';
|
||||||
|
|
||||||
|
import { computed, ref } from 'vue';
|
||||||
|
|
||||||
|
import { useVbenModal } from '@vben/common-ui';
|
||||||
|
|
||||||
|
import { ElMessage } from 'element-plus';
|
||||||
|
|
||||||
|
import { useVbenForm } from '#/adapter/form';
|
||||||
|
import {
|
||||||
|
createDemo02Category,
|
||||||
|
getDemo02Category,
|
||||||
|
updateDemo02Category,
|
||||||
|
} from '#/api/infra/demo/demo02';
|
||||||
|
import { $t } from '#/locales';
|
||||||
|
|
||||||
|
import { useFormSchema } from '../data';
|
||||||
|
|
||||||
|
const emit = defineEmits(['success']);
|
||||||
|
const formData = ref<Demo02CategoryApi.Demo02Category>();
|
||||||
|
const getTitle = computed(() => {
|
||||||
|
return formData.value?.id
|
||||||
|
? $t('ui.actionTitle.edit', ['示例分类'])
|
||||||
|
: $t('ui.actionTitle.create', ['示例分类']);
|
||||||
|
});
|
||||||
|
|
||||||
|
const [Form, formApi] = useVbenForm({
|
||||||
|
commonConfig: {
|
||||||
|
componentProps: {
|
||||||
|
class: 'w-full',
|
||||||
|
},
|
||||||
|
formItemClass: 'col-span-2',
|
||||||
|
labelWidth: 80,
|
||||||
|
},
|
||||||
|
layout: 'horizontal',
|
||||||
|
schema: useFormSchema(),
|
||||||
|
showDefaultActions: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
const [Modal, modalApi] = useVbenModal({
|
||||||
|
async onConfirm() {
|
||||||
|
const { valid } = await formApi.validate();
|
||||||
|
if (!valid) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
modalApi.lock();
|
||||||
|
// 提交表单
|
||||||
|
const data =
|
||||||
|
(await formApi.getValues()) as Demo02CategoryApi.Demo02Category;
|
||||||
|
try {
|
||||||
|
await (formData.value?.id
|
||||||
|
? updateDemo02Category(data)
|
||||||
|
: createDemo02Category(data));
|
||||||
|
// 关闭并提示
|
||||||
|
await modalApi.close();
|
||||||
|
emit('success');
|
||||||
|
ElMessage.success($t('ui.actionMessage.operationSuccess'));
|
||||||
|
} finally {
|
||||||
|
modalApi.unlock();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
async onOpenChange(isOpen: boolean) {
|
||||||
|
if (!isOpen) {
|
||||||
|
formData.value = undefined;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 加载数据
|
||||||
|
let data = modalApi.getData<Demo02CategoryApi.Demo02Category>();
|
||||||
|
if (!data) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (data.id) {
|
||||||
|
modalApi.lock();
|
||||||
|
try {
|
||||||
|
data = await getDemo02Category(data.id);
|
||||||
|
} finally {
|
||||||
|
modalApi.unlock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 设置到 values
|
||||||
|
formData.value = data;
|
||||||
|
await formApi.setValues(formData.value);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<Modal :title="getTitle">
|
||||||
|
<Form class="mx-4" />
|
||||||
|
</Modal>
|
||||||
|
</template>
|
||||||
|
|
@ -0,0 +1,378 @@
|
||||||
|
import type { VbenFormSchema } from '#/adapter/form';
|
||||||
|
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||||
|
import type { Demo03StudentApi } from '#/api/infra/demo/demo03/erp';
|
||||||
|
|
||||||
|
import { DICT_TYPE, getDictOptions, getRangePickerDefaultProps } from '#/utils';
|
||||||
|
|
||||||
|
/** 新增/修改的表单 */
|
||||||
|
export function useFormSchema(): VbenFormSchema[] {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
fieldName: 'id',
|
||||||
|
component: 'Input',
|
||||||
|
dependencies: {
|
||||||
|
triggerFields: [''],
|
||||||
|
show: () => false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
fieldName: 'name',
|
||||||
|
label: '名字',
|
||||||
|
rules: 'required',
|
||||||
|
component: 'Input',
|
||||||
|
componentProps: {
|
||||||
|
placeholder: '请输入名字',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
fieldName: 'sex',
|
||||||
|
label: '性别',
|
||||||
|
rules: 'required',
|
||||||
|
component: 'RadioGroup',
|
||||||
|
componentProps: {
|
||||||
|
options: getDictOptions(DICT_TYPE.SYSTEM_USER_SEX, 'number'),
|
||||||
|
buttonStyle: 'solid',
|
||||||
|
optionType: 'button',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
fieldName: 'birthday',
|
||||||
|
label: '出生日期',
|
||||||
|
rules: 'required',
|
||||||
|
component: 'DatePicker',
|
||||||
|
componentProps: {
|
||||||
|
showTime: true,
|
||||||
|
format: 'YYYY-MM-DD HH:mm:ss',
|
||||||
|
valueFormat: 'x',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
fieldName: 'description',
|
||||||
|
label: '简介',
|
||||||
|
rules: 'required',
|
||||||
|
component: 'RichTextarea',
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 列表的搜索表单 */
|
||||||
|
export function useGridFormSchema(): VbenFormSchema[] {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
fieldName: 'name',
|
||||||
|
label: '名字',
|
||||||
|
component: 'Input',
|
||||||
|
componentProps: {
|
||||||
|
allowClear: true,
|
||||||
|
placeholder: '请输入名字',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
fieldName: 'sex',
|
||||||
|
label: '性别',
|
||||||
|
component: 'Select',
|
||||||
|
componentProps: {
|
||||||
|
allowClear: true,
|
||||||
|
options: getDictOptions(DICT_TYPE.SYSTEM_USER_SEX, 'number'),
|
||||||
|
placeholder: '请选择性别',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
fieldName: 'description',
|
||||||
|
label: '简介',
|
||||||
|
component: 'Input',
|
||||||
|
componentProps: {
|
||||||
|
allowClear: true,
|
||||||
|
placeholder: '请输入简介',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
fieldName: 'createTime',
|
||||||
|
label: '创建时间',
|
||||||
|
component: 'RangePicker',
|
||||||
|
componentProps: {
|
||||||
|
...getRangePickerDefaultProps(),
|
||||||
|
allowClear: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 列表的字段 */
|
||||||
|
export function useGridColumns(): VxeTableGridOptions<Demo03StudentApi.Demo03Student>['columns'] {
|
||||||
|
return [
|
||||||
|
{ type: 'checkbox', width: 40 },
|
||||||
|
{
|
||||||
|
field: 'id',
|
||||||
|
title: '编号',
|
||||||
|
minWidth: 120,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'name',
|
||||||
|
title: '名字',
|
||||||
|
minWidth: 120,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'sex',
|
||||||
|
title: '性别',
|
||||||
|
minWidth: 120,
|
||||||
|
cellRender: {
|
||||||
|
name: 'CellDict',
|
||||||
|
props: { type: DICT_TYPE.SYSTEM_USER_SEX },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'birthday',
|
||||||
|
title: '出生日期',
|
||||||
|
minWidth: 120,
|
||||||
|
formatter: 'formatDateTime',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'description',
|
||||||
|
title: '简介',
|
||||||
|
minWidth: 120,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'createTime',
|
||||||
|
title: '创建时间',
|
||||||
|
minWidth: 120,
|
||||||
|
formatter: 'formatDateTime',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '操作',
|
||||||
|
width: 200,
|
||||||
|
fixed: 'right',
|
||||||
|
slots: { default: 'actions' },
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
// ==================== 子表(学生课程) ====================
|
||||||
|
|
||||||
|
/** 新增/修改的表单 */
|
||||||
|
export function useDemo03CourseFormSchema(): VbenFormSchema[] {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
fieldName: 'id',
|
||||||
|
component: 'Input',
|
||||||
|
dependencies: {
|
||||||
|
triggerFields: [''],
|
||||||
|
show: () => false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
fieldName: 'name',
|
||||||
|
label: '名字',
|
||||||
|
rules: 'required',
|
||||||
|
component: 'Input',
|
||||||
|
componentProps: {
|
||||||
|
placeholder: '请输入名字',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
fieldName: 'score',
|
||||||
|
label: '分数',
|
||||||
|
rules: 'required',
|
||||||
|
component: 'Input',
|
||||||
|
componentProps: {
|
||||||
|
placeholder: '请输入分数',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 列表的搜索表单 */
|
||||||
|
export function useDemo03CourseGridFormSchema(): VbenFormSchema[] {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
fieldName: 'studentId',
|
||||||
|
label: '学生编号',
|
||||||
|
component: 'Input',
|
||||||
|
componentProps: {
|
||||||
|
allowClear: true,
|
||||||
|
placeholder: '请输入学生编号',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
fieldName: 'name',
|
||||||
|
label: '名字',
|
||||||
|
component: 'Input',
|
||||||
|
componentProps: {
|
||||||
|
allowClear: true,
|
||||||
|
placeholder: '请输入名字',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
fieldName: 'score',
|
||||||
|
label: '分数',
|
||||||
|
component: 'Input',
|
||||||
|
componentProps: {
|
||||||
|
allowClear: true,
|
||||||
|
placeholder: '请输入分数',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
fieldName: 'createTime',
|
||||||
|
label: '创建时间',
|
||||||
|
component: 'RangePicker',
|
||||||
|
componentProps: {
|
||||||
|
...getRangePickerDefaultProps(),
|
||||||
|
allowClear: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 列表的字段 */
|
||||||
|
export function useDemo03CourseGridColumns(): VxeTableGridOptions<Demo03StudentApi.Demo03Course>['columns'] {
|
||||||
|
return [
|
||||||
|
{ type: 'checkbox', width: 40 },
|
||||||
|
{
|
||||||
|
field: 'id',
|
||||||
|
title: '编号',
|
||||||
|
minWidth: 120,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'studentId',
|
||||||
|
title: '学生编号',
|
||||||
|
minWidth: 120,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'name',
|
||||||
|
title: '名字',
|
||||||
|
minWidth: 120,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'score',
|
||||||
|
title: '分数',
|
||||||
|
minWidth: 120,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'createTime',
|
||||||
|
title: '创建时间',
|
||||||
|
minWidth: 120,
|
||||||
|
formatter: 'formatDateTime',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '操作',
|
||||||
|
width: 200,
|
||||||
|
fixed: 'right',
|
||||||
|
slots: { default: 'actions' },
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
// ==================== 子表(学生班级) ====================
|
||||||
|
|
||||||
|
/** 新增/修改的表单 */
|
||||||
|
export function useDemo03GradeFormSchema(): VbenFormSchema[] {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
fieldName: 'id',
|
||||||
|
component: 'Input',
|
||||||
|
dependencies: {
|
||||||
|
triggerFields: [''],
|
||||||
|
show: () => false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
fieldName: 'name',
|
||||||
|
label: '名字',
|
||||||
|
rules: 'required',
|
||||||
|
component: 'Input',
|
||||||
|
componentProps: {
|
||||||
|
placeholder: '请输入名字',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
fieldName: 'teacher',
|
||||||
|
label: '班主任',
|
||||||
|
rules: 'required',
|
||||||
|
component: 'Input',
|
||||||
|
componentProps: {
|
||||||
|
placeholder: '请输入班主任',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 列表的搜索表单 */
|
||||||
|
export function useDemo03GradeGridFormSchema(): VbenFormSchema[] {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
fieldName: 'studentId',
|
||||||
|
label: '学生编号',
|
||||||
|
component: 'Input',
|
||||||
|
componentProps: {
|
||||||
|
allowClear: true,
|
||||||
|
placeholder: '请输入学生编号',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
fieldName: 'name',
|
||||||
|
label: '名字',
|
||||||
|
component: 'Input',
|
||||||
|
componentProps: {
|
||||||
|
allowClear: true,
|
||||||
|
placeholder: '请输入名字',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
fieldName: 'teacher',
|
||||||
|
label: '班主任',
|
||||||
|
component: 'Input',
|
||||||
|
componentProps: {
|
||||||
|
allowClear: true,
|
||||||
|
placeholder: '请输入班主任',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
fieldName: 'createTime',
|
||||||
|
label: '创建时间',
|
||||||
|
component: 'RangePicker',
|
||||||
|
componentProps: {
|
||||||
|
...getRangePickerDefaultProps(),
|
||||||
|
allowClear: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 列表的字段 */
|
||||||
|
export function useDemo03GradeGridColumns(): VxeTableGridOptions<Demo03StudentApi.Demo03Grade>['columns'] {
|
||||||
|
return [
|
||||||
|
{ type: 'checkbox', width: 40 },
|
||||||
|
{
|
||||||
|
field: 'id',
|
||||||
|
title: '编号',
|
||||||
|
minWidth: 120,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'studentId',
|
||||||
|
title: '学生编号',
|
||||||
|
minWidth: 120,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'name',
|
||||||
|
title: '名字',
|
||||||
|
minWidth: 120,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'teacher',
|
||||||
|
title: '班主任',
|
||||||
|
minWidth: 120,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'createTime',
|
||||||
|
title: '创建时间',
|
||||||
|
minWidth: 120,
|
||||||
|
formatter: 'formatDateTime',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '操作',
|
||||||
|
width: 200,
|
||||||
|
fixed: 'right',
|
||||||
|
slots: { default: 'actions' },
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,207 @@
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||||
|
import type { Demo03StudentApi } from '#/api/infra/demo/demo03/erp';
|
||||||
|
|
||||||
|
import { ref } from 'vue';
|
||||||
|
|
||||||
|
import { Page, useVbenModal } from '@vben/common-ui';
|
||||||
|
import { downloadFileFromBlobPart, isEmpty } from '@vben/utils';
|
||||||
|
|
||||||
|
import { ElLoading, ElMessage, ElTabPane, ElTabs } from 'element-plus';
|
||||||
|
|
||||||
|
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||||
|
import {
|
||||||
|
deleteDemo03Student,
|
||||||
|
deleteDemo03StudentList,
|
||||||
|
exportDemo03Student,
|
||||||
|
getDemo03StudentPage,
|
||||||
|
} from '#/api/infra/demo/demo03/erp';
|
||||||
|
import { $t } from '#/locales';
|
||||||
|
|
||||||
|
import { useGridColumns, useGridFormSchema } from './data';
|
||||||
|
import Demo03CourseList from './modules/demo03-course-list.vue';
|
||||||
|
import Demo03GradeList from './modules/demo03-grade-list.vue';
|
||||||
|
import Form from './modules/form.vue';
|
||||||
|
|
||||||
|
/** 子表的列表 */
|
||||||
|
const subTabsName = ref('demo03Course');
|
||||||
|
const selectDemo03Student = ref<Demo03StudentApi.Demo03Student>();
|
||||||
|
|
||||||
|
const [FormModal, formModalApi] = useVbenModal({
|
||||||
|
connectedComponent: Form,
|
||||||
|
destroyOnClose: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
/** 刷新表格 */
|
||||||
|
function onRefresh() {
|
||||||
|
gridApi.query();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 创建学生 */
|
||||||
|
function handleCreate() {
|
||||||
|
formModalApi.setData({}).open();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 编辑学生 */
|
||||||
|
function handleEdit(row: Demo03StudentApi.Demo03Student) {
|
||||||
|
formModalApi.setData(row).open();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 删除学生 */
|
||||||
|
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 as number);
|
||||||
|
ElMessage.success($t('ui.actionMessage.deleteSuccess', [row.id]));
|
||||||
|
onRefresh();
|
||||||
|
} finally {
|
||||||
|
loadingInstance.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 批量删除学生 */
|
||||||
|
async function handleDeleteBatch() {
|
||||||
|
const loadingInstance = ElLoading.service({
|
||||||
|
text: $t('ui.actionMessage.deleting'),
|
||||||
|
background: 'rgba(0, 0, 0, 0.7)',
|
||||||
|
});
|
||||||
|
try {
|
||||||
|
await deleteDemo03StudentList(checkedIds.value);
|
||||||
|
ElMessage.success($t('ui.actionMessage.deleteSuccess'));
|
||||||
|
onRefresh();
|
||||||
|
} finally {
|
||||||
|
loadingInstance.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const checkedIds = ref<number[]>([]);
|
||||||
|
function handleRowCheckboxChange({
|
||||||
|
records,
|
||||||
|
}: {
|
||||||
|
records: Demo03StudentApi.Demo03Student[];
|
||||||
|
}) {
|
||||||
|
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(),
|
||||||
|
},
|
||||||
|
gridOptions: {
|
||||||
|
columns: useGridColumns(),
|
||||||
|
height: '600px',
|
||||||
|
pagerConfig: {
|
||||||
|
enabled: true,
|
||||||
|
},
|
||||||
|
proxyConfig: {
|
||||||
|
ajax: {
|
||||||
|
query: async ({ page }, formValues) => {
|
||||||
|
return await getDemo03StudentPage({
|
||||||
|
pageNo: page.currentPage,
|
||||||
|
pageSize: page.pageSize,
|
||||||
|
...formValues,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
rowConfig: {
|
||||||
|
keyField: 'id',
|
||||||
|
isHover: true,
|
||||||
|
isCurrent: true,
|
||||||
|
},
|
||||||
|
toolbarConfig: {
|
||||||
|
refresh: { code: 'query' },
|
||||||
|
search: true,
|
||||||
|
},
|
||||||
|
} as VxeTableGridOptions<Demo03StudentApi.Demo03Student>,
|
||||||
|
gridEvents: {
|
||||||
|
cellClick: ({ row }: { row: Demo03StudentApi.Demo03Student }) => {
|
||||||
|
selectDemo03Student.value = row;
|
||||||
|
},
|
||||||
|
checkboxAll: handleRowCheckboxChange,
|
||||||
|
checkboxChange: handleRowCheckboxChange,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<Page auto-content-height>
|
||||||
|
<FormModal @success="onRefresh" />
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<Grid table-title="学生列表">
|
||||||
|
<template #toolbar-tools>
|
||||||
|
<TableAction
|
||||||
|
:actions="[
|
||||||
|
{
|
||||||
|
label: $t('ui.actionTitle.create', ['学生']),
|
||||||
|
type: 'primary',
|
||||||
|
icon: ACTION_ICON.ADD,
|
||||||
|
auth: ['infra:demo03-student:create'],
|
||||||
|
onClick: handleCreate,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: $t('ui.actionTitle.export'),
|
||||||
|
type: 'primary',
|
||||||
|
icon: ACTION_ICON.DOWNLOAD,
|
||||||
|
auth: ['infra:demo03-student:export'],
|
||||||
|
onClick: handleExport,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: $t('ui.actionTitle.deleteBatch'),
|
||||||
|
type: 'danger',
|
||||||
|
icon: ACTION_ICON.DELETE,
|
||||||
|
disabled: isEmpty(checkedIds),
|
||||||
|
auth: ['infra:demo03-student:delete'],
|
||||||
|
onClick: handleDeleteBatch,
|
||||||
|
},
|
||||||
|
]"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
<template #actions="{ row }">
|
||||||
|
<TableAction
|
||||||
|
:actions="[
|
||||||
|
{
|
||||||
|
label: $t('common.edit'),
|
||||||
|
type: 'text',
|
||||||
|
icon: ACTION_ICON.EDIT,
|
||||||
|
auth: ['infra:demo03-student:update'],
|
||||||
|
onClick: handleEdit.bind(null, row),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: $t('common.delete'),
|
||||||
|
type: 'danger',
|
||||||
|
text: true,
|
||||||
|
icon: ACTION_ICON.DELETE,
|
||||||
|
auth: ['infra:demo03-student:delete'],
|
||||||
|
popConfirm: {
|
||||||
|
title: $t('ui.actionMessage.deleteConfirm', [row.id]),
|
||||||
|
confirm: handleDelete.bind(null, row),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
]"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
</Grid>
|
||||||
|
|
||||||
|
<!-- 子表的表单 -->
|
||||||
|
<ElTabs v-model="subTabsName" class="mt-2">
|
||||||
|
<ElTabPane name="demo03Course" label="学生课程">
|
||||||
|
<Demo03CourseList :student-id="selectDemo03Student?.id" />
|
||||||
|
</ElTabPane>
|
||||||
|
<ElTabPane name="demo03Grade" label="学生班级">
|
||||||
|
<Demo03GradeList :student-id="selectDemo03Student?.id" />
|
||||||
|
</ElTabPane>
|
||||||
|
</ElTabs>
|
||||||
|
</div>
|
||||||
|
</Page>
|
||||||
|
</template>
|
||||||
|
|
@ -0,0 +1,94 @@
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import type { Demo03StudentApi } from '#/api/infra/demo/demo03/erp';
|
||||||
|
|
||||||
|
import { computed, ref } from 'vue';
|
||||||
|
|
||||||
|
import { useVbenModal } from '@vben/common-ui';
|
||||||
|
|
||||||
|
import { ElMessage } from 'element-plus';
|
||||||
|
|
||||||
|
import { useVbenForm } from '#/adapter/form';
|
||||||
|
import {
|
||||||
|
createDemo03Course,
|
||||||
|
getDemo03Course,
|
||||||
|
updateDemo03Course,
|
||||||
|
} from '#/api/infra/demo/demo03/erp';
|
||||||
|
import { $t } from '#/locales';
|
||||||
|
|
||||||
|
import { useDemo03CourseFormSchema } from '../data';
|
||||||
|
|
||||||
|
const emit = defineEmits(['success']);
|
||||||
|
const formData = ref<Demo03StudentApi.Demo03Course>();
|
||||||
|
const getTitle = computed(() => {
|
||||||
|
return formData.value?.id
|
||||||
|
? $t('ui.actionTitle.edit', ['学生课程'])
|
||||||
|
: $t('ui.actionTitle.create', ['学生课程']);
|
||||||
|
});
|
||||||
|
|
||||||
|
const [Form, formApi] = useVbenForm({
|
||||||
|
commonConfig: {
|
||||||
|
componentProps: {
|
||||||
|
class: 'w-full',
|
||||||
|
},
|
||||||
|
formItemClass: 'col-span-2',
|
||||||
|
labelWidth: 80,
|
||||||
|
},
|
||||||
|
layout: 'horizontal',
|
||||||
|
schema: useDemo03CourseFormSchema(),
|
||||||
|
showDefaultActions: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
const [Modal, modalApi] = useVbenModal({
|
||||||
|
async onConfirm() {
|
||||||
|
const { valid } = await formApi.validate();
|
||||||
|
if (!valid) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
modalApi.lock();
|
||||||
|
// 提交表单
|
||||||
|
const data = (await formApi.getValues()) as Demo03StudentApi.Demo03Course;
|
||||||
|
data.studentId = formData.value?.studentId;
|
||||||
|
try {
|
||||||
|
await (formData.value?.id
|
||||||
|
? updateDemo03Course(data)
|
||||||
|
: createDemo03Course(data));
|
||||||
|
// 关闭并提示
|
||||||
|
await modalApi.close();
|
||||||
|
emit('success');
|
||||||
|
ElMessage.success($t('ui.actionMessage.operationSuccess'));
|
||||||
|
} finally {
|
||||||
|
modalApi.unlock();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
async onOpenChange(isOpen: boolean) {
|
||||||
|
if (!isOpen) {
|
||||||
|
formData.value = undefined;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 加载数据
|
||||||
|
let data = modalApi.getData<Demo03StudentApi.Demo03Course>();
|
||||||
|
if (!data) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (data.id) {
|
||||||
|
modalApi.lock();
|
||||||
|
try {
|
||||||
|
data = await getDemo03Course(data.id);
|
||||||
|
} finally {
|
||||||
|
modalApi.unlock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 设置到 values
|
||||||
|
formData.value = data;
|
||||||
|
await formApi.setValues(formData.value);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<Modal :title="getTitle">
|
||||||
|
<Form class="mx-4" />
|
||||||
|
</Modal>
|
||||||
|
</template>
|
||||||
|
|
@ -0,0 +1,196 @@
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||||
|
import type { Demo03StudentApi } from '#/api/infra/demo/demo03/erp';
|
||||||
|
|
||||||
|
import { nextTick, ref, watch } from 'vue';
|
||||||
|
|
||||||
|
import { useVbenModal } from '@vben/common-ui';
|
||||||
|
import { isEmpty } from '@vben/utils';
|
||||||
|
|
||||||
|
import { ElLoading, ElMessage } from 'element-plus';
|
||||||
|
|
||||||
|
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||||
|
import {
|
||||||
|
deleteDemo03Course,
|
||||||
|
deleteDemo03CourseList,
|
||||||
|
getDemo03CoursePage,
|
||||||
|
} from '#/api/infra/demo/demo03/erp';
|
||||||
|
import { $t } from '#/locales';
|
||||||
|
|
||||||
|
import {
|
||||||
|
useDemo03CourseGridColumns,
|
||||||
|
useDemo03CourseGridFormSchema,
|
||||||
|
} from '../data';
|
||||||
|
import Demo03CourseForm from './demo03-course-form.vue';
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
studentId?: number; // 学生编号(主表的关联字段)
|
||||||
|
}>();
|
||||||
|
|
||||||
|
const [FormModal, formModalApi] = useVbenModal({
|
||||||
|
connectedComponent: Demo03CourseForm,
|
||||||
|
destroyOnClose: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
/** 创建学生课程 */
|
||||||
|
function handleCreate() {
|
||||||
|
if (!props.studentId) {
|
||||||
|
ElMessage.warning('请先选择一个学生!');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
formModalApi.setData({ studentId: props.studentId }).open();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 编辑学生课程 */
|
||||||
|
function handleEdit(row: Demo03StudentApi.Demo03Course) {
|
||||||
|
formModalApi.setData(row).open();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 删除学生课程 */
|
||||||
|
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 as number);
|
||||||
|
ElMessage.success($t('ui.actionMessage.deleteSuccess', [row.id]));
|
||||||
|
onRefresh();
|
||||||
|
} finally {
|
||||||
|
loadingInstance.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 批量删除学生课程 */
|
||||||
|
async function handleDeleteBatch() {
|
||||||
|
const loadingInstance = ElLoading.service({
|
||||||
|
text: $t('ui.actionMessage.deleting'),
|
||||||
|
background: 'rgba(0, 0, 0, 0.7)',
|
||||||
|
});
|
||||||
|
try {
|
||||||
|
await deleteDemo03CourseList(checkedIds.value);
|
||||||
|
ElMessage.success($t('ui.actionMessage.deleteSuccess'));
|
||||||
|
onRefresh();
|
||||||
|
} finally {
|
||||||
|
loadingInstance.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const checkedIds = ref<number[]>([]);
|
||||||
|
function handleRowCheckboxChange({
|
||||||
|
records,
|
||||||
|
}: {
|
||||||
|
records: Demo03StudentApi.Demo03Course[];
|
||||||
|
}) {
|
||||||
|
checkedIds.value = records.map((item) => item.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
const [Grid, gridApi] = useVbenVxeGrid({
|
||||||
|
formOptions: {
|
||||||
|
schema: useDemo03CourseGridFormSchema(),
|
||||||
|
},
|
||||||
|
gridOptions: {
|
||||||
|
columns: useDemo03CourseGridColumns(),
|
||||||
|
proxyConfig: {
|
||||||
|
ajax: {
|
||||||
|
query: async ({ page }, formValues) => {
|
||||||
|
if (!props.studentId) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
return await getDemo03CoursePage({
|
||||||
|
pageNo: page.currentPage,
|
||||||
|
pageSize: page.pageSize,
|
||||||
|
studentId: props.studentId,
|
||||||
|
...formValues,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
pagerConfig: {
|
||||||
|
enabled: true,
|
||||||
|
},
|
||||||
|
toolbarConfig: {
|
||||||
|
refresh: { code: 'query' },
|
||||||
|
search: true,
|
||||||
|
},
|
||||||
|
height: '600px',
|
||||||
|
rowConfig: {
|
||||||
|
keyField: 'id',
|
||||||
|
isHover: true,
|
||||||
|
},
|
||||||
|
} as VxeTableGridOptions<Demo03StudentApi.Demo03Course>,
|
||||||
|
gridEvents: {
|
||||||
|
checkboxAll: handleRowCheckboxChange,
|
||||||
|
checkboxChange: handleRowCheckboxChange,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
/** 刷新表格 */
|
||||||
|
async function onRefresh() {
|
||||||
|
await gridApi.query();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 监听主表的关联字段的变化,加载对应的子表数据 */
|
||||||
|
watch(
|
||||||
|
() => props.studentId,
|
||||||
|
async (val) => {
|
||||||
|
if (!val) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await nextTick();
|
||||||
|
await onRefresh();
|
||||||
|
},
|
||||||
|
{ immediate: true },
|
||||||
|
);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<FormModal @success="onRefresh" />
|
||||||
|
<Grid table-title="学生课程列表">
|
||||||
|
<template #toolbar-tools>
|
||||||
|
<TableAction
|
||||||
|
:actions="[
|
||||||
|
{
|
||||||
|
label: $t('ui.actionTitle.create', ['学生']),
|
||||||
|
type: 'primary',
|
||||||
|
icon: ACTION_ICON.ADD,
|
||||||
|
auth: ['infra:demo03-student:create'],
|
||||||
|
onClick: handleCreate,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: $t('ui.actionTitle.deleteBatch'),
|
||||||
|
type: 'danger',
|
||||||
|
icon: ACTION_ICON.DELETE,
|
||||||
|
disabled: isEmpty(checkedIds),
|
||||||
|
auth: ['infra:demo03-student:delete'],
|
||||||
|
onClick: handleDeleteBatch,
|
||||||
|
},
|
||||||
|
]"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
<template #actions="{ row }">
|
||||||
|
<TableAction
|
||||||
|
:actions="[
|
||||||
|
{
|
||||||
|
label: $t('common.edit'),
|
||||||
|
type: 'text',
|
||||||
|
icon: ACTION_ICON.EDIT,
|
||||||
|
auth: ['infra:demo03-student:update'],
|
||||||
|
onClick: handleEdit.bind(null, row),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: $t('common.delete'),
|
||||||
|
type: 'danger',
|
||||||
|
text: true,
|
||||||
|
icon: ACTION_ICON.DELETE,
|
||||||
|
auth: ['infra:demo03-student:delete'],
|
||||||
|
popConfirm: {
|
||||||
|
title: $t('ui.actionMessage.deleteConfirm', [row.id]),
|
||||||
|
confirm: handleDelete.bind(null, row),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
]"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
</Grid>
|
||||||
|
</template>
|
||||||
|
|
@ -0,0 +1,94 @@
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import type { Demo03StudentApi } from '#/api/infra/demo/demo03/erp';
|
||||||
|
|
||||||
|
import { computed, ref } from 'vue';
|
||||||
|
|
||||||
|
import { useVbenModal } from '@vben/common-ui';
|
||||||
|
|
||||||
|
import { ElMessage } from 'element-plus';
|
||||||
|
|
||||||
|
import { useVbenForm } from '#/adapter/form';
|
||||||
|
import {
|
||||||
|
createDemo03Grade,
|
||||||
|
getDemo03Grade,
|
||||||
|
updateDemo03Grade,
|
||||||
|
} from '#/api/infra/demo/demo03/erp';
|
||||||
|
import { $t } from '#/locales';
|
||||||
|
|
||||||
|
import { useDemo03GradeFormSchema } from '../data';
|
||||||
|
|
||||||
|
const emit = defineEmits(['success']);
|
||||||
|
const formData = ref<Demo03StudentApi.Demo03Grade>();
|
||||||
|
const getTitle = computed(() => {
|
||||||
|
return formData.value?.id
|
||||||
|
? $t('ui.actionTitle.edit', ['学生班级'])
|
||||||
|
: $t('ui.actionTitle.create', ['学生班级']);
|
||||||
|
});
|
||||||
|
|
||||||
|
const [Form, formApi] = useVbenForm({
|
||||||
|
commonConfig: {
|
||||||
|
componentProps: {
|
||||||
|
class: 'w-full',
|
||||||
|
},
|
||||||
|
formItemClass: 'col-span-2',
|
||||||
|
labelWidth: 80,
|
||||||
|
},
|
||||||
|
layout: 'horizontal',
|
||||||
|
schema: useDemo03GradeFormSchema(),
|
||||||
|
showDefaultActions: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
const [Modal, modalApi] = useVbenModal({
|
||||||
|
async onConfirm() {
|
||||||
|
const { valid } = await formApi.validate();
|
||||||
|
if (!valid) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
modalApi.lock();
|
||||||
|
// 提交表单
|
||||||
|
const data = (await formApi.getValues()) as Demo03StudentApi.Demo03Grade;
|
||||||
|
data.studentId = formData.value?.studentId;
|
||||||
|
try {
|
||||||
|
await (formData.value?.id
|
||||||
|
? updateDemo03Grade(data)
|
||||||
|
: createDemo03Grade(data));
|
||||||
|
// 关闭并提示
|
||||||
|
await modalApi.close();
|
||||||
|
emit('success');
|
||||||
|
ElMessage.success($t('ui.actionMessage.operationSuccess'));
|
||||||
|
} finally {
|
||||||
|
modalApi.unlock();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
async onOpenChange(isOpen: boolean) {
|
||||||
|
if (!isOpen) {
|
||||||
|
formData.value = undefined;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 加载数据
|
||||||
|
let data = modalApi.getData<Demo03StudentApi.Demo03Grade>();
|
||||||
|
if (!data) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (data.id) {
|
||||||
|
modalApi.lock();
|
||||||
|
try {
|
||||||
|
data = await getDemo03Grade(data.id);
|
||||||
|
} finally {
|
||||||
|
modalApi.unlock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 设置到 values
|
||||||
|
formData.value = data;
|
||||||
|
await formApi.setValues(formData.value);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<Modal :title="getTitle">
|
||||||
|
<Form class="mx-4" />
|
||||||
|
</Modal>
|
||||||
|
</template>
|
||||||
|
|
@ -0,0 +1,196 @@
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||||
|
import type { Demo03StudentApi } from '#/api/infra/demo/demo03/erp';
|
||||||
|
|
||||||
|
import { nextTick, ref, watch } from 'vue';
|
||||||
|
|
||||||
|
import { useVbenModal } from '@vben/common-ui';
|
||||||
|
import { isEmpty } from '@vben/utils';
|
||||||
|
|
||||||
|
import { ElLoading, ElMessage } from 'element-plus';
|
||||||
|
|
||||||
|
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||||
|
import {
|
||||||
|
deleteDemo03Grade,
|
||||||
|
deleteDemo03GradeList,
|
||||||
|
getDemo03GradePage,
|
||||||
|
} from '#/api/infra/demo/demo03/erp';
|
||||||
|
import { $t } from '#/locales';
|
||||||
|
|
||||||
|
import {
|
||||||
|
useDemo03GradeGridColumns,
|
||||||
|
useDemo03GradeGridFormSchema,
|
||||||
|
} from '../data';
|
||||||
|
import Demo03GradeForm from './demo03-grade-form.vue';
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
studentId?: number; // 学生编号(主表的关联字段)
|
||||||
|
}>();
|
||||||
|
|
||||||
|
const [FormModal, formModalApi] = useVbenModal({
|
||||||
|
connectedComponent: Demo03GradeForm,
|
||||||
|
destroyOnClose: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
/** 创建学生班级 */
|
||||||
|
function handleCreate() {
|
||||||
|
if (!props.studentId) {
|
||||||
|
ElMessage.warning('请先选择一个学生!');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
formModalApi.setData({ studentId: props.studentId }).open();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 编辑学生班级 */
|
||||||
|
function handleEdit(row: Demo03StudentApi.Demo03Grade) {
|
||||||
|
formModalApi.setData(row).open();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 删除学生班级 */
|
||||||
|
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 as number);
|
||||||
|
ElMessage.success($t('ui.actionMessage.deleteSuccess', [row.id]));
|
||||||
|
onRefresh();
|
||||||
|
} finally {
|
||||||
|
loadingInstance.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 批量删除学生班级 */
|
||||||
|
async function handleDeleteBatch() {
|
||||||
|
const loadingInstance = ElLoading.service({
|
||||||
|
text: $t('ui.actionMessage.deleting'),
|
||||||
|
background: 'rgba(0, 0, 0, 0.7)',
|
||||||
|
});
|
||||||
|
try {
|
||||||
|
await deleteDemo03GradeList(checkedIds.value);
|
||||||
|
ElMessage.success($t('ui.actionMessage.deleteSuccess'));
|
||||||
|
onRefresh();
|
||||||
|
} finally {
|
||||||
|
loadingInstance.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const checkedIds = ref<number[]>([]);
|
||||||
|
function handleRowCheckboxChange({
|
||||||
|
records,
|
||||||
|
}: {
|
||||||
|
records: Demo03StudentApi.Demo03Grade[];
|
||||||
|
}) {
|
||||||
|
checkedIds.value = records.map((item) => item.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
const [Grid, gridApi] = useVbenVxeGrid({
|
||||||
|
formOptions: {
|
||||||
|
schema: useDemo03GradeGridFormSchema(),
|
||||||
|
},
|
||||||
|
gridOptions: {
|
||||||
|
columns: useDemo03GradeGridColumns(),
|
||||||
|
proxyConfig: {
|
||||||
|
ajax: {
|
||||||
|
query: async ({ page }, formValues) => {
|
||||||
|
if (!props.studentId) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
return await getDemo03GradePage({
|
||||||
|
pageNo: page.currentPage,
|
||||||
|
pageSize: page.pageSize,
|
||||||
|
studentId: props.studentId,
|
||||||
|
...formValues,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
pagerConfig: {
|
||||||
|
enabled: true,
|
||||||
|
},
|
||||||
|
toolbarConfig: {
|
||||||
|
refresh: { code: 'query' },
|
||||||
|
search: true,
|
||||||
|
},
|
||||||
|
height: '600px',
|
||||||
|
rowConfig: {
|
||||||
|
keyField: 'id',
|
||||||
|
isHover: true,
|
||||||
|
},
|
||||||
|
} as VxeTableGridOptions<Demo03StudentApi.Demo03Grade>,
|
||||||
|
gridEvents: {
|
||||||
|
checkboxAll: handleRowCheckboxChange,
|
||||||
|
checkboxChange: handleRowCheckboxChange,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
/** 刷新表格 */
|
||||||
|
async function onRefresh() {
|
||||||
|
await gridApi.query();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 监听主表的关联字段的变化,加载对应的子表数据 */
|
||||||
|
watch(
|
||||||
|
() => props.studentId,
|
||||||
|
async (val) => {
|
||||||
|
if (!val) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await nextTick();
|
||||||
|
await onRefresh();
|
||||||
|
},
|
||||||
|
{ immediate: true },
|
||||||
|
);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<FormModal @success="onRefresh" />
|
||||||
|
<Grid table-title="学生班级列表">
|
||||||
|
<template #toolbar-tools>
|
||||||
|
<TableAction
|
||||||
|
:actions="[
|
||||||
|
{
|
||||||
|
label: $t('ui.actionTitle.create', ['学生']),
|
||||||
|
type: 'primary',
|
||||||
|
icon: ACTION_ICON.ADD,
|
||||||
|
auth: ['infra:demo03-student:create'],
|
||||||
|
onClick: handleCreate,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: $t('ui.actionTitle.deleteBatch'),
|
||||||
|
type: 'danger',
|
||||||
|
icon: ACTION_ICON.DELETE,
|
||||||
|
disabled: isEmpty(checkedIds),
|
||||||
|
auth: ['infra:demo03-student:delete'],
|
||||||
|
onClick: handleDeleteBatch,
|
||||||
|
},
|
||||||
|
]"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
<template #actions="{ row }">
|
||||||
|
<TableAction
|
||||||
|
:actions="[
|
||||||
|
{
|
||||||
|
label: $t('common.edit'),
|
||||||
|
type: 'text',
|
||||||
|
icon: ACTION_ICON.EDIT,
|
||||||
|
auth: ['infra:demo03-student:update'],
|
||||||
|
onClick: handleEdit.bind(null, row),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: $t('common.delete'),
|
||||||
|
type: 'danger',
|
||||||
|
text: true,
|
||||||
|
icon: ACTION_ICON.DELETE,
|
||||||
|
auth: ['infra:demo03-student:delete'],
|
||||||
|
popConfirm: {
|
||||||
|
title: $t('ui.actionMessage.deleteConfirm', [row.id]),
|
||||||
|
confirm: handleDelete.bind(null, row),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
]"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
</Grid>
|
||||||
|
</template>
|
||||||
|
|
@ -0,0 +1,91 @@
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import type { Demo03StudentApi } from '#/api/infra/demo/demo03/erp';
|
||||||
|
|
||||||
|
import { computed, ref } from 'vue';
|
||||||
|
|
||||||
|
import { useVbenModal } from '@vben/common-ui';
|
||||||
|
|
||||||
|
import { ElMessage } from 'element-plus';
|
||||||
|
|
||||||
|
import { useVbenForm } from '#/adapter/form';
|
||||||
|
import {
|
||||||
|
createDemo03Student,
|
||||||
|
getDemo03Student,
|
||||||
|
updateDemo03Student,
|
||||||
|
} from '#/api/infra/demo/demo03/erp';
|
||||||
|
import { $t } from '#/locales';
|
||||||
|
|
||||||
|
import { useFormSchema } from '../data';
|
||||||
|
|
||||||
|
const emit = defineEmits(['success']);
|
||||||
|
const formData = ref<Demo03StudentApi.Demo03Student>();
|
||||||
|
const getTitle = computed(() => {
|
||||||
|
return formData.value?.id
|
||||||
|
? $t('ui.actionTitle.edit', ['学生'])
|
||||||
|
: $t('ui.actionTitle.create', ['学生']);
|
||||||
|
});
|
||||||
|
|
||||||
|
const [Form, formApi] = useVbenForm({
|
||||||
|
commonConfig: {
|
||||||
|
componentProps: {
|
||||||
|
class: 'w-full',
|
||||||
|
},
|
||||||
|
formItemClass: 'col-span-2',
|
||||||
|
labelWidth: 80,
|
||||||
|
},
|
||||||
|
layout: 'horizontal',
|
||||||
|
schema: useFormSchema(),
|
||||||
|
showDefaultActions: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
const [Modal, modalApi] = useVbenModal({
|
||||||
|
async onConfirm() {
|
||||||
|
const { valid } = await formApi.validate();
|
||||||
|
if (!valid) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
modalApi.lock();
|
||||||
|
// 提交表单
|
||||||
|
const data = (await formApi.getValues()) as Demo03StudentApi.Demo03Student;
|
||||||
|
try {
|
||||||
|
await (formData.value?.id
|
||||||
|
? updateDemo03Student(data)
|
||||||
|
: createDemo03Student(data));
|
||||||
|
// 关闭并提示
|
||||||
|
await modalApi.close();
|
||||||
|
emit('success');
|
||||||
|
ElMessage.success($t('ui.actionMessage.operationSuccess'));
|
||||||
|
} finally {
|
||||||
|
modalApi.unlock();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
async onOpenChange(isOpen: boolean) {
|
||||||
|
if (!isOpen) {
|
||||||
|
formData.value = undefined;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 加载数据
|
||||||
|
let data = modalApi.getData<Demo03StudentApi.Demo03Student>();
|
||||||
|
if (!data) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (data.id) {
|
||||||
|
modalApi.lock();
|
||||||
|
try {
|
||||||
|
data = await getDemo03Student(data.id);
|
||||||
|
} finally {
|
||||||
|
modalApi.unlock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 设置到 values
|
||||||
|
formData.value = data;
|
||||||
|
await formApi.setValues(formData.value);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<Modal :title="getTitle">
|
||||||
|
<Form class="mx-4" />
|
||||||
|
</Modal>
|
||||||
|
</template>
|
||||||
|
|
@ -0,0 +1,272 @@
|
||||||
|
import type { VbenFormSchema } from '#/adapter/form';
|
||||||
|
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||||
|
import type { Demo03StudentApi } from '#/api/infra/demo/demo03/inner';
|
||||||
|
|
||||||
|
import { DICT_TYPE, getDictOptions, getRangePickerDefaultProps } from '#/utils';
|
||||||
|
|
||||||
|
/** 新增/修改的表单 */
|
||||||
|
export function useFormSchema(): VbenFormSchema[] {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
fieldName: 'id',
|
||||||
|
component: 'Input',
|
||||||
|
dependencies: {
|
||||||
|
triggerFields: [''],
|
||||||
|
show: () => false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
fieldName: 'name',
|
||||||
|
label: '名字',
|
||||||
|
rules: 'required',
|
||||||
|
component: 'Input',
|
||||||
|
componentProps: {
|
||||||
|
placeholder: '请输入名字',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
fieldName: 'sex',
|
||||||
|
label: '性别',
|
||||||
|
rules: 'required',
|
||||||
|
component: 'RadioGroup',
|
||||||
|
componentProps: {
|
||||||
|
options: getDictOptions(DICT_TYPE.SYSTEM_USER_SEX, 'number'),
|
||||||
|
buttonStyle: 'solid',
|
||||||
|
optionType: 'button',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
fieldName: 'birthday',
|
||||||
|
label: '出生日期',
|
||||||
|
rules: 'required',
|
||||||
|
component: 'DatePicker',
|
||||||
|
componentProps: {
|
||||||
|
showTime: true,
|
||||||
|
format: 'YYYY-MM-DD HH:mm:ss',
|
||||||
|
valueFormat: 'x',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
fieldName: 'description',
|
||||||
|
label: '简介',
|
||||||
|
rules: 'required',
|
||||||
|
component: 'RichTextarea',
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 列表的搜索表单 */
|
||||||
|
export function useGridFormSchema(): VbenFormSchema[] {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
fieldName: 'name',
|
||||||
|
label: '名字',
|
||||||
|
component: 'Input',
|
||||||
|
componentProps: {
|
||||||
|
allowClear: true,
|
||||||
|
placeholder: '请输入名字',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
fieldName: 'sex',
|
||||||
|
label: '性别',
|
||||||
|
component: 'Select',
|
||||||
|
componentProps: {
|
||||||
|
allowClear: true,
|
||||||
|
options: getDictOptions(DICT_TYPE.SYSTEM_USER_SEX, 'number'),
|
||||||
|
placeholder: '请选择性别',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
fieldName: 'description',
|
||||||
|
label: '简介',
|
||||||
|
component: 'Input',
|
||||||
|
componentProps: {
|
||||||
|
allowClear: true,
|
||||||
|
placeholder: '请输入简介',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
fieldName: 'createTime',
|
||||||
|
label: '创建时间',
|
||||||
|
component: 'RangePicker',
|
||||||
|
componentProps: {
|
||||||
|
...getRangePickerDefaultProps(),
|
||||||
|
allowClear: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 列表的字段 */
|
||||||
|
export function useGridColumns(): VxeTableGridOptions<Demo03StudentApi.Demo03Student>['columns'] {
|
||||||
|
return [
|
||||||
|
{ type: 'checkbox', width: 40 },
|
||||||
|
{ type: 'expand', width: 80, slots: { content: 'expand_content' } },
|
||||||
|
{
|
||||||
|
field: 'id',
|
||||||
|
title: '编号',
|
||||||
|
minWidth: 120,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'name',
|
||||||
|
title: '名字',
|
||||||
|
minWidth: 120,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'sex',
|
||||||
|
title: '性别',
|
||||||
|
minWidth: 120,
|
||||||
|
cellRender: {
|
||||||
|
name: 'CellDict',
|
||||||
|
props: { type: DICT_TYPE.SYSTEM_USER_SEX },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'birthday',
|
||||||
|
title: '出生日期',
|
||||||
|
minWidth: 120,
|
||||||
|
formatter: 'formatDateTime',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'description',
|
||||||
|
title: '简介',
|
||||||
|
minWidth: 120,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'createTime',
|
||||||
|
title: '创建时间',
|
||||||
|
minWidth: 120,
|
||||||
|
formatter: 'formatDateTime',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '操作',
|
||||||
|
width: 200,
|
||||||
|
fixed: 'right',
|
||||||
|
slots: { default: 'actions' },
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
// ==================== 子表(学生课程) ====================
|
||||||
|
|
||||||
|
/** 新增/修改列表的字段 */
|
||||||
|
export function useDemo03CourseGridEditColumns(): VxeTableGridOptions<Demo03StudentApi.Demo03Course>['columns'] {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
field: 'name',
|
||||||
|
title: '名字',
|
||||||
|
minWidth: 120,
|
||||||
|
slots: { default: 'name' },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'score',
|
||||||
|
title: '分数',
|
||||||
|
minWidth: 120,
|
||||||
|
slots: { default: 'score' },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '操作',
|
||||||
|
width: 200,
|
||||||
|
fixed: 'right',
|
||||||
|
slots: { default: 'actions' },
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 列表的字段 */
|
||||||
|
export function useDemo03CourseGridColumns(): VxeTableGridOptions<Demo03StudentApi.Demo03Course>['columns'] {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
field: 'id',
|
||||||
|
title: '编号',
|
||||||
|
minWidth: 120,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'studentId',
|
||||||
|
title: '学生编号',
|
||||||
|
minWidth: 120,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'name',
|
||||||
|
title: '名字',
|
||||||
|
minWidth: 120,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'score',
|
||||||
|
title: '分数',
|
||||||
|
minWidth: 120,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'createTime',
|
||||||
|
title: '创建时间',
|
||||||
|
minWidth: 120,
|
||||||
|
formatter: 'formatDateTime',
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
// ==================== 子表(学生班级) ====================
|
||||||
|
|
||||||
|
/** 新增/修改的表单 */
|
||||||
|
export function useDemo03GradeFormSchema(): VbenFormSchema[] {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
fieldName: 'id',
|
||||||
|
component: 'Input',
|
||||||
|
dependencies: {
|
||||||
|
triggerFields: [''],
|
||||||
|
show: () => false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
fieldName: 'name',
|
||||||
|
label: '名字',
|
||||||
|
rules: 'required',
|
||||||
|
component: 'Input',
|
||||||
|
componentProps: {
|
||||||
|
placeholder: '请输入名字',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
fieldName: 'teacher',
|
||||||
|
label: '班主任',
|
||||||
|
rules: 'required',
|
||||||
|
component: 'Input',
|
||||||
|
componentProps: {
|
||||||
|
placeholder: '请输入班主任',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 列表的字段 */
|
||||||
|
export function useDemo03GradeGridColumns(): VxeTableGridOptions<Demo03StudentApi.Demo03Grade>['columns'] {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
field: 'id',
|
||||||
|
title: '编号',
|
||||||
|
minWidth: 120,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'studentId',
|
||||||
|
title: '学生编号',
|
||||||
|
minWidth: 120,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'name',
|
||||||
|
title: '名字',
|
||||||
|
minWidth: 120,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'teacher',
|
||||||
|
title: '班主任',
|
||||||
|
minWidth: 120,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'createTime',
|
||||||
|
title: '创建时间',
|
||||||
|
minWidth: 120,
|
||||||
|
formatter: 'formatDateTime',
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,201 @@
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||||
|
import type { Demo03StudentApi } from '#/api/infra/demo/demo03/inner';
|
||||||
|
|
||||||
|
import { ref } from 'vue';
|
||||||
|
|
||||||
|
import { Page, useVbenModal } from '@vben/common-ui';
|
||||||
|
import { downloadFileFromBlobPart, isEmpty } from '@vben/utils';
|
||||||
|
|
||||||
|
import { ElLoading, ElMessage, ElTabPane, ElTabs } from 'element-plus';
|
||||||
|
|
||||||
|
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||||
|
import {
|
||||||
|
deleteDemo03Student,
|
||||||
|
deleteDemo03StudentList,
|
||||||
|
exportDemo03Student,
|
||||||
|
getDemo03StudentPage,
|
||||||
|
} from '#/api/infra/demo/demo03/inner';
|
||||||
|
import { $t } from '#/locales';
|
||||||
|
|
||||||
|
import { useGridColumns, useGridFormSchema } from './data';
|
||||||
|
import Demo03CourseList from './modules/demo03-course-list.vue';
|
||||||
|
import Demo03GradeList from './modules/demo03-grade-list.vue';
|
||||||
|
import Form from './modules/form.vue';
|
||||||
|
|
||||||
|
/** 子表的列表 */
|
||||||
|
const subTabsName = ref('demo03Course');
|
||||||
|
|
||||||
|
const [FormModal, formModalApi] = useVbenModal({
|
||||||
|
connectedComponent: Form,
|
||||||
|
destroyOnClose: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
/** 刷新表格 */
|
||||||
|
function onRefresh() {
|
||||||
|
gridApi.reload();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 创建学生 */
|
||||||
|
function handleCreate() {
|
||||||
|
formModalApi.setData({}).open();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 编辑学生 */
|
||||||
|
function handleEdit(row: Demo03StudentApi.Demo03Student) {
|
||||||
|
formModalApi.setData(row).open();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 删除学生 */
|
||||||
|
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 as number);
|
||||||
|
ElMessage.success($t('ui.actionMessage.deleteSuccess', [row.id]));
|
||||||
|
onRefresh();
|
||||||
|
} finally {
|
||||||
|
loadingInstance.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 批量删除学生 */
|
||||||
|
async function handleDeleteBatch() {
|
||||||
|
const loadingInstance = ElLoading.service({
|
||||||
|
text: $t('ui.actionMessage.deleting'),
|
||||||
|
background: 'rgba(0, 0, 0, 0.7)',
|
||||||
|
});
|
||||||
|
try {
|
||||||
|
await deleteDemo03StudentList(checkedIds.value);
|
||||||
|
ElMessage.success($t('ui.actionMessage.deleteSuccess'));
|
||||||
|
onRefresh();
|
||||||
|
} finally {
|
||||||
|
loadingInstance.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const checkedIds = ref<number[]>([]);
|
||||||
|
function handleRowCheckboxChange({
|
||||||
|
records,
|
||||||
|
}: {
|
||||||
|
records: Demo03StudentApi.Demo03Student[];
|
||||||
|
}) {
|
||||||
|
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(),
|
||||||
|
},
|
||||||
|
gridOptions: {
|
||||||
|
columns: useGridColumns(),
|
||||||
|
height: 'auto',
|
||||||
|
pagerConfig: {
|
||||||
|
enabled: true,
|
||||||
|
},
|
||||||
|
proxyConfig: {
|
||||||
|
ajax: {
|
||||||
|
query: async ({ page }, formValues) => {
|
||||||
|
return await getDemo03StudentPage({
|
||||||
|
pageNo: page.currentPage,
|
||||||
|
pageSize: page.pageSize,
|
||||||
|
...formValues,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
rowConfig: {
|
||||||
|
keyField: 'id',
|
||||||
|
isHover: true,
|
||||||
|
},
|
||||||
|
toolbarConfig: {
|
||||||
|
refresh: { code: 'query' },
|
||||||
|
search: true,
|
||||||
|
},
|
||||||
|
} as VxeTableGridOptions<Demo03StudentApi.Demo03Student>,
|
||||||
|
gridEvents: {
|
||||||
|
checkboxAll: handleRowCheckboxChange,
|
||||||
|
checkboxChange: handleRowCheckboxChange,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<Page auto-content-height>
|
||||||
|
<FormModal @success="onRefresh" />
|
||||||
|
|
||||||
|
<Grid table-title="学生列表">
|
||||||
|
<template #expand_content="{ row }">
|
||||||
|
<!-- 子表的表单 -->
|
||||||
|
<ElTabs v-model="subTabsName" class="mx-8">
|
||||||
|
<ElTabPane name="demo03Course" label="学生课程">
|
||||||
|
<Demo03CourseList :student-id="row?.id" />
|
||||||
|
</ElTabPane>
|
||||||
|
<ElTabPane name="demo03Grade" label="学生班级">
|
||||||
|
<Demo03GradeList :student-id="row?.id" />
|
||||||
|
</ElTabPane>
|
||||||
|
</ElTabs>
|
||||||
|
</template>
|
||||||
|
<template #toolbar-tools>
|
||||||
|
<TableAction
|
||||||
|
:actions="[
|
||||||
|
{
|
||||||
|
label: $t('ui.actionTitle.create', ['学生']),
|
||||||
|
type: 'primary',
|
||||||
|
icon: ACTION_ICON.ADD,
|
||||||
|
auth: ['infra:demo03-student:create'],
|
||||||
|
onClick: handleCreate,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: $t('ui.actionTitle.export'),
|
||||||
|
type: 'primary',
|
||||||
|
icon: ACTION_ICON.DOWNLOAD,
|
||||||
|
auth: ['infra:demo03-student:export'],
|
||||||
|
onClick: handleExport,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: $t('ui.actionTitle.deleteBatch'),
|
||||||
|
type: 'danger',
|
||||||
|
icon: ACTION_ICON.DELETE,
|
||||||
|
disabled: isEmpty(checkedIds),
|
||||||
|
auth: ['infra:demo03-student:delete'],
|
||||||
|
onClick: handleDeleteBatch,
|
||||||
|
},
|
||||||
|
]"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
<template #actions="{ row }">
|
||||||
|
<TableAction
|
||||||
|
:actions="[
|
||||||
|
{
|
||||||
|
label: $t('common.edit'),
|
||||||
|
type: 'text',
|
||||||
|
icon: ACTION_ICON.EDIT,
|
||||||
|
auth: ['infra:demo03-student:update'],
|
||||||
|
onClick: handleEdit.bind(null, row),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: $t('common.delete'),
|
||||||
|
type: 'danger',
|
||||||
|
text: true,
|
||||||
|
icon: ACTION_ICON.DELETE,
|
||||||
|
auth: ['infra:demo03-student:delete'],
|
||||||
|
popConfirm: {
|
||||||
|
title: $t('ui.actionMessage.deleteConfirm', [row.id]),
|
||||||
|
confirm: handleDelete.bind(null, row),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
]"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
</Grid>
|
||||||
|
</Page>
|
||||||
|
</template>
|
||||||
|
|
@ -0,0 +1,116 @@
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import type { OnActionClickParams } from '#/adapter/vxe-table';
|
||||||
|
import type { Demo03StudentApi } from '#/api/infra/demo/demo03/inner';
|
||||||
|
|
||||||
|
import { nextTick, watch } from 'vue';
|
||||||
|
|
||||||
|
import { Plus } from '@vben/icons';
|
||||||
|
|
||||||
|
import { ElButton, ElInput } from 'element-plus';
|
||||||
|
|
||||||
|
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||||
|
import { getDemo03CourseListByStudentId } from '#/api/infra/demo/demo03/inner';
|
||||||
|
import { $t } from '#/locales';
|
||||||
|
|
||||||
|
import { useDemo03CourseGridEditColumns } from '../data';
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
studentId?: number; // 学生编号(主表的关联字段)
|
||||||
|
}>();
|
||||||
|
|
||||||
|
/** 表格操作按钮的回调函数 */
|
||||||
|
function onActionClick({
|
||||||
|
code,
|
||||||
|
row,
|
||||||
|
}: OnActionClickParams<Demo03StudentApi.Demo03Course>) {
|
||||||
|
switch (code) {
|
||||||
|
case 'delete': {
|
||||||
|
onDelete(row);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const [Grid, gridApi] = useVbenVxeGrid({
|
||||||
|
gridOptions: {
|
||||||
|
columns: useDemo03CourseGridEditColumns(onActionClick),
|
||||||
|
border: true,
|
||||||
|
showOverflow: true,
|
||||||
|
autoResize: true,
|
||||||
|
keepSource: true,
|
||||||
|
rowConfig: {
|
||||||
|
keyField: 'id',
|
||||||
|
},
|
||||||
|
pagerConfig: {
|
||||||
|
enabled: false,
|
||||||
|
},
|
||||||
|
toolbarConfig: {
|
||||||
|
enabled: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
/** 添加学生课程 */
|
||||||
|
const onAdd = async () => {
|
||||||
|
await gridApi.grid.insertAt({} as Demo03StudentApi.Demo03Course, -1);
|
||||||
|
};
|
||||||
|
|
||||||
|
/** 删除学生课程 */
|
||||||
|
const onDelete = async (row: Demo03StudentApi.Demo03Course) => {
|
||||||
|
await gridApi.grid.remove(row);
|
||||||
|
};
|
||||||
|
|
||||||
|
/** 提供获取表格数据的方法供父组件调用 */
|
||||||
|
defineExpose({
|
||||||
|
getData: (): 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),
|
||||||
|
),
|
||||||
|
...insertRecords.map((row: any) => ({ ...row, id: undefined })),
|
||||||
|
];
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
/** 监听主表的关联字段的变化,加载对应的子表数据 */
|
||||||
|
watch(
|
||||||
|
() => props.studentId,
|
||||||
|
async (val) => {
|
||||||
|
if (!val) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await nextTick();
|
||||||
|
await gridApi.grid.loadData(
|
||||||
|
await getDemo03CourseListByStudentId(props.studentId!),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
{ immediate: true },
|
||||||
|
);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<Grid class="mx-4">
|
||||||
|
<template #name="{ row }">
|
||||||
|
<ElInput v-model="row.name" />
|
||||||
|
</template>
|
||||||
|
<template #score="{ row }">
|
||||||
|
<ElInput v-model="row.score" />
|
||||||
|
</template>
|
||||||
|
</Grid>
|
||||||
|
<div class="-mt-4 flex justify-center">
|
||||||
|
<ElButton
|
||||||
|
:icon="Plus"
|
||||||
|
type="primary"
|
||||||
|
plain
|
||||||
|
@click="onAdd"
|
||||||
|
v-access:code="['infra:demo03-student:create']"
|
||||||
|
>
|
||||||
|
{{ $t('ui.actionTitle.create', ['学生课程']) }}
|
||||||
|
</ElButton>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
@ -0,0 +1,56 @@
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||||
|
import type { Demo03StudentApi } from '#/api/infra/demo/demo03/inner';
|
||||||
|
|
||||||
|
import { nextTick, watch } from 'vue';
|
||||||
|
|
||||||
|
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||||
|
import { getDemo03CourseListByStudentId } from '#/api/infra/demo/demo03/inner';
|
||||||
|
|
||||||
|
import { useDemo03CourseGridColumns } from '../data';
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
studentId?: number; // 学生编号(主表的关联字段)
|
||||||
|
}>();
|
||||||
|
|
||||||
|
const [Grid, gridApi] = useVbenVxeGrid({
|
||||||
|
gridOptions: {
|
||||||
|
columns: useDemo03CourseGridColumns(),
|
||||||
|
pagerConfig: {
|
||||||
|
nabled: false,
|
||||||
|
},
|
||||||
|
toolbarConfig: {
|
||||||
|
enabled: false,
|
||||||
|
},
|
||||||
|
height: '600px',
|
||||||
|
rowConfig: {
|
||||||
|
keyField: 'id',
|
||||||
|
isHover: true,
|
||||||
|
},
|
||||||
|
} as VxeTableGridOptions<Demo03StudentApi.Demo03Course>,
|
||||||
|
});
|
||||||
|
|
||||||
|
/** 刷新表格 */
|
||||||
|
async function onRefresh() {
|
||||||
|
await gridApi.grid.loadData(
|
||||||
|
await getDemo03CourseListByStudentId(props.studentId!),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 监听主表的关联字段的变化,加载对应的子表数据 */
|
||||||
|
watch(
|
||||||
|
() => props.studentId,
|
||||||
|
async (val) => {
|
||||||
|
if (!val) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await nextTick();
|
||||||
|
await onRefresh();
|
||||||
|
},
|
||||||
|
{ immediate: true },
|
||||||
|
);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<Grid table-title="学生课程列表" />
|
||||||
|
</template>
|
||||||
|
|
@ -0,0 +1,51 @@
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import { nextTick, watch } from 'vue';
|
||||||
|
|
||||||
|
import { useVbenForm } from '#/adapter/form';
|
||||||
|
import { getDemo03GradeByStudentId } from '#/api/infra/demo/demo03/inner';
|
||||||
|
|
||||||
|
import { useDemo03GradeFormSchema } from '../data';
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
studentId?: number; // 学生编号(主表的关联字段)
|
||||||
|
}>();
|
||||||
|
|
||||||
|
const [Form, formApi] = useVbenForm({
|
||||||
|
commonConfig: {
|
||||||
|
componentProps: {
|
||||||
|
class: 'w-full',
|
||||||
|
},
|
||||||
|
formItemClass: 'col-span-2',
|
||||||
|
labelWidth: 80,
|
||||||
|
},
|
||||||
|
layout: 'horizontal',
|
||||||
|
schema: useDemo03GradeFormSchema(),
|
||||||
|
showDefaultActions: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
/** 暴露出表单校验方法和表单值获取方法 */
|
||||||
|
defineExpose({
|
||||||
|
validate: async () => {
|
||||||
|
const { valid } = await formApi.validate();
|
||||||
|
return valid;
|
||||||
|
},
|
||||||
|
getValues: formApi.getValues,
|
||||||
|
});
|
||||||
|
|
||||||
|
/** 监听主表的关联字段的变化,加载对应的子表数据 */
|
||||||
|
watch(
|
||||||
|
() => props.studentId,
|
||||||
|
async (val) => {
|
||||||
|
if (!val) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await nextTick();
|
||||||
|
await formApi.setValues(await getDemo03GradeByStudentId(props.studentId!));
|
||||||
|
},
|
||||||
|
{ immediate: true },
|
||||||
|
);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<Form class="mx-4" />
|
||||||
|
</template>
|
||||||
|
|
@ -0,0 +1,56 @@
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||||
|
import type { Demo03StudentApi } from '#/api/infra/demo/demo03/inner';
|
||||||
|
|
||||||
|
import { nextTick, watch } from 'vue';
|
||||||
|
|
||||||
|
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||||
|
import { getDemo03GradeByStudentId } from '#/api/infra/demo/demo03/inner';
|
||||||
|
|
||||||
|
import { useDemo03GradeGridColumns } from '../data';
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
studentId?: number; // 学生编号(主表的关联字段)
|
||||||
|
}>();
|
||||||
|
|
||||||
|
const [Grid, gridApi] = useVbenVxeGrid({
|
||||||
|
gridOptions: {
|
||||||
|
columns: useDemo03GradeGridColumns(),
|
||||||
|
pagerConfig: {
|
||||||
|
nabled: false,
|
||||||
|
},
|
||||||
|
toolbarConfig: {
|
||||||
|
enabled: false,
|
||||||
|
},
|
||||||
|
height: '600px',
|
||||||
|
rowConfig: {
|
||||||
|
keyField: 'id',
|
||||||
|
isHover: true,
|
||||||
|
},
|
||||||
|
} as VxeTableGridOptions<Demo03StudentApi.Demo03Grade>,
|
||||||
|
});
|
||||||
|
|
||||||
|
/** 刷新表格 */
|
||||||
|
async function onRefresh() {
|
||||||
|
await gridApi.grid.loadData([
|
||||||
|
await getDemo03GradeByStudentId(props.studentId!),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 监听主表的关联字段的变化,加载对应的子表数据 */
|
||||||
|
watch(
|
||||||
|
() => props.studentId,
|
||||||
|
async (val) => {
|
||||||
|
if (!val) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await nextTick();
|
||||||
|
await onRefresh();
|
||||||
|
},
|
||||||
|
{ immediate: true },
|
||||||
|
);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<Grid table-title="学生班级列表" />
|
||||||
|
</template>
|
||||||
|
|
@ -0,0 +1,119 @@
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import type { Demo03StudentApi } from '#/api/infra/demo/demo03/inner';
|
||||||
|
|
||||||
|
import { computed, ref } from 'vue';
|
||||||
|
|
||||||
|
import { useVbenModal } from '@vben/common-ui';
|
||||||
|
|
||||||
|
import { ElMessage, ElTabPane, ElTabs } from 'element-plus';
|
||||||
|
|
||||||
|
import { useVbenForm } from '#/adapter/form';
|
||||||
|
import {
|
||||||
|
createDemo03Student,
|
||||||
|
getDemo03Student,
|
||||||
|
updateDemo03Student,
|
||||||
|
} from '#/api/infra/demo/demo03/inner';
|
||||||
|
import { $t } from '#/locales';
|
||||||
|
|
||||||
|
import { useFormSchema } from '../data';
|
||||||
|
import Demo03CourseForm from './demo03-course-form.vue';
|
||||||
|
import Demo03GradeForm from './demo03-grade-form.vue';
|
||||||
|
|
||||||
|
const emit = defineEmits(['success']);
|
||||||
|
const formData = ref<Demo03StudentApi.Demo03Student>();
|
||||||
|
const getTitle = computed(() => {
|
||||||
|
return formData.value?.id
|
||||||
|
? $t('ui.actionTitle.edit', ['学生'])
|
||||||
|
: $t('ui.actionTitle.create', ['学生']);
|
||||||
|
});
|
||||||
|
|
||||||
|
/** 子表的表单 */
|
||||||
|
const subTabsName = ref('demo03Course');
|
||||||
|
const demo03CourseFormRef = ref<InstanceType<typeof Demo03CourseForm>>();
|
||||||
|
const demo03GradeFormRef = ref<InstanceType<typeof Demo03GradeForm>>();
|
||||||
|
|
||||||
|
const [Form, formApi] = useVbenForm({
|
||||||
|
commonConfig: {
|
||||||
|
componentProps: {
|
||||||
|
class: 'w-full',
|
||||||
|
},
|
||||||
|
formItemClass: 'col-span-2',
|
||||||
|
labelWidth: 80,
|
||||||
|
},
|
||||||
|
layout: 'horizontal',
|
||||||
|
schema: useFormSchema(),
|
||||||
|
showDefaultActions: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
const [Modal, modalApi] = useVbenModal({
|
||||||
|
async onConfirm() {
|
||||||
|
const { valid } = await formApi.validate();
|
||||||
|
if (!valid) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 校验子表单
|
||||||
|
const demo03GradeValid = await demo03GradeFormRef.value?.validate();
|
||||||
|
if (!demo03GradeValid) {
|
||||||
|
subTabsName.value = 'demo03Grade';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
modalApi.lock();
|
||||||
|
// 提交表单
|
||||||
|
const data = (await formApi.getValues()) as Demo03StudentApi.Demo03Student;
|
||||||
|
// 拼接子表的数据
|
||||||
|
data.demo03Courses = demo03CourseFormRef.value?.getData();
|
||||||
|
data.demo03Grade = await demo03GradeFormRef.value?.getValues();
|
||||||
|
try {
|
||||||
|
await (formData.value?.id
|
||||||
|
? updateDemo03Student(data)
|
||||||
|
: createDemo03Student(data));
|
||||||
|
// 关闭并提示
|
||||||
|
await modalApi.close();
|
||||||
|
emit('success');
|
||||||
|
ElMessage.success($t('ui.actionMessage.operationSuccess'));
|
||||||
|
} finally {
|
||||||
|
modalApi.unlock();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
async onOpenChange(isOpen: boolean) {
|
||||||
|
if (!isOpen) {
|
||||||
|
formData.value = undefined;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 加载数据
|
||||||
|
let data = modalApi.getData<Demo03StudentApi.Demo03Student>();
|
||||||
|
if (!data) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (data.id) {
|
||||||
|
modalApi.lock();
|
||||||
|
try {
|
||||||
|
data = await getDemo03Student(data.id);
|
||||||
|
} finally {
|
||||||
|
modalApi.unlock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 设置到 values
|
||||||
|
formData.value = data;
|
||||||
|
await formApi.setValues(formData.value);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<Modal :title="getTitle">
|
||||||
|
<Form class="mx-4" />
|
||||||
|
<!-- 子表的表单 -->
|
||||||
|
<ElTabs v-model="subTabsName">
|
||||||
|
<ElTabPane name="demo03Course" label="学生课程">
|
||||||
|
<Demo03CourseForm
|
||||||
|
ref="demo03CourseFormRef"
|
||||||
|
:student-id="formData?.id"
|
||||||
|
/>
|
||||||
|
</ElTabPane>
|
||||||
|
<ElTabPane name="demo03Grade" label="学生班级">
|
||||||
|
<Demo03GradeForm ref="demo03GradeFormRef" :student-id="formData?.id" />
|
||||||
|
</ElTabPane>
|
||||||
|
</ElTabs>
|
||||||
|
</Modal>
|
||||||
|
</template>
|
||||||
|
|
@ -0,0 +1,208 @@
|
||||||
|
import type { VbenFormSchema } from '#/adapter/form';
|
||||||
|
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||||
|
import type { Demo03StudentApi } from '#/api/infra/demo/demo03/normal';
|
||||||
|
|
||||||
|
import { DICT_TYPE, getDictOptions, getRangePickerDefaultProps } from '#/utils';
|
||||||
|
|
||||||
|
/** 新增/修改的表单 */
|
||||||
|
export function useFormSchema(): VbenFormSchema[] {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
fieldName: 'id',
|
||||||
|
component: 'Input',
|
||||||
|
dependencies: {
|
||||||
|
triggerFields: [''],
|
||||||
|
show: () => false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
fieldName: 'name',
|
||||||
|
label: '名字',
|
||||||
|
rules: 'required',
|
||||||
|
component: 'Input',
|
||||||
|
componentProps: {
|
||||||
|
placeholder: '请输入名字',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
fieldName: 'sex',
|
||||||
|
label: '性别',
|
||||||
|
rules: 'required',
|
||||||
|
component: 'RadioGroup',
|
||||||
|
componentProps: {
|
||||||
|
options: getDictOptions(DICT_TYPE.SYSTEM_USER_SEX, 'number'),
|
||||||
|
buttonStyle: 'solid',
|
||||||
|
optionType: 'button',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
fieldName: 'birthday',
|
||||||
|
label: '出生日期',
|
||||||
|
rules: 'required',
|
||||||
|
component: 'DatePicker',
|
||||||
|
componentProps: {
|
||||||
|
showTime: true,
|
||||||
|
format: 'YYYY-MM-DD HH:mm:ss',
|
||||||
|
valueFormat: 'x',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
fieldName: 'description',
|
||||||
|
label: '简介',
|
||||||
|
rules: 'required',
|
||||||
|
component: 'RichTextarea',
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 列表的搜索表单 */
|
||||||
|
export function useGridFormSchema(): VbenFormSchema[] {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
fieldName: 'name',
|
||||||
|
label: '名字',
|
||||||
|
component: 'Input',
|
||||||
|
componentProps: {
|
||||||
|
allowClear: true,
|
||||||
|
placeholder: '请输入名字',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
fieldName: 'sex',
|
||||||
|
label: '性别',
|
||||||
|
component: 'Select',
|
||||||
|
componentProps: {
|
||||||
|
allowClear: true,
|
||||||
|
options: getDictOptions(DICT_TYPE.SYSTEM_USER_SEX, 'number'),
|
||||||
|
placeholder: '请选择性别',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
fieldName: 'description',
|
||||||
|
label: '简介',
|
||||||
|
component: 'Input',
|
||||||
|
componentProps: {
|
||||||
|
allowClear: true,
|
||||||
|
placeholder: '请输入简介',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
fieldName: 'createTime',
|
||||||
|
label: '创建时间',
|
||||||
|
component: 'RangePicker',
|
||||||
|
componentProps: {
|
||||||
|
...getRangePickerDefaultProps(),
|
||||||
|
allowClear: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 列表的字段 */
|
||||||
|
export function useGridColumns(): VxeTableGridOptions<Demo03StudentApi.Demo03Student>['columns'] {
|
||||||
|
return [
|
||||||
|
{ type: 'checkbox', width: 40 },
|
||||||
|
{
|
||||||
|
field: 'id',
|
||||||
|
title: '编号',
|
||||||
|
minWidth: 120,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'name',
|
||||||
|
title: '名字',
|
||||||
|
minWidth: 120,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'sex',
|
||||||
|
title: '性别',
|
||||||
|
minWidth: 120,
|
||||||
|
cellRender: {
|
||||||
|
name: 'CellDict',
|
||||||
|
props: { type: DICT_TYPE.SYSTEM_USER_SEX },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'birthday',
|
||||||
|
title: '出生日期',
|
||||||
|
minWidth: 120,
|
||||||
|
formatter: 'formatDateTime',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'description',
|
||||||
|
title: '简介',
|
||||||
|
minWidth: 120,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'createTime',
|
||||||
|
title: '创建时间',
|
||||||
|
minWidth: 120,
|
||||||
|
formatter: 'formatDateTime',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '操作',
|
||||||
|
width: 200,
|
||||||
|
fixed: 'right',
|
||||||
|
slots: { default: 'actions' },
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
// ==================== 子表(学生课程) ====================
|
||||||
|
|
||||||
|
/** 新增/修改列表的字段 */
|
||||||
|
export function useDemo03CourseGridEditColumns(): VxeTableGridOptions<Demo03StudentApi.Demo03Course>['columns'] {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
field: 'name',
|
||||||
|
title: '名字',
|
||||||
|
minWidth: 120,
|
||||||
|
slots: { default: 'name' },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'score',
|
||||||
|
title: '分数',
|
||||||
|
minWidth: 120,
|
||||||
|
slots: { default: 'score' },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '操作',
|
||||||
|
width: 200,
|
||||||
|
fixed: 'right',
|
||||||
|
slots: { default: 'actions' },
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
// ==================== 子表(学生班级) ====================
|
||||||
|
|
||||||
|
/** 新增/修改的表单 */
|
||||||
|
export function useDemo03GradeFormSchema(): VbenFormSchema[] {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
fieldName: 'id',
|
||||||
|
component: 'Input',
|
||||||
|
dependencies: {
|
||||||
|
triggerFields: [''],
|
||||||
|
show: () => false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
fieldName: 'name',
|
||||||
|
label: '名字',
|
||||||
|
rules: 'required',
|
||||||
|
component: 'Input',
|
||||||
|
componentProps: {
|
||||||
|
placeholder: '请输入名字',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
fieldName: 'teacher',
|
||||||
|
label: '班主任',
|
||||||
|
rules: 'required',
|
||||||
|
component: 'Input',
|
||||||
|
componentProps: {
|
||||||
|
placeholder: '请输入班主任',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,185 @@
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||||
|
import type { Demo03StudentApi } from '#/api/infra/demo/demo03/normal';
|
||||||
|
|
||||||
|
import { ref } from 'vue';
|
||||||
|
|
||||||
|
import { Page, useVbenModal } from '@vben/common-ui';
|
||||||
|
import { downloadFileFromBlobPart, isEmpty } from '@vben/utils';
|
||||||
|
|
||||||
|
import { ElLoading, ElMessage } from 'element-plus';
|
||||||
|
|
||||||
|
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||||
|
import {
|
||||||
|
deleteDemo03Student,
|
||||||
|
deleteDemo03StudentList,
|
||||||
|
exportDemo03Student,
|
||||||
|
getDemo03StudentPage,
|
||||||
|
} from '#/api/infra/demo/demo03/normal';
|
||||||
|
import { $t } from '#/locales';
|
||||||
|
|
||||||
|
import { useGridColumns, useGridFormSchema } from './data';
|
||||||
|
import Form from './modules/form.vue';
|
||||||
|
|
||||||
|
const [FormModal, formModalApi] = useVbenModal({
|
||||||
|
connectedComponent: Form,
|
||||||
|
destroyOnClose: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
/** 刷新表格 */
|
||||||
|
function onRefresh() {
|
||||||
|
gridApi.query();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 创建学生 */
|
||||||
|
function handleCreate() {
|
||||||
|
formModalApi.setData({}).open();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 编辑学生 */
|
||||||
|
function handleEdit(row: Demo03StudentApi.Demo03Student) {
|
||||||
|
formModalApi.setData(row).open();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 删除学生 */
|
||||||
|
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 as number);
|
||||||
|
ElMessage.success($t('ui.actionMessage.deleteSuccess', [row.id]));
|
||||||
|
onRefresh();
|
||||||
|
} finally {
|
||||||
|
loadingInstance.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 批量删除学生 */
|
||||||
|
async function handleDeleteBatch() {
|
||||||
|
const loadingInstance = ElLoading.service({
|
||||||
|
text: $t('ui.actionMessage.deleting'),
|
||||||
|
background: 'rgba(0, 0, 0, 0.7)',
|
||||||
|
});
|
||||||
|
try {
|
||||||
|
await deleteDemo03StudentList(checkedIds.value);
|
||||||
|
ElMessage.success($t('ui.actionMessage.deleteSuccess'));
|
||||||
|
onRefresh();
|
||||||
|
} finally {
|
||||||
|
loadingInstance.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const checkedIds = ref<number[]>([]);
|
||||||
|
function handleRowCheckboxChange({
|
||||||
|
records,
|
||||||
|
}: {
|
||||||
|
records: Demo03StudentApi.Demo03Student[];
|
||||||
|
}) {
|
||||||
|
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(),
|
||||||
|
},
|
||||||
|
gridOptions: {
|
||||||
|
columns: useGridColumns(),
|
||||||
|
height: 'auto',
|
||||||
|
pagerConfig: {
|
||||||
|
enabled: true,
|
||||||
|
},
|
||||||
|
proxyConfig: {
|
||||||
|
ajax: {
|
||||||
|
query: async ({ page }, formValues) => {
|
||||||
|
return await getDemo03StudentPage({
|
||||||
|
pageNo: page.currentPage,
|
||||||
|
pageSize: page.pageSize,
|
||||||
|
...formValues,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
rowConfig: {
|
||||||
|
keyField: 'id',
|
||||||
|
isHover: true,
|
||||||
|
},
|
||||||
|
toolbarConfig: {
|
||||||
|
refresh: { code: 'query' },
|
||||||
|
search: true,
|
||||||
|
},
|
||||||
|
} as VxeTableGridOptions<Demo03StudentApi.Demo03Student>,
|
||||||
|
gridEvents: {
|
||||||
|
checkboxAll: handleRowCheckboxChange,
|
||||||
|
checkboxChange: handleRowCheckboxChange,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<Page auto-content-height>
|
||||||
|
<FormModal @success="onRefresh" />
|
||||||
|
|
||||||
|
<Grid table-title="学生列表">
|
||||||
|
<template #toolbar-tools>
|
||||||
|
<TableAction
|
||||||
|
:actions="[
|
||||||
|
{
|
||||||
|
label: $t('ui.actionTitle.create', ['学生']),
|
||||||
|
type: 'primary',
|
||||||
|
icon: ACTION_ICON.ADD,
|
||||||
|
auth: ['infra:demo03-student:create'],
|
||||||
|
onClick: handleCreate,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: $t('ui.actionTitle.export'),
|
||||||
|
type: 'primary',
|
||||||
|
icon: ACTION_ICON.DOWNLOAD,
|
||||||
|
auth: ['infra:demo03-student:export'],
|
||||||
|
onClick: handleExport,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: $t('ui.actionTitle.deleteBatch'),
|
||||||
|
type: 'danger',
|
||||||
|
icon: ACTION_ICON.DELETE,
|
||||||
|
disabled: isEmpty(checkedIds),
|
||||||
|
auth: ['infra:demo03-student:delete'],
|
||||||
|
onClick: handleDeleteBatch,
|
||||||
|
},
|
||||||
|
]"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
<template #actions="{ row }">
|
||||||
|
<TableAction
|
||||||
|
:actions="[
|
||||||
|
{
|
||||||
|
label: $t('common.edit'),
|
||||||
|
type: 'text',
|
||||||
|
icon: ACTION_ICON.EDIT,
|
||||||
|
auth: ['infra:demo03-student:update'],
|
||||||
|
onClick: handleEdit.bind(null, row),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: $t('common.delete'),
|
||||||
|
type: 'danger',
|
||||||
|
text: true,
|
||||||
|
icon: ACTION_ICON.DELETE,
|
||||||
|
auth: ['infra:demo03-student:delete'],
|
||||||
|
popConfirm: {
|
||||||
|
title: $t('ui.actionMessage.deleteConfirm', [row.id]),
|
||||||
|
confirm: handleDelete.bind(null, row),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
]"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
</Grid>
|
||||||
|
</Page>
|
||||||
|
</template>
|
||||||
|
|
@ -0,0 +1,116 @@
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import type { OnActionClickParams } from '#/adapter/vxe-table';
|
||||||
|
import type { Demo03StudentApi } from '#/api/infra/demo/demo03/normal';
|
||||||
|
|
||||||
|
import { nextTick, watch } from 'vue';
|
||||||
|
|
||||||
|
import { Plus } from '@vben/icons';
|
||||||
|
|
||||||
|
import { ElButton, ElInput } from 'element-plus';
|
||||||
|
|
||||||
|
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||||
|
import { getDemo03CourseListByStudentId } from '#/api/infra/demo/demo03/normal';
|
||||||
|
import { $t } from '#/locales';
|
||||||
|
|
||||||
|
import { useDemo03CourseGridEditColumns } from '../data';
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
studentId?: number; // 学生编号(主表的关联字段)
|
||||||
|
}>();
|
||||||
|
|
||||||
|
/** 表格操作按钮的回调函数 */
|
||||||
|
function onActionClick({
|
||||||
|
code,
|
||||||
|
row,
|
||||||
|
}: OnActionClickParams<Demo03StudentApi.Demo03Course>) {
|
||||||
|
switch (code) {
|
||||||
|
case 'delete': {
|
||||||
|
onDelete(row);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const [Grid, gridApi] = useVbenVxeGrid({
|
||||||
|
gridOptions: {
|
||||||
|
columns: useDemo03CourseGridEditColumns(onActionClick),
|
||||||
|
border: true,
|
||||||
|
showOverflow: true,
|
||||||
|
autoResize: true,
|
||||||
|
keepSource: true,
|
||||||
|
rowConfig: {
|
||||||
|
keyField: 'id',
|
||||||
|
},
|
||||||
|
pagerConfig: {
|
||||||
|
enabled: false,
|
||||||
|
},
|
||||||
|
toolbarConfig: {
|
||||||
|
enabled: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
/** 添加学生课程 */
|
||||||
|
const onAdd = async () => {
|
||||||
|
await gridApi.grid.insertAt({} as Demo03StudentApi.Demo03Course, -1);
|
||||||
|
};
|
||||||
|
|
||||||
|
/** 删除学生课程 */
|
||||||
|
const onDelete = async (row: Demo03StudentApi.Demo03Course) => {
|
||||||
|
await gridApi.grid.remove(row);
|
||||||
|
};
|
||||||
|
|
||||||
|
/** 提供获取表格数据的方法供父组件调用 */
|
||||||
|
defineExpose({
|
||||||
|
getData: (): 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),
|
||||||
|
),
|
||||||
|
...insertRecords.map((row: any) => ({ ...row, id: undefined })),
|
||||||
|
];
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
/** 监听主表的关联字段的变化,加载对应的子表数据 */
|
||||||
|
watch(
|
||||||
|
() => props.studentId,
|
||||||
|
async (val) => {
|
||||||
|
if (!val) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await nextTick();
|
||||||
|
await gridApi.grid.loadData(
|
||||||
|
await getDemo03CourseListByStudentId(props.studentId!),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
{ immediate: true },
|
||||||
|
);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<Grid class="mx-4">
|
||||||
|
<template #name="{ row }">
|
||||||
|
<ElInput v-model="row.name" />
|
||||||
|
</template>
|
||||||
|
<template #score="{ row }">
|
||||||
|
<ElInput v-model="row.score" />
|
||||||
|
</template>
|
||||||
|
</Grid>
|
||||||
|
<div class="-mt-4 flex justify-center">
|
||||||
|
<ElButton
|
||||||
|
:icon="Plus"
|
||||||
|
type="primary"
|
||||||
|
plain
|
||||||
|
@click="onAdd"
|
||||||
|
v-access:code="['infra:demo03-student:create']"
|
||||||
|
>
|
||||||
|
{{ $t('ui.actionTitle.create', ['学生课程']) }}
|
||||||
|
</ElButton>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
@ -0,0 +1,51 @@
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import { nextTick, watch } from 'vue';
|
||||||
|
|
||||||
|
import { useVbenForm } from '#/adapter/form';
|
||||||
|
import { getDemo03GradeByStudentId } from '#/api/infra/demo/demo03/normal';
|
||||||
|
|
||||||
|
import { useDemo03GradeFormSchema } from '../data';
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
studentId?: number; // 学生编号(主表的关联字段)
|
||||||
|
}>();
|
||||||
|
|
||||||
|
const [Form, formApi] = useVbenForm({
|
||||||
|
commonConfig: {
|
||||||
|
componentProps: {
|
||||||
|
class: 'w-full',
|
||||||
|
},
|
||||||
|
formItemClass: 'col-span-2',
|
||||||
|
labelWidth: 80,
|
||||||
|
},
|
||||||
|
layout: 'horizontal',
|
||||||
|
schema: useDemo03GradeFormSchema(),
|
||||||
|
showDefaultActions: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
/** 暴露出表单校验方法和表单值获取方法 */
|
||||||
|
defineExpose({
|
||||||
|
validate: async () => {
|
||||||
|
const { valid } = await formApi.validate();
|
||||||
|
return valid;
|
||||||
|
},
|
||||||
|
getValues: formApi.getValues,
|
||||||
|
});
|
||||||
|
|
||||||
|
/** 监听主表的关联字段的变化,加载对应的子表数据 */
|
||||||
|
watch(
|
||||||
|
() => props.studentId,
|
||||||
|
async (val) => {
|
||||||
|
if (!val) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await nextTick();
|
||||||
|
await formApi.setValues(await getDemo03GradeByStudentId(props.studentId!));
|
||||||
|
},
|
||||||
|
{ immediate: true },
|
||||||
|
);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<Form class="mx-4" />
|
||||||
|
</template>
|
||||||
|
|
@ -0,0 +1,119 @@
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import type { Demo03StudentApi } from '#/api/infra/demo/demo03/normal';
|
||||||
|
|
||||||
|
import { computed, ref } from 'vue';
|
||||||
|
|
||||||
|
import { useVbenModal } from '@vben/common-ui';
|
||||||
|
|
||||||
|
import { ElMessage, ElTabPane, ElTabs } from 'element-plus';
|
||||||
|
|
||||||
|
import { useVbenForm } from '#/adapter/form';
|
||||||
|
import {
|
||||||
|
createDemo03Student,
|
||||||
|
getDemo03Student,
|
||||||
|
updateDemo03Student,
|
||||||
|
} from '#/api/infra/demo/demo03/normal';
|
||||||
|
import { $t } from '#/locales';
|
||||||
|
|
||||||
|
import { useFormSchema } from '../data';
|
||||||
|
import Demo03CourseForm from './demo03-course-form.vue';
|
||||||
|
import Demo03GradeForm from './demo03-grade-form.vue';
|
||||||
|
|
||||||
|
const emit = defineEmits(['success']);
|
||||||
|
const formData = ref<Demo03StudentApi.Demo03Student>();
|
||||||
|
const getTitle = computed(() => {
|
||||||
|
return formData.value?.id
|
||||||
|
? $t('ui.actionTitle.edit', ['学生'])
|
||||||
|
: $t('ui.actionTitle.create', ['学生']);
|
||||||
|
});
|
||||||
|
|
||||||
|
/** 子表的表单 */
|
||||||
|
const subTabsName = ref('demo03Course');
|
||||||
|
const demo03CourseFormRef = ref<InstanceType<typeof Demo03CourseForm>>();
|
||||||
|
const demo03GradeFormRef = ref<InstanceType<typeof Demo03GradeForm>>();
|
||||||
|
|
||||||
|
const [Form, formApi] = useVbenForm({
|
||||||
|
commonConfig: {
|
||||||
|
componentProps: {
|
||||||
|
class: 'w-full',
|
||||||
|
},
|
||||||
|
formItemClass: 'col-span-2',
|
||||||
|
labelWidth: 80,
|
||||||
|
},
|
||||||
|
layout: 'horizontal',
|
||||||
|
schema: useFormSchema(),
|
||||||
|
showDefaultActions: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
const [Modal, modalApi] = useVbenModal({
|
||||||
|
async onConfirm() {
|
||||||
|
const { valid } = await formApi.validate();
|
||||||
|
if (!valid) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 校验子表单
|
||||||
|
const demo03GradeValid = await demo03GradeFormRef.value?.validate();
|
||||||
|
if (!demo03GradeValid) {
|
||||||
|
subTabsName.value = 'demo03Grade';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
modalApi.lock();
|
||||||
|
// 提交表单
|
||||||
|
const data = (await formApi.getValues()) as Demo03StudentApi.Demo03Student;
|
||||||
|
// 拼接子表的数据
|
||||||
|
data.demo03Courses = demo03CourseFormRef.value?.getData();
|
||||||
|
data.demo03Grade = await demo03GradeFormRef.value?.getValues();
|
||||||
|
try {
|
||||||
|
await (formData.value?.id
|
||||||
|
? updateDemo03Student(data)
|
||||||
|
: createDemo03Student(data));
|
||||||
|
// 关闭并提示
|
||||||
|
await modalApi.close();
|
||||||
|
emit('success');
|
||||||
|
ElMessage.success($t('ui.actionMessage.operationSuccess'));
|
||||||
|
} finally {
|
||||||
|
modalApi.unlock();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
async onOpenChange(isOpen: boolean) {
|
||||||
|
if (!isOpen) {
|
||||||
|
formData.value = undefined;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 加载数据
|
||||||
|
let data = modalApi.getData<Demo03StudentApi.Demo03Student>();
|
||||||
|
if (!data) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (data.id) {
|
||||||
|
modalApi.lock();
|
||||||
|
try {
|
||||||
|
data = await getDemo03Student(data.id);
|
||||||
|
} finally {
|
||||||
|
modalApi.unlock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 设置到 values
|
||||||
|
formData.value = data;
|
||||||
|
await formApi.setValues(formData.value);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<Modal :title="getTitle">
|
||||||
|
<Form class="mx-4" />
|
||||||
|
<!-- 子表的表单 -->
|
||||||
|
<ElTabs v-model="subTabsName">
|
||||||
|
<ElTabPane name="demo03Course" label="学生课程">
|
||||||
|
<Demo03CourseForm
|
||||||
|
ref="demo03CourseFormRef"
|
||||||
|
:student-id="formData?.id"
|
||||||
|
/>
|
||||||
|
</ElTabPane>
|
||||||
|
<ElTabPane name="demo03Grade" label="学生班级">
|
||||||
|
<Demo03GradeForm ref="demo03GradeFormRef" :student-id="formData?.id" />
|
||||||
|
</ElTabPane>
|
||||||
|
</ElTabs>
|
||||||
|
</Modal>
|
||||||
|
</template>
|
||||||
|
|
@ -0,0 +1,316 @@
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import type { Demo01ContactApi } from '#/api/infra/demo/demo01';
|
||||||
|
|
||||||
|
import { h, onMounted, reactive, ref } from 'vue';
|
||||||
|
|
||||||
|
import { Page, useVbenModal } from '@vben/common-ui';
|
||||||
|
import { Download, Plus, Trash2 } from '@vben/icons';
|
||||||
|
import {
|
||||||
|
cloneDeep,
|
||||||
|
downloadFileFromBlobPart,
|
||||||
|
formatDateTime,
|
||||||
|
isEmpty,
|
||||||
|
} from '@vben/utils';
|
||||||
|
|
||||||
|
import {
|
||||||
|
ElButton,
|
||||||
|
ElDatePicker,
|
||||||
|
ElForm,
|
||||||
|
ElFormItem,
|
||||||
|
ElInput,
|
||||||
|
ElLoading,
|
||||||
|
ElMessage,
|
||||||
|
ElOption,
|
||||||
|
ElPagination,
|
||||||
|
ElSelect,
|
||||||
|
} from 'element-plus';
|
||||||
|
|
||||||
|
import { VxeColumn, VxeTable } from '#/adapter/vxe-table';
|
||||||
|
import {
|
||||||
|
deleteDemo01Contact,
|
||||||
|
deleteDemo01ContactList,
|
||||||
|
exportDemo01Contact,
|
||||||
|
getDemo01ContactPage,
|
||||||
|
} from '#/api/infra/demo/demo01';
|
||||||
|
import { ContentWrap } from '#/components/content-wrap';
|
||||||
|
import { DictTag } from '#/components/dict-tag';
|
||||||
|
import { TableToolbar } from '#/components/table-toolbar';
|
||||||
|
import { useTableToolbar } from '#/hooks';
|
||||||
|
import { $t } from '#/locales';
|
||||||
|
import { DICT_TYPE, getDictOptions } from '#/utils';
|
||||||
|
|
||||||
|
import Demo01ContactForm from './modules/form.vue';
|
||||||
|
|
||||||
|
const loading = ref(true); // 列表的加载中
|
||||||
|
const list = ref<Demo01ContactApi.Demo01Contact[]>([]); // 列表的数据
|
||||||
|
|
||||||
|
const total = ref(0); // 列表的总页数
|
||||||
|
const queryParams = reactive({
|
||||||
|
pageNo: 1,
|
||||||
|
pageSize: 10,
|
||||||
|
name: undefined,
|
||||||
|
sex: undefined,
|
||||||
|
createTime: undefined,
|
||||||
|
});
|
||||||
|
const queryFormRef = ref(); // 搜索的表单
|
||||||
|
const exportLoading = ref(false); // 导出的加载中
|
||||||
|
|
||||||
|
/** 查询列表 */
|
||||||
|
const getList = async () => {
|
||||||
|
loading.value = true;
|
||||||
|
try {
|
||||||
|
const params = cloneDeep(queryParams) as any;
|
||||||
|
if (params.createTime && Array.isArray(params.createTime)) {
|
||||||
|
params.createTime = (params.createTime as string[]).join(',');
|
||||||
|
}
|
||||||
|
const data = await getDemo01ContactPage(params);
|
||||||
|
list.value = data.list;
|
||||||
|
total.value = data.total;
|
||||||
|
} finally {
|
||||||
|
loading.value = false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/** 搜索按钮操作 */
|
||||||
|
const handleQuery = () => {
|
||||||
|
queryParams.pageNo = 1;
|
||||||
|
getList();
|
||||||
|
};
|
||||||
|
|
||||||
|
/** 重置按钮操作 */
|
||||||
|
const resetQuery = () => {
|
||||||
|
queryFormRef.value.resetFields();
|
||||||
|
handleQuery();
|
||||||
|
};
|
||||||
|
|
||||||
|
const [FormModal, formModalApi] = useVbenModal({
|
||||||
|
connectedComponent: Demo01ContactForm,
|
||||||
|
destroyOnClose: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
/** 创建示例联系人 */
|
||||||
|
function handleCreate() {
|
||||||
|
formModalApi.setData({}).open();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 编辑示例联系人 */
|
||||||
|
function handleEdit(row: Demo01ContactApi.Demo01Contact) {
|
||||||
|
formModalApi.setData(row).open();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 删除示例联系人 */
|
||||||
|
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 as number);
|
||||||
|
ElMessage.success($t('ui.actionMessage.deleteSuccess', [row.id]));
|
||||||
|
await getList();
|
||||||
|
} finally {
|
||||||
|
loadingInstance.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 批量删除示例联系人 */
|
||||||
|
async function handleDeleteBatch() {
|
||||||
|
const loadingInstance = ElLoading.service({
|
||||||
|
text: $t('ui.actionMessage.deleting'),
|
||||||
|
background: 'rgba(0, 0, 0, 0.7)',
|
||||||
|
});
|
||||||
|
try {
|
||||||
|
await deleteDemo01ContactList(checkedIds.value);
|
||||||
|
ElMessage.success($t('ui.actionMessage.deleteSuccess'));
|
||||||
|
await getList();
|
||||||
|
} finally {
|
||||||
|
loadingInstance.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const checkedIds = ref<number[]>([]);
|
||||||
|
function handleRowCheckboxChange({
|
||||||
|
records,
|
||||||
|
}: {
|
||||||
|
records: Demo01ContactApi.Demo01Contact[];
|
||||||
|
}) {
|
||||||
|
checkedIds.value = records.map((item) => item.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 导出表格 */
|
||||||
|
async function onExport() {
|
||||||
|
try {
|
||||||
|
exportLoading.value = true;
|
||||||
|
const data = await exportDemo01Contact(queryParams);
|
||||||
|
downloadFileFromBlobPart({ fileName: '示例联系人.xls', source: data });
|
||||||
|
} finally {
|
||||||
|
exportLoading.value = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 初始化 */
|
||||||
|
const { hiddenSearchBar, tableToolbarRef, tableRef } = useTableToolbar();
|
||||||
|
onMounted(() => {
|
||||||
|
getList();
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<Page auto-content-height>
|
||||||
|
<FormModal @success="getList" />
|
||||||
|
|
||||||
|
<ContentWrap v-if="!hiddenSearchBar">
|
||||||
|
<!-- 搜索工作栏 -->
|
||||||
|
<ElForm :model="queryParams" ref="queryFormRef" inline>
|
||||||
|
<ElFormItem label="名字">
|
||||||
|
<ElInput
|
||||||
|
v-model="queryParams.name"
|
||||||
|
placeholder="请输入名字"
|
||||||
|
clearable
|
||||||
|
@keyup.enter="handleQuery"
|
||||||
|
class="!w-[240px]"
|
||||||
|
/>
|
||||||
|
</ElFormItem>
|
||||||
|
<ElFormItem label="性别">
|
||||||
|
<ElSelect
|
||||||
|
v-model="queryParams.sex"
|
||||||
|
placeholder="请选择性别"
|
||||||
|
clearable
|
||||||
|
class="!w-[240px]"
|
||||||
|
>
|
||||||
|
<ElOption
|
||||||
|
v-for="dict in getDictOptions(
|
||||||
|
DICT_TYPE.SYSTEM_USER_SEX,
|
||||||
|
'number',
|
||||||
|
)"
|
||||||
|
:key="dict.value"
|
||||||
|
:value="dict.value"
|
||||||
|
:label="dict.label"
|
||||||
|
/>
|
||||||
|
</ElSelect>
|
||||||
|
</ElFormItem>
|
||||||
|
<ElFormItem label="创建时间">
|
||||||
|
<ElDatePicker
|
||||||
|
v-model="queryParams.createTime"
|
||||||
|
type="daterange"
|
||||||
|
value-format="YYYY-MM-DD"
|
||||||
|
range-separator="至"
|
||||||
|
start-placeholder="开始日期"
|
||||||
|
end-placeholder="结束日期"
|
||||||
|
class="!w-[240px]"
|
||||||
|
/>
|
||||||
|
</ElFormItem>
|
||||||
|
<ElFormItem>
|
||||||
|
<ElButton class="ml-2" @click="resetQuery"> 重置 </ElButton>
|
||||||
|
<ElButton class="ml-2" @click="handleQuery" type="primary">
|
||||||
|
搜索
|
||||||
|
</ElButton>
|
||||||
|
</ElFormItem>
|
||||||
|
</ElForm>
|
||||||
|
</ContentWrap>
|
||||||
|
|
||||||
|
<!-- 列表 -->
|
||||||
|
<ContentWrap title="示例联系人">
|
||||||
|
<template #extra>
|
||||||
|
<TableToolbar
|
||||||
|
ref="tableToolbarRef"
|
||||||
|
v-model:hidden-search="hiddenSearchBar"
|
||||||
|
>
|
||||||
|
<ElButton
|
||||||
|
class="ml-2"
|
||||||
|
:icon="h(Plus)"
|
||||||
|
type="primary"
|
||||||
|
@click="handleCreate"
|
||||||
|
v-access:code="['infra:demo01-contact:create']"
|
||||||
|
>
|
||||||
|
{{ $t('ui.actionTitle.create', ['示例联系人']) }}
|
||||||
|
</ElButton>
|
||||||
|
<ElButton
|
||||||
|
:icon="h(Download)"
|
||||||
|
type="primary"
|
||||||
|
class="ml-2"
|
||||||
|
:loading="exportLoading"
|
||||||
|
@click="onExport"
|
||||||
|
v-access:code="['infra:demo01-contact:export']"
|
||||||
|
>
|
||||||
|
{{ $t('ui.actionTitle.export') }}
|
||||||
|
</ElButton>
|
||||||
|
<ElButton
|
||||||
|
:icon="h(Trash2)"
|
||||||
|
type="danger"
|
||||||
|
class="ml-2"
|
||||||
|
:disabled="isEmpty(checkedIds)"
|
||||||
|
@click="handleDeleteBatch"
|
||||||
|
v-access:code="['infra:demo01-contact:delete']"
|
||||||
|
>
|
||||||
|
批量删除
|
||||||
|
</ElButton>
|
||||||
|
</TableToolbar>
|
||||||
|
</template>
|
||||||
|
<VxeTable
|
||||||
|
ref="tableRef"
|
||||||
|
:data="list"
|
||||||
|
show-overflow
|
||||||
|
:loading="loading"
|
||||||
|
@checkbox-all="handleRowCheckboxChange"
|
||||||
|
@checkbox-change="handleRowCheckboxChange"
|
||||||
|
>
|
||||||
|
<VxeColumn type="checkbox" width="40" />
|
||||||
|
<VxeColumn field="id" title="编号" align="center" />
|
||||||
|
<VxeColumn field="name" title="名字" align="center" />
|
||||||
|
<VxeColumn field="sex" title="性别" align="center">
|
||||||
|
<template #default="{ row }">
|
||||||
|
<DictTag :type="DICT_TYPE.SYSTEM_USER_SEX" :value="row.sex" />
|
||||||
|
</template>
|
||||||
|
</VxeColumn>
|
||||||
|
<VxeColumn field="birthday" title="出生年" align="center">
|
||||||
|
<template #default="{ row }">
|
||||||
|
{{ formatDateTime(row.birthday) }}
|
||||||
|
</template>
|
||||||
|
</VxeColumn>
|
||||||
|
<VxeColumn field="description" title="简介" align="center" />
|
||||||
|
<VxeColumn field="avatar" title="头像" align="center" />
|
||||||
|
<VxeColumn field="createTime" title="创建时间" align="center">
|
||||||
|
<template #default="{ row }">
|
||||||
|
{{ formatDateTime(row.createTime) }}
|
||||||
|
</template>
|
||||||
|
</VxeColumn>
|
||||||
|
<VxeColumn field="operation" title="操作" align="center">
|
||||||
|
<template #default="{ row }">
|
||||||
|
<ElButton
|
||||||
|
size="small"
|
||||||
|
type="primary"
|
||||||
|
link
|
||||||
|
@click="handleEdit(row as any)"
|
||||||
|
v-access:code="['infra:demo01-contact:update']"
|
||||||
|
>
|
||||||
|
{{ $t('ui.actionTitle.edit') }}
|
||||||
|
</ElButton>
|
||||||
|
<ElButton
|
||||||
|
size="small"
|
||||||
|
type="danger"
|
||||||
|
link
|
||||||
|
class="ml-2"
|
||||||
|
@click="handleDelete(row as any)"
|
||||||
|
v-access:code="['infra:demo01-contact:delete']"
|
||||||
|
>
|
||||||
|
{{ $t('ui.actionTitle.delete') }}
|
||||||
|
</ElButton>
|
||||||
|
</template>
|
||||||
|
</VxeColumn>
|
||||||
|
</VxeTable>
|
||||||
|
<!-- 分页 -->
|
||||||
|
<div class="mt-2 flex justify-end">
|
||||||
|
<ElPagination
|
||||||
|
:total="total"
|
||||||
|
v-model:current-page="queryParams.pageNo"
|
||||||
|
v-model:page-size="queryParams.pageSize"
|
||||||
|
:page-sizes="[10, 20, 50, 100]"
|
||||||
|
layout="total, sizes, prev, pager, next, jumper"
|
||||||
|
@size-change="getList"
|
||||||
|
@current-change="getList"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</ContentWrap>
|
||||||
|
</Page>
|
||||||
|
</template>
|
||||||
|
|
@ -0,0 +1,145 @@
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import type { FormRules } from 'element-plus';
|
||||||
|
|
||||||
|
import type { Demo01ContactApi } from '#/api/infra/demo/demo01';
|
||||||
|
|
||||||
|
import { computed, reactive, ref } from 'vue';
|
||||||
|
|
||||||
|
import { useVbenModal } from '@vben/common-ui';
|
||||||
|
|
||||||
|
import {
|
||||||
|
ElDatePicker,
|
||||||
|
ElForm,
|
||||||
|
ElFormItem,
|
||||||
|
ElInput,
|
||||||
|
ElMessage,
|
||||||
|
ElRadio,
|
||||||
|
ElRadioGroup,
|
||||||
|
} from 'element-plus';
|
||||||
|
|
||||||
|
import {
|
||||||
|
createDemo01Contact,
|
||||||
|
getDemo01Contact,
|
||||||
|
updateDemo01Contact,
|
||||||
|
} from '#/api/infra/demo/demo01';
|
||||||
|
import { Tinymce as RichTextarea } from '#/components/tinymce';
|
||||||
|
import { ImageUpload } from '#/components/upload';
|
||||||
|
import { $t } from '#/locales';
|
||||||
|
import { DICT_TYPE, getDictOptions } from '#/utils';
|
||||||
|
|
||||||
|
const emit = defineEmits(['success']);
|
||||||
|
|
||||||
|
const formRef = ref();
|
||||||
|
const formData = ref<Partial<Demo01ContactApi.Demo01Contact>>({
|
||||||
|
id: undefined,
|
||||||
|
name: undefined,
|
||||||
|
sex: undefined,
|
||||||
|
birthday: undefined,
|
||||||
|
description: undefined,
|
||||||
|
avatar: undefined,
|
||||||
|
});
|
||||||
|
const rules = reactive<FormRules>({
|
||||||
|
name: [{ required: true, message: '名字不能为空', trigger: 'blur' }],
|
||||||
|
sex: [{ required: true, message: '性别不能为空', trigger: 'blur' }],
|
||||||
|
birthday: [{ required: true, message: '出生年不能为空', trigger: 'blur' }],
|
||||||
|
description: [{ required: true, message: '简介不能为空', trigger: 'blur' }],
|
||||||
|
});
|
||||||
|
const getTitle = computed(() => {
|
||||||
|
return formData.value?.id
|
||||||
|
? $t('ui.actionTitle.edit', ['示例联系人'])
|
||||||
|
: $t('ui.actionTitle.create', ['示例联系人']);
|
||||||
|
});
|
||||||
|
|
||||||
|
/** 重置表单 */
|
||||||
|
const resetForm = () => {
|
||||||
|
formData.value = {
|
||||||
|
id: undefined,
|
||||||
|
name: undefined,
|
||||||
|
sex: undefined,
|
||||||
|
birthday: undefined,
|
||||||
|
description: undefined,
|
||||||
|
avatar: undefined,
|
||||||
|
};
|
||||||
|
formRef.value?.resetFields();
|
||||||
|
};
|
||||||
|
|
||||||
|
const [Modal, modalApi] = useVbenModal({
|
||||||
|
async onConfirm() {
|
||||||
|
await formRef.value?.validate();
|
||||||
|
modalApi.lock();
|
||||||
|
// 提交表单
|
||||||
|
const data = formData.value as Demo01ContactApi.Demo01Contact;
|
||||||
|
try {
|
||||||
|
await (formData.value?.id
|
||||||
|
? updateDemo01Contact(data)
|
||||||
|
: createDemo01Contact(data));
|
||||||
|
// 关闭并提示
|
||||||
|
await modalApi.close();
|
||||||
|
emit('success');
|
||||||
|
ElMessage.success($t('ui.actionMessage.operationSuccess'));
|
||||||
|
} finally {
|
||||||
|
modalApi.unlock();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
async onOpenChange(isOpen: boolean) {
|
||||||
|
if (!isOpen) {
|
||||||
|
resetForm();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 加载数据
|
||||||
|
let data = modalApi.getData<Demo01ContactApi.Demo01Contact>();
|
||||||
|
if (!data) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (data.id) {
|
||||||
|
modalApi.lock();
|
||||||
|
try {
|
||||||
|
data = await getDemo01Contact(data.id);
|
||||||
|
} finally {
|
||||||
|
modalApi.unlock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
formData.value = data;
|
||||||
|
},
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<Modal :title="getTitle">
|
||||||
|
<ElForm
|
||||||
|
ref="formRef"
|
||||||
|
:model="formData"
|
||||||
|
:rules="rules"
|
||||||
|
label-width="120px"
|
||||||
|
label-position="right"
|
||||||
|
>
|
||||||
|
<ElFormItem label="名字" prop="name">
|
||||||
|
<ElInput v-model="formData.name" placeholder="请输入名字" />
|
||||||
|
</ElFormItem>
|
||||||
|
<ElFormItem label="性别" prop="sex">
|
||||||
|
<ElRadioGroup v-model="formData.sex">
|
||||||
|
<ElRadio
|
||||||
|
v-for="dict in getDictOptions(DICT_TYPE.SYSTEM_USER_SEX, 'number')"
|
||||||
|
:key="dict.value"
|
||||||
|
:label="dict.value"
|
||||||
|
>
|
||||||
|
{{ dict.label }}
|
||||||
|
</ElRadio>
|
||||||
|
</ElRadioGroup>
|
||||||
|
</ElFormItem>
|
||||||
|
<ElFormItem label="出生年" prop="birthday">
|
||||||
|
<ElDatePicker
|
||||||
|
v-model="formData.birthday"
|
||||||
|
value-format="x"
|
||||||
|
placeholder="选择出生年"
|
||||||
|
/>
|
||||||
|
</ElFormItem>
|
||||||
|
<ElFormItem label="简介" prop="description">
|
||||||
|
<RichTextarea v-model="formData.description" height="500px" />
|
||||||
|
</ElFormItem>
|
||||||
|
<ElFormItem label="头像" prop="avatar">
|
||||||
|
<ImageUpload v-model="formData.avatar" />
|
||||||
|
</ElFormItem>
|
||||||
|
</ElForm>
|
||||||
|
</Modal>
|
||||||
|
</template>
|
||||||
|
|
@ -0,0 +1,267 @@
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import type { Demo02CategoryApi } from '#/api/infra/demo/demo02';
|
||||||
|
|
||||||
|
import { h, onMounted, reactive, ref } from 'vue';
|
||||||
|
|
||||||
|
import { Page, useVbenModal } from '@vben/common-ui';
|
||||||
|
import { Download, Plus } from '@vben/icons';
|
||||||
|
import {
|
||||||
|
cloneDeep,
|
||||||
|
downloadFileFromBlobPart,
|
||||||
|
formatDateTime,
|
||||||
|
isEmpty,
|
||||||
|
} from '@vben/utils';
|
||||||
|
|
||||||
|
import {
|
||||||
|
ElButton,
|
||||||
|
ElDatePicker,
|
||||||
|
ElForm,
|
||||||
|
ElFormItem,
|
||||||
|
ElInput,
|
||||||
|
ElLoading,
|
||||||
|
ElMessage,
|
||||||
|
} from 'element-plus';
|
||||||
|
|
||||||
|
import { VxeColumn, VxeTable } from '#/adapter/vxe-table';
|
||||||
|
import {
|
||||||
|
deleteDemo02Category,
|
||||||
|
exportDemo02Category,
|
||||||
|
getDemo02CategoryList,
|
||||||
|
} from '#/api/infra/demo/demo02';
|
||||||
|
import { ContentWrap } from '#/components/content-wrap';
|
||||||
|
import { TableToolbar } from '#/components/table-toolbar';
|
||||||
|
import { useTableToolbar } from '#/hooks';
|
||||||
|
import { $t } from '#/locales';
|
||||||
|
|
||||||
|
import Demo02CategoryForm from './modules/form.vue';
|
||||||
|
|
||||||
|
const loading = ref(true); // 列表的加载中
|
||||||
|
const list = ref<any[]>([]); // 树列表的数据
|
||||||
|
|
||||||
|
const queryParams = reactive({
|
||||||
|
name: undefined,
|
||||||
|
parentId: undefined,
|
||||||
|
createTime: undefined,
|
||||||
|
});
|
||||||
|
const queryFormRef = ref(); // 搜索的表单
|
||||||
|
const exportLoading = ref(false); // 导出的加载中
|
||||||
|
|
||||||
|
/** 查询列表 */
|
||||||
|
const getList = async () => {
|
||||||
|
loading.value = true;
|
||||||
|
try {
|
||||||
|
const params = cloneDeep(queryParams) as any;
|
||||||
|
if (params.createTime && Array.isArray(params.createTime)) {
|
||||||
|
params.createTime = (params.createTime as string[]).join(',');
|
||||||
|
}
|
||||||
|
list.value = await getDemo02CategoryList(params);
|
||||||
|
} finally {
|
||||||
|
loading.value = false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/** 搜索按钮操作 */
|
||||||
|
const handleQuery = () => {
|
||||||
|
getList();
|
||||||
|
};
|
||||||
|
|
||||||
|
/** 重置按钮操作 */
|
||||||
|
const resetQuery = () => {
|
||||||
|
queryFormRef.value.resetFields();
|
||||||
|
handleQuery();
|
||||||
|
};
|
||||||
|
|
||||||
|
const [FormModal, formModalApi] = useVbenModal({
|
||||||
|
connectedComponent: Demo02CategoryForm,
|
||||||
|
destroyOnClose: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
/** 创建示例分类 */
|
||||||
|
function handleCreate() {
|
||||||
|
formModalApi.setData({}).open();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 编辑示例分类 */
|
||||||
|
function handleEdit(row: Demo02CategoryApi.Demo02Category) {
|
||||||
|
formModalApi.setData(row).open();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 新增下级示例分类 */
|
||||||
|
function handleAppend(row: Demo02CategoryApi.Demo02Category) {
|
||||||
|
formModalApi.setData({ parentId: row.id }).open();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 删除示例分类 */
|
||||||
|
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 as number);
|
||||||
|
ElMessage.success($t('ui.actionMessage.deleteSuccess', [row.id]));
|
||||||
|
await getList();
|
||||||
|
} finally {
|
||||||
|
loadingInstance.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 导出表格 */
|
||||||
|
async function onExport() {
|
||||||
|
try {
|
||||||
|
exportLoading.value = true;
|
||||||
|
const data = await exportDemo02Category(queryParams);
|
||||||
|
downloadFileFromBlobPart({ fileName: '示例分类.xls', source: data });
|
||||||
|
} finally {
|
||||||
|
exportLoading.value = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 切换树形展开/收缩状态 */
|
||||||
|
const isExpanded = ref(true);
|
||||||
|
function toggleExpand() {
|
||||||
|
isExpanded.value = !isExpanded.value;
|
||||||
|
tableRef.value?.setAllTreeExpand(isExpanded.value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 初始化 */
|
||||||
|
const { hiddenSearchBar, tableToolbarRef, tableRef } = useTableToolbar();
|
||||||
|
onMounted(() => {
|
||||||
|
getList();
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<Page auto-content-height>
|
||||||
|
<FormModal @success="getList" />
|
||||||
|
|
||||||
|
<ContentWrap v-if="!hiddenSearchBar">
|
||||||
|
<!-- 搜索工作栏 -->
|
||||||
|
<ElForm :model="queryParams" ref="queryFormRef" inline>
|
||||||
|
<ElFormItem label="名字">
|
||||||
|
<ElInput
|
||||||
|
v-model="queryParams.name"
|
||||||
|
placeholder="请输入名字"
|
||||||
|
clearable
|
||||||
|
@keyup.enter="handleQuery"
|
||||||
|
class="!w-[240px]"
|
||||||
|
/>
|
||||||
|
</ElFormItem>
|
||||||
|
<ElFormItem label="父级编号">
|
||||||
|
<ElInput
|
||||||
|
v-model="queryParams.parentId"
|
||||||
|
placeholder="请输入父级编号"
|
||||||
|
clearable
|
||||||
|
@keyup.enter="handleQuery"
|
||||||
|
class="!w-[240px]"
|
||||||
|
/>
|
||||||
|
</ElFormItem>
|
||||||
|
<ElFormItem label="创建时间">
|
||||||
|
<ElDatePicker
|
||||||
|
v-model="queryParams.createTime"
|
||||||
|
type="daterange"
|
||||||
|
value-format="YYYY-MM-DD"
|
||||||
|
range-separator="至"
|
||||||
|
start-placeholder="开始日期"
|
||||||
|
end-placeholder="结束日期"
|
||||||
|
class="!w-[240px]"
|
||||||
|
/>
|
||||||
|
</ElFormItem>
|
||||||
|
<ElFormItem>
|
||||||
|
<ElButton class="ml-2" @click="resetQuery"> 重置 </ElButton>
|
||||||
|
<ElButton class="ml-2" @click="handleQuery" type="primary">
|
||||||
|
搜索
|
||||||
|
</ElButton>
|
||||||
|
</ElFormItem>
|
||||||
|
</ElForm>
|
||||||
|
</ContentWrap>
|
||||||
|
|
||||||
|
<!-- 列表 -->
|
||||||
|
<ContentWrap title="示例分类">
|
||||||
|
<template #extra>
|
||||||
|
<TableToolbar
|
||||||
|
ref="tableToolbarRef"
|
||||||
|
v-model:hidden-search="hiddenSearchBar"
|
||||||
|
>
|
||||||
|
<ElButton @click="toggleExpand" class="mr-2">
|
||||||
|
{{ isExpanded ? '收缩' : '展开' }}
|
||||||
|
</ElButton>
|
||||||
|
<ElButton
|
||||||
|
class="ml-2"
|
||||||
|
:icon="h(Plus)"
|
||||||
|
type="primary"
|
||||||
|
@click="handleCreate"
|
||||||
|
v-access:code="['infra:demo02-category:create']"
|
||||||
|
>
|
||||||
|
{{ $t('ui.actionTitle.create', ['示例分类']) }}
|
||||||
|
</ElButton>
|
||||||
|
<ElButton
|
||||||
|
:icon="h(Download)"
|
||||||
|
type="primary"
|
||||||
|
class="ml-2"
|
||||||
|
:loading="exportLoading"
|
||||||
|
@click="onExport"
|
||||||
|
v-access:code="['infra:demo02-category:export']"
|
||||||
|
>
|
||||||
|
{{ $t('ui.actionTitle.export') }}
|
||||||
|
</ElButton>
|
||||||
|
</TableToolbar>
|
||||||
|
</template>
|
||||||
|
<VxeTable
|
||||||
|
ref="tableRef"
|
||||||
|
:data="list"
|
||||||
|
:tree-config="{
|
||||||
|
parentField: 'parentId',
|
||||||
|
rowField: 'id',
|
||||||
|
transform: true,
|
||||||
|
expandAll: true,
|
||||||
|
reserve: true,
|
||||||
|
}"
|
||||||
|
show-overflow
|
||||||
|
:loading="loading"
|
||||||
|
>
|
||||||
|
<VxeColumn field="id" title="编号" align="center" />
|
||||||
|
<VxeColumn field="name" title="名字" align="center" tree-node />
|
||||||
|
<VxeColumn field="parentId" title="父级编号" align="center" />
|
||||||
|
<VxeColumn field="createTime" title="创建时间" align="center">
|
||||||
|
<template #default="{ row }">
|
||||||
|
{{ formatDateTime(row.createTime) }}
|
||||||
|
</template>
|
||||||
|
</VxeColumn>
|
||||||
|
<VxeColumn field="operation" title="操作" align="center">
|
||||||
|
<template #default="{ row }">
|
||||||
|
<ElButton
|
||||||
|
size="small"
|
||||||
|
type="primary"
|
||||||
|
link
|
||||||
|
@click="handleAppend(row as any)"
|
||||||
|
v-access:code="['infra:demo02-category:create']"
|
||||||
|
>
|
||||||
|
新增下级
|
||||||
|
</ElButton>
|
||||||
|
<ElButton
|
||||||
|
size="small"
|
||||||
|
type="primary"
|
||||||
|
link
|
||||||
|
@click="handleEdit(row as any)"
|
||||||
|
v-access:code="['infra:demo02-category:update']"
|
||||||
|
>
|
||||||
|
{{ $t('ui.actionTitle.edit') }}
|
||||||
|
</ElButton>
|
||||||
|
<ElButton
|
||||||
|
size="small"
|
||||||
|
type="danger"
|
||||||
|
link
|
||||||
|
class="ml-2"
|
||||||
|
:disabled="!isEmpty(row?.children)"
|
||||||
|
@click="handleDelete(row as any)"
|
||||||
|
v-access:code="['infra:demo02-category:delete']"
|
||||||
|
>
|
||||||
|
{{ $t('ui.actionTitle.delete') }}
|
||||||
|
</ElButton>
|
||||||
|
</template>
|
||||||
|
</VxeColumn>
|
||||||
|
</VxeTable>
|
||||||
|
</ContentWrap>
|
||||||
|
</Page>
|
||||||
|
</template>
|
||||||
|
|
@ -0,0 +1,138 @@
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import type { FormRules } from 'element-plus';
|
||||||
|
|
||||||
|
import type { Demo02CategoryApi } from '#/api/infra/demo/demo02';
|
||||||
|
|
||||||
|
import { computed, reactive, ref } from 'vue';
|
||||||
|
|
||||||
|
import { useVbenModal } from '@vben/common-ui';
|
||||||
|
import { handleTree } from '@vben/utils';
|
||||||
|
|
||||||
|
import {
|
||||||
|
ElForm,
|
||||||
|
ElFormItem,
|
||||||
|
ElInput,
|
||||||
|
ElMessage,
|
||||||
|
ElTreeSelect,
|
||||||
|
} from 'element-plus';
|
||||||
|
|
||||||
|
import {
|
||||||
|
createDemo02Category,
|
||||||
|
getDemo02Category,
|
||||||
|
getDemo02CategoryList,
|
||||||
|
updateDemo02Category,
|
||||||
|
} from '#/api/infra/demo/demo02';
|
||||||
|
import { $t } from '#/locales';
|
||||||
|
|
||||||
|
const emit = defineEmits(['success']);
|
||||||
|
|
||||||
|
const formRef = ref();
|
||||||
|
const formData = ref<Partial<Demo02CategoryApi.Demo02Category>>({
|
||||||
|
id: undefined,
|
||||||
|
name: undefined,
|
||||||
|
parentId: undefined,
|
||||||
|
});
|
||||||
|
const rules = reactive<FormRules>({
|
||||||
|
name: [{ required: true, message: '名字不能为空', trigger: 'blur' }],
|
||||||
|
parentId: [{ required: true, message: '父级编号不能为空', trigger: 'blur' }],
|
||||||
|
});
|
||||||
|
const demo02CategoryTree = ref<any[]>([]); // 树形结构
|
||||||
|
const getTitle = computed(() => {
|
||||||
|
return formData.value?.id
|
||||||
|
? $t('ui.actionTitle.edit', ['示例分类'])
|
||||||
|
: $t('ui.actionTitle.create', ['示例分类']);
|
||||||
|
});
|
||||||
|
|
||||||
|
/** 重置表单 */
|
||||||
|
const resetForm = () => {
|
||||||
|
formData.value = {
|
||||||
|
id: undefined,
|
||||||
|
name: undefined,
|
||||||
|
parentId: undefined,
|
||||||
|
};
|
||||||
|
formRef.value?.resetFields();
|
||||||
|
};
|
||||||
|
|
||||||
|
/** 获得示例分类树 */
|
||||||
|
const getDemo02CategoryTree = async () => {
|
||||||
|
demo02CategoryTree.value = [];
|
||||||
|
const data = await getDemo02CategoryList({});
|
||||||
|
data.unshift({
|
||||||
|
id: 0,
|
||||||
|
name: '顶级示例分类',
|
||||||
|
});
|
||||||
|
demo02CategoryTree.value = handleTree(data);
|
||||||
|
};
|
||||||
|
|
||||||
|
const [Modal, modalApi] = useVbenModal({
|
||||||
|
async onConfirm() {
|
||||||
|
await formRef.value?.validate();
|
||||||
|
modalApi.lock();
|
||||||
|
// 提交表单
|
||||||
|
const data = formData.value as Demo02CategoryApi.Demo02Category;
|
||||||
|
try {
|
||||||
|
await (formData.value?.id
|
||||||
|
? updateDemo02Category(data)
|
||||||
|
: createDemo02Category(data));
|
||||||
|
// 关闭并提示
|
||||||
|
await modalApi.close();
|
||||||
|
emit('success');
|
||||||
|
ElMessage.success($t('ui.actionMessage.operationSuccess'));
|
||||||
|
} finally {
|
||||||
|
modalApi.unlock();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
async onOpenChange(isOpen: boolean) {
|
||||||
|
if (!isOpen) {
|
||||||
|
resetForm();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 加载数据
|
||||||
|
let data = modalApi.getData<Demo02CategoryApi.Demo02Category>();
|
||||||
|
if (!data) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (data.id) {
|
||||||
|
modalApi.lock();
|
||||||
|
try {
|
||||||
|
data = await getDemo02Category(data.id);
|
||||||
|
} finally {
|
||||||
|
modalApi.unlock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
formData.value = data;
|
||||||
|
// 加载树数据
|
||||||
|
await getDemo02CategoryTree();
|
||||||
|
},
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<Modal :title="getTitle">
|
||||||
|
<ElForm
|
||||||
|
ref="formRef"
|
||||||
|
:model="formData"
|
||||||
|
:rules="rules"
|
||||||
|
label-width="120px"
|
||||||
|
label-position="right"
|
||||||
|
>
|
||||||
|
<ElFormItem label="名字" prop="name">
|
||||||
|
<ElInput v-model="formData.name" placeholder="请输入名字" />
|
||||||
|
</ElFormItem>
|
||||||
|
<ElFormItem label="父级编号" prop="parentId">
|
||||||
|
<ElTreeSelect
|
||||||
|
v-model="formData.parentId"
|
||||||
|
:data="demo02CategoryTree"
|
||||||
|
:props="{
|
||||||
|
label: 'name',
|
||||||
|
value: 'id',
|
||||||
|
children: 'children',
|
||||||
|
}"
|
||||||
|
check-strictly
|
||||||
|
default-expand-all
|
||||||
|
placeholder="请选择父级编号"
|
||||||
|
/>
|
||||||
|
</ElFormItem>
|
||||||
|
</ElForm>
|
||||||
|
</Modal>
|
||||||
|
</template>
|
||||||
|
|
@ -0,0 +1,344 @@
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import type { Demo03StudentApi } from '#/api/infra/demo/demo03/erp';
|
||||||
|
|
||||||
|
import { h, onMounted, reactive, ref } from 'vue';
|
||||||
|
|
||||||
|
import { Page, useVbenModal } from '@vben/common-ui';
|
||||||
|
import { Download, Plus, Trash2 } from '@vben/icons';
|
||||||
|
import {
|
||||||
|
cloneDeep,
|
||||||
|
downloadFileFromBlobPart,
|
||||||
|
formatDateTime,
|
||||||
|
isEmpty,
|
||||||
|
} from '@vben/utils';
|
||||||
|
|
||||||
|
import {
|
||||||
|
ElButton,
|
||||||
|
ElDatePicker,
|
||||||
|
ElForm,
|
||||||
|
ElFormItem,
|
||||||
|
ElInput,
|
||||||
|
ElLoading,
|
||||||
|
ElMessage,
|
||||||
|
ElOption,
|
||||||
|
ElPagination,
|
||||||
|
ElSelect,
|
||||||
|
ElTabPane,
|
||||||
|
ElTabs,
|
||||||
|
} from 'element-plus';
|
||||||
|
|
||||||
|
import { VxeColumn, VxeTable } from '#/adapter/vxe-table';
|
||||||
|
import {
|
||||||
|
deleteDemo03Student,
|
||||||
|
deleteDemo03StudentList,
|
||||||
|
exportDemo03Student,
|
||||||
|
getDemo03StudentPage,
|
||||||
|
} from '#/api/infra/demo/demo03/erp';
|
||||||
|
import { ContentWrap } from '#/components/content-wrap';
|
||||||
|
import { DictTag } from '#/components/dict-tag';
|
||||||
|
import { TableToolbar } from '#/components/table-toolbar';
|
||||||
|
import { useTableToolbar } from '#/hooks';
|
||||||
|
import { $t } from '#/locales';
|
||||||
|
import { DICT_TYPE, getDictOptions } from '#/utils';
|
||||||
|
|
||||||
|
import Demo03CourseList from './modules/demo03-course-list.vue';
|
||||||
|
import Demo03GradeList from './modules/demo03-grade-list.vue';
|
||||||
|
import Demo03StudentForm from './modules/form.vue';
|
||||||
|
|
||||||
|
/** 子表的列表 */
|
||||||
|
const subTabsName = ref('demo03Course');
|
||||||
|
const selectDemo03Student = ref<Demo03StudentApi.Demo03Student>();
|
||||||
|
async function onCellClick({ row }: { row: Demo03StudentApi.Demo03Student }) {
|
||||||
|
selectDemo03Student.value = row;
|
||||||
|
}
|
||||||
|
|
||||||
|
const loading = ref(true); // 列表的加载中
|
||||||
|
const list = ref<Demo03StudentApi.Demo03Student[]>([]); // 列表的数据
|
||||||
|
|
||||||
|
const total = ref(0); // 列表的总页数
|
||||||
|
const queryParams = reactive({
|
||||||
|
pageNo: 1,
|
||||||
|
pageSize: 10,
|
||||||
|
name: undefined,
|
||||||
|
sex: undefined,
|
||||||
|
description: undefined,
|
||||||
|
createTime: undefined,
|
||||||
|
});
|
||||||
|
const queryFormRef = ref(); // 搜索的表单
|
||||||
|
const exportLoading = ref(false); // 导出的加载中
|
||||||
|
|
||||||
|
/** 查询列表 */
|
||||||
|
const getList = async () => {
|
||||||
|
loading.value = true;
|
||||||
|
try {
|
||||||
|
const params = cloneDeep(queryParams) as any;
|
||||||
|
if (params.createTime && Array.isArray(params.createTime)) {
|
||||||
|
params.createTime = (params.createTime as string[]).join(',');
|
||||||
|
}
|
||||||
|
const data = await getDemo03StudentPage(params);
|
||||||
|
list.value = data.list;
|
||||||
|
total.value = data.total;
|
||||||
|
} finally {
|
||||||
|
loading.value = false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/** 搜索按钮操作 */
|
||||||
|
const handleQuery = () => {
|
||||||
|
queryParams.pageNo = 1;
|
||||||
|
getList();
|
||||||
|
};
|
||||||
|
|
||||||
|
/** 重置按钮操作 */
|
||||||
|
const resetQuery = () => {
|
||||||
|
queryFormRef.value.resetFields();
|
||||||
|
handleQuery();
|
||||||
|
};
|
||||||
|
|
||||||
|
const [FormModal, formModalApi] = useVbenModal({
|
||||||
|
connectedComponent: Demo03StudentForm,
|
||||||
|
destroyOnClose: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
/** 创建学生 */
|
||||||
|
function handleCreate() {
|
||||||
|
formModalApi.setData({}).open();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 编辑学生 */
|
||||||
|
function handleEdit(row: Demo03StudentApi.Demo03Student) {
|
||||||
|
formModalApi.setData(row).open();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 删除学生 */
|
||||||
|
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 as number);
|
||||||
|
ElMessage.success($t('ui.actionMessage.deleteSuccess', [row.id]));
|
||||||
|
await getList();
|
||||||
|
} finally {
|
||||||
|
loadingInstance.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 批量删除学生 */
|
||||||
|
async function handleDeleteBatch() {
|
||||||
|
const loadingInstance = ElLoading.service({
|
||||||
|
text: $t('ui.actionMessage.deleting'),
|
||||||
|
background: 'rgba(0, 0, 0, 0.7)',
|
||||||
|
});
|
||||||
|
try {
|
||||||
|
await deleteDemo03StudentList(checkedIds.value);
|
||||||
|
ElMessage.success($t('ui.actionMessage.deleteSuccess'));
|
||||||
|
await getList();
|
||||||
|
} finally {
|
||||||
|
loadingInstance.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const checkedIds = ref<number[]>([]);
|
||||||
|
function handleRowCheckboxChange({
|
||||||
|
records,
|
||||||
|
}: {
|
||||||
|
records: Demo03StudentApi.Demo03Student[];
|
||||||
|
}) {
|
||||||
|
checkedIds.value = records.map((item) => item.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 导出表格 */
|
||||||
|
async function onExport() {
|
||||||
|
try {
|
||||||
|
exportLoading.value = true;
|
||||||
|
const data = await exportDemo03Student(queryParams);
|
||||||
|
downloadFileFromBlobPart({ fileName: '学生.xls', source: data });
|
||||||
|
} finally {
|
||||||
|
exportLoading.value = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 初始化 */
|
||||||
|
const { hiddenSearchBar, tableToolbarRef, tableRef } = useTableToolbar();
|
||||||
|
onMounted(() => {
|
||||||
|
getList();
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<Page auto-content-height>
|
||||||
|
<FormModal @success="getList" />
|
||||||
|
|
||||||
|
<ContentWrap v-if="!hiddenSearchBar">
|
||||||
|
<!-- 搜索工作栏 -->
|
||||||
|
<ElForm :model="queryParams" ref="queryFormRef" inline>
|
||||||
|
<ElFormItem label="名字">
|
||||||
|
<ElInput
|
||||||
|
v-model="queryParams.name"
|
||||||
|
placeholder="请输入名字"
|
||||||
|
clearable
|
||||||
|
@keyup.enter="handleQuery"
|
||||||
|
class="!w-[240px]"
|
||||||
|
/>
|
||||||
|
</ElFormItem>
|
||||||
|
<ElFormItem label="性别">
|
||||||
|
<ElSelect
|
||||||
|
v-model="queryParams.sex"
|
||||||
|
placeholder="请选择性别"
|
||||||
|
clearable
|
||||||
|
class="!w-[240px]"
|
||||||
|
>
|
||||||
|
<ElOption
|
||||||
|
v-for="dict in getDictOptions(
|
||||||
|
DICT_TYPE.SYSTEM_USER_SEX,
|
||||||
|
'number',
|
||||||
|
)"
|
||||||
|
:key="dict.value"
|
||||||
|
:value="dict.value"
|
||||||
|
:label="dict.label"
|
||||||
|
/>
|
||||||
|
</ElSelect>
|
||||||
|
</ElFormItem>
|
||||||
|
<ElFormItem label="创建时间">
|
||||||
|
<ElDatePicker
|
||||||
|
v-model="queryParams.createTime"
|
||||||
|
type="daterange"
|
||||||
|
value-format="YYYY-MM-DD"
|
||||||
|
range-separator="至"
|
||||||
|
start-placeholder="开始日期"
|
||||||
|
end-placeholder="结束日期"
|
||||||
|
class="!w-[240px]"
|
||||||
|
/>
|
||||||
|
</ElFormItem>
|
||||||
|
<ElFormItem>
|
||||||
|
<ElButton class="ml-2" @click="resetQuery"> 重置 </ElButton>
|
||||||
|
<ElButton class="ml-2" @click="handleQuery" type="primary">
|
||||||
|
搜索
|
||||||
|
</ElButton>
|
||||||
|
</ElFormItem>
|
||||||
|
</ElForm>
|
||||||
|
</ContentWrap>
|
||||||
|
|
||||||
|
<!-- 列表 -->
|
||||||
|
<ContentWrap title="学生">
|
||||||
|
<template #extra>
|
||||||
|
<TableToolbar
|
||||||
|
ref="tableToolbarRef"
|
||||||
|
v-model:hidden-search="hiddenSearchBar"
|
||||||
|
>
|
||||||
|
<ElButton
|
||||||
|
class="ml-2"
|
||||||
|
:icon="h(Plus)"
|
||||||
|
type="primary"
|
||||||
|
@click="handleCreate"
|
||||||
|
v-access:code="['infra:demo03-student:create']"
|
||||||
|
>
|
||||||
|
{{ $t('ui.actionTitle.create', ['学生']) }}
|
||||||
|
</ElButton>
|
||||||
|
<ElButton
|
||||||
|
:icon="h(Download)"
|
||||||
|
type="primary"
|
||||||
|
class="ml-2"
|
||||||
|
:loading="exportLoading"
|
||||||
|
@click="onExport"
|
||||||
|
v-access:code="['infra:demo03-student:export']"
|
||||||
|
>
|
||||||
|
{{ $t('ui.actionTitle.export') }}
|
||||||
|
</ElButton>
|
||||||
|
<ElButton
|
||||||
|
:icon="h(Trash2)"
|
||||||
|
type="danger"
|
||||||
|
class="ml-2"
|
||||||
|
:disabled="isEmpty(checkedIds)"
|
||||||
|
@click="handleDeleteBatch"
|
||||||
|
v-access:code="['infra:demo03-student:delete']"
|
||||||
|
>
|
||||||
|
批量删除
|
||||||
|
</ElButton>
|
||||||
|
</TableToolbar>
|
||||||
|
</template>
|
||||||
|
<VxeTable
|
||||||
|
ref="tableRef"
|
||||||
|
:data="list"
|
||||||
|
@cell-click="onCellClick"
|
||||||
|
:row-config="{
|
||||||
|
keyField: 'id',
|
||||||
|
isHover: true,
|
||||||
|
isCurrent: true,
|
||||||
|
}"
|
||||||
|
show-overflow
|
||||||
|
:loading="loading"
|
||||||
|
@checkbox-all="handleRowCheckboxChange"
|
||||||
|
@checkbox-change="handleRowCheckboxChange"
|
||||||
|
>
|
||||||
|
<VxeColumn type="checkbox" width="40" />
|
||||||
|
<VxeColumn field="id" title="编号" align="center" />
|
||||||
|
<VxeColumn field="name" title="名字" align="center" />
|
||||||
|
<VxeColumn field="sex" title="性别" align="center">
|
||||||
|
<template #default="{ row }">
|
||||||
|
<DictTag :type="DICT_TYPE.SYSTEM_USER_SEX" :value="row.sex" />
|
||||||
|
</template>
|
||||||
|
</VxeColumn>
|
||||||
|
<VxeColumn field="birthday" title="出生日期" align="center">
|
||||||
|
<template #default="{ row }">
|
||||||
|
{{ formatDateTime(row.birthday) }}
|
||||||
|
</template>
|
||||||
|
</VxeColumn>
|
||||||
|
<VxeColumn field="description" title="简介" align="center" />
|
||||||
|
<VxeColumn field="createTime" title="创建时间" align="center">
|
||||||
|
<template #default="{ row }">
|
||||||
|
{{ formatDateTime(row.createTime) }}
|
||||||
|
</template>
|
||||||
|
</VxeColumn>
|
||||||
|
<VxeColumn field="operation" title="操作" align="center">
|
||||||
|
<template #default="{ row }">
|
||||||
|
<ElButton
|
||||||
|
size="small"
|
||||||
|
type="primary"
|
||||||
|
link
|
||||||
|
@click="handleEdit(row as any)"
|
||||||
|
v-access:code="['infra:demo03-student:update']"
|
||||||
|
>
|
||||||
|
{{ $t('ui.actionTitle.edit') }}
|
||||||
|
</ElButton>
|
||||||
|
<ElButton
|
||||||
|
size="small"
|
||||||
|
type="danger"
|
||||||
|
link
|
||||||
|
class="ml-2"
|
||||||
|
@click="handleDelete(row as any)"
|
||||||
|
v-access:code="['infra:demo03-student:delete']"
|
||||||
|
>
|
||||||
|
{{ $t('ui.actionTitle.delete') }}
|
||||||
|
</ElButton>
|
||||||
|
</template>
|
||||||
|
</VxeColumn>
|
||||||
|
</VxeTable>
|
||||||
|
<!-- 分页 -->
|
||||||
|
<div class="mt-2 flex justify-end">
|
||||||
|
<ElPagination
|
||||||
|
:total="total"
|
||||||
|
v-model:current-page="queryParams.pageNo"
|
||||||
|
v-model:page-size="queryParams.pageSize"
|
||||||
|
:page-sizes="[10, 20, 50, 100]"
|
||||||
|
layout="total, sizes, prev, pager, next, jumper"
|
||||||
|
@size-change="getList"
|
||||||
|
@current-change="getList"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</ContentWrap>
|
||||||
|
<ContentWrap>
|
||||||
|
<!-- 子表的表单 -->
|
||||||
|
<ElTabs v-model="subTabsName">
|
||||||
|
<ElTabPane name="demo03Course" label="学生课程">
|
||||||
|
<Demo03CourseList :student-id="selectDemo03Student?.id" />
|
||||||
|
</ElTabPane>
|
||||||
|
<ElTabPane name="demo03Grade" label="学生班级">
|
||||||
|
<Demo03GradeList :student-id="selectDemo03Student?.id" />
|
||||||
|
</ElTabPane>
|
||||||
|
</ElTabs>
|
||||||
|
</ContentWrap>
|
||||||
|
</Page>
|
||||||
|
</template>
|
||||||
|
|
@ -0,0 +1,114 @@
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import type { FormRules } from 'element-plus';
|
||||||
|
|
||||||
|
import type { Demo03StudentApi } from '#/api/infra/demo/demo03/erp';
|
||||||
|
|
||||||
|
import { computed, reactive, ref } from 'vue';
|
||||||
|
|
||||||
|
import { useVbenModal } from '@vben/common-ui';
|
||||||
|
|
||||||
|
import { ElForm, ElFormItem, ElInput, ElMessage } from 'element-plus';
|
||||||
|
|
||||||
|
import {
|
||||||
|
createDemo03Course,
|
||||||
|
getDemo03Course,
|
||||||
|
updateDemo03Course,
|
||||||
|
} from '#/api/infra/demo/demo03/erp';
|
||||||
|
import { $t } from '#/locales';
|
||||||
|
|
||||||
|
const emit = defineEmits(['success']);
|
||||||
|
const getTitle = computed(() => {
|
||||||
|
return formData.value?.id
|
||||||
|
? $t('ui.actionTitle.edit', ['学生课程'])
|
||||||
|
: $t('ui.actionTitle.create', ['学生课程']);
|
||||||
|
});
|
||||||
|
|
||||||
|
const formRef = ref();
|
||||||
|
const formData = ref<Partial<Demo03StudentApi.Demo03Course>>({
|
||||||
|
id: undefined,
|
||||||
|
studentId: undefined,
|
||||||
|
name: undefined,
|
||||||
|
score: undefined,
|
||||||
|
});
|
||||||
|
const rules = reactive<FormRules>({
|
||||||
|
studentId: [{ required: true, message: '学生编号不能为空', trigger: 'blur' }],
|
||||||
|
name: [{ required: true, message: '名字不能为空', trigger: 'blur' }],
|
||||||
|
score: [{ required: true, message: '分数不能为空', trigger: 'blur' }],
|
||||||
|
});
|
||||||
|
|
||||||
|
const [Modal, modalApi] = useVbenModal({
|
||||||
|
async onConfirm() {
|
||||||
|
await formRef.value?.validate();
|
||||||
|
|
||||||
|
modalApi.lock();
|
||||||
|
// 提交表单
|
||||||
|
const data = formData.value as Demo03StudentApi.Demo03Course;
|
||||||
|
try {
|
||||||
|
await (formData.value?.id
|
||||||
|
? updateDemo03Course(data)
|
||||||
|
: createDemo03Course(data));
|
||||||
|
// 关闭并提示
|
||||||
|
await modalApi.close();
|
||||||
|
emit('success');
|
||||||
|
ElMessage.success($t('ui.actionMessage.operationSuccess'));
|
||||||
|
} finally {
|
||||||
|
modalApi.unlock();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
async onOpenChange(isOpen: boolean) {
|
||||||
|
if (!isOpen) {
|
||||||
|
resetForm();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 加载数据
|
||||||
|
let data = modalApi.getData<Demo03StudentApi.Demo03Course>();
|
||||||
|
if (!data) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (data.id) {
|
||||||
|
modalApi.lock();
|
||||||
|
try {
|
||||||
|
data = await getDemo03Course(data.id);
|
||||||
|
} finally {
|
||||||
|
modalApi.unlock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 设置到 values
|
||||||
|
formData.value = data;
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
/** 重置表单 */
|
||||||
|
const resetForm = () => {
|
||||||
|
formData.value = {
|
||||||
|
id: undefined,
|
||||||
|
studentId: undefined,
|
||||||
|
name: undefined,
|
||||||
|
score: undefined,
|
||||||
|
};
|
||||||
|
formRef.value?.resetFields();
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<Modal :title="getTitle">
|
||||||
|
<ElForm
|
||||||
|
ref="formRef"
|
||||||
|
:model="formData"
|
||||||
|
:rules="rules"
|
||||||
|
label-width="120px"
|
||||||
|
label-position="right"
|
||||||
|
>
|
||||||
|
<ElFormItem label="学生编号" prop="studentId">
|
||||||
|
<ElInput v-model="formData.studentId" placeholder="请输入学生编号" />
|
||||||
|
</ElFormItem>
|
||||||
|
<ElFormItem label="名字" prop="name">
|
||||||
|
<ElInput v-model="formData.name" placeholder="请输入名字" />
|
||||||
|
</ElFormItem>
|
||||||
|
<ElFormItem label="分数" prop="score">
|
||||||
|
<ElInput v-model="formData.score" placeholder="请输入分数" />
|
||||||
|
</ElFormItem>
|
||||||
|
</ElForm>
|
||||||
|
</Modal>
|
||||||
|
</template>
|
||||||
|
|
@ -0,0 +1,297 @@
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import type { Demo03StudentApi } from '#/api/infra/demo/demo03/erp';
|
||||||
|
|
||||||
|
import { h, nextTick, onMounted, reactive, ref, watch } from 'vue';
|
||||||
|
|
||||||
|
import { useVbenModal } from '@vben/common-ui';
|
||||||
|
import { Plus, Trash2 } from '@vben/icons';
|
||||||
|
import { cloneDeep, formatDateTime, isEmpty } from '@vben/utils';
|
||||||
|
|
||||||
|
import {
|
||||||
|
ElButton,
|
||||||
|
ElDatePicker,
|
||||||
|
ElForm,
|
||||||
|
ElFormItem,
|
||||||
|
ElInput,
|
||||||
|
ElLoading,
|
||||||
|
ElMessage,
|
||||||
|
ElPagination,
|
||||||
|
} from 'element-plus';
|
||||||
|
|
||||||
|
import { VxeColumn, VxeTable } from '#/adapter/vxe-table';
|
||||||
|
import {
|
||||||
|
deleteDemo03Course,
|
||||||
|
deleteDemo03CourseList,
|
||||||
|
getDemo03CoursePage,
|
||||||
|
} from '#/api/infra/demo/demo03/erp';
|
||||||
|
import { ContentWrap } from '#/components/content-wrap';
|
||||||
|
import { TableToolbar } from '#/components/table-toolbar';
|
||||||
|
import { useTableToolbar } from '#/hooks';
|
||||||
|
import { $t } from '#/locales';
|
||||||
|
|
||||||
|
import Demo03CourseForm from './demo03-course-form.vue';
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
studentId?: number; // 学生编号(主表的关联字段)
|
||||||
|
}>();
|
||||||
|
|
||||||
|
const [FormModal, formModalApi] = useVbenModal({
|
||||||
|
connectedComponent: Demo03CourseForm,
|
||||||
|
destroyOnClose: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
/** 创建学生课程 */
|
||||||
|
function handleCreate() {
|
||||||
|
if (!props.studentId) {
|
||||||
|
ElMessage.warning('请先选择一个学生!');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
formModalApi.setData({ studentId: props.studentId }).open();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 编辑学生课程 */
|
||||||
|
function handleEdit(row: Demo03StudentApi.Demo03Course) {
|
||||||
|
formModalApi.setData(row).open();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 删除学生课程 */
|
||||||
|
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 as number);
|
||||||
|
ElMessage.success($t('ui.actionMessage.deleteSuccess', [row.id]));
|
||||||
|
await getList();
|
||||||
|
} finally {
|
||||||
|
loadingInstance.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 批量删除学生课程 */
|
||||||
|
async function handleDeleteBatch() {
|
||||||
|
const loadingInstance = ElLoading.service({
|
||||||
|
text: $t('ui.actionMessage.deleting'),
|
||||||
|
background: 'rgba(0, 0, 0, 0.7)',
|
||||||
|
});
|
||||||
|
try {
|
||||||
|
await deleteDemo03CourseList(checkedIds.value);
|
||||||
|
ElMessage.success($t('ui.actionMessage.deleteSuccess'));
|
||||||
|
await getList();
|
||||||
|
} finally {
|
||||||
|
loadingInstance.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const checkedIds = ref<number[]>([]);
|
||||||
|
function handleRowCheckboxChange({
|
||||||
|
records,
|
||||||
|
}: {
|
||||||
|
records: Demo03StudentApi.Demo03Course[];
|
||||||
|
}) {
|
||||||
|
checkedIds.value = records.map((item) => item.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
const loading = ref(true); // 列表的加载中
|
||||||
|
const list = ref<Demo03StudentApi.Demo03Course[]>([]); // 列表的数据
|
||||||
|
const total = ref(0); // 列表的总页数
|
||||||
|
const queryFormRef = ref(); // 搜索的表单
|
||||||
|
const queryParams = reactive({
|
||||||
|
pageNo: 1,
|
||||||
|
pageSize: 10,
|
||||||
|
studentId: undefined,
|
||||||
|
name: undefined,
|
||||||
|
score: undefined,
|
||||||
|
createTime: undefined,
|
||||||
|
});
|
||||||
|
|
||||||
|
/** 搜索按钮操作 */
|
||||||
|
const handleQuery = () => {
|
||||||
|
queryParams.pageNo = 1;
|
||||||
|
getList();
|
||||||
|
};
|
||||||
|
|
||||||
|
/** 重置按钮操作 */
|
||||||
|
const resetQuery = () => {
|
||||||
|
queryFormRef.value.resetFields();
|
||||||
|
handleQuery();
|
||||||
|
};
|
||||||
|
/** 查询列表 */
|
||||||
|
const getList = async () => {
|
||||||
|
loading.value = true;
|
||||||
|
try {
|
||||||
|
if (!props.studentId) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
const params = cloneDeep(queryParams) as any;
|
||||||
|
if (params.createTime && Array.isArray(params.createTime)) {
|
||||||
|
params.createTime = (params.createTime as string[]).join(',');
|
||||||
|
}
|
||||||
|
params.studentId = props.studentId;
|
||||||
|
const data = await getDemo03CoursePage(params);
|
||||||
|
list.value = data.list;
|
||||||
|
total.value = data.total;
|
||||||
|
} finally {
|
||||||
|
loading.value = false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/** 监听主表的关联字段的变化,加载对应的子表数据 */
|
||||||
|
watch(
|
||||||
|
() => props.studentId,
|
||||||
|
async (val) => {
|
||||||
|
if (!val) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await nextTick();
|
||||||
|
await getList();
|
||||||
|
},
|
||||||
|
{ immediate: true },
|
||||||
|
);
|
||||||
|
|
||||||
|
/** 初始化 */
|
||||||
|
const { hiddenSearchBar, tableToolbarRef, tableRef } = useTableToolbar();
|
||||||
|
onMounted(() => {
|
||||||
|
getList();
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<FormModal @success="getList" />
|
||||||
|
<div class="h-[600px]">
|
||||||
|
<ContentWrap v-if="!hiddenSearchBar">
|
||||||
|
<!-- 搜索工作栏 -->
|
||||||
|
<ElForm :model="queryParams" ref="queryFormRef" inline>
|
||||||
|
<ElFormItem label="学生编号">
|
||||||
|
<ElInput
|
||||||
|
v-model="queryParams.studentId"
|
||||||
|
placeholder="请输入学生编号"
|
||||||
|
clearable
|
||||||
|
@keyup.enter="handleQuery"
|
||||||
|
class="!w-[240px]"
|
||||||
|
/>
|
||||||
|
</ElFormItem>
|
||||||
|
<ElFormItem label="名字">
|
||||||
|
<ElInput
|
||||||
|
v-model="queryParams.name"
|
||||||
|
placeholder="请输入名字"
|
||||||
|
clearable
|
||||||
|
@keyup.enter="handleQuery"
|
||||||
|
class="!w-[240px]"
|
||||||
|
/>
|
||||||
|
</ElFormItem>
|
||||||
|
<ElFormItem label="分数">
|
||||||
|
<ElInput
|
||||||
|
v-model="queryParams.score"
|
||||||
|
placeholder="请输入分数"
|
||||||
|
clearable
|
||||||
|
@keyup.enter="handleQuery"
|
||||||
|
class="!w-[240px]"
|
||||||
|
/>
|
||||||
|
</ElFormItem>
|
||||||
|
<ElFormItem label="创建时间">
|
||||||
|
<ElDatePicker
|
||||||
|
v-model="queryParams.createTime"
|
||||||
|
type="daterange"
|
||||||
|
value-format="YYYY-MM-DD"
|
||||||
|
range-separator="至"
|
||||||
|
start-placeholder="开始日期"
|
||||||
|
end-placeholder="结束日期"
|
||||||
|
class="!w-[240px]"
|
||||||
|
/>
|
||||||
|
</ElFormItem>
|
||||||
|
<ElFormItem>
|
||||||
|
<ElButton class="ml-2" @click="resetQuery"> 重置 </ElButton>
|
||||||
|
<ElButton class="ml-2" @click="handleQuery" type="primary">
|
||||||
|
搜索
|
||||||
|
</ElButton>
|
||||||
|
</ElFormItem>
|
||||||
|
</ElForm>
|
||||||
|
</ContentWrap>
|
||||||
|
|
||||||
|
<!-- 列表 -->
|
||||||
|
<ContentWrap title="学生">
|
||||||
|
<template #extra>
|
||||||
|
<TableToolbar
|
||||||
|
ref="tableToolbarRef"
|
||||||
|
v-model:hidden-search="hiddenSearchBar"
|
||||||
|
>
|
||||||
|
<ElButton
|
||||||
|
class="ml-2"
|
||||||
|
:icon="h(Plus)"
|
||||||
|
type="primary"
|
||||||
|
@click="handleCreate"
|
||||||
|
v-access:code="['infra:demo03-student:create']"
|
||||||
|
>
|
||||||
|
{{ $t('ui.actionTitle.create', ['学生']) }}
|
||||||
|
</ElButton>
|
||||||
|
<ElButton
|
||||||
|
:icon="h(Trash2)"
|
||||||
|
type="danger"
|
||||||
|
class="ml-2"
|
||||||
|
:disabled="isEmpty(checkedIds)"
|
||||||
|
@click="handleDeleteBatch"
|
||||||
|
v-access:code="['infra:demo03-student:delete']"
|
||||||
|
>
|
||||||
|
批量删除
|
||||||
|
</ElButton>
|
||||||
|
</TableToolbar>
|
||||||
|
</template>
|
||||||
|
<VxeTable
|
||||||
|
ref="tableRef"
|
||||||
|
:data="list"
|
||||||
|
show-overflow
|
||||||
|
:loading="loading"
|
||||||
|
@checkbox-all="handleRowCheckboxChange"
|
||||||
|
@checkbox-change="handleRowCheckboxChange"
|
||||||
|
>
|
||||||
|
<VxeColumn type="checkbox" width="40" />
|
||||||
|
<VxeColumn field="id" title="编号" align="center" />
|
||||||
|
<VxeColumn field="studentId" title="学生编号" align="center" />
|
||||||
|
<VxeColumn field="name" title="名字" align="center" />
|
||||||
|
<VxeColumn field="score" title="分数" align="center" />
|
||||||
|
<VxeColumn field="createTime" title="创建时间" align="center">
|
||||||
|
<template #default="{ row }">
|
||||||
|
{{ formatDateTime(row.createTime) }}
|
||||||
|
</template>
|
||||||
|
</VxeColumn>
|
||||||
|
<VxeColumn field="operation" title="操作" align="center">
|
||||||
|
<template #default="{ row }">
|
||||||
|
<ElButton
|
||||||
|
size="small"
|
||||||
|
type="primary"
|
||||||
|
link
|
||||||
|
@click="handleEdit(row as any)"
|
||||||
|
v-access:code="['infra:demo03-student:update']"
|
||||||
|
>
|
||||||
|
{{ $t('ui.actionTitle.edit') }}
|
||||||
|
</ElButton>
|
||||||
|
<ElButton
|
||||||
|
size="small"
|
||||||
|
type="danger"
|
||||||
|
link
|
||||||
|
class="ml-2"
|
||||||
|
@click="handleDelete(row as any)"
|
||||||
|
v-access:code="['infra:demo03-student:delete']"
|
||||||
|
>
|
||||||
|
{{ $t('ui.actionTitle.delete') }}
|
||||||
|
</ElButton>
|
||||||
|
</template>
|
||||||
|
</VxeColumn>
|
||||||
|
</VxeTable>
|
||||||
|
<!-- 分页 -->
|
||||||
|
<div class="mt-2 flex justify-end">
|
||||||
|
<ElPagination
|
||||||
|
:total="total"
|
||||||
|
v-model:current-page="queryParams.pageNo"
|
||||||
|
v-model:page-size="queryParams.pageSize"
|
||||||
|
:page-sizes="[10, 20, 50, 100]"
|
||||||
|
layout="total, sizes, prev, pager, next, jumper"
|
||||||
|
@size-change="getList"
|
||||||
|
@current-change="getList"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</ContentWrap>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
@ -0,0 +1,114 @@
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import type { FormRules } from 'element-plus';
|
||||||
|
|
||||||
|
import type { Demo03StudentApi } from '#/api/infra/demo/demo03/erp';
|
||||||
|
|
||||||
|
import { computed, reactive, ref } from 'vue';
|
||||||
|
|
||||||
|
import { useVbenModal } from '@vben/common-ui';
|
||||||
|
|
||||||
|
import { ElForm, ElFormItem, ElInput, ElMessage } from 'element-plus';
|
||||||
|
|
||||||
|
import {
|
||||||
|
createDemo03Grade,
|
||||||
|
getDemo03Grade,
|
||||||
|
updateDemo03Grade,
|
||||||
|
} from '#/api/infra/demo/demo03/erp';
|
||||||
|
import { $t } from '#/locales';
|
||||||
|
|
||||||
|
const emit = defineEmits(['success']);
|
||||||
|
const getTitle = computed(() => {
|
||||||
|
return formData.value?.id
|
||||||
|
? $t('ui.actionTitle.edit', ['学生班级'])
|
||||||
|
: $t('ui.actionTitle.create', ['学生班级']);
|
||||||
|
});
|
||||||
|
|
||||||
|
const formRef = ref();
|
||||||
|
const formData = ref<Partial<Demo03StudentApi.Demo03Grade>>({
|
||||||
|
id: undefined,
|
||||||
|
studentId: undefined,
|
||||||
|
name: undefined,
|
||||||
|
teacher: undefined,
|
||||||
|
});
|
||||||
|
const rules = reactive<FormRules>({
|
||||||
|
studentId: [{ required: true, message: '学生编号不能为空', trigger: 'blur' }],
|
||||||
|
name: [{ required: true, message: '名字不能为空', trigger: 'blur' }],
|
||||||
|
teacher: [{ required: true, message: '班主任不能为空', trigger: 'blur' }],
|
||||||
|
});
|
||||||
|
|
||||||
|
const [Modal, modalApi] = useVbenModal({
|
||||||
|
async onConfirm() {
|
||||||
|
await formRef.value?.validate();
|
||||||
|
|
||||||
|
modalApi.lock();
|
||||||
|
// 提交表单
|
||||||
|
const data = formData.value as Demo03StudentApi.Demo03Grade;
|
||||||
|
try {
|
||||||
|
await (formData.value?.id
|
||||||
|
? updateDemo03Grade(data)
|
||||||
|
: createDemo03Grade(data));
|
||||||
|
// 关闭并提示
|
||||||
|
await modalApi.close();
|
||||||
|
emit('success');
|
||||||
|
ElMessage.success($t('ui.actionMessage.operationSuccess'));
|
||||||
|
} finally {
|
||||||
|
modalApi.unlock();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
async onOpenChange(isOpen: boolean) {
|
||||||
|
if (!isOpen) {
|
||||||
|
resetForm();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 加载数据
|
||||||
|
let data = modalApi.getData<Demo03StudentApi.Demo03Grade>();
|
||||||
|
if (!data) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (data.id) {
|
||||||
|
modalApi.lock();
|
||||||
|
try {
|
||||||
|
data = await getDemo03Grade(data.id);
|
||||||
|
} finally {
|
||||||
|
modalApi.unlock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 设置到 values
|
||||||
|
formData.value = data;
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
/** 重置表单 */
|
||||||
|
const resetForm = () => {
|
||||||
|
formData.value = {
|
||||||
|
id: undefined,
|
||||||
|
studentId: undefined,
|
||||||
|
name: undefined,
|
||||||
|
teacher: undefined,
|
||||||
|
};
|
||||||
|
formRef.value?.resetFields();
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<Modal :title="getTitle">
|
||||||
|
<ElForm
|
||||||
|
ref="formRef"
|
||||||
|
:model="formData"
|
||||||
|
:rules="rules"
|
||||||
|
label-width="120px"
|
||||||
|
label-position="right"
|
||||||
|
>
|
||||||
|
<ElFormItem label="学生编号" prop="studentId">
|
||||||
|
<ElInput v-model="formData.studentId" placeholder="请输入学生编号" />
|
||||||
|
</ElFormItem>
|
||||||
|
<ElFormItem label="名字" prop="name">
|
||||||
|
<ElInput v-model="formData.name" placeholder="请输入名字" />
|
||||||
|
</ElFormItem>
|
||||||
|
<ElFormItem label="班主任" prop="teacher">
|
||||||
|
<ElInput v-model="formData.teacher" placeholder="请输入班主任" />
|
||||||
|
</ElFormItem>
|
||||||
|
</ElForm>
|
||||||
|
</Modal>
|
||||||
|
</template>
|
||||||
|
|
@ -0,0 +1,297 @@
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import type { Demo03StudentApi } from '#/api/infra/demo/demo03/erp';
|
||||||
|
|
||||||
|
import { h, nextTick, onMounted, reactive, ref, watch } from 'vue';
|
||||||
|
|
||||||
|
import { useVbenModal } from '@vben/common-ui';
|
||||||
|
import { Plus, Trash2 } from '@vben/icons';
|
||||||
|
import { cloneDeep, formatDateTime, isEmpty } from '@vben/utils';
|
||||||
|
|
||||||
|
import {
|
||||||
|
ElButton,
|
||||||
|
ElDatePicker,
|
||||||
|
ElForm,
|
||||||
|
ElFormItem,
|
||||||
|
ElInput,
|
||||||
|
ElLoading,
|
||||||
|
ElMessage,
|
||||||
|
ElPagination,
|
||||||
|
} from 'element-plus';
|
||||||
|
|
||||||
|
import { VxeColumn, VxeTable } from '#/adapter/vxe-table';
|
||||||
|
import {
|
||||||
|
deleteDemo03Grade,
|
||||||
|
deleteDemo03GradeList,
|
||||||
|
getDemo03GradePage,
|
||||||
|
} from '#/api/infra/demo/demo03/erp';
|
||||||
|
import { ContentWrap } from '#/components/content-wrap';
|
||||||
|
import { TableToolbar } from '#/components/table-toolbar';
|
||||||
|
import { useTableToolbar } from '#/hooks';
|
||||||
|
import { $t } from '#/locales';
|
||||||
|
|
||||||
|
import Demo03GradeForm from './demo03-grade-form.vue';
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
studentId?: number; // 学生编号(主表的关联字段)
|
||||||
|
}>();
|
||||||
|
|
||||||
|
const [FormModal, formModalApi] = useVbenModal({
|
||||||
|
connectedComponent: Demo03GradeForm,
|
||||||
|
destroyOnClose: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
/** 创建学生班级 */
|
||||||
|
function handleCreate() {
|
||||||
|
if (!props.studentId) {
|
||||||
|
ElMessage.warning('请先选择一个学生!');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
formModalApi.setData({ studentId: props.studentId }).open();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 编辑学生班级 */
|
||||||
|
function handleEdit(row: Demo03StudentApi.Demo03Grade) {
|
||||||
|
formModalApi.setData(row).open();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 删除学生班级 */
|
||||||
|
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 as number);
|
||||||
|
ElMessage.success($t('ui.actionMessage.deleteSuccess', [row.id]));
|
||||||
|
await getList();
|
||||||
|
} finally {
|
||||||
|
loadingInstance.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 批量删除学生班级 */
|
||||||
|
async function handleDeleteBatch() {
|
||||||
|
const loadingInstance = ElLoading.service({
|
||||||
|
text: $t('ui.actionMessage.deleting'),
|
||||||
|
background: 'rgba(0, 0, 0, 0.7)',
|
||||||
|
});
|
||||||
|
try {
|
||||||
|
await deleteDemo03GradeList(checkedIds.value);
|
||||||
|
ElMessage.success($t('ui.actionMessage.deleteSuccess'));
|
||||||
|
await getList();
|
||||||
|
} finally {
|
||||||
|
loadingInstance.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const checkedIds = ref<number[]>([]);
|
||||||
|
function handleRowCheckboxChange({
|
||||||
|
records,
|
||||||
|
}: {
|
||||||
|
records: Demo03StudentApi.Demo03Grade[];
|
||||||
|
}) {
|
||||||
|
checkedIds.value = records.map((item) => item.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
const loading = ref(true); // 列表的加载中
|
||||||
|
const list = ref<Demo03StudentApi.Demo03Grade[]>([]); // 列表的数据
|
||||||
|
const total = ref(0); // 列表的总页数
|
||||||
|
const queryFormRef = ref(); // 搜索的表单
|
||||||
|
const queryParams = reactive({
|
||||||
|
pageNo: 1,
|
||||||
|
pageSize: 10,
|
||||||
|
studentId: undefined,
|
||||||
|
name: undefined,
|
||||||
|
teacher: undefined,
|
||||||
|
createTime: undefined,
|
||||||
|
});
|
||||||
|
|
||||||
|
/** 搜索按钮操作 */
|
||||||
|
const handleQuery = () => {
|
||||||
|
queryParams.pageNo = 1;
|
||||||
|
getList();
|
||||||
|
};
|
||||||
|
|
||||||
|
/** 重置按钮操作 */
|
||||||
|
const resetQuery = () => {
|
||||||
|
queryFormRef.value.resetFields();
|
||||||
|
handleQuery();
|
||||||
|
};
|
||||||
|
/** 查询列表 */
|
||||||
|
const getList = async () => {
|
||||||
|
loading.value = true;
|
||||||
|
try {
|
||||||
|
if (!props.studentId) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
const params = cloneDeep(queryParams) as any;
|
||||||
|
if (params.createTime && Array.isArray(params.createTime)) {
|
||||||
|
params.createTime = (params.createTime as string[]).join(',');
|
||||||
|
}
|
||||||
|
params.studentId = props.studentId;
|
||||||
|
const data = await getDemo03GradePage(params);
|
||||||
|
list.value = data.list;
|
||||||
|
total.value = data.total;
|
||||||
|
} finally {
|
||||||
|
loading.value = false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/** 监听主表的关联字段的变化,加载对应的子表数据 */
|
||||||
|
watch(
|
||||||
|
() => props.studentId,
|
||||||
|
async (val) => {
|
||||||
|
if (!val) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await nextTick();
|
||||||
|
await getList();
|
||||||
|
},
|
||||||
|
{ immediate: true },
|
||||||
|
);
|
||||||
|
|
||||||
|
/** 初始化 */
|
||||||
|
const { hiddenSearchBar, tableToolbarRef, tableRef } = useTableToolbar();
|
||||||
|
onMounted(() => {
|
||||||
|
getList();
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<FormModal @success="getList" />
|
||||||
|
<div class="h-[600px]">
|
||||||
|
<ContentWrap v-if="!hiddenSearchBar">
|
||||||
|
<!-- 搜索工作栏 -->
|
||||||
|
<ElForm :model="queryParams" ref="queryFormRef" inline>
|
||||||
|
<ElFormItem label="学生编号">
|
||||||
|
<ElInput
|
||||||
|
v-model="queryParams.studentId"
|
||||||
|
placeholder="请输入学生编号"
|
||||||
|
clearable
|
||||||
|
@keyup.enter="handleQuery"
|
||||||
|
class="!w-[240px]"
|
||||||
|
/>
|
||||||
|
</ElFormItem>
|
||||||
|
<ElFormItem label="名字">
|
||||||
|
<ElInput
|
||||||
|
v-model="queryParams.name"
|
||||||
|
placeholder="请输入名字"
|
||||||
|
clearable
|
||||||
|
@keyup.enter="handleQuery"
|
||||||
|
class="!w-[240px]"
|
||||||
|
/>
|
||||||
|
</ElFormItem>
|
||||||
|
<ElFormItem label="班主任">
|
||||||
|
<ElInput
|
||||||
|
v-model="queryParams.teacher"
|
||||||
|
placeholder="请输入班主任"
|
||||||
|
clearable
|
||||||
|
@keyup.enter="handleQuery"
|
||||||
|
class="!w-[240px]"
|
||||||
|
/>
|
||||||
|
</ElFormItem>
|
||||||
|
<ElFormItem label="创建时间">
|
||||||
|
<ElDatePicker
|
||||||
|
v-model="queryParams.createTime"
|
||||||
|
type="daterange"
|
||||||
|
value-format="YYYY-MM-DD"
|
||||||
|
range-separator="至"
|
||||||
|
start-placeholder="开始日期"
|
||||||
|
end-placeholder="结束日期"
|
||||||
|
class="!w-[240px]"
|
||||||
|
/>
|
||||||
|
</ElFormItem>
|
||||||
|
<ElFormItem>
|
||||||
|
<ElButton class="ml-2" @click="resetQuery"> 重置 </ElButton>
|
||||||
|
<ElButton class="ml-2" @click="handleQuery" type="primary">
|
||||||
|
搜索
|
||||||
|
</ElButton>
|
||||||
|
</ElFormItem>
|
||||||
|
</ElForm>
|
||||||
|
</ContentWrap>
|
||||||
|
|
||||||
|
<!-- 列表 -->
|
||||||
|
<ContentWrap title="学生">
|
||||||
|
<template #extra>
|
||||||
|
<TableToolbar
|
||||||
|
ref="tableToolbarRef"
|
||||||
|
v-model:hidden-search="hiddenSearchBar"
|
||||||
|
>
|
||||||
|
<ElButton
|
||||||
|
class="ml-2"
|
||||||
|
:icon="h(Plus)"
|
||||||
|
type="primary"
|
||||||
|
@click="handleCreate"
|
||||||
|
v-access:code="['infra:demo03-student:create']"
|
||||||
|
>
|
||||||
|
{{ $t('ui.actionTitle.create', ['学生']) }}
|
||||||
|
</ElButton>
|
||||||
|
<ElButton
|
||||||
|
:icon="h(Trash2)"
|
||||||
|
type="danger"
|
||||||
|
class="ml-2"
|
||||||
|
:disabled="isEmpty(checkedIds)"
|
||||||
|
@click="handleDeleteBatch"
|
||||||
|
v-access:code="['infra:demo03-student:delete']"
|
||||||
|
>
|
||||||
|
批量删除
|
||||||
|
</ElButton>
|
||||||
|
</TableToolbar>
|
||||||
|
</template>
|
||||||
|
<VxeTable
|
||||||
|
ref="tableRef"
|
||||||
|
:data="list"
|
||||||
|
show-overflow
|
||||||
|
:loading="loading"
|
||||||
|
@checkbox-all="handleRowCheckboxChange"
|
||||||
|
@checkbox-change="handleRowCheckboxChange"
|
||||||
|
>
|
||||||
|
<VxeColumn type="checkbox" width="40" />
|
||||||
|
<VxeColumn field="id" title="编号" align="center" />
|
||||||
|
<VxeColumn field="studentId" title="学生编号" align="center" />
|
||||||
|
<VxeColumn field="name" title="名字" align="center" />
|
||||||
|
<VxeColumn field="teacher" title="班主任" align="center" />
|
||||||
|
<VxeColumn field="createTime" title="创建时间" align="center">
|
||||||
|
<template #default="{ row }">
|
||||||
|
{{ formatDateTime(row.createTime) }}
|
||||||
|
</template>
|
||||||
|
</VxeColumn>
|
||||||
|
<VxeColumn field="operation" title="操作" align="center">
|
||||||
|
<template #default="{ row }">
|
||||||
|
<ElButton
|
||||||
|
size="small"
|
||||||
|
type="primary"
|
||||||
|
link
|
||||||
|
@click="handleEdit(row as any)"
|
||||||
|
v-access:code="['infra:demo03-student:update']"
|
||||||
|
>
|
||||||
|
{{ $t('ui.actionTitle.edit') }}
|
||||||
|
</ElButton>
|
||||||
|
<ElButton
|
||||||
|
size="small"
|
||||||
|
type="danger"
|
||||||
|
link
|
||||||
|
class="ml-2"
|
||||||
|
@click="handleDelete(row as any)"
|
||||||
|
v-access:code="['infra:demo03-student:delete']"
|
||||||
|
>
|
||||||
|
{{ $t('ui.actionTitle.delete') }}
|
||||||
|
</ElButton>
|
||||||
|
</template>
|
||||||
|
</VxeColumn>
|
||||||
|
</VxeTable>
|
||||||
|
<!-- 分页 -->
|
||||||
|
<div class="mt-2 flex justify-end">
|
||||||
|
<ElPagination
|
||||||
|
:total="total"
|
||||||
|
v-model:current-page="queryParams.pageNo"
|
||||||
|
v-model:page-size="queryParams.pageSize"
|
||||||
|
:page-sizes="[10, 20, 50, 100]"
|
||||||
|
layout="total, sizes, prev, pager, next, jumper"
|
||||||
|
@size-change="getList"
|
||||||
|
@current-change="getList"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</ContentWrap>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
@ -0,0 +1,139 @@
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import type { FormRules } from 'element-plus';
|
||||||
|
|
||||||
|
import type { Demo03StudentApi } from '#/api/infra/demo/demo03/erp';
|
||||||
|
|
||||||
|
import { computed, reactive, ref } from 'vue';
|
||||||
|
|
||||||
|
import { useVbenModal } from '@vben/common-ui';
|
||||||
|
|
||||||
|
import {
|
||||||
|
ElDatePicker,
|
||||||
|
ElForm,
|
||||||
|
ElFormItem,
|
||||||
|
ElInput,
|
||||||
|
ElMessage,
|
||||||
|
ElRadio,
|
||||||
|
ElRadioGroup,
|
||||||
|
} from 'element-plus';
|
||||||
|
|
||||||
|
import {
|
||||||
|
createDemo03Student,
|
||||||
|
getDemo03Student,
|
||||||
|
updateDemo03Student,
|
||||||
|
} from '#/api/infra/demo/demo03/erp';
|
||||||
|
import { Tinymce as RichTextarea } from '#/components/tinymce';
|
||||||
|
import { $t } from '#/locales';
|
||||||
|
import { DICT_TYPE, getDictOptions } from '#/utils';
|
||||||
|
|
||||||
|
const emit = defineEmits(['success']);
|
||||||
|
|
||||||
|
const formRef = ref();
|
||||||
|
const formData = ref<Partial<Demo03StudentApi.Demo03Student>>({
|
||||||
|
id: undefined,
|
||||||
|
name: undefined,
|
||||||
|
sex: undefined,
|
||||||
|
birthday: undefined,
|
||||||
|
description: undefined,
|
||||||
|
});
|
||||||
|
const rules = reactive<FormRules>({
|
||||||
|
name: [{ required: true, message: '名字不能为空', trigger: 'blur' }],
|
||||||
|
sex: [{ required: true, message: '性别不能为空', trigger: 'blur' }],
|
||||||
|
birthday: [{ required: true, message: '出生日期不能为空', trigger: 'blur' }],
|
||||||
|
description: [{ required: true, message: '简介不能为空', trigger: 'blur' }],
|
||||||
|
});
|
||||||
|
const getTitle = computed(() => {
|
||||||
|
return formData.value?.id
|
||||||
|
? $t('ui.actionTitle.edit', ['学生'])
|
||||||
|
: $t('ui.actionTitle.create', ['学生']);
|
||||||
|
});
|
||||||
|
|
||||||
|
/** 重置表单 */
|
||||||
|
const resetForm = () => {
|
||||||
|
formData.value = {
|
||||||
|
id: undefined,
|
||||||
|
name: undefined,
|
||||||
|
sex: undefined,
|
||||||
|
birthday: undefined,
|
||||||
|
description: undefined,
|
||||||
|
};
|
||||||
|
formRef.value?.resetFields();
|
||||||
|
};
|
||||||
|
|
||||||
|
const [Modal, modalApi] = useVbenModal({
|
||||||
|
async onConfirm() {
|
||||||
|
await formRef.value?.validate();
|
||||||
|
modalApi.lock();
|
||||||
|
// 提交表单
|
||||||
|
const data = formData.value as Demo03StudentApi.Demo03Student;
|
||||||
|
try {
|
||||||
|
await (formData.value?.id
|
||||||
|
? updateDemo03Student(data)
|
||||||
|
: createDemo03Student(data));
|
||||||
|
// 关闭并提示
|
||||||
|
await modalApi.close();
|
||||||
|
emit('success');
|
||||||
|
ElMessage.success($t('ui.actionMessage.operationSuccess'));
|
||||||
|
} finally {
|
||||||
|
modalApi.unlock();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
async onOpenChange(isOpen: boolean) {
|
||||||
|
if (!isOpen) {
|
||||||
|
resetForm();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 加载数据
|
||||||
|
let data = modalApi.getData<Demo03StudentApi.Demo03Student>();
|
||||||
|
if (!data) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (data.id) {
|
||||||
|
modalApi.lock();
|
||||||
|
try {
|
||||||
|
data = await getDemo03Student(data.id);
|
||||||
|
} finally {
|
||||||
|
modalApi.unlock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
formData.value = data;
|
||||||
|
},
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<Modal :title="getTitle">
|
||||||
|
<ElForm
|
||||||
|
ref="formRef"
|
||||||
|
:model="formData"
|
||||||
|
:rules="rules"
|
||||||
|
label-width="120px"
|
||||||
|
label-position="right"
|
||||||
|
>
|
||||||
|
<ElFormItem label="名字" prop="name">
|
||||||
|
<ElInput v-model="formData.name" placeholder="请输入名字" />
|
||||||
|
</ElFormItem>
|
||||||
|
<ElFormItem label="性别" prop="sex">
|
||||||
|
<ElRadioGroup v-model="formData.sex">
|
||||||
|
<ElRadio
|
||||||
|
v-for="dict in getDictOptions(DICT_TYPE.SYSTEM_USER_SEX, 'number')"
|
||||||
|
:key="dict.value"
|
||||||
|
:label="dict.value"
|
||||||
|
>
|
||||||
|
{{ dict.label }}
|
||||||
|
</ElRadio>
|
||||||
|
</ElRadioGroup>
|
||||||
|
</ElFormItem>
|
||||||
|
<ElFormItem label="出生日期" prop="birthday">
|
||||||
|
<ElDatePicker
|
||||||
|
v-model="formData.birthday"
|
||||||
|
value-format="x"
|
||||||
|
placeholder="选择出生日期"
|
||||||
|
/>
|
||||||
|
</ElFormItem>
|
||||||
|
<ElFormItem label="简介" prop="description">
|
||||||
|
<RichTextarea v-model="formData.description" height="500px" />
|
||||||
|
</ElFormItem>
|
||||||
|
</ElForm>
|
||||||
|
</Modal>
|
||||||
|
</template>
|
||||||
|
|
@ -0,0 +1,337 @@
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import type { Demo03StudentApi } from '#/api/infra/demo/demo03/inner';
|
||||||
|
|
||||||
|
import { h, onMounted, reactive, ref } from 'vue';
|
||||||
|
|
||||||
|
import { Page, useVbenModal } from '@vben/common-ui';
|
||||||
|
import { Download, Plus, Trash2 } from '@vben/icons';
|
||||||
|
import {
|
||||||
|
cloneDeep,
|
||||||
|
downloadFileFromBlobPart,
|
||||||
|
formatDateTime,
|
||||||
|
isEmpty,
|
||||||
|
} from '@vben/utils';
|
||||||
|
|
||||||
|
import {
|
||||||
|
ElButton,
|
||||||
|
ElDatePicker,
|
||||||
|
ElForm,
|
||||||
|
ElFormItem,
|
||||||
|
ElInput,
|
||||||
|
ElLoading,
|
||||||
|
ElMessage,
|
||||||
|
ElOption,
|
||||||
|
ElPagination,
|
||||||
|
ElSelect,
|
||||||
|
ElTabPane,
|
||||||
|
ElTabs,
|
||||||
|
} from 'element-plus';
|
||||||
|
|
||||||
|
import { VxeColumn, VxeTable } from '#/adapter/vxe-table';
|
||||||
|
import {
|
||||||
|
deleteDemo03Student,
|
||||||
|
deleteDemo03StudentList,
|
||||||
|
exportDemo03Student,
|
||||||
|
getDemo03StudentPage,
|
||||||
|
} from '#/api/infra/demo/demo03/inner';
|
||||||
|
import { ContentWrap } from '#/components/content-wrap';
|
||||||
|
import { DictTag } from '#/components/dict-tag';
|
||||||
|
import { TableToolbar } from '#/components/table-toolbar';
|
||||||
|
import { useTableToolbar } from '#/hooks';
|
||||||
|
import { $t } from '#/locales';
|
||||||
|
import { DICT_TYPE, getDictOptions } from '#/utils';
|
||||||
|
|
||||||
|
import Demo03CourseList from './modules/demo03-course-list.vue';
|
||||||
|
import Demo03GradeList from './modules/demo03-grade-list.vue';
|
||||||
|
import Demo03StudentForm from './modules/form.vue';
|
||||||
|
|
||||||
|
/** 子表的列表 */
|
||||||
|
const subTabsName = ref('demo03Course');
|
||||||
|
|
||||||
|
const loading = ref(true); // 列表的加载中
|
||||||
|
const list = ref<Demo03StudentApi.Demo03Student[]>([]); // 列表的数据
|
||||||
|
|
||||||
|
const total = ref(0); // 列表的总页数
|
||||||
|
const queryParams = reactive({
|
||||||
|
pageNo: 1,
|
||||||
|
pageSize: 10,
|
||||||
|
name: undefined,
|
||||||
|
sex: undefined,
|
||||||
|
description: undefined,
|
||||||
|
createTime: undefined,
|
||||||
|
});
|
||||||
|
const queryFormRef = ref(); // 搜索的表单
|
||||||
|
const exportLoading = ref(false); // 导出的加载中
|
||||||
|
|
||||||
|
/** 查询列表 */
|
||||||
|
const getList = async () => {
|
||||||
|
loading.value = true;
|
||||||
|
try {
|
||||||
|
const params = cloneDeep(queryParams) as any;
|
||||||
|
if (params.createTime && Array.isArray(params.createTime)) {
|
||||||
|
params.createTime = (params.createTime as string[]).join(',');
|
||||||
|
}
|
||||||
|
const data = await getDemo03StudentPage(params);
|
||||||
|
list.value = data.list;
|
||||||
|
total.value = data.total;
|
||||||
|
} finally {
|
||||||
|
loading.value = false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/** 搜索按钮操作 */
|
||||||
|
const handleQuery = () => {
|
||||||
|
queryParams.pageNo = 1;
|
||||||
|
getList();
|
||||||
|
};
|
||||||
|
|
||||||
|
/** 重置按钮操作 */
|
||||||
|
const resetQuery = () => {
|
||||||
|
queryFormRef.value.resetFields();
|
||||||
|
handleQuery();
|
||||||
|
};
|
||||||
|
|
||||||
|
const [FormModal, formModalApi] = useVbenModal({
|
||||||
|
connectedComponent: Demo03StudentForm,
|
||||||
|
destroyOnClose: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
/** 创建学生 */
|
||||||
|
function handleCreate() {
|
||||||
|
formModalApi.setData({}).open();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 编辑学生 */
|
||||||
|
function handleEdit(row: Demo03StudentApi.Demo03Student) {
|
||||||
|
formModalApi.setData(row).open();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 删除学生 */
|
||||||
|
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 as number);
|
||||||
|
ElMessage.success($t('ui.actionMessage.deleteSuccess', [row.id]));
|
||||||
|
await getList();
|
||||||
|
} finally {
|
||||||
|
loadingInstance.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 批量删除学生 */
|
||||||
|
async function handleDeleteBatch() {
|
||||||
|
const loadingInstance = ElLoading.service({
|
||||||
|
text: $t('ui.actionMessage.deleting'),
|
||||||
|
background: 'rgba(0, 0, 0, 0.7)',
|
||||||
|
});
|
||||||
|
try {
|
||||||
|
await deleteDemo03StudentList(checkedIds.value);
|
||||||
|
ElMessage.success($t('ui.actionMessage.deleteSuccess'));
|
||||||
|
await getList();
|
||||||
|
} finally {
|
||||||
|
loadingInstance.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const checkedIds = ref<number[]>([]);
|
||||||
|
function handleRowCheckboxChange({
|
||||||
|
records,
|
||||||
|
}: {
|
||||||
|
records: Demo03StudentApi.Demo03Student[];
|
||||||
|
}) {
|
||||||
|
checkedIds.value = records.map((item) => item.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 导出表格 */
|
||||||
|
async function onExport() {
|
||||||
|
try {
|
||||||
|
exportLoading.value = true;
|
||||||
|
const data = await exportDemo03Student(queryParams);
|
||||||
|
downloadFileFromBlobPart({ fileName: '学生.xls', source: data });
|
||||||
|
} finally {
|
||||||
|
exportLoading.value = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 初始化 */
|
||||||
|
const { hiddenSearchBar, tableToolbarRef, tableRef } = useTableToolbar();
|
||||||
|
onMounted(() => {
|
||||||
|
getList();
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<Page auto-content-height>
|
||||||
|
<FormModal @success="getList" />
|
||||||
|
|
||||||
|
<ContentWrap v-if="!hiddenSearchBar">
|
||||||
|
<!-- 搜索工作栏 -->
|
||||||
|
<ElForm :model="queryParams" ref="queryFormRef" inline>
|
||||||
|
<ElFormItem label="名字">
|
||||||
|
<ElInput
|
||||||
|
v-model="queryParams.name"
|
||||||
|
placeholder="请输入名字"
|
||||||
|
clearable
|
||||||
|
@keyup.enter="handleQuery"
|
||||||
|
class="!w-[240px]"
|
||||||
|
/>
|
||||||
|
</ElFormItem>
|
||||||
|
<ElFormItem label="性别">
|
||||||
|
<ElSelect
|
||||||
|
v-model="queryParams.sex"
|
||||||
|
placeholder="请选择性别"
|
||||||
|
clearable
|
||||||
|
class="!w-[240px]"
|
||||||
|
>
|
||||||
|
<ElOption
|
||||||
|
v-for="dict in getDictOptions(
|
||||||
|
DICT_TYPE.SYSTEM_USER_SEX,
|
||||||
|
'number',
|
||||||
|
)"
|
||||||
|
:key="dict.value"
|
||||||
|
:value="dict.value"
|
||||||
|
:label="dict.label"
|
||||||
|
/>
|
||||||
|
</ElSelect>
|
||||||
|
</ElFormItem>
|
||||||
|
<ElFormItem label="创建时间">
|
||||||
|
<ElDatePicker
|
||||||
|
v-model="queryParams.createTime"
|
||||||
|
type="daterange"
|
||||||
|
value-format="YYYY-MM-DD"
|
||||||
|
range-separator="至"
|
||||||
|
start-placeholder="开始日期"
|
||||||
|
end-placeholder="结束日期"
|
||||||
|
class="!w-[240px]"
|
||||||
|
/>
|
||||||
|
</ElFormItem>
|
||||||
|
<ElFormItem>
|
||||||
|
<ElButton class="ml-2" @click="resetQuery"> 重置 </ElButton>
|
||||||
|
<ElButton class="ml-2" @click="handleQuery" type="primary">
|
||||||
|
搜索
|
||||||
|
</ElButton>
|
||||||
|
</ElFormItem>
|
||||||
|
</ElForm>
|
||||||
|
</ContentWrap>
|
||||||
|
|
||||||
|
<!-- 列表 -->
|
||||||
|
<ContentWrap title="学生">
|
||||||
|
<template #extra>
|
||||||
|
<TableToolbar
|
||||||
|
ref="tableToolbarRef"
|
||||||
|
v-model:hidden-search="hiddenSearchBar"
|
||||||
|
>
|
||||||
|
<ElButton
|
||||||
|
class="ml-2"
|
||||||
|
:icon="h(Plus)"
|
||||||
|
type="primary"
|
||||||
|
@click="handleCreate"
|
||||||
|
v-access:code="['infra:demo03-student:create']"
|
||||||
|
>
|
||||||
|
{{ $t('ui.actionTitle.create', ['学生']) }}
|
||||||
|
</ElButton>
|
||||||
|
<ElButton
|
||||||
|
:icon="h(Download)"
|
||||||
|
type="primary"
|
||||||
|
class="ml-2"
|
||||||
|
:loading="exportLoading"
|
||||||
|
@click="onExport"
|
||||||
|
v-access:code="['infra:demo03-student:export']"
|
||||||
|
>
|
||||||
|
{{ $t('ui.actionTitle.export') }}
|
||||||
|
</ElButton>
|
||||||
|
<ElButton
|
||||||
|
:icon="h(Trash2)"
|
||||||
|
type="danger"
|
||||||
|
class="ml-2"
|
||||||
|
:disabled="isEmpty(checkedIds)"
|
||||||
|
@click="handleDeleteBatch"
|
||||||
|
v-access:code="['infra:demo03-student:delete']"
|
||||||
|
>
|
||||||
|
批量删除
|
||||||
|
</ElButton>
|
||||||
|
</TableToolbar>
|
||||||
|
</template>
|
||||||
|
<VxeTable
|
||||||
|
ref="tableRef"
|
||||||
|
:data="list"
|
||||||
|
show-overflow
|
||||||
|
:loading="loading"
|
||||||
|
@checkbox-all="handleRowCheckboxChange"
|
||||||
|
@checkbox-change="handleRowCheckboxChange"
|
||||||
|
>
|
||||||
|
<VxeColumn type="checkbox" width="40" />
|
||||||
|
<!-- 子表的列表 -->
|
||||||
|
<VxeColumn type="expand" width="60">
|
||||||
|
<template #content="{ row }">
|
||||||
|
<!-- 子表的表单 -->
|
||||||
|
<ElTabs v-model="subTabsName" class="mx-8">
|
||||||
|
<ElTabPane name="demo03Course" label="学生课程">
|
||||||
|
<Demo03CourseList :student-id="row?.id" />
|
||||||
|
</ElTabPane>
|
||||||
|
<ElTabPane name="demo03Grade" label="学生班级">
|
||||||
|
<Demo03GradeList :student-id="row?.id" />
|
||||||
|
</ElTabPane>
|
||||||
|
</ElTabs>
|
||||||
|
</template>
|
||||||
|
</VxeColumn>
|
||||||
|
<VxeColumn field="id" title="编号" align="center" />
|
||||||
|
<VxeColumn field="name" title="名字" align="center" />
|
||||||
|
<VxeColumn field="sex" title="性别" align="center">
|
||||||
|
<template #default="{ row }">
|
||||||
|
<DictTag :type="DICT_TYPE.SYSTEM_USER_SEX" :value="row.sex" />
|
||||||
|
</template>
|
||||||
|
</VxeColumn>
|
||||||
|
<VxeColumn field="birthday" title="出生日期" align="center">
|
||||||
|
<template #default="{ row }">
|
||||||
|
{{ formatDateTime(row.birthday) }}
|
||||||
|
</template>
|
||||||
|
</VxeColumn>
|
||||||
|
<VxeColumn field="description" title="简介" align="center" />
|
||||||
|
<VxeColumn field="createTime" title="创建时间" align="center">
|
||||||
|
<template #default="{ row }">
|
||||||
|
{{ formatDateTime(row.createTime) }}
|
||||||
|
</template>
|
||||||
|
</VxeColumn>
|
||||||
|
<VxeColumn field="operation" title="操作" align="center">
|
||||||
|
<template #default="{ row }">
|
||||||
|
<ElButton
|
||||||
|
size="small"
|
||||||
|
type="primary"
|
||||||
|
link
|
||||||
|
@click="handleEdit(row as any)"
|
||||||
|
v-access:code="['infra:demo03-student:update']"
|
||||||
|
>
|
||||||
|
{{ $t('ui.actionTitle.edit') }}
|
||||||
|
</ElButton>
|
||||||
|
<ElButton
|
||||||
|
size="small"
|
||||||
|
type="danger"
|
||||||
|
link
|
||||||
|
class="ml-2"
|
||||||
|
@click="handleDelete(row as any)"
|
||||||
|
v-access:code="['infra:demo03-student:delete']"
|
||||||
|
>
|
||||||
|
{{ $t('ui.actionTitle.delete') }}
|
||||||
|
</ElButton>
|
||||||
|
</template>
|
||||||
|
</VxeColumn>
|
||||||
|
</VxeTable>
|
||||||
|
<!-- 分页 -->
|
||||||
|
<div class="mt-2 flex justify-end">
|
||||||
|
<ElPagination
|
||||||
|
:total="total"
|
||||||
|
v-model:current-page="queryParams.pageNo"
|
||||||
|
v-model:page-size="queryParams.pageSize"
|
||||||
|
:page-sizes="[10, 20, 50, 100]"
|
||||||
|
layout="total, sizes, prev, pager, next, jumper"
|
||||||
|
@size-change="getList"
|
||||||
|
@current-change="getList"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</ContentWrap>
|
||||||
|
</Page>
|
||||||
|
</template>
|
||||||
|
|
@ -0,0 +1,95 @@
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import type { VxeTableInstance } from '#/adapter/vxe-table';
|
||||||
|
import type { Demo03StudentApi } from '#/api/infra/demo/demo03/inner';
|
||||||
|
|
||||||
|
import { h, ref, watch } from 'vue';
|
||||||
|
|
||||||
|
import { Plus } from '@vben/icons';
|
||||||
|
|
||||||
|
import { ElButton, ElInput } from 'element-plus';
|
||||||
|
|
||||||
|
import { VxeColumn, VxeTable } from '#/adapter/vxe-table';
|
||||||
|
import { getDemo03CourseListByStudentId } from '#/api/infra/demo/demo03/inner';
|
||||||
|
import { $t } from '#/locales';
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
studentId?: number; // 学生编号(主表的关联字段)
|
||||||
|
}>();
|
||||||
|
|
||||||
|
const list = ref<Demo03StudentApi.Demo03Course[]>([]); // 列表的数据
|
||||||
|
const tableRef = ref<VxeTableInstance>();
|
||||||
|
/** 添加学生课程 */
|
||||||
|
const onAdd = async () => {
|
||||||
|
await tableRef.value?.insertAt({} as Demo03StudentApi.Demo03Course, -1);
|
||||||
|
};
|
||||||
|
|
||||||
|
/** 删除学生课程 */
|
||||||
|
const onDelete = async (row: Demo03StudentApi.Demo03Course) => {
|
||||||
|
await tableRef.value?.remove(row);
|
||||||
|
};
|
||||||
|
|
||||||
|
/** 提供获取表格数据的方法供父组件调用 */
|
||||||
|
defineExpose({
|
||||||
|
getData: (): Demo03StudentApi.Demo03Course[] => {
|
||||||
|
const data = list.value as Demo03StudentApi.Demo03Course[];
|
||||||
|
const removeRecords =
|
||||||
|
tableRef.value?.getRemoveRecords() as Demo03StudentApi.Demo03Course[];
|
||||||
|
const insertRecords =
|
||||||
|
tableRef.value?.getInsertRecords() as Demo03StudentApi.Demo03Course[];
|
||||||
|
return data
|
||||||
|
.filter((row) => !removeRecords.some((removed) => removed.id === row.id))
|
||||||
|
?.concat(insertRecords.map((row: any) => ({ ...row, id: undefined })));
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
/** 监听主表的关联字段的变化,加载对应的子表数据 */
|
||||||
|
watch(
|
||||||
|
() => props.studentId,
|
||||||
|
async (val) => {
|
||||||
|
if (!val) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
list.value = await getDemo03CourseListByStudentId(props.studentId!);
|
||||||
|
},
|
||||||
|
{ immediate: true },
|
||||||
|
);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<VxeTable ref="tableRef" :data="list" show-overflow class="mx-4">
|
||||||
|
<VxeColumn field="name" title="名字" align="center">
|
||||||
|
<template #default="{ row }">
|
||||||
|
<ElInput v-model="row.name" />
|
||||||
|
</template>
|
||||||
|
</VxeColumn>
|
||||||
|
<VxeColumn field="score" title="分数" align="center">
|
||||||
|
<template #default="{ row }">
|
||||||
|
<ElInput v-model="row.score" />
|
||||||
|
</template>
|
||||||
|
</VxeColumn>
|
||||||
|
<VxeColumn field="operation" title="操作" align="center">
|
||||||
|
<template #default="{ row }">
|
||||||
|
<ElButton
|
||||||
|
size="small"
|
||||||
|
type="danger"
|
||||||
|
link
|
||||||
|
@click="onDelete(row as any)"
|
||||||
|
v-access:code="['infra:demo03-student:delete']"
|
||||||
|
>
|
||||||
|
{{ $t('ui.actionTitle.delete') }}
|
||||||
|
</ElButton>
|
||||||
|
</template>
|
||||||
|
</VxeColumn>
|
||||||
|
</VxeTable>
|
||||||
|
<div class="mt-4 flex justify-center">
|
||||||
|
<ElButton
|
||||||
|
:icon="h(Plus)"
|
||||||
|
type="primary"
|
||||||
|
plain
|
||||||
|
@click="onAdd"
|
||||||
|
v-access:code="['infra:demo03-student:create']"
|
||||||
|
>
|
||||||
|
{{ $t('ui.actionTitle.create', ['学生课程']) }}
|
||||||
|
</ElButton>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
@ -0,0 +1,59 @@
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import type { Demo03StudentApi } from '#/api/infra/demo/demo03/inner';
|
||||||
|
|
||||||
|
import { nextTick, ref, watch } from 'vue';
|
||||||
|
|
||||||
|
import { formatDateTime } from '@vben/utils';
|
||||||
|
|
||||||
|
import { VxeColumn, VxeTable } from '#/adapter/vxe-table';
|
||||||
|
import { getDemo03CourseListByStudentId } from '#/api/infra/demo/demo03/inner';
|
||||||
|
import { ContentWrap } from '#/components/content-wrap';
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
studentId?: number; // 学生编号(主表的关联字段)
|
||||||
|
}>();
|
||||||
|
|
||||||
|
const loading = ref(true); // 列表的加载中
|
||||||
|
const list = ref<Demo03StudentApi.Demo03Course[]>([]); // 列表的数据
|
||||||
|
/** 查询列表 */
|
||||||
|
const getList = async () => {
|
||||||
|
loading.value = true;
|
||||||
|
try {
|
||||||
|
if (!props.studentId) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
list.value = await getDemo03CourseListByStudentId(props.studentId!);
|
||||||
|
} finally {
|
||||||
|
loading.value = false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/** 监听主表的关联字段的变化,加载对应的子表数据 */
|
||||||
|
watch(
|
||||||
|
() => props.studentId,
|
||||||
|
async (val) => {
|
||||||
|
if (!val) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await nextTick();
|
||||||
|
await getList();
|
||||||
|
},
|
||||||
|
{ immediate: true },
|
||||||
|
);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<ContentWrap title="学生课程列表">
|
||||||
|
<VxeTable :data="list" show-overflow :loading="loading">
|
||||||
|
<VxeColumn field="id" title="编号" align="center" />
|
||||||
|
<VxeColumn field="studentId" title="学生编号" align="center" />
|
||||||
|
<VxeColumn field="name" title="名字" align="center" />
|
||||||
|
<VxeColumn field="score" title="分数" align="center" />
|
||||||
|
<VxeColumn field="createTime" title="创建时间" align="center">
|
||||||
|
<template #default="{ row }">
|
||||||
|
{{ formatDateTime(row.createTime) }}
|
||||||
|
</template>
|
||||||
|
</VxeColumn>
|
||||||
|
</VxeTable>
|
||||||
|
</ContentWrap>
|
||||||
|
</template>
|
||||||
|
|
@ -0,0 +1,67 @@
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import type { FormRules } from 'element-plus';
|
||||||
|
|
||||||
|
import type { Demo03StudentApi } from '#/api/infra/demo/demo03/inner';
|
||||||
|
|
||||||
|
import { nextTick, reactive, ref, watch } from 'vue';
|
||||||
|
|
||||||
|
import { ElForm, ElFormItem, ElInput } from 'element-plus';
|
||||||
|
|
||||||
|
import { getDemo03GradeByStudentId } from '#/api/infra/demo/demo03/inner';
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
studentId?: number; // 学生编号(主表的关联字段)
|
||||||
|
}>();
|
||||||
|
|
||||||
|
const formRef = ref();
|
||||||
|
const formData = ref<Partial<Demo03StudentApi.Demo03Grade>>({
|
||||||
|
id: undefined,
|
||||||
|
studentId: undefined,
|
||||||
|
name: undefined,
|
||||||
|
teacher: undefined,
|
||||||
|
});
|
||||||
|
const rules = reactive<FormRules>({
|
||||||
|
studentId: [{ required: true, message: '学生编号不能为空', trigger: 'blur' }],
|
||||||
|
name: [{ required: true, message: '名字不能为空', trigger: 'blur' }],
|
||||||
|
teacher: [{ required: true, message: '班主任不能为空', trigger: 'blur' }],
|
||||||
|
});
|
||||||
|
/** 暴露出表单校验方法和表单值获取方法 */
|
||||||
|
defineExpose({
|
||||||
|
validate: async () => await formRef.value?.validate(),
|
||||||
|
getValues: () => formData.value,
|
||||||
|
});
|
||||||
|
|
||||||
|
/** 监听主表的关联字段的变化,加载对应的子表数据 */
|
||||||
|
watch(
|
||||||
|
() => props.studentId,
|
||||||
|
async (val) => {
|
||||||
|
if (!val) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await nextTick();
|
||||||
|
formData.value = await getDemo03GradeByStudentId(props.studentId!);
|
||||||
|
},
|
||||||
|
{ immediate: true },
|
||||||
|
);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<ElForm
|
||||||
|
ref="formRef"
|
||||||
|
class="mx-4"
|
||||||
|
:model="formData"
|
||||||
|
:rules="rules"
|
||||||
|
label-width="120px"
|
||||||
|
label-position="right"
|
||||||
|
>
|
||||||
|
<ElFormItem label="学生编号" prop="studentId">
|
||||||
|
<ElInput v-model="formData.studentId" placeholder="请输入学生编号" />
|
||||||
|
</ElFormItem>
|
||||||
|
<ElFormItem label="名字" prop="name">
|
||||||
|
<ElInput v-model="formData.name" placeholder="请输入名字" />
|
||||||
|
</ElFormItem>
|
||||||
|
<ElFormItem label="班主任" prop="teacher">
|
||||||
|
<ElInput v-model="formData.teacher" placeholder="请输入班主任" />
|
||||||
|
</ElFormItem>
|
||||||
|
</ElForm>
|
||||||
|
</template>
|
||||||
|
|
@ -0,0 +1,59 @@
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import type { Demo03StudentApi } from '#/api/infra/demo/demo03/inner';
|
||||||
|
|
||||||
|
import { nextTick, ref, watch } from 'vue';
|
||||||
|
|
||||||
|
import { formatDateTime } from '@vben/utils';
|
||||||
|
|
||||||
|
import { VxeColumn, VxeTable } from '#/adapter/vxe-table';
|
||||||
|
import { getDemo03GradeByStudentId } from '#/api/infra/demo/demo03/inner';
|
||||||
|
import { ContentWrap } from '#/components/content-wrap';
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
studentId?: number; // 学生编号(主表的关联字段)
|
||||||
|
}>();
|
||||||
|
|
||||||
|
const loading = ref(true); // 列表的加载中
|
||||||
|
const list = ref<Demo03StudentApi.Demo03Grade[]>([]); // 列表的数据
|
||||||
|
/** 查询列表 */
|
||||||
|
const getList = async () => {
|
||||||
|
loading.value = true;
|
||||||
|
try {
|
||||||
|
if (!props.studentId) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
list.value = [await getDemo03GradeByStudentId(props.studentId!)];
|
||||||
|
} finally {
|
||||||
|
loading.value = false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/** 监听主表的关联字段的变化,加载对应的子表数据 */
|
||||||
|
watch(
|
||||||
|
() => props.studentId,
|
||||||
|
async (val) => {
|
||||||
|
if (!val) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await nextTick();
|
||||||
|
await getList();
|
||||||
|
},
|
||||||
|
{ immediate: true },
|
||||||
|
);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<ContentWrap title="学生班级列表">
|
||||||
|
<VxeTable :data="list" show-overflow :loading="loading">
|
||||||
|
<VxeColumn field="id" title="编号" align="center" />
|
||||||
|
<VxeColumn field="studentId" title="学生编号" align="center" />
|
||||||
|
<VxeColumn field="name" title="名字" align="center" />
|
||||||
|
<VxeColumn field="teacher" title="班主任" align="center" />
|
||||||
|
<VxeColumn field="createTime" title="创建时间" align="center">
|
||||||
|
<template #default="{ row }">
|
||||||
|
{{ formatDateTime(row.createTime) }}
|
||||||
|
</template>
|
||||||
|
</VxeColumn>
|
||||||
|
</VxeTable>
|
||||||
|
</ContentWrap>
|
||||||
|
</template>
|
||||||
|
|
@ -0,0 +1,171 @@
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import type { FormRules } from 'element-plus';
|
||||||
|
|
||||||
|
import type { Demo03StudentApi } from '#/api/infra/demo/demo03/inner';
|
||||||
|
|
||||||
|
import { computed, reactive, ref } from 'vue';
|
||||||
|
|
||||||
|
import { useVbenModal } from '@vben/common-ui';
|
||||||
|
|
||||||
|
import {
|
||||||
|
ElDatePicker,
|
||||||
|
ElForm,
|
||||||
|
ElFormItem,
|
||||||
|
ElInput,
|
||||||
|
ElMessage,
|
||||||
|
ElRadio,
|
||||||
|
ElRadioGroup,
|
||||||
|
ElTabPane,
|
||||||
|
ElTabs,
|
||||||
|
} from 'element-plus';
|
||||||
|
|
||||||
|
import {
|
||||||
|
createDemo03Student,
|
||||||
|
getDemo03Student,
|
||||||
|
updateDemo03Student,
|
||||||
|
} from '#/api/infra/demo/demo03/inner';
|
||||||
|
import { Tinymce as RichTextarea } from '#/components/tinymce';
|
||||||
|
import { $t } from '#/locales';
|
||||||
|
import { DICT_TYPE, getDictOptions } from '#/utils';
|
||||||
|
|
||||||
|
import Demo03CourseForm from './demo03-course-form.vue';
|
||||||
|
import Demo03GradeForm from './demo03-grade-form.vue';
|
||||||
|
|
||||||
|
const emit = defineEmits(['success']);
|
||||||
|
|
||||||
|
const formRef = ref();
|
||||||
|
const formData = ref<Partial<Demo03StudentApi.Demo03Student>>({
|
||||||
|
id: undefined,
|
||||||
|
name: undefined,
|
||||||
|
sex: undefined,
|
||||||
|
birthday: undefined,
|
||||||
|
description: undefined,
|
||||||
|
});
|
||||||
|
const rules = reactive<FormRules>({
|
||||||
|
name: [{ required: true, message: '名字不能为空', trigger: 'blur' }],
|
||||||
|
sex: [{ required: true, message: '性别不能为空', trigger: 'blur' }],
|
||||||
|
birthday: [{ required: true, message: '出生日期不能为空', trigger: 'blur' }],
|
||||||
|
description: [{ required: true, message: '简介不能为空', trigger: 'blur' }],
|
||||||
|
});
|
||||||
|
const getTitle = computed(() => {
|
||||||
|
return formData.value?.id
|
||||||
|
? $t('ui.actionTitle.edit', ['学生'])
|
||||||
|
: $t('ui.actionTitle.create', ['学生']);
|
||||||
|
});
|
||||||
|
|
||||||
|
/** 子表的表单 */
|
||||||
|
const subTabsName = ref('demo03Course');
|
||||||
|
const demo03CourseFormRef = ref<InstanceType<typeof Demo03CourseForm>>();
|
||||||
|
const demo03GradeFormRef = ref<InstanceType<typeof Demo03GradeForm>>();
|
||||||
|
|
||||||
|
/** 重置表单 */
|
||||||
|
const resetForm = () => {
|
||||||
|
formData.value = {
|
||||||
|
id: undefined,
|
||||||
|
name: undefined,
|
||||||
|
sex: undefined,
|
||||||
|
birthday: undefined,
|
||||||
|
description: undefined,
|
||||||
|
};
|
||||||
|
formRef.value?.resetFields();
|
||||||
|
};
|
||||||
|
|
||||||
|
const [Modal, modalApi] = useVbenModal({
|
||||||
|
async onConfirm() {
|
||||||
|
await formRef.value?.validate();
|
||||||
|
// 校验子表单
|
||||||
|
try {
|
||||||
|
await demo03GradeFormRef.value?.validate();
|
||||||
|
} catch {
|
||||||
|
subTabsName.value = 'demo03Grade';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
modalApi.lock();
|
||||||
|
// 提交表单
|
||||||
|
const data = formData.value as Demo03StudentApi.Demo03Student;
|
||||||
|
// 拼接子表的数据
|
||||||
|
data.demo03Courses = demo03CourseFormRef.value?.getData();
|
||||||
|
data.demo03Grade = demo03GradeFormRef.value?.getValues();
|
||||||
|
try {
|
||||||
|
await (formData.value?.id
|
||||||
|
? updateDemo03Student(data)
|
||||||
|
: createDemo03Student(data));
|
||||||
|
// 关闭并提示
|
||||||
|
await modalApi.close();
|
||||||
|
emit('success');
|
||||||
|
ElMessage.success($t('ui.actionMessage.operationSuccess'));
|
||||||
|
} finally {
|
||||||
|
modalApi.unlock();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
async onOpenChange(isOpen: boolean) {
|
||||||
|
if (!isOpen) {
|
||||||
|
resetForm();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 加载数据
|
||||||
|
let data = modalApi.getData<Demo03StudentApi.Demo03Student>();
|
||||||
|
if (!data) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (data.id) {
|
||||||
|
modalApi.lock();
|
||||||
|
try {
|
||||||
|
data = await getDemo03Student(data.id);
|
||||||
|
} finally {
|
||||||
|
modalApi.unlock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
formData.value = data;
|
||||||
|
},
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<Modal :title="getTitle">
|
||||||
|
<ElForm
|
||||||
|
ref="formRef"
|
||||||
|
:model="formData"
|
||||||
|
:rules="rules"
|
||||||
|
label-width="120px"
|
||||||
|
label-position="right"
|
||||||
|
>
|
||||||
|
<ElFormItem label="名字" prop="name">
|
||||||
|
<ElInput v-model="formData.name" placeholder="请输入名字" />
|
||||||
|
</ElFormItem>
|
||||||
|
<ElFormItem label="性别" prop="sex">
|
||||||
|
<ElRadioGroup v-model="formData.sex">
|
||||||
|
<ElRadio
|
||||||
|
v-for="dict in getDictOptions(DICT_TYPE.SYSTEM_USER_SEX, 'number')"
|
||||||
|
:key="dict.value"
|
||||||
|
:label="dict.value"
|
||||||
|
>
|
||||||
|
{{ dict.label }}
|
||||||
|
</ElRadio>
|
||||||
|
</ElRadioGroup>
|
||||||
|
</ElFormItem>
|
||||||
|
<ElFormItem label="出生日期" prop="birthday">
|
||||||
|
<ElDatePicker
|
||||||
|
v-model="formData.birthday"
|
||||||
|
value-format="x"
|
||||||
|
placeholder="选择出生日期"
|
||||||
|
/>
|
||||||
|
</ElFormItem>
|
||||||
|
<ElFormItem label="简介" prop="description">
|
||||||
|
<RichTextarea v-model="formData.description" height="500px" />
|
||||||
|
</ElFormItem>
|
||||||
|
</ElForm>
|
||||||
|
<!-- 子表的表单 -->
|
||||||
|
<ElTabs v-model="subTabsName">
|
||||||
|
<ElTabPane name="demo03Course" label="学生课程">
|
||||||
|
<Demo03CourseForm
|
||||||
|
ref="demo03CourseFormRef"
|
||||||
|
:student-id="formData?.id"
|
||||||
|
/>
|
||||||
|
</ElTabPane>
|
||||||
|
<ElTabPane name="demo03Grade" label="学生班级">
|
||||||
|
<Demo03GradeForm ref="demo03GradeFormRef" :student-id="formData?.id" />
|
||||||
|
</ElTabPane>
|
||||||
|
</ElTabs>
|
||||||
|
</Modal>
|
||||||
|
</template>
|
||||||
|
|
@ -0,0 +1,316 @@
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import type { Demo03StudentApi } from '#/api/infra/demo/demo03/normal';
|
||||||
|
|
||||||
|
import { h, onMounted, reactive, ref } from 'vue';
|
||||||
|
|
||||||
|
import { Page, useVbenModal } from '@vben/common-ui';
|
||||||
|
import { Download, Plus, Trash2 } from '@vben/icons';
|
||||||
|
import {
|
||||||
|
cloneDeep,
|
||||||
|
downloadFileFromBlobPart,
|
||||||
|
formatDateTime,
|
||||||
|
isEmpty,
|
||||||
|
} from '@vben/utils';
|
||||||
|
|
||||||
|
import {
|
||||||
|
ElButton,
|
||||||
|
ElDatePicker,
|
||||||
|
ElForm,
|
||||||
|
ElFormItem,
|
||||||
|
ElInput,
|
||||||
|
ElLoading,
|
||||||
|
ElMessage,
|
||||||
|
ElOption,
|
||||||
|
ElPagination,
|
||||||
|
ElSelect,
|
||||||
|
} from 'element-plus';
|
||||||
|
|
||||||
|
import { VxeColumn, VxeTable } from '#/adapter/vxe-table';
|
||||||
|
import {
|
||||||
|
deleteDemo03Student,
|
||||||
|
deleteDemo03StudentList,
|
||||||
|
exportDemo03Student,
|
||||||
|
getDemo03StudentPage,
|
||||||
|
} from '#/api/infra/demo/demo03/normal';
|
||||||
|
import { ContentWrap } from '#/components/content-wrap';
|
||||||
|
import { DictTag } from '#/components/dict-tag';
|
||||||
|
import { TableToolbar } from '#/components/table-toolbar';
|
||||||
|
import { useTableToolbar } from '#/hooks';
|
||||||
|
import { $t } from '#/locales';
|
||||||
|
import { DICT_TYPE, getDictOptions } from '#/utils';
|
||||||
|
|
||||||
|
import Demo03StudentForm from './modules/form.vue';
|
||||||
|
|
||||||
|
const loading = ref(true); // 列表的加载中
|
||||||
|
const list = ref<Demo03StudentApi.Demo03Student[]>([]); // 列表的数据
|
||||||
|
|
||||||
|
const total = ref(0); // 列表的总页数
|
||||||
|
const queryParams = reactive({
|
||||||
|
pageNo: 1,
|
||||||
|
pageSize: 10,
|
||||||
|
name: undefined,
|
||||||
|
sex: undefined,
|
||||||
|
description: undefined,
|
||||||
|
createTime: undefined,
|
||||||
|
});
|
||||||
|
const queryFormRef = ref(); // 搜索的表单
|
||||||
|
const exportLoading = ref(false); // 导出的加载中
|
||||||
|
|
||||||
|
/** 查询列表 */
|
||||||
|
const getList = async () => {
|
||||||
|
loading.value = true;
|
||||||
|
try {
|
||||||
|
const params = cloneDeep(queryParams) as any;
|
||||||
|
if (params.createTime && Array.isArray(params.createTime)) {
|
||||||
|
params.createTime = (params.createTime as string[]).join(',');
|
||||||
|
}
|
||||||
|
const data = await getDemo03StudentPage(params);
|
||||||
|
list.value = data.list;
|
||||||
|
total.value = data.total;
|
||||||
|
} finally {
|
||||||
|
loading.value = false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/** 搜索按钮操作 */
|
||||||
|
const handleQuery = () => {
|
||||||
|
queryParams.pageNo = 1;
|
||||||
|
getList();
|
||||||
|
};
|
||||||
|
|
||||||
|
/** 重置按钮操作 */
|
||||||
|
const resetQuery = () => {
|
||||||
|
queryFormRef.value.resetFields();
|
||||||
|
handleQuery();
|
||||||
|
};
|
||||||
|
|
||||||
|
const [FormModal, formModalApi] = useVbenModal({
|
||||||
|
connectedComponent: Demo03StudentForm,
|
||||||
|
destroyOnClose: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
/** 创建学生 */
|
||||||
|
function handleCreate() {
|
||||||
|
formModalApi.setData({}).open();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 编辑学生 */
|
||||||
|
function handleEdit(row: Demo03StudentApi.Demo03Student) {
|
||||||
|
formModalApi.setData(row).open();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 删除学生 */
|
||||||
|
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 as number);
|
||||||
|
ElMessage.success($t('ui.actionMessage.deleteSuccess', [row.id]));
|
||||||
|
await getList();
|
||||||
|
} finally {
|
||||||
|
loadingInstance.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 批量删除学生 */
|
||||||
|
async function handleDeleteBatch() {
|
||||||
|
const loadingInstance = ElLoading.service({
|
||||||
|
text: $t('ui.actionMessage.deleting'),
|
||||||
|
background: 'rgba(0, 0, 0, 0.7)',
|
||||||
|
});
|
||||||
|
try {
|
||||||
|
await deleteDemo03StudentList(checkedIds.value);
|
||||||
|
ElMessage.success($t('ui.actionMessage.deleteSuccess'));
|
||||||
|
await getList();
|
||||||
|
} finally {
|
||||||
|
loadingInstance.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const checkedIds = ref<number[]>([]);
|
||||||
|
function handleRowCheckboxChange({
|
||||||
|
records,
|
||||||
|
}: {
|
||||||
|
records: Demo03StudentApi.Demo03Student[];
|
||||||
|
}) {
|
||||||
|
checkedIds.value = records.map((item) => item.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 导出表格 */
|
||||||
|
async function onExport() {
|
||||||
|
try {
|
||||||
|
exportLoading.value = true;
|
||||||
|
const data = await exportDemo03Student(queryParams);
|
||||||
|
downloadFileFromBlobPart({ fileName: '学生.xls', source: data });
|
||||||
|
} finally {
|
||||||
|
exportLoading.value = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 初始化 */
|
||||||
|
const { hiddenSearchBar, tableToolbarRef, tableRef } = useTableToolbar();
|
||||||
|
onMounted(() => {
|
||||||
|
getList();
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<Page auto-content-height>
|
||||||
|
<FormModal @success="getList" />
|
||||||
|
|
||||||
|
<ContentWrap v-if="!hiddenSearchBar">
|
||||||
|
<!-- 搜索工作栏 -->
|
||||||
|
<ElForm :model="queryParams" ref="queryFormRef" inline>
|
||||||
|
<ElFormItem label="名字">
|
||||||
|
<ElInput
|
||||||
|
v-model="queryParams.name"
|
||||||
|
placeholder="请输入名字"
|
||||||
|
clearable
|
||||||
|
@keyup.enter="handleQuery"
|
||||||
|
class="!w-[240px]"
|
||||||
|
/>
|
||||||
|
</ElFormItem>
|
||||||
|
<ElFormItem label="性别">
|
||||||
|
<ElSelect
|
||||||
|
v-model="queryParams.sex"
|
||||||
|
placeholder="请选择性别"
|
||||||
|
clearable
|
||||||
|
class="!w-[240px]"
|
||||||
|
>
|
||||||
|
<ElOption
|
||||||
|
v-for="dict in getDictOptions(
|
||||||
|
DICT_TYPE.SYSTEM_USER_SEX,
|
||||||
|
'number',
|
||||||
|
)"
|
||||||
|
:key="dict.value"
|
||||||
|
:value="dict.value"
|
||||||
|
:label="dict.label"
|
||||||
|
/>
|
||||||
|
</ElSelect>
|
||||||
|
</ElFormItem>
|
||||||
|
<ElFormItem label="创建时间">
|
||||||
|
<ElDatePicker
|
||||||
|
v-model="queryParams.createTime"
|
||||||
|
type="daterange"
|
||||||
|
value-format="YYYY-MM-DD"
|
||||||
|
range-separator="至"
|
||||||
|
start-placeholder="开始日期"
|
||||||
|
end-placeholder="结束日期"
|
||||||
|
class="!w-[240px]"
|
||||||
|
/>
|
||||||
|
</ElFormItem>
|
||||||
|
<ElFormItem>
|
||||||
|
<ElButton class="ml-2" @click="resetQuery"> 重置 </ElButton>
|
||||||
|
<ElButton class="ml-2" @click="handleQuery" type="primary">
|
||||||
|
搜索
|
||||||
|
</ElButton>
|
||||||
|
</ElFormItem>
|
||||||
|
</ElForm>
|
||||||
|
</ContentWrap>
|
||||||
|
|
||||||
|
<!-- 列表 -->
|
||||||
|
<ContentWrap title="学生">
|
||||||
|
<template #extra>
|
||||||
|
<TableToolbar
|
||||||
|
ref="tableToolbarRef"
|
||||||
|
v-model:hidden-search="hiddenSearchBar"
|
||||||
|
>
|
||||||
|
<ElButton
|
||||||
|
class="ml-2"
|
||||||
|
:icon="h(Plus)"
|
||||||
|
type="primary"
|
||||||
|
@click="handleCreate"
|
||||||
|
v-access:code="['infra:demo03-student:create']"
|
||||||
|
>
|
||||||
|
{{ $t('ui.actionTitle.create', ['学生']) }}
|
||||||
|
</ElButton>
|
||||||
|
<ElButton
|
||||||
|
:icon="h(Download)"
|
||||||
|
type="primary"
|
||||||
|
class="ml-2"
|
||||||
|
:loading="exportLoading"
|
||||||
|
@click="onExport"
|
||||||
|
v-access:code="['infra:demo03-student:export']"
|
||||||
|
>
|
||||||
|
{{ $t('ui.actionTitle.export') }}
|
||||||
|
</ElButton>
|
||||||
|
<ElButton
|
||||||
|
:icon="h(Trash2)"
|
||||||
|
type="danger"
|
||||||
|
class="ml-2"
|
||||||
|
:disabled="isEmpty(checkedIds)"
|
||||||
|
@click="handleDeleteBatch"
|
||||||
|
v-access:code="['infra:demo03-student:delete']"
|
||||||
|
>
|
||||||
|
批量删除
|
||||||
|
</ElButton>
|
||||||
|
</TableToolbar>
|
||||||
|
</template>
|
||||||
|
<VxeTable
|
||||||
|
ref="tableRef"
|
||||||
|
:data="list"
|
||||||
|
show-overflow
|
||||||
|
:loading="loading"
|
||||||
|
@checkbox-all="handleRowCheckboxChange"
|
||||||
|
@checkbox-change="handleRowCheckboxChange"
|
||||||
|
>
|
||||||
|
<VxeColumn type="checkbox" width="40" />
|
||||||
|
<VxeColumn field="id" title="编号" align="center" />
|
||||||
|
<VxeColumn field="name" title="名字" align="center" />
|
||||||
|
<VxeColumn field="sex" title="性别" align="center">
|
||||||
|
<template #default="{ row }">
|
||||||
|
<DictTag :type="DICT_TYPE.SYSTEM_USER_SEX" :value="row.sex" />
|
||||||
|
</template>
|
||||||
|
</VxeColumn>
|
||||||
|
<VxeColumn field="birthday" title="出生日期" align="center">
|
||||||
|
<template #default="{ row }">
|
||||||
|
{{ formatDateTime(row.birthday) }}
|
||||||
|
</template>
|
||||||
|
</VxeColumn>
|
||||||
|
<VxeColumn field="description" title="简介" align="center" />
|
||||||
|
<VxeColumn field="createTime" title="创建时间" align="center">
|
||||||
|
<template #default="{ row }">
|
||||||
|
{{ formatDateTime(row.createTime) }}
|
||||||
|
</template>
|
||||||
|
</VxeColumn>
|
||||||
|
<VxeColumn field="operation" title="操作" align="center">
|
||||||
|
<template #default="{ row }">
|
||||||
|
<ElButton
|
||||||
|
size="small"
|
||||||
|
type="primary"
|
||||||
|
link
|
||||||
|
@click="handleEdit(row as any)"
|
||||||
|
v-access:code="['infra:demo03-student:update']"
|
||||||
|
>
|
||||||
|
{{ $t('ui.actionTitle.edit') }}
|
||||||
|
</ElButton>
|
||||||
|
<ElButton
|
||||||
|
size="small"
|
||||||
|
type="danger"
|
||||||
|
link
|
||||||
|
class="ml-2"
|
||||||
|
@click="handleDelete(row as any)"
|
||||||
|
v-access:code="['infra:demo03-student:delete']"
|
||||||
|
>
|
||||||
|
{{ $t('ui.actionTitle.delete') }}
|
||||||
|
</ElButton>
|
||||||
|
</template>
|
||||||
|
</VxeColumn>
|
||||||
|
</VxeTable>
|
||||||
|
<!-- 分页 -->
|
||||||
|
<div class="mt-2 flex justify-end">
|
||||||
|
<ElPagination
|
||||||
|
:total="total"
|
||||||
|
v-model:current-page="queryParams.pageNo"
|
||||||
|
v-model:page-size="queryParams.pageSize"
|
||||||
|
:page-sizes="[10, 20, 50, 100]"
|
||||||
|
layout="total, sizes, prev, pager, next, jumper"
|
||||||
|
@size-change="getList"
|
||||||
|
@current-change="getList"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</ContentWrap>
|
||||||
|
</Page>
|
||||||
|
</template>
|
||||||
|
|
@ -0,0 +1,95 @@
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import type { VxeTableInstance } from '#/adapter/vxe-table';
|
||||||
|
import type { Demo03StudentApi } from '#/api/infra/demo/demo03/normal';
|
||||||
|
|
||||||
|
import { h, ref, watch } from 'vue';
|
||||||
|
|
||||||
|
import { Plus } from '@vben/icons';
|
||||||
|
|
||||||
|
import { ElButton, ElInput } from 'element-plus';
|
||||||
|
|
||||||
|
import { VxeColumn, VxeTable } from '#/adapter/vxe-table';
|
||||||
|
import { getDemo03CourseListByStudentId } from '#/api/infra/demo/demo03/normal';
|
||||||
|
import { $t } from '#/locales';
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
studentId?: number; // 学生编号(主表的关联字段)
|
||||||
|
}>();
|
||||||
|
|
||||||
|
const list = ref<Demo03StudentApi.Demo03Course[]>([]); // 列表的数据
|
||||||
|
const tableRef = ref<VxeTableInstance>();
|
||||||
|
/** 添加学生课程 */
|
||||||
|
const onAdd = async () => {
|
||||||
|
await tableRef.value?.insertAt({} as Demo03StudentApi.Demo03Course, -1);
|
||||||
|
};
|
||||||
|
|
||||||
|
/** 删除学生课程 */
|
||||||
|
const onDelete = async (row: Demo03StudentApi.Demo03Course) => {
|
||||||
|
await tableRef.value?.remove(row);
|
||||||
|
};
|
||||||
|
|
||||||
|
/** 提供获取表格数据的方法供父组件调用 */
|
||||||
|
defineExpose({
|
||||||
|
getData: (): Demo03StudentApi.Demo03Course[] => {
|
||||||
|
const data = list.value as Demo03StudentApi.Demo03Course[];
|
||||||
|
const removeRecords =
|
||||||
|
tableRef.value?.getRemoveRecords() as Demo03StudentApi.Demo03Course[];
|
||||||
|
const insertRecords =
|
||||||
|
tableRef.value?.getInsertRecords() as Demo03StudentApi.Demo03Course[];
|
||||||
|
return data
|
||||||
|
.filter((row) => !removeRecords.some((removed) => removed.id === row.id))
|
||||||
|
?.concat(insertRecords.map((row: any) => ({ ...row, id: undefined })));
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
/** 监听主表的关联字段的变化,加载对应的子表数据 */
|
||||||
|
watch(
|
||||||
|
() => props.studentId,
|
||||||
|
async (val) => {
|
||||||
|
if (!val) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
list.value = await getDemo03CourseListByStudentId(props.studentId!);
|
||||||
|
},
|
||||||
|
{ immediate: true },
|
||||||
|
);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<VxeTable ref="tableRef" :data="list" show-overflow class="mx-4">
|
||||||
|
<VxeColumn field="name" title="名字" align="center">
|
||||||
|
<template #default="{ row }">
|
||||||
|
<ElInput v-model="row.name" />
|
||||||
|
</template>
|
||||||
|
</VxeColumn>
|
||||||
|
<VxeColumn field="score" title="分数" align="center">
|
||||||
|
<template #default="{ row }">
|
||||||
|
<ElInput v-model="row.score" />
|
||||||
|
</template>
|
||||||
|
</VxeColumn>
|
||||||
|
<VxeColumn field="operation" title="操作" align="center">
|
||||||
|
<template #default="{ row }">
|
||||||
|
<ElButton
|
||||||
|
size="small"
|
||||||
|
type="danger"
|
||||||
|
link
|
||||||
|
@click="onDelete(row as any)"
|
||||||
|
v-access:code="['infra:demo03-student:delete']"
|
||||||
|
>
|
||||||
|
{{ $t('ui.actionTitle.delete') }}
|
||||||
|
</ElButton>
|
||||||
|
</template>
|
||||||
|
</VxeColumn>
|
||||||
|
</VxeTable>
|
||||||
|
<div class="mt-4 flex justify-center">
|
||||||
|
<ElButton
|
||||||
|
:icon="h(Plus)"
|
||||||
|
type="primary"
|
||||||
|
plain
|
||||||
|
@click="onAdd"
|
||||||
|
v-access:code="['infra:demo03-student:create']"
|
||||||
|
>
|
||||||
|
{{ $t('ui.actionTitle.create', ['学生课程']) }}
|
||||||
|
</ElButton>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
@ -0,0 +1,67 @@
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import type { FormRules } from 'element-plus';
|
||||||
|
|
||||||
|
import type { Demo03StudentApi } from '#/api/infra/demo/demo03/normal';
|
||||||
|
|
||||||
|
import { nextTick, reactive, ref, watch } from 'vue';
|
||||||
|
|
||||||
|
import { ElForm, ElFormItem, ElInput } from 'element-plus';
|
||||||
|
|
||||||
|
import { getDemo03GradeByStudentId } from '#/api/infra/demo/demo03/normal';
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
studentId?: number; // 学生编号(主表的关联字段)
|
||||||
|
}>();
|
||||||
|
|
||||||
|
const formRef = ref();
|
||||||
|
const formData = ref<Partial<Demo03StudentApi.Demo03Grade>>({
|
||||||
|
id: undefined,
|
||||||
|
studentId: undefined,
|
||||||
|
name: undefined,
|
||||||
|
teacher: undefined,
|
||||||
|
});
|
||||||
|
const rules = reactive<FormRules>({
|
||||||
|
studentId: [{ required: true, message: '学生编号不能为空', trigger: 'blur' }],
|
||||||
|
name: [{ required: true, message: '名字不能为空', trigger: 'blur' }],
|
||||||
|
teacher: [{ required: true, message: '班主任不能为空', trigger: 'blur' }],
|
||||||
|
});
|
||||||
|
/** 暴露出表单校验方法和表单值获取方法 */
|
||||||
|
defineExpose({
|
||||||
|
validate: async () => await formRef.value?.validate(),
|
||||||
|
getValues: () => formData.value,
|
||||||
|
});
|
||||||
|
|
||||||
|
/** 监听主表的关联字段的变化,加载对应的子表数据 */
|
||||||
|
watch(
|
||||||
|
() => props.studentId,
|
||||||
|
async (val) => {
|
||||||
|
if (!val) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await nextTick();
|
||||||
|
formData.value = await getDemo03GradeByStudentId(props.studentId!);
|
||||||
|
},
|
||||||
|
{ immediate: true },
|
||||||
|
);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<ElForm
|
||||||
|
ref="formRef"
|
||||||
|
class="mx-4"
|
||||||
|
:model="formData"
|
||||||
|
:rules="rules"
|
||||||
|
label-width="120px"
|
||||||
|
label-position="right"
|
||||||
|
>
|
||||||
|
<ElFormItem label="学生编号" prop="studentId">
|
||||||
|
<ElInput v-model="formData.studentId" placeholder="请输入学生编号" />
|
||||||
|
</ElFormItem>
|
||||||
|
<ElFormItem label="名字" prop="name">
|
||||||
|
<ElInput v-model="formData.name" placeholder="请输入名字" />
|
||||||
|
</ElFormItem>
|
||||||
|
<ElFormItem label="班主任" prop="teacher">
|
||||||
|
<ElInput v-model="formData.teacher" placeholder="请输入班主任" />
|
||||||
|
</ElFormItem>
|
||||||
|
</ElForm>
|
||||||
|
</template>
|
||||||
|
|
@ -0,0 +1,171 @@
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import type { FormRules } from 'element-plus';
|
||||||
|
|
||||||
|
import type { Demo03StudentApi } from '#/api/infra/demo/demo03/normal';
|
||||||
|
|
||||||
|
import { computed, reactive, ref } from 'vue';
|
||||||
|
|
||||||
|
import { useVbenModal } from '@vben/common-ui';
|
||||||
|
|
||||||
|
import {
|
||||||
|
ElDatePicker,
|
||||||
|
ElForm,
|
||||||
|
ElFormItem,
|
||||||
|
ElInput,
|
||||||
|
ElMessage,
|
||||||
|
ElRadio,
|
||||||
|
ElRadioGroup,
|
||||||
|
ElTabPane,
|
||||||
|
ElTabs,
|
||||||
|
} from 'element-plus';
|
||||||
|
|
||||||
|
import {
|
||||||
|
createDemo03Student,
|
||||||
|
getDemo03Student,
|
||||||
|
updateDemo03Student,
|
||||||
|
} from '#/api/infra/demo/demo03/normal';
|
||||||
|
import { Tinymce as RichTextarea } from '#/components/tinymce';
|
||||||
|
import { $t } from '#/locales';
|
||||||
|
import { DICT_TYPE, getDictOptions } from '#/utils';
|
||||||
|
|
||||||
|
import Demo03CourseForm from './demo03-course-form.vue';
|
||||||
|
import Demo03GradeForm from './demo03-grade-form.vue';
|
||||||
|
|
||||||
|
const emit = defineEmits(['success']);
|
||||||
|
|
||||||
|
const formRef = ref();
|
||||||
|
const formData = ref<Partial<Demo03StudentApi.Demo03Student>>({
|
||||||
|
id: undefined,
|
||||||
|
name: undefined,
|
||||||
|
sex: undefined,
|
||||||
|
birthday: undefined,
|
||||||
|
description: undefined,
|
||||||
|
});
|
||||||
|
const rules = reactive<FormRules>({
|
||||||
|
name: [{ required: true, message: '名字不能为空', trigger: 'blur' }],
|
||||||
|
sex: [{ required: true, message: '性别不能为空', trigger: 'blur' }],
|
||||||
|
birthday: [{ required: true, message: '出生日期不能为空', trigger: 'blur' }],
|
||||||
|
description: [{ required: true, message: '简介不能为空', trigger: 'blur' }],
|
||||||
|
});
|
||||||
|
const getTitle = computed(() => {
|
||||||
|
return formData.value?.id
|
||||||
|
? $t('ui.actionTitle.edit', ['学生'])
|
||||||
|
: $t('ui.actionTitle.create', ['学生']);
|
||||||
|
});
|
||||||
|
|
||||||
|
/** 子表的表单 */
|
||||||
|
const subTabsName = ref('demo03Course');
|
||||||
|
const demo03CourseFormRef = ref<InstanceType<typeof Demo03CourseForm>>();
|
||||||
|
const demo03GradeFormRef = ref<InstanceType<typeof Demo03GradeForm>>();
|
||||||
|
|
||||||
|
/** 重置表单 */
|
||||||
|
const resetForm = () => {
|
||||||
|
formData.value = {
|
||||||
|
id: undefined,
|
||||||
|
name: undefined,
|
||||||
|
sex: undefined,
|
||||||
|
birthday: undefined,
|
||||||
|
description: undefined,
|
||||||
|
};
|
||||||
|
formRef.value?.resetFields();
|
||||||
|
};
|
||||||
|
|
||||||
|
const [Modal, modalApi] = useVbenModal({
|
||||||
|
async onConfirm() {
|
||||||
|
await formRef.value?.validate();
|
||||||
|
// 校验子表单
|
||||||
|
try {
|
||||||
|
await demo03GradeFormRef.value?.validate();
|
||||||
|
} catch {
|
||||||
|
subTabsName.value = 'demo03Grade';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
modalApi.lock();
|
||||||
|
// 提交表单
|
||||||
|
const data = formData.value as Demo03StudentApi.Demo03Student;
|
||||||
|
// 拼接子表的数据
|
||||||
|
data.demo03Courses = demo03CourseFormRef.value?.getData();
|
||||||
|
data.demo03Grade = demo03GradeFormRef.value?.getValues();
|
||||||
|
try {
|
||||||
|
await (formData.value?.id
|
||||||
|
? updateDemo03Student(data)
|
||||||
|
: createDemo03Student(data));
|
||||||
|
// 关闭并提示
|
||||||
|
await modalApi.close();
|
||||||
|
emit('success');
|
||||||
|
ElMessage.success($t('ui.actionMessage.operationSuccess'));
|
||||||
|
} finally {
|
||||||
|
modalApi.unlock();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
async onOpenChange(isOpen: boolean) {
|
||||||
|
if (!isOpen) {
|
||||||
|
resetForm();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 加载数据
|
||||||
|
let data = modalApi.getData<Demo03StudentApi.Demo03Student>();
|
||||||
|
if (!data) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (data.id) {
|
||||||
|
modalApi.lock();
|
||||||
|
try {
|
||||||
|
data = await getDemo03Student(data.id);
|
||||||
|
} finally {
|
||||||
|
modalApi.unlock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
formData.value = data;
|
||||||
|
},
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<Modal :title="getTitle">
|
||||||
|
<ElForm
|
||||||
|
ref="formRef"
|
||||||
|
:model="formData"
|
||||||
|
:rules="rules"
|
||||||
|
label-width="120px"
|
||||||
|
label-position="right"
|
||||||
|
>
|
||||||
|
<ElFormItem label="名字" prop="name">
|
||||||
|
<ElInput v-model="formData.name" placeholder="请输入名字" />
|
||||||
|
</ElFormItem>
|
||||||
|
<ElFormItem label="性别" prop="sex">
|
||||||
|
<ElRadioGroup v-model="formData.sex">
|
||||||
|
<ElRadio
|
||||||
|
v-for="dict in getDictOptions(DICT_TYPE.SYSTEM_USER_SEX, 'number')"
|
||||||
|
:key="dict.value"
|
||||||
|
:label="dict.value"
|
||||||
|
>
|
||||||
|
{{ dict.label }}
|
||||||
|
</ElRadio>
|
||||||
|
</ElRadioGroup>
|
||||||
|
</ElFormItem>
|
||||||
|
<ElFormItem label="出生日期" prop="birthday">
|
||||||
|
<ElDatePicker
|
||||||
|
v-model="formData.birthday"
|
||||||
|
value-format="x"
|
||||||
|
placeholder="选择出生日期"
|
||||||
|
/>
|
||||||
|
</ElFormItem>
|
||||||
|
<ElFormItem label="简介" prop="description">
|
||||||
|
<RichTextarea v-model="formData.description" height="500px" />
|
||||||
|
</ElFormItem>
|
||||||
|
</ElForm>
|
||||||
|
<!-- 子表的表单 -->
|
||||||
|
<ElTabs v-model="subTabsName">
|
||||||
|
<ElTabPane name="demo03Course" label="学生课程">
|
||||||
|
<Demo03CourseForm
|
||||||
|
ref="demo03CourseFormRef"
|
||||||
|
:student-id="formData?.id"
|
||||||
|
/>
|
||||||
|
</ElTabPane>
|
||||||
|
<ElTabPane name="demo03Grade" label="学生班级">
|
||||||
|
<Demo03GradeForm ref="demo03GradeFormRef" :student-id="formData?.id" />
|
||||||
|
</ElTabPane>
|
||||||
|
</ElTabs>
|
||||||
|
</Modal>
|
||||||
|
</template>
|
||||||
|
|
@ -1,8 +1,7 @@
|
||||||
import type { VbenFormSchema } from '#/adapter/form';
|
import type { VbenFormSchema } from '#/adapter/form';
|
||||||
import type { OnActionClickFn, VxeTableGridOptions } from '#/adapter/vxe-table';
|
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||||
import type { SystemUserApi } from '#/api/system/user';
|
import type { SystemUserApi } from '#/api/system/user';
|
||||||
|
|
||||||
import { useAccess } from '@vben/access';
|
|
||||||
import { $t } from '@vben/locales';
|
import { $t } from '@vben/locales';
|
||||||
import { handleTree } from '@vben/utils';
|
import { handleTree } from '@vben/utils';
|
||||||
|
|
||||||
|
|
@ -17,8 +16,6 @@ import {
|
||||||
getRangePickerDefaultProps,
|
getRangePickerDefaultProps,
|
||||||
} from '#/utils';
|
} from '#/utils';
|
||||||
|
|
||||||
const { hasAccessByCodes } = useAccess();
|
|
||||||
|
|
||||||
/** 新增/修改的表单 */
|
/** 新增/修改的表单 */
|
||||||
export function useFormSchema(): VbenFormSchema[] {
|
export function useFormSchema(): VbenFormSchema[] {
|
||||||
return [
|
return [
|
||||||
|
|
@ -282,7 +279,6 @@ export function useGridFormSchema(): VbenFormSchema[] {
|
||||||
|
|
||||||
/** 列表的字段 */
|
/** 列表的字段 */
|
||||||
export function useGridColumns<T = SystemUserApi.User>(
|
export function useGridColumns<T = SystemUserApi.User>(
|
||||||
onActionClick: OnActionClickFn<T>,
|
|
||||||
onStatusChange?: (
|
onStatusChange?: (
|
||||||
newStatus: number,
|
newStatus: number,
|
||||||
row: T,
|
row: T,
|
||||||
|
|
@ -335,41 +331,10 @@ export function useGridColumns<T = SystemUserApi.User>(
|
||||||
formatter: 'formatDateTime',
|
formatter: 'formatDateTime',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
field: 'operation',
|
|
||||||
title: '操作',
|
title: '操作',
|
||||||
minWidth: 130,
|
width: 180,
|
||||||
fixed: 'right',
|
fixed: 'right',
|
||||||
align: 'center',
|
slots: { default: 'actions' },
|
||||||
cellRender: {
|
|
||||||
attrs: {
|
|
||||||
nameField: 'username',
|
|
||||||
nameTitle: '用户',
|
|
||||||
onClick: onActionClick,
|
|
||||||
},
|
|
||||||
name: 'CellOperation',
|
|
||||||
// TODO @芋艿:后续把 delete、assign-role、reset-password 搞成"更多"
|
|
||||||
options: [
|
|
||||||
{
|
|
||||||
code: 'edit',
|
|
||||||
show: hasAccessByCodes(['system:user:update']),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
code: 'delete',
|
|
||||||
show: hasAccessByCodes(['system:user:delete']),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
code: 'assign-role',
|
|
||||||
text: '分配角色',
|
|
||||||
show: hasAccessByCodes(['system:permission:assign-user-role']),
|
|
||||||
'v-access:code': 'system:user:assign-role1',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
code: 'reset-password',
|
|
||||||
text: '重置密码',
|
|
||||||
show: hasAccessByCodes(['system:user:update-password']),
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,20 +1,16 @@
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import type {
|
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||||
OnActionClickParams,
|
|
||||||
VxeTableGridOptions,
|
|
||||||
} from '#/adapter/vxe-table';
|
|
||||||
import type { SystemDeptApi } from '#/api/system/dept';
|
import type { SystemDeptApi } from '#/api/system/dept';
|
||||||
import type { SystemUserApi } from '#/api/system/user';
|
import type { SystemUserApi } from '#/api/system/user';
|
||||||
|
|
||||||
import { ref } from 'vue';
|
import { ref } from 'vue';
|
||||||
|
|
||||||
import { confirm, Page, useVbenModal } from '@vben/common-ui';
|
import { confirm, Page, useVbenModal } from '@vben/common-ui';
|
||||||
import { Download, Plus, Upload } from '@vben/icons';
|
|
||||||
import { downloadFileFromBlobPart } from '@vben/utils';
|
import { downloadFileFromBlobPart } from '@vben/utils';
|
||||||
|
|
||||||
import { ElButton, ElLoading, ElMessage } from 'element-plus';
|
import { ElLoading, ElMessage } from 'element-plus';
|
||||||
|
|
||||||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||||
import {
|
import {
|
||||||
deleteUser,
|
deleteUser,
|
||||||
exportUser,
|
exportUser,
|
||||||
|
|
@ -138,34 +134,12 @@ async function onStatusChange(
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 表格操作按钮的回调函数 */
|
|
||||||
function onActionClick({ code, row }: OnActionClickParams<SystemUserApi.User>) {
|
|
||||||
switch (code) {
|
|
||||||
case 'assign-role': {
|
|
||||||
onAssignRole(row);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 'delete': {
|
|
||||||
onDelete(row);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 'edit': {
|
|
||||||
onEdit(row);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 'reset-password': {
|
|
||||||
onResetPassword(row);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const [Grid, gridApi] = useVbenVxeGrid({
|
const [Grid, gridApi] = useVbenVxeGrid({
|
||||||
formOptions: {
|
formOptions: {
|
||||||
schema: useGridFormSchema(),
|
schema: useGridFormSchema(),
|
||||||
},
|
},
|
||||||
gridOptions: {
|
gridOptions: {
|
||||||
columns: useGridColumns(onActionClick, onStatusChange),
|
columns: useGridColumns(onStatusChange),
|
||||||
height: 'auto',
|
height: 'auto',
|
||||||
keepSource: true,
|
keepSource: true,
|
||||||
proxyConfig: {
|
proxyConfig: {
|
||||||
|
|
@ -216,32 +190,69 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
||||||
<div class="w-5/6">
|
<div class="w-5/6">
|
||||||
<Grid table-title="用户列表">
|
<Grid table-title="用户列表">
|
||||||
<template #toolbar-tools>
|
<template #toolbar-tools>
|
||||||
<ElButton
|
<TableAction
|
||||||
type="primary"
|
:actions="[
|
||||||
@click="onCreate"
|
{
|
||||||
v-access:code="['system:user:create']"
|
label: $t('ui.actionTitle.create', ['用户']),
|
||||||
>
|
type: 'primary',
|
||||||
<Plus class="mr-2 size-5" />
|
icon: ACTION_ICON.ADD,
|
||||||
{{ $t('ui.actionTitle.create', ['用户']) }}
|
auth: ['system:user:create'],
|
||||||
</ElButton>
|
onClick: onCreate,
|
||||||
<ElButton
|
},
|
||||||
type="primary"
|
{
|
||||||
class="ml-2"
|
label: $t('ui.actionTitle.export'),
|
||||||
@click="onExport"
|
type: 'primary',
|
||||||
v-access:code="['system:user:export']"
|
icon: ACTION_ICON.DOWNLOAD,
|
||||||
>
|
auth: ['system:user:export'],
|
||||||
<Download class="mr-2 size-5" />
|
onClick: onExport,
|
||||||
{{ $t('ui.actionTitle.export') }}
|
},
|
||||||
</ElButton>
|
{
|
||||||
<ElButton
|
label: $t('ui.actionTitle.import', ['用户']),
|
||||||
type="primary"
|
type: 'primary',
|
||||||
class="ml-2"
|
icon: ACTION_ICON.UPLOAD,
|
||||||
@click="onImport"
|
auth: ['system:user:import'],
|
||||||
v-access:code="['system:user:import']"
|
onClick: onImport,
|
||||||
>
|
},
|
||||||
<Upload class="mr-2 size-5" />
|
]"
|
||||||
{{ $t('ui.actionTitle.import', ['用户']) }}
|
/>
|
||||||
</ElButton>
|
</template>
|
||||||
|
<template #actions="{ row }">
|
||||||
|
<TableAction
|
||||||
|
:actions="[
|
||||||
|
{
|
||||||
|
label: $t('common.edit'),
|
||||||
|
type: 'text',
|
||||||
|
icon: ACTION_ICON.EDIT,
|
||||||
|
auth: ['system:user:update'],
|
||||||
|
onClick: onEdit.bind(null, row),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: $t('common.delete'),
|
||||||
|
type: 'danger',
|
||||||
|
text: true,
|
||||||
|
icon: ACTION_ICON.DELETE,
|
||||||
|
auth: ['system:user:delete'],
|
||||||
|
popConfirm: {
|
||||||
|
title: $t('ui.actionMessage.deleteConfirm', [row.name]),
|
||||||
|
confirm: onDelete.bind(null, row),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
]"
|
||||||
|
:drop-down-actions="[
|
||||||
|
{
|
||||||
|
label: '分配角色',
|
||||||
|
type: 'text',
|
||||||
|
auth: ['system:permission:assign-user-role'],
|
||||||
|
onClick: onAssignRole.bind(null, row),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '重置密码',
|
||||||
|
type: 'text',
|
||||||
|
auth: ['system:user:update-password'],
|
||||||
|
onClick: onResetPassword.bind(null, row),
|
||||||
|
},
|
||||||
|
]"
|
||||||
|
/>
|
||||||
</template>
|
</template>
|
||||||
</Grid>
|
</Grid>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue