diff --git a/apps/web-antd/src/api/infra/demo/demo01/index.ts b/apps/web-antd/src/api/infra/demo/demo01/index.ts new file mode 100644 index 000000000..287117584 --- /dev/null +++ b/apps/web-antd/src/api/infra/demo/demo01/index.ts @@ -0,0 +1,45 @@ +import type { PageParam, PageResult } from '@vben/request'; + +import { requestClient } from '#/api/request'; + +export namespace Demo01ContactApi { + /** 示例联系人信息 */ + export interface Demo01Contact { + id: number; // 编号 + name?: string; // 名字 + sex?: number; // 性别 + birthday?: Date; // 出生年 + description?: string; // 简介 + avatar: string; // 头像 + } +} + +/** 查询示例联系人分页 */ +export function getDemo01ContactPage(params: PageParam) { + return requestClient.get>('/infra/demo01-contact/page', { params }); +} + +/** 查询示例联系人详情 */ +export function getDemo01Contact(id: number) { + return requestClient.get(`/infra/demo01-contact/get?id=${id}`); +} + +/** 新增示例联系人 */ +export function createDemo01Contact(data: Demo01ContactApi.Demo01Contact) { + return requestClient.post('/infra/demo01-contact/create', data); +} + +/** 修改示例联系人 */ +export function updateDemo01Contact(data: Demo01ContactApi.Demo01Contact) { + return requestClient.put('/infra/demo01-contact/update', data); +} + +/** 删除示例联系人 */ +export function deleteDemo01Contact(id: number) { + return requestClient.delete(`/infra/demo01-contact/delete?id=${id}`); +} + +/** 导出示例联系人 */ +export function exportDemo01Contact(params: any) { + return requestClient.download('/infra/demo01-contact/export-excel', params); +} diff --git a/apps/web-antd/src/api/infra/demo/demo02/index.ts b/apps/web-antd/src/api/infra/demo/demo02/index.ts new file mode 100644 index 000000000..c231f8d94 --- /dev/null +++ b/apps/web-antd/src/api/infra/demo/demo02/index.ts @@ -0,0 +1,41 @@ +import { requestClient } from '#/api/request'; + +export namespace Demo02CategoryApi { + /** 示例分类信息 */ + export interface Demo02Category { + id: number; // 编号 + name?: string; // 名字 + parentId?: number; // 父级编号 + children?: Demo02Category[]; + } +} + +/** 查询示例分类列表 */ +export function getDemo02CategoryList(params: any) { + return requestClient.get('/infra/demo02-category/list', { params }); +} + +/** 查询示例分类详情 */ +export function getDemo02Category(id: number) { + return requestClient.get(`/infra/demo02-category/get?id=${id}`); +} + +/** 新增示例分类 */ +export function createDemo02Category(data: Demo02CategoryApi.Demo02Category) { + return requestClient.post('/infra/demo02-category/create', data); +} + +/** 修改示例分类 */ +export function updateDemo02Category(data: Demo02CategoryApi.Demo02Category) { + return requestClient.put('/infra/demo02-category/update', data); +} + +/** 删除示例分类 */ +export function deleteDemo02Category(id: number) { + return requestClient.delete(`/infra/demo02-category/delete?id=${id}`); +} + +/** 导出示例分类 */ +export function exportDemo02Category(params: any) { + return requestClient.download('/infra/demo02-category/export-excel', params); +} diff --git a/apps/web-antd/src/views/infra/demo/demo01/data.ts b/apps/web-antd/src/views/infra/demo/demo01/data.ts new file mode 100644 index 000000000..f1afa10a1 --- /dev/null +++ b/apps/web-antd/src/views/infra/demo/demo01/data.ts @@ -0,0 +1,177 @@ +import type { VbenFormSchema } from '#/adapter/form'; +import type { OnActionClickFn, VxeTableGridOptions } from '#/adapter/vxe-table'; +import type { Demo01ContactApi } from '#/api/infra/demo/demo01'; + +import { getRangePickerDefaultProps } from '#/utils/date'; +import { DICT_TYPE, getDictOptions } from '#/utils/dict'; + +import { useAccess } from '@vben/access'; + +const { hasAccessByCodes } = useAccess(); + +/** 新增/修改的表单 */ +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: 'Editor', + }, + { + fieldName: 'avatar', + label: '头像', + component: 'FileUpload', + componentProps: { + fileType: 'image', + maxCount: 1, + }, + }, + ]; +} + +/** 列表的搜索表单 */ +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'), + }, + }, + { + fieldName: 'createTime', + label: '创建时间', + component: 'RangePicker', + componentProps: { + ...getRangePickerDefaultProps(), + allowClear: true, + }, + }, + ]; +} + +/** 列表的字段 */ +export function useGridColumns( + onActionClick: OnActionClickFn, +): VxeTableGridOptions['columns'] { + return [ + { + 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', + }, + { + field: 'operation', + title: '操作', + minWidth: 180, + align: 'center', + fixed: 'right', + cellRender: { + attrs: { + nameField: 'id', + nameTitle: '示例联系人', + onClick: onActionClick, + }, + name: 'CellOperation', + options: [ + { + code: 'edit', + show: hasAccessByCodes(['infra:demo01-contact:update']), + }, + { + code: 'delete', + show: hasAccessByCodes(['infra:demo01-contact:delete']), + }, + ], + }, + }, + ]; +} diff --git a/apps/web-antd/src/views/infra/demo/demo01/index.vue b/apps/web-antd/src/views/infra/demo/demo01/index.vue new file mode 100644 index 000000000..aec93edf7 --- /dev/null +++ b/apps/web-antd/src/views/infra/demo/demo01/index.vue @@ -0,0 +1,125 @@ + + + diff --git a/apps/web-antd/src/views/infra/demo/demo01/modules/form.vue b/apps/web-antd/src/views/infra/demo/demo01/modules/form.vue new file mode 100644 index 000000000..3893a7db0 --- /dev/null +++ b/apps/web-antd/src/views/infra/demo/demo01/modules/form.vue @@ -0,0 +1,76 @@ + + + diff --git a/apps/web-antd/src/views/infra/demo/demo02/data.ts b/apps/web-antd/src/views/infra/demo/demo02/data.ts new file mode 100644 index 000000000..9cd221563 --- /dev/null +++ b/apps/web-antd/src/views/infra/demo/demo02/data.ts @@ -0,0 +1,154 @@ +import type { VbenFormSchema } from '#/adapter/form'; +import type { OnActionClickFn } from '#/adapter/vxe-table'; +import type { Demo02CategoryApi } from '#/api/infra/demo/demo02'; +import type { VxeTableGridOptions } from '@vben/plugins/vxe-table'; + +import { getDemo02CategoryList } from '#/api/infra/demo/demo02'; +import { handleTree } from '#/utils/tree'; + +import { useAccess } from '@vben/access'; + +const { hasAccessByCodes } = useAccess(); + +/** 新增/修改的表单 */ +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); + }, + class: 'w-full', + 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: { + allowClear: true, + }, + }, + ]; +} + +/** 列表的字段 */ +export function useGridColumns( + onActionClick?: OnActionClickFn, +): VxeTableGridOptions['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', + }, + { + field: 'operation', + title: '操作', + minWidth: 200, + align: 'right', + fixed: 'right', + headerAlign: 'center', + showOverflow: false, + cellRender: { + attrs: { + nameField: 'id', + nameTitle: '示例分类', + onClick: onActionClick, + }, + name: 'CellOperation', + options: [ + { + code: 'add_child', + text: '新增下级', + show: hasAccessByCodes(['infra:demo02-category:create']), + }, + { + code: 'edit', + show: hasAccessByCodes(['infra:demo02-category:update']), + }, + { + code: 'delete', + show: hasAccessByCodes(['infra:demo02-category:delete']), + disabled: (row: Demo02CategoryApi.Demo02Category) => { + return !!(row.children && row.children.length > 0); + }, + }, + ], + }, + }, + ]; +} diff --git a/apps/web-antd/src/views/infra/demo/demo02/index.vue b/apps/web-antd/src/views/infra/demo/demo02/index.vue new file mode 100644 index 000000000..a3793e08a --- /dev/null +++ b/apps/web-antd/src/views/infra/demo/demo02/index.vue @@ -0,0 +1,152 @@ + + + diff --git a/apps/web-antd/src/views/infra/demo/demo02/modules/form.vue b/apps/web-antd/src/views/infra/demo/demo02/modules/form.vue new file mode 100644 index 000000000..06d5951d5 --- /dev/null +++ b/apps/web-antd/src/views/infra/demo/demo02/modules/form.vue @@ -0,0 +1,98 @@ + + +