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