diff --git a/apps/web-antd/src/api/system/post/index.ts b/apps/web-antd/src/api/system/post/index.ts index c6d096c92..848941e23 100644 --- a/apps/web-antd/src/api/system/post/index.ts +++ b/apps/web-antd/src/api/system/post/index.ts @@ -1,37 +1,43 @@ import { requestClient } from '#/api/request'; +import type {PageParam, PageResult} from '@vben/request'; -export interface PostVO { - id?: number; - name: string; - code: string; - sort: number; - status: number; - remark: string; - createTime?: Date; +export namespace SystemPostApi { + /** 岗位信息 */ + export interface SystemPost { + id?: number; + name: string; + code: string; + sort: number; + status: number; + remark: string; + createTime?: Date; + } } /** 查询岗位列表 */ -export function getPostPage(params: any) { - return requestClient.get('/system/post/page', { params }); +export function getPostPage(params: PageParam) { + return requestClient.get>('/system/post/page', { + params + }); } /** 获取岗位精简信息列表 */ export function getSimplePostList() { - return requestClient.get('/system/post/simple-list'); + return requestClient.get('/system/post/simple-list'); } /** 查询岗位详情 */ export function getPost(id: number) { - return requestClient.get(`/system/post/get?id=${id}`); + return requestClient.get(`/system/post/get?id=${id}`); } /** 新增岗位 */ -export function createPost(data: PostVO) { +export function createPost(data: SystemPostApi.SystemPost) { return requestClient.post('/system/post/create', data); } /** 修改岗位 */ -export function updatePost(data: PostVO) { +export function updatePost(data: SystemPostApi.SystemPost) { return requestClient.put('/system/post/update', data); } diff --git a/apps/web-antd/src/views/system/dept/data.ts b/apps/web-antd/src/views/system/dept/data.ts index eba3c4601..2947e9f0f 100644 --- a/apps/web-antd/src/views/system/dept/data.ts +++ b/apps/web-antd/src/views/system/dept/data.ts @@ -12,8 +12,17 @@ import { CommonStatusEnum } from '#/utils/constants'; import { handleTree } from '#/utils/tree'; /** 获取编辑表单的字段配置 */ -export function useSchema(): VbenFormSchema[] { +export function useFormSchema(): VbenFormSchema[] { return [ + { + component: 'Input', + fieldName: 'id', + label: 'id', + dependencies: { + triggerFields: [''], + show: () => false, + }, + }, { component: 'ApiTreeSelect', componentProps: { @@ -35,12 +44,7 @@ export function useSchema(): VbenFormSchema[] { }, fieldName: 'parentId', label: '上级部门', - // TODO @芋艿:number 的必填,写起来有点麻烦,后续得研究下; - rules: z - .number() - .nullable() - .refine((val) => val != null && val >= 0, '上级部门不能为空') - .default(null), + rules: 'selectRequired' }, { component: 'Input', @@ -49,10 +53,7 @@ export function useSchema(): VbenFormSchema[] { }, fieldName: 'name', label: '部门名称', - rules: z - .string() - .min(2, $t('ui.formRules.minLength', ['部门名称', 2])) - .max(20, $t('ui.formRules.maxLength', ['部门名称', 20])), + rules: 'required', }, { component: 'InputNumber', @@ -60,15 +61,11 @@ export function useSchema(): VbenFormSchema[] { min: 0, class: 'w-full', controlsPosition: 'right', - placeholder: '请输入显示排序', + placeholder: '请输入部门顺序', }, fieldName: 'sort', - label: '显示排序', - rules: z - .number() - .nullable() - .refine((val) => val != null && val >= 0, '显示排序不能为空') - .default(null), + label: '部门顺序', + rules: 'required', }, { component: 'ApiSelect', @@ -116,6 +113,8 @@ export function useSchema(): VbenFormSchema[] { component: 'RadioGroup', componentProps: { options: getDictOptions(DICT_TYPE.COMMON_STATUS, 'number'), + buttonStyle: 'solid', + optionType: 'button', }, fieldName: 'status', label: '状态', @@ -126,7 +125,7 @@ export function useSchema(): VbenFormSchema[] { /** 获取表格列配置 */ const userList = await getSimpleUserList(); -export function useColumns( +export function useGridColumns( onActionClick?: OnActionClickFn, ): VxeTableGridOptions['columns'] { return [ @@ -150,7 +149,7 @@ export function useColumns( }, { field: 'sort', - title: '排序', + title: '部门顺序', minWidth: 100, }, { @@ -159,7 +158,7 @@ export function useColumns( props: { type: DICT_TYPE.COMMON_STATUS }, }, field: 'status', - title: '状态', + title: '部门状态', minWidth: 100, }, { diff --git a/apps/web-antd/src/views/system/dept/index.vue b/apps/web-antd/src/views/system/dept/index.vue index 756227d6e..dd8933b7e 100644 --- a/apps/web-antd/src/views/system/dept/index.vue +++ b/apps/web-antd/src/views/system/dept/index.vue @@ -8,13 +8,13 @@ import type { SystemDeptApi } from '#/api/system/dept'; import { ref } from 'vue'; import { $t } from '#/locales'; import { useVbenVxeGrid } from '#/adapter/vxe-table'; -import { deleteDept, getDeptList } from '#/api/system/dept'; +import { getDeptList, deleteDept } from '#/api/system/dept'; import { Page, useVbenModal } from '@vben/common-ui'; import { Button, message } from 'ant-design-vue'; import { Plus } from '@vben/icons'; -import { useColumns } from './data'; +import { useGridColumns } from './data'; import Form from './modules/form.vue'; const [FormModal, formModalApi] = useVbenModal({ @@ -32,7 +32,7 @@ function onAppend(row: SystemDeptApi.SystemDept) { formModalApi.setData({ parentId: row.id }).open(); } -/** 创建新部门 */ +/** 创建部门 */ function onCreate() { formModalApi.setData(null).open(); } @@ -78,9 +78,8 @@ function onActionClick({ } const [Grid, gridApi] = useVbenVxeGrid({ - gridEvents: {}, gridOptions: { - columns: useColumns(onActionClick), + columns: useGridColumns(onActionClick), height: 'auto', keepSource: true, pagerConfig: { @@ -97,10 +96,7 @@ const [Grid, gridApi] = useVbenVxeGrid({ keyField: 'id', }, toolbarConfig: { - custom: true, - export: false, refresh: { code: 'query' }, - zoom: true, }, treeConfig: { parentField: 'parentId', diff --git a/apps/web-antd/src/views/system/dept/modules/form.vue b/apps/web-antd/src/views/system/dept/modules/form.vue index d7aba739c..7cce034bb 100644 --- a/apps/web-antd/src/views/system/dept/modules/form.vue +++ b/apps/web-antd/src/views/system/dept/modules/form.vue @@ -4,13 +4,13 @@ import type { SystemDeptApi } from '#/api/system/dept'; import { computed, ref } from 'vue'; import { useVbenModal } from '@vben/common-ui'; -import { Button } from 'ant-design-vue'; +import { Button, message } from 'ant-design-vue'; import { useVbenForm } from '#/adapter/form'; import { createDept, updateDept, getDept } from '#/api/system/dept'; import { $t } from '#/locales'; -import { useSchema } from '../data'; +import { useFormSchema } from '../data'; const emit = defineEmits(['success']); const formData = ref(); @@ -22,7 +22,7 @@ const getTitle = computed(() => { const [Form, formApi] = useVbenForm({ layout: 'horizontal', - schema: useSchema(), + schema: useFormSchema(), showDefaultActions: false, }); @@ -41,10 +41,14 @@ const [Modal, modalApi] = useVbenModal({ const data = (await formApi.getValues()) as SystemDeptApi.SystemDept; try { await (formData.value?.id - ? updateDept({ id: formData.value.id, ...data }) + ? updateDept(data) : createDept(data)); await modalApi.close(); emit('success'); + message.success({ + content: $t('ui.actionMessage.operationSuccess'), + key: 'action_process_msg', + }); } finally { modalApi.lock(false); } diff --git a/apps/web-antd/src/views/system/post/PostModal.vue b/apps/web-antd/src/views/system/post/PostModal.vue deleted file mode 100644 index 64ce6a2de..000000000 --- a/apps/web-antd/src/views/system/post/PostModal.vue +++ /dev/null @@ -1,54 +0,0 @@ - - diff --git a/apps/web-antd/src/views/system/post/data.ts b/apps/web-antd/src/views/system/post/data.ts new file mode 100644 index 000000000..268bb664d --- /dev/null +++ b/apps/web-antd/src/views/system/post/data.ts @@ -0,0 +1,146 @@ +import {type VbenFormSchema, z} from '#/adapter/form'; +import type { OnActionClickFn, VxeTableGridOptions } from '#/adapter/vxe-table'; +import type { SystemPostApi } from '#/api/system/post'; + +import { DICT_TYPE, getDictOptions } from '#/utils/dict'; +import { CommonStatusEnum } from '#/utils/constants'; + +export function useFormSchema(): VbenFormSchema[] { + return [ + { + component: 'Input', + fieldName: 'id', + label: 'id', + dependencies: { + triggerFields: [''], + show: () => false, + }, + }, + { + component: 'Input', + fieldName: 'name', + label: '岗位名称', + rules: 'required', + }, + { + component: 'Input', + fieldName: 'code', + label: '岗位编码', + rules: 'required', + }, + { + component: 'InputNumber', + componentProps: { + min: 0, + class: 'w-full', + controlsPosition: 'right', + placeholder: '请输入岗位顺序', + }, + fieldName: 'sort', + label: '岗位顺序', + rules: 'required', + }, + { + component: 'RadioGroup', + componentProps: { + options: getDictOptions(DICT_TYPE.COMMON_STATUS, 'number'), + buttonStyle: 'solid', + optionType: 'button', + }, + fieldName: 'status', + label: '岗位岗位', + rules: z.number().default(CommonStatusEnum.ENABLE), + }, + { + component: 'Textarea', + fieldName: 'remark', + label: '岗位备注', + }, + ]; +} + +export function useGridFormSchema(): VbenFormSchema[] { + return [ + { + component: 'Input', + fieldName: 'name', + label: '岗位名称', + }, + { + component: 'Input', + fieldName: 'code', + label: '岗位编码', + }, + { + component: 'Select', + componentProps: { + allowClear: true, + options: getDictOptions(DICT_TYPE.COMMON_STATUS, 'number'), + }, + fieldName: 'status', + label: '岗位状态', + } + ]; +} + +export function useGridColumns( + onActionClick: OnActionClickFn, +): VxeTableGridOptions['columns'] { + return [ + { + field: 'id', + title: '岗位编号', + minWidth: 200, + }, + { + field: 'name', + title: '岗位名称', + minWidth: 200, + }, + { + field: 'code', + title: '岗位编码', + minWidth: 200, + }, + { + field: 'sort', + title: '岗位顺序', + minWidth: 100, + }, + { + field: 'remark', + title: '岗位备注', + minWidth: 200, + }, + { + cellRender: { + name: 'CellDict', + props: { type: DICT_TYPE.COMMON_STATUS }, + }, + field: 'status', + title: '状态', + minWidth: 100, + }, + { + field: 'createTime', + title: '创建时间', + minWidth: 180, + formatter: 'formatDateTime', + }, + { + align: 'center', + cellRender: { + attrs: { + nameField: 'name', + nameTitle: '岗位', + onClick: onActionClick, + }, + name: 'CellOperation', + }, + field: 'operation', + fixed: 'right', + title: '操作', + minWidth: 130, + }, + ]; +} diff --git a/apps/web-antd/src/views/system/post/index.vue b/apps/web-antd/src/views/system/post/index.vue index bf2895519..f014c6cef 100644 --- a/apps/web-antd/src/views/system/post/index.vue +++ b/apps/web-antd/src/views/system/post/index.vue @@ -1,115 +1,117 @@ -