16 changed files with 388 additions and 439 deletions
@ -1,58 +1,31 @@
@@ -1,58 +1,31 @@
|
||||
import { DepartVO, DeptDto, Depart, DeptListItem, DeptListGetResultModel } from './model/deptModel'; |
||||
import { defHttp } from '/@/utils/http/axios'; |
||||
import {listToTree} from "/@/utils/helper/treeHelper"; |
||||
import {isDef} from "/@/utils/is"; |
||||
/** |
||||
* 提供api模板规范代码参考,请尽量保证编写代码风格跟模板规范代码一致 |
||||
* Copyright © 2020-2022 <a href="http://www.entfrm.com/">entfrm</a> All rights reserved. |
||||
* author entfrm开发团队-王翔 |
||||
*/ |
||||
|
||||
const prefix = '/system_proxy/system'; |
||||
import { DeptDto, Dept } from './model/deptModel'; |
||||
import { defHttp } from '/@/utils/http/axios'; |
||||
|
||||
enum Api { |
||||
List = '/dept/list', |
||||
Save = '/dept/save', |
||||
Update = '/dept/update', |
||||
Remove = '/dept/remove', |
||||
DeptList = '/dept/deptTree', |
||||
list = '/system_proxy/system/dept/list', |
||||
add = '/system_proxy/system/dept/save', |
||||
get = '/system_proxy/system/dept', |
||||
edit = '/system_proxy/system/dept/update', |
||||
del = '/system_proxy/system/dept/remove', |
||||
} |
||||
|
||||
//获取部门根据id
|
||||
export const getDeptById = (params: {id: string}) => |
||||
defHttp.get({url: prefix + `/dept/${params.id}` }) |
||||
// 查询部门列表
|
||||
export const listDept = (params?: Partial<DeptDto>) => defHttp.get({ url: Api.list, params }); |
||||
|
||||
//部门列表
|
||||
export const deptList = (params?: Partial<DeptDto>) => defHttp.get({ url: prefix + Api.List, params }); |
||||
|
||||
// 部门树
|
||||
export const departTreeList = (params?: DepartVO) => { |
||||
return defHttp.get({ url: prefix + Api.List, params }).then(data => { |
||||
return listToTree(data, { |
||||
id: 'deptId', |
||||
children: 'children', |
||||
parentId: 'parentId', |
||||
}) as any[]; |
||||
}); |
||||
} |
||||
// 新增部门
|
||||
export const addDept = (params: Partial<Dept>) => defHttp.post({ url: Api.add, data: params }); |
||||
|
||||
export const departTreeHasTop = (params?: DepartVO) => { |
||||
return defHttp.get({ url: prefix + Api.List, params }).then(data => { |
||||
data.unshift({ deptId: '0', sort: 0, name: '顶级部门', children: [] }); |
||||
return listToTree(data, { |
||||
id: 'deptId', |
||||
children: 'children', |
||||
parentId: 'parentId', |
||||
}) as any[]; |
||||
}); |
||||
} |
||||
|
||||
export const departSet = (params: Depart) => { |
||||
if (isDef(params.id)){ |
||||
return defHttp.put({ url: prefix + Api.Update, params }); |
||||
}else { |
||||
return defHttp.post({ url: prefix + Api.Save, params }); |
||||
} |
||||
} |
||||
// 修改部门
|
||||
export const editDept = (params: Partial<Dept>) => defHttp.put({ url: Api.edit, data: params }); |
||||
|
||||
// 删除
|
||||
export const departRemove = (params: { id: String }) => |
||||
defHttp.delete<boolean>({ url: prefix + Api.Remove + `/${params.id}` }); |
||||
// 查询部门详细
|
||||
export const getDept = (id: string) => defHttp.get<Dept>({ url: `${Api.get}/${id}` }); |
||||
|
||||
export const getDeptList = (params?: DeptListItem) => |
||||
defHttp.get<DeptListGetResultModel>({ url: prefix + Api.DeptList, params }); |
||||
// 删除部门
|
||||
export const delDept = (id: string) => defHttp.delete({ url: `${Api.del}/${id}` }); |
||||
|
@ -1,80 +1,89 @@
@@ -1,80 +1,89 @@
|
||||
<template> |
||||
<BasicModal |
||||
v-bind="$attrs" |
||||
@register="registerModal" |
||||
@ok="handleSubmit" |
||||
width="720px"> |
||||
<BasicForm @register="registerForm" /> |
||||
<BasicModal v-bind="$attrs" |
||||
width="720px" |
||||
@ok="handleSubmit" |
||||
@register="registerModal" |
||||
> |
||||
<BasicForm @register="registerForm"/> |
||||
</BasicModal> |
||||
</template> |
||||
<script lang="ts"> |
||||
import { defineComponent, ref, computed, unref } from 'vue'; |
||||
import {BasicModal, ModalProps, useModalInner} from '/@/components/Modal'; |
||||
import { BasicForm, useForm } from '/@/components/Form/index'; |
||||
import { formSchema } from './dept.data'; |
||||
import { deptList, departSet } from '/@/api/controller/system/dept'; |
||||
import {isDef} from "/@/utils/is"; |
||||
import {listToTree} from "/@/utils/helper/treeHelper"; |
||||
<script lang="ts" setup> |
||||
/** |
||||
* 提供模板规范代码参考,请尽量保证编写代码风格跟模板规范代码一致 |
||||
* 采用vben-动态表格表单封装组件编写,采用 setup 写法 |
||||
* Copyright © 2020-2022 <a href="http://www.entfrm.com/">entfrm</a> All rights reserved. |
||||
* author entfrm开发团队-王翔 |
||||
*/ |
||||
import { ref, unref } from 'vue'; |
||||
import { BasicForm, useForm } from '/@/components/Form/index'; |
||||
import { formSchema } from './dept.data'; |
||||
import { BasicModal, ModalProps, useModalInner } from '/@/components/Modal'; |
||||
import { listDept, addDept, editDept, getDept } from '/@/api/controller/system/dept'; |
||||
import { listToTree } from "/@/utils/helper/treeHelper"; |
||||
|
||||
export default defineComponent({ |
||||
name: 'DeptModal', |
||||
components: { BasicModal, BasicForm }, |
||||
emits: ['success', 'register'], |
||||
setup(_, { emit }) { |
||||
const isUpdate = ref(true); |
||||
|
||||
const [registerForm, { resetFields, setFieldsValue, updateSchema, validate }] = useForm({ |
||||
labelWidth: 100, |
||||
schemas: formSchema, |
||||
showActionButtonGroup: false, |
||||
baseColProps: { span: 24 } |
||||
}); |
||||
|
||||
const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => { |
||||
await resetFields(); |
||||
const props: Partial<ModalProps> = { confirmLoading: false }; |
||||
|
||||
isUpdate.value = !!data?.isUpdate; |
||||
|
||||
if (unref(isUpdate)) { |
||||
await setFieldsValue({ |
||||
...data.record, |
||||
}); |
||||
props.title = "编辑部门"; |
||||
}else { |
||||
props.title = "新增部门"; |
||||
} |
||||
let treeData = await deptList(); |
||||
treeData.unshift({ deptId: '0', sort: 0, name: '顶级部门', children: [] }); |
||||
treeData = listToTree(treeData,{ |
||||
id: 'deptId', |
||||
children: 'children', |
||||
parentId: 'parentId', |
||||
}); |
||||
await updateSchema({ |
||||
field: 'parentId', |
||||
componentProps: { treeData }, |
||||
}); |
||||
if (isDef(data.record?.deptId)){ |
||||
await setFieldsValue({parentId: data.record?.deptId}) |
||||
/** 通用变量统一声明区域 */ |
||||
const tag = ref<string>(''); |
||||
/** https://v3.cn.vuejs.org/api/options-data.html#emits */ |
||||
const emit = defineEmits(['success', 'register']); |
||||
const [registerForm, { resetFields, setFieldsValue, updateSchema, validate, clearValidate }] = useForm({ |
||||
labelWidth: 100, |
||||
schemas: formSchema, |
||||
showActionButtonGroup: false, |
||||
baseColProps: { span: 24 } |
||||
}); |
||||
const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data: WindowInnerData = { _tag: '' }) => { |
||||
// 处理清除脏数据 |
||||
await resetFields(); |
||||
await clearValidate(); |
||||
// 处理设置数据 |
||||
tag.value = data._tag; |
||||
const topDept = { id: '0', name: '顶级部门', children: [] }; |
||||
topMenu.children = listToTree(await listDept()); |
||||
await updateSchema( { |
||||
field: 'parentId', |
||||
componentProps: { |
||||
treeData: [topDept] |
||||
} |
||||
|
||||
setModalProps(props); |
||||
}); |
||||
const deptId = data.record?.id; |
||||
const props: Partial<ModalProps> = { confirmLoading: false }; |
||||
// 采用tag标签区分操作 |
||||
switch (unref(tag)) { |
||||
case 'add': |
||||
props.title = '新增部门'; |
||||
deptId && await setFieldsValue({ parentId: deptId }); |
||||
break; |
||||
case 'edit': |
||||
props.title = '编辑部门'; |
||||
await setFieldsValue(await getDept(deptId)); |
||||
break; |
||||
} |
||||
// 尾部:设置处理后的最终配置数据 |
||||
setModalProps(props); |
||||
}); |
||||
|
||||
async function handleSubmit() { |
||||
try { |
||||
const values = await validate(); |
||||
setModalProps({ confirmLoading: true }); |
||||
await departSet(values); |
||||
closeModal(); |
||||
emit('success'); |
||||
} finally { |
||||
setModalProps({ confirmLoading: false }); |
||||
/** 处理弹出框提交 */ |
||||
async function handleSubmit() { |
||||
try { |
||||
// 提取验证数据 |
||||
const formData = await validate(); |
||||
// 处理提交之前逻辑 |
||||
setModalProps({ confirmLoading: true }); |
||||
// 采用tag标签区分操作 |
||||
switch (unref(tag)) { |
||||
case 'add': |
||||
await addDept(formData); |
||||
break; |
||||
case 'edit': |
||||
await editDept(formData); |
||||
break; |
||||
} |
||||
// 处理提交完成之后逻辑 |
||||
closeModal(); |
||||
emit('success'); |
||||
} finally { |
||||
setModalProps({ confirmLoading: false }); |
||||
} |
||||
} |
||||
|
||||
return { registerModal, registerForm, handleSubmit }; |
||||
}, |
||||
}); |
||||
</script> |
||||
|
@ -1,165 +1,192 @@
@@ -1,165 +1,192 @@
|
||||
import {BasicColumn} from '/@/components/Table'; |
||||
import {FormSchema} from '/@/components/Table'; |
||||
import {h} from 'vue'; |
||||
import {Tag} from 'ant-design-vue'; |
||||
/** |
||||
* @program: kicc-ui |
||||
* @description: 部门模块动态渲染配置 |
||||
* @author: entfrm开发团队-王翔 |
||||
* @create: 2022/4/21 |
||||
*/ |
||||
|
||||
import { BasicColumn } from '/@/components/Table'; |
||||
import { FormSchema } from '/@/components/Table'; |
||||
import { h } from 'vue'; |
||||
import { Tag } from 'ant-design-vue'; |
||||
|
||||
/** 表格列配置 */ |
||||
export const columns: BasicColumn[] = [ |
||||
{ |
||||
title: '部门名称', |
||||
dataIndex: 'name', |
||||
width: 160, |
||||
align: 'left', |
||||
}, |
||||
{ |
||||
title: '部门编码', |
||||
dataIndex: 'code', |
||||
width: 160, |
||||
}, |
||||
{ |
||||
title: '排序', |
||||
dataIndex: 'sort', |
||||
width: 50, |
||||
}, |
||||
{ |
||||
title: '状态', |
||||
dataIndex: 'status', |
||||
width: 80, |
||||
customRender: ({record}) => { |
||||
const status = record.status; |
||||
const enable = ~~status === 0; |
||||
const color = enable ? 'green' : 'red'; |
||||
const text = enable ? '启用' : '停用'; |
||||
return h(Tag, {color: color}, () => text); |
||||
}, |
||||
}, |
||||
{ |
||||
title: '创建时间', |
||||
dataIndex: 'createTime', |
||||
width: 180, |
||||
}, |
||||
{ |
||||
title: '部门名称', |
||||
dataIndex: 'name', |
||||
align: 'left' |
||||
}, |
||||
{ |
||||
title: '部门编码', |
||||
dataIndex: 'code' |
||||
}, |
||||
{ |
||||
title: '排序', |
||||
dataIndex: 'sort', |
||||
width: 80 |
||||
}, |
||||
{ |
||||
title: '状态', |
||||
dataIndex: 'status', |
||||
width: 80, |
||||
customRender: ({record}) => { |
||||
const status = record.status; |
||||
// 采用二进制~~取反,只要为null或者0等等一些其他的空元素都会转为0
|
||||
// 第一次取反会运算为-1,在后一次取反会运算为0
|
||||
const enable = ~~status === 0; |
||||
const color = enable ? 'green' : 'red'; |
||||
const text = enable ? '启用' : '停用'; |
||||
return h(Tag, { color: color }, () => text); |
||||
} |
||||
}, |
||||
{ |
||||
title: '创建时间', |
||||
dataIndex: 'createTime' |
||||
} |
||||
]; |
||||
|
||||
/** 搜索表单配置 */ |
||||
export const searchFormSchema: FormSchema[] = [ |
||||
{ |
||||
field: 'keyword', |
||||
label: '关键字', |
||||
component: 'Input', |
||||
componentProps: { |
||||
placeholder: '请输入名称/编码', |
||||
}, |
||||
colProps: {span: 8}, |
||||
}, |
||||
{ |
||||
field: 'dateRange', |
||||
label: '创建时间', |
||||
component: 'RangePicker', |
||||
componentProps: { |
||||
style: { width:'100%' }, |
||||
valueFormat: 'YYYY-MM-DD', |
||||
placeholder: ['开始日期','结束日期'] |
||||
}, |
||||
colProps: { span: 8 } |
||||
} |
||||
{ |
||||
field: 'name', |
||||
label: '部门名称', |
||||
component: 'Input', |
||||
componentProps: { |
||||
placeholder: '请输入部门名称' |
||||
}, |
||||
colProps: {span: 8} |
||||
}, |
||||
{ |
||||
field: 'status', |
||||
label: '状态', |
||||
component: 'Select', |
||||
componentProps: { |
||||
options: [ |
||||
{ label: '正常', value: '0' }, |
||||
{ label: '停用', value: '1' } |
||||
] |
||||
}, |
||||
colProps: { span: 7 } |
||||
}, |
||||
{ |
||||
field: 'dateRange', |
||||
label: '创建时间', |
||||
component: 'RangePicker', |
||||
componentProps: { |
||||
style: { width:'100%' }, |
||||
valueFormat: 'YYYY-MM-DD', |
||||
placeholder: ['开始日期','结束日期'] |
||||
}, |
||||
colProps: { span: 8 } |
||||
} |
||||
]; |
||||
|
||||
/** 表单配置 */ |
||||
export const formSchema: FormSchema[] = [ |
||||
{ |
||||
field: 'deptId', |
||||
label: 'ID', |
||||
component: 'Input', |
||||
show: false |
||||
}, |
||||
{ |
||||
field: 'name', |
||||
label: '部门名称', |
||||
component: 'Input', |
||||
required: true |
||||
}, |
||||
{ |
||||
field: 'parentId', |
||||
label: '上级部门', |
||||
component: 'TreeSelect', |
||||
componentProps: { |
||||
replaceFields: { |
||||
title: 'name', |
||||
key: 'deptId', |
||||
value: 'deptId', |
||||
}, |
||||
getPopupContainer: () => document.body, |
||||
}, |
||||
required: true, |
||||
colProps: { |
||||
span: 12 |
||||
} |
||||
}, |
||||
{ |
||||
field: 'code', |
||||
label: '部门编码', |
||||
component: 'Input', |
||||
required: true, |
||||
colProps: { |
||||
span: 12 |
||||
} |
||||
}, |
||||
{ |
||||
field: 'sort', |
||||
label: '排序', |
||||
component: 'Input', |
||||
required: true, |
||||
colProps: { |
||||
span: 12 |
||||
} |
||||
}, |
||||
{ |
||||
field: 'contacts', |
||||
label: '联系人', |
||||
component: 'Input', |
||||
required: false, |
||||
colProps: { |
||||
span: 12 |
||||
} |
||||
}, |
||||
{ |
||||
field: 'phone', |
||||
label: '联系人电话', |
||||
component: 'Input', |
||||
required: false, |
||||
colProps: { |
||||
span: 12 |
||||
} |
||||
}, |
||||
{ |
||||
field: 'address', |
||||
label: '联系地址', |
||||
component: 'Input', |
||||
required: false, |
||||
colProps: { |
||||
span: 12 |
||||
} |
||||
}, |
||||
{ |
||||
field: 'email', |
||||
label: '邮箱', |
||||
component: 'Input', |
||||
required: false, |
||||
colProps: { |
||||
span: 12 |
||||
} |
||||
}, |
||||
{ |
||||
field: 'status', |
||||
label: '状态', |
||||
component: 'RadioButtonGroup', |
||||
defaultValue: '0', |
||||
componentProps: { |
||||
options: [ |
||||
{label: '启用', value: '0'}, |
||||
{label: '停用', value: '1'}, |
||||
], |
||||
}, |
||||
required: true, |
||||
colProps: { |
||||
span: 12 |
||||
} |
||||
}, |
||||
{ |
||||
field: 'deptId', |
||||
label: 'ID', |
||||
component: 'Input', |
||||
show: false |
||||
}, |
||||
{ |
||||
field: 'parentId', |
||||
label: '上级部门', |
||||
component: 'TreeSelect', |
||||
defaultValue: '0', |
||||
componentProps: { |
||||
replaceFields: { |
||||
title: 'name', |
||||
key: 'deptId', |
||||
value: 'deptId', |
||||
}, |
||||
getPopupContainer: () => document.body, |
||||
} |
||||
}, |
||||
{ |
||||
field: 'name', |
||||
label: '部门名称', |
||||
component: 'Input', |
||||
required: true, |
||||
colProps: { |
||||
span: 12 |
||||
} |
||||
}, |
||||
{ |
||||
field: 'code', |
||||
label: '部门代码', |
||||
component: 'Input', |
||||
required: true, |
||||
colProps: { |
||||
span: 12 |
||||
} |
||||
}, |
||||
{ |
||||
field: 'contacts', |
||||
label: '联系人', |
||||
component: 'Input', |
||||
colProps: { |
||||
span: 12 |
||||
} |
||||
}, |
||||
{ |
||||
field: 'phone', |
||||
label: '联系人电话', |
||||
component: 'Input', |
||||
rules: [ |
||||
{ |
||||
pattern: new RegExp('^1[3|4|5|6|7|8|9][0-9]\\d{8}$'), |
||||
message: '请输入正确的手机号码!', |
||||
validateTrigger: 'change' |
||||
} |
||||
], |
||||
colProps: { |
||||
span: 12 |
||||
} |
||||
}, |
||||
{ |
||||
field: 'sort', |
||||
label: '部门排序', |
||||
component: 'InputNumber', |
||||
componentProps: { |
||||
style: { width:'100%' }, |
||||
min: 0 |
||||
}, |
||||
required: true, |
||||
colProps: { |
||||
span: 12 |
||||
} |
||||
}, |
||||
{ |
||||
field: 'email', |
||||
label: '邮箱', |
||||
component: 'Input', |
||||
rules: [ |
||||
{ |
||||
type: 'email', |
||||
message: '请输入正确的邮箱地址!', |
||||
validateTrigger: 'change' |
||||
} |
||||
], |
||||
colProps: { |
||||
span: 12 |
||||
} |
||||
}, |
||||
{ |
||||
field: 'status', |
||||
label: '状态', |
||||
component: 'RadioGroup', |
||||
defaultValue: '0', |
||||
componentProps: { |
||||
options: [ |
||||
{ label: '正常', value: '0' }, |
||||
{ label: '停用', value: '1' } |
||||
] |
||||
}, |
||||
required: true, |
||||
colProps: { |
||||
span: 12 |
||||
} |
||||
} |
||||
]; |
||||
|
Loading…
Reference in new issue