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/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 @@ + + +