feat:岗位 post 的实现 80%(crud 功能)
This commit is contained in:
@@ -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<SystemDeptApi.SystemDept>,
|
||||
): VxeTableGridOptions<SystemDeptApi.SystemDept>['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,
|
||||
},
|
||||
{
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -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<SystemDeptApi.SystemDept>();
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user