diff --git a/src/api/system/dept.ts b/src/api/system/dept.ts index 2509c5a7..288a16ef 100644 --- a/src/api/system/dept.ts +++ b/src/api/system/dept.ts @@ -37,18 +37,6 @@ export function getDept(deptId: string | number) { }); } -/** - * 查询部门详细 - * @param deptId 部门ID - * @returns object - */ -export function getTenant(deptId: string | number) { - return request({ - url: `/system/tenant/${deptId}`, - method: 'get', - }); -} - /** * 新增部门 * @param data 部门对象 diff --git a/src/api/system/tenant.ts b/src/api/system/tenant.ts new file mode 100644 index 00000000..7869e23d --- /dev/null +++ b/src/api/system/tenant.ts @@ -0,0 +1,99 @@ +import { request } from '@/plugins/http-fetch'; + +/** + * 查询部门列表 + * @param query 查询参数 + * @returns object + */ +export function listDept(query: Record) { + return request({ + url: '/system/tenant/list', + method: 'get', + params: query, + }); +} + +/** + * 查询部门列表(排除节点) + * @param deptId 部门ID + * @returns object + */ +export function listDeptExcludeChild(deptId: string | number) { + return request({ + url: `/system/tenant/list/exclude/${deptId}`, + method: 'get', + }); +} + +/** + * 查询部门详细 + * @param deptId 部门ID + * @returns object + */ +export function getDept(deptId: string | number) { + return request({ + url: `/system/tenant/${deptId}`, + method: 'get', + }); +} + +/** + * 新增部门 + * @param data 部门对象 + * @returns object + */ +export function addDept(data: Record) { + return request({ + url: '/system/tenant', + method: 'post', + data: data, + }); +} + +/** + * 修改部门 + * @param data 部门对象 + * @returns object + */ +export function updateDept(data: Record) { + return request({ + url: '/system/tenant', + method: 'put', + data: data, + }); +} + +/** + * 删除部门 + * @param deptId 部门ID + * @returns object + */ +export function delDept(deptId: string | number) { + return request({ + url: `/system/tenant/${deptId}`, + method: 'delete', + }); +} + +/** + * 查询部门下拉树结构 + * @returns object + */ +export function deptTreeSelect() { + return request({ + url: '/system/tenant/treeSelect', + method: 'get', + }); +} + +/** + * 部门树结构列表(指定角色) + * @param roleId 角色ID + * @returns object + */ +export function roleDeptTreeSelect(roleId: string | number) { + return request({ + url: `/system/tenant/roleDeptTreeSelect/${roleId}`, + method: 'get', + }); +} diff --git a/src/views/system/dept/index.vue b/src/views/system/dept/index.vue index 90fbeb15..960dc516 100644 --- a/src/views/system/dept/index.vue +++ b/src/views/system/dept/index.vue @@ -8,12 +8,11 @@ import { ColumnsType } from 'ant-design-vue/lib/table'; import { listDept, getDept, - getTenant, delDept, addDept, updateDept, listDeptExcludeChild, -} from '@/api/system/dept'; +} from '@/api/system/tenant'; import { parseDateToStr } from '@/utils/date-utils'; import { regExpMobile, regExpEmail } from '@/utils/regular-utils'; import useDictStore from '@/store/modules/dict'; @@ -34,7 +33,7 @@ let dict: { /**查询参数 */ let queryParams = reactive({ /**部门名称 */ - deptName: '', + tenantName: '', /**部门状态 */ status: undefined, }); @@ -42,14 +41,14 @@ let queryParams = reactive({ /**查询参数重置 */ function fnQueryReset() { queryParams = Object.assign(queryParams, { - deptName: '', + tenantName: '', status: undefined, }); fnGetList(); } /**表格全展开行key */ -let expandedRowKeys: string[] = []; +let expandedRowKeys: any[] = []; /**表格状态类型 */ type TabeStateType = { @@ -81,13 +80,13 @@ let tableState: TabeStateType = reactive({ let tableColumns: ColumnsType = [ { title: t('views.system.dept.className'), - dataIndex: 'deptName', + dataIndex: 'tenantName', align: 'left', width: 300, }, { title: t('views.system.dept.classId'), - dataIndex: 'deptId', + dataIndex: 'tenantId', align: 'left', width: 150, }, @@ -110,6 +109,18 @@ let tableColumns: ColumnsType = [ key: 'type', align: 'center', width: 150, + customRender(opt) { + switch (opt.value) { + case 'SD-SST': + return t('views.system.dept.SDSST'); + case 'APN': + return t('views.system.dept.APN'); + case 'IMSI': + return t('views.system.dept.IMSI'); + default: + return ''; + } + }, }, { title: t('views.system.dept.createTime'), @@ -123,7 +134,7 @@ let tableColumns: ColumnsType = [ }, { title: t('common.operate'), - key: 'deptId', + key: 'tenantId', align: 'left', }, ]; @@ -133,8 +144,8 @@ const modalStateFromOption = reactive({ { label: t('views.system.dept.SDSST'), value: 'SD-SST' }, { label: t('views.system.dept.APN'), value: 'APN' }, { label: t('views.system.dept.IMSI'), value: 'IMSI' }, - ] -}) + ], +}); /**表格紧凑型变更操作 */ function fnTableSize({ key }: MenuInfo) { @@ -176,8 +187,8 @@ let modalState: ModalStateType = reactive({ visibleByEdit: false, title: '部门', from: { - deptId: undefined, - deptName: '', + tenantId: undefined, + tenantName: '', email: '', leader: '', orderNum: 0, @@ -203,7 +214,7 @@ const modalStateFrom = Form.useForm( message: t('views.system.dept.highClass') + t('common.unableNull'), }, ], - deptName: [ + tenantName: [ { required: true, min: 1, @@ -216,26 +227,30 @@ const modalStateFrom = Form.useForm( /** * 对话框弹出显示为 查看 - * @param deptId 部门编号id + * @param tenantId 部门编号id */ -function fnModalVisibleByVive(deptId: string | number) { - if (!deptId) { +function fnModalVisibleByVive(tenantId: string | number) { + if (!tenantId) { message.error(t('common.getInfoFail'), 2); return; } if (modalState.confirmLoading) return; const hide = message.loading(t('common.loading'), 0); modalState.confirmLoading = true; - getTenant(deptId).then(res => { + getDept(tenantId).then(res => { modalState.confirmLoading = false; hide(); if (res.code === RESULT_CODE_SUCCESS && res.data) { if (res.data.parentId === '0') { modalState.treeData = [ - { deptId: '0', parentId: '0', deptName: t('views.system.dept.node') }, + { + tenantId: '0', + parentId: '0', + tenantName: t('views.system.dept.node'), + }, ]; } else { - modalState.treeData = treeDataAll; + //modalState.treeData = treeDataAll; } modalState.from = Object.assign(modalState.from, res.data); modalState.title = t('views.system.dept.classInfo'); @@ -248,14 +263,14 @@ function fnModalVisibleByVive(deptId: string | number) { /** * 对话框弹出显示为 新增或者修改 - * @param deptId 部门编号id, 不传为新增 + * @param tenantId 部门编号id, 不传为新增 * @param parentId 上级部门id */ function fnModalVisibleByEdit( - deptId?: string | number, + tenantId?: string | number, parentId?: string | number ) { - if (!deptId) { + if (!tenantId) { modalStateFrom.resetFields(); if (parentId) { modalState.from.parentId = parentId; @@ -268,7 +283,7 @@ function fnModalVisibleByEdit( const hide = message.loading(t('common.loading'), 0); modalState.confirmLoading = true; // 获取部门信息同时查询部门列表(排除节点) - Promise.all([getTenant(deptId), listDeptExcludeChild(deptId)]) + Promise.all([getDept(tenantId), listDeptExcludeChild(tenantId)]) .then(resArr => { if (resArr[0].code === RESULT_CODE_SUCCESS && resArr[0].data) { modalState.from = Object.assign(modalState.from, resArr[0].data); @@ -279,13 +294,17 @@ function fnModalVisibleByEdit( if (resArr[1].data.length === 0) { modalState.treeData = [ { - deptId: '0', + tenantId: '0', parentId: '0', - deptName: t('views.system.dept.node'), + tenantName: t('views.system.dept.node'), }, ]; } else { - modalState.treeData = parseDataToTree(resArr[1].data, 'deptId'); + const a = resArr[1].data.map(s=>{ + delete s.key + return s + }) + modalState.treeData = parseDataToTree(a, 'tenantId'); } } modalState.title = @@ -312,7 +331,8 @@ function fnModalOk() { .then(() => { modalState.confirmLoading = true; const from = toRaw(modalState.from); - const dept = from.deptId ? updateDept(from) : addDept(from); + console.log('from', from); + const dept = from.tenantId ? updateDept(from) : addDept(from); const hide = message.loading(t('common.loading'), 0); dept .then(res => { @@ -323,7 +343,7 @@ function fnModalOk() { }); modalState.visibleByEdit = false; // 新增时清空上级部门树重新获取 - if (!from.deptId) { + if (!from.tenantId) { treeDataAll = []; } modalStateFrom.resetFields(); @@ -357,15 +377,15 @@ function fnModalCancel() { /** * 部门删除 - * @param deptId 部门编号id + * @param tenantId 部门编号id */ -function fnRecordDelete(deptId: string | number) { +function fnRecordDelete(tenantId: string | number) { Modal.confirm({ title: t('common.tipTitle'), - content: t('views.system.dept.delSure', { deptId: deptId }), + content: t('views.system.dept.delSure', { tenantId: tenantId }), onOk() { const hide = message.loading(t('common.loading'), 0); - delDept(deptId).then(res => { + delDept(tenantId).then(res => { hide(); if (res.code === RESULT_CODE_SUCCESS) { message.success({ @@ -390,13 +410,20 @@ function fnGetList() { tableState.loading = true; listDept(toRaw(queryParams)).then(res => { if (res.code === RESULT_CODE_SUCCESS && Array.isArray(res.data)) { - const treeData = parseDataToTree(res.data, 'deptId'); + var a: any = res.data.map(item => { + delete item.key; + return item; + }); + + // 转换树状数据 + const treeData = parseDataToTree(a, 'tenantId'); + console.log(treeData); // 初始上级部门和展开编号key if (treeDataAll.length <= 0) { // 转换树状数据 treeDataAll = treeData; // 展开编号key - expandedRowKeys = [...new Set(res.data.map(item => item.parentId))]; + expandedRowKeys = [...new Set(a.map((item:any) => item.parentId))]; fnTableExpandedRowsAll(tableState.expandedRowAll); } tableState.data = treeData; @@ -430,10 +457,10 @@ onMounted(() => { @@ -538,7 +565,7 @@ onMounted(() => { { -