diff --git a/kicc-ui/src/api/system/dept.ts b/kicc-ui/src/api/system/dept.ts index 89992aed..0f3340f4 100644 --- a/kicc-ui/src/api/system/dept.ts +++ b/kicc-ui/src/api/system/dept.ts @@ -1,25 +1,58 @@ 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"; + +const prefix = '/system_proxy/system'; enum Api { - list = '/system_proxy/system/dept/list', - List = '/mate-system/depart/list', - Set = '/mate-system/depart/set', - Del = '/mate-system/depart/del', - DeptList = '/mate-system/depart/list', + List = '/dept/list', + Save = '/dept/save', + Update = '/dept/update', + Remove = '/dept/remove', + DeptList = '/dept/deptTree', } -// 菜单树 -export const departList = (params?: DepartVO) => defHttp.get({ url: Api.List, params }); +//获取部门根据id +export const getDeptById = (params: {id: string}) => + defHttp.get({url: prefix + `/dept/${params.id}` }) -// 保存 -export const departSet = (params: Depart) => defHttp.post({ url: Api.Set, params }); +//部门列表 +export const deptList = (params?: Partial) => defHttp.get({ url: prefix + Api.List, params }); -// 删除 -export const departDel = (params: { ids: String }) => - defHttp.post({ url: Api.Del + `?ids=${params.ids}` }); +// 部门树 +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 => { + 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 getDeptList = (params?: DeptListItem) => defHttp.get({ url: Api.DeptList, params }); +// 删除 +export const departRemove = (params: { id: String }) => + defHttp.delete({ url: prefix + Api.Remove + `/${params.id}` }); -// 查询部门列表 -export const deptList = (params?: Partial) => defHttp.get({ url: Api.list, params }); +export const getDeptList = (params?: DeptListItem) => + defHttp.get({ url: prefix + Api.DeptList, params }); diff --git a/kicc-ui/src/views/system/depart/DeptModal.vue b/kicc-ui/src/views/system/depart/DeptModal.vue deleted file mode 100644 index 57865e46..00000000 --- a/kicc-ui/src/views/system/depart/DeptModal.vue +++ /dev/null @@ -1,61 +0,0 @@ - - diff --git a/kicc-ui/src/views/system/depart/dept.data.ts b/kicc-ui/src/views/system/depart/dept.data.ts deleted file mode 100644 index 85dc0302..00000000 --- a/kicc-ui/src/views/system/depart/dept.data.ts +++ /dev/null @@ -1,108 +0,0 @@ -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: '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, - }, -]; - -export const searchFormSchema: FormSchema[] = [ - { - field: 'keyword', - label: '关键字', - component: 'Input', - componentProps: { - placeholder: '请输入名称/编码', - }, - colProps: { span: 8 }, - }, - { - field: 'startDate', - label: '起始时间', - component: 'DatePicker', - colProps: { span: 8 }, - }, - { - field: 'endDate', - label: '截止时间', - component: 'DatePicker', - colProps: { span: 8 }, - }, -]; - -export const formSchema: FormSchema[] = [ - { - field: 'id', - label: 'ID', - component: 'Input', - show: false, - }, - { - field: 'name', - label: '部门名称', - component: 'Input', - required: true, - }, - { - field: 'parentId', - label: '上级部门', - component: 'TreeSelect', - - componentProps: { - replaceFields: { - title: 'name', - key: 'id', - value: 'id', - }, - getPopupContainer: () => document.body, - }, - required: true, - }, - { - field: 'sort', - label: '排序', - component: 'InputNumber', - required: true, - }, - { - field: 'status', - label: '状态', - component: 'RadioButtonGroup', - defaultValue: '0', - componentProps: { - options: [ - { label: '启用', value: '0' }, - { label: '停用', value: '1' }, - ], - }, - required: true, - }, -]; diff --git a/kicc-ui/src/views/system/dept/DeptModal.vue b/kicc-ui/src/views/system/dept/DeptModal.vue new file mode 100644 index 00000000..ce881b7d --- /dev/null +++ b/kicc-ui/src/views/system/dept/DeptModal.vue @@ -0,0 +1,80 @@ + + diff --git a/kicc-ui/src/views/system/dept/dept.data.ts b/kicc-ui/src/views/system/dept/dept.data.ts new file mode 100644 index 00000000..f2f32d77 --- /dev/null +++ b/kicc-ui/src/views/system/dept/dept.data.ts @@ -0,0 +1,165 @@ +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, + }, +]; + +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 } + } +]; + +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 + } + }, +]; diff --git a/kicc-ui/src/views/system/depart/index.vue b/kicc-ui/src/views/system/dept/index.vue similarity index 53% rename from kicc-ui/src/views/system/depart/index.vue rename to kicc-ui/src/views/system/dept/index.vue index bcf51ea4..6ba262a1 100644 --- a/kicc-ui/src/views/system/depart/index.vue +++ b/kicc-ui/src/views/system/dept/index.vue @@ -2,24 +2,33 @@
@@ -32,8 +41,9 @@ import { useModal } from '/@/components/Modal'; import DeptModal from './DeptModal.vue'; import { columns, searchFormSchema } from './dept.data'; - import { departDel, departList } from '/@/api/system/dept'; + import { departRemove, departTreeList } from '/@/api/system/dept'; import { useMessage } from '/@/hooks/web/useMessage'; + import {convertDateRange} from "/@/utils/dateUtil"; const { createMessage } = useMessage(); @@ -44,7 +54,7 @@ const [registerModal, { openModal }] = useModal(); const [registerTable, { reload }] = useTable({ title: '部门列表', - api: departList, + api: departTreeList, columns, formConfig: { labelWidth: 120, @@ -58,33 +68,33 @@ showIndexColumn: false, canResize: false, actionColumn: { - width: 80, + width: 150, title: '操作', dataIndex: 'action', slots: { customRender: 'action' }, - fixed: undefined, + fixed: false, }, + handleSearchInfoFn: (queryParams) => convertDateRange(queryParams, 'dateRange') }); - function handleCreate() { - openModal(true, { - isUpdate: false, - }); + /** 新增按钮操作,行内新增与工具栏局域新增通用 */ + function handleAdd(record?: Recordable) { + openModal(true,{ isUpdate: false, record }); } + /** 编辑按钮操作,行内编辑 */ function handleEdit(record: Recordable) { - openModal(true, { - record, - isUpdate: true, - }); + openModal(true, { isUpdate: true, record }); } - async function handleDelete(record: Recordable) { - await departDel({ ids: record.id }); + /** 删除按钮操作,行内删除 */ + async function handleDel(record: Recordable) { + await departRemove(record.id); createMessage.success('删除成功!'); handleSuccess(); } + /** 处理表单提交成功 */ function handleSuccess() { reload(); } @@ -92,9 +102,9 @@ return { registerTable, registerModal, - handleCreate, + handleAdd, handleEdit, - handleDelete, + handleDel, handleSuccess, }; }, diff --git a/kicc-ui/src/views/system/user/DeptTree.vue b/kicc-ui/src/views/system/user/DeptTree.vue index 9b434a48..6e0a6a46 100644 --- a/kicc-ui/src/views/system/user/DeptTree.vue +++ b/kicc-ui/src/views/system/user/DeptTree.vue @@ -13,8 +13,7 @@