租户管理异常(数据库需要把key字段改名)

This commit is contained in:
lai
2024-06-06 17:46:52 +08:00
parent 9152f14430
commit e35356a8c6
3 changed files with 185 additions and 68 deletions

View File

@@ -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 部门对象 * @param data 部门对象

99
src/api/system/tenant.ts Normal file
View File

@@ -0,0 +1,99 @@
import { request } from '@/plugins/http-fetch';
/**
* 查询部门列表
* @param query 查询参数
* @returns object
*/
export function listDept(query: Record<string, any>) {
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<string, any>) {
return request({
url: '/system/tenant',
method: 'post',
data: data,
});
}
/**
* 修改部门
* @param data 部门对象
* @returns object
*/
export function updateDept(data: Record<string, any>) {
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',
});
}

View File

@@ -8,12 +8,11 @@ import { ColumnsType } from 'ant-design-vue/lib/table';
import { import {
listDept, listDept,
getDept, getDept,
getTenant,
delDept, delDept,
addDept, addDept,
updateDept, updateDept,
listDeptExcludeChild, listDeptExcludeChild,
} from '@/api/system/dept'; } from '@/api/system/tenant';
import { parseDateToStr } from '@/utils/date-utils'; import { parseDateToStr } from '@/utils/date-utils';
import { regExpMobile, regExpEmail } from '@/utils/regular-utils'; import { regExpMobile, regExpEmail } from '@/utils/regular-utils';
import useDictStore from '@/store/modules/dict'; import useDictStore from '@/store/modules/dict';
@@ -34,7 +33,7 @@ let dict: {
/**查询参数 */ /**查询参数 */
let queryParams = reactive({ let queryParams = reactive({
/**部门名称 */ /**部门名称 */
deptName: '', tenantName: '',
/**部门状态 */ /**部门状态 */
status: undefined, status: undefined,
}); });
@@ -42,14 +41,14 @@ let queryParams = reactive({
/**查询参数重置 */ /**查询参数重置 */
function fnQueryReset() { function fnQueryReset() {
queryParams = Object.assign(queryParams, { queryParams = Object.assign(queryParams, {
deptName: '', tenantName: '',
status: undefined, status: undefined,
}); });
fnGetList(); fnGetList();
} }
/**表格全展开行key */ /**表格全展开行key */
let expandedRowKeys: string[] = []; let expandedRowKeys: any[] = [];
/**表格状态类型 */ /**表格状态类型 */
type TabeStateType = { type TabeStateType = {
@@ -81,13 +80,13 @@ let tableState: TabeStateType = reactive({
let tableColumns: ColumnsType = [ let tableColumns: ColumnsType = [
{ {
title: t('views.system.dept.className'), title: t('views.system.dept.className'),
dataIndex: 'deptName', dataIndex: 'tenantName',
align: 'left', align: 'left',
width: 300, width: 300,
}, },
{ {
title: t('views.system.dept.classId'), title: t('views.system.dept.classId'),
dataIndex: 'deptId', dataIndex: 'tenantId',
align: 'left', align: 'left',
width: 150, width: 150,
}, },
@@ -110,6 +109,18 @@ let tableColumns: ColumnsType = [
key: 'type', key: 'type',
align: 'center', align: 'center',
width: 150, 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'), title: t('views.system.dept.createTime'),
@@ -123,7 +134,7 @@ let tableColumns: ColumnsType = [
}, },
{ {
title: t('common.operate'), title: t('common.operate'),
key: 'deptId', key: 'tenantId',
align: 'left', align: 'left',
}, },
]; ];
@@ -133,8 +144,8 @@ const modalStateFromOption = reactive({
{ label: t('views.system.dept.SDSST'), value: 'SD-SST' }, { label: t('views.system.dept.SDSST'), value: 'SD-SST' },
{ label: t('views.system.dept.APN'), value: 'APN' }, { label: t('views.system.dept.APN'), value: 'APN' },
{ label: t('views.system.dept.IMSI'), value: 'IMSI' }, { label: t('views.system.dept.IMSI'), value: 'IMSI' },
] ],
}) });
/**表格紧凑型变更操作 */ /**表格紧凑型变更操作 */
function fnTableSize({ key }: MenuInfo) { function fnTableSize({ key }: MenuInfo) {
@@ -176,8 +187,8 @@ let modalState: ModalStateType = reactive({
visibleByEdit: false, visibleByEdit: false,
title: '部门', title: '部门',
from: { from: {
deptId: undefined, tenantId: undefined,
deptName: '', tenantName: '',
email: '', email: '',
leader: '', leader: '',
orderNum: 0, orderNum: 0,
@@ -203,7 +214,7 @@ const modalStateFrom = Form.useForm(
message: t('views.system.dept.highClass') + t('common.unableNull'), message: t('views.system.dept.highClass') + t('common.unableNull'),
}, },
], ],
deptName: [ tenantName: [
{ {
required: true, required: true,
min: 1, min: 1,
@@ -216,26 +227,30 @@ const modalStateFrom = Form.useForm(
/** /**
* 对话框弹出显示为 查看 * 对话框弹出显示为 查看
* @param deptId 部门编号id * @param tenantId 部门编号id
*/ */
function fnModalVisibleByVive(deptId: string | number) { function fnModalVisibleByVive(tenantId: string | number) {
if (!deptId) { if (!tenantId) {
message.error(t('common.getInfoFail'), 2); message.error(t('common.getInfoFail'), 2);
return; return;
} }
if (modalState.confirmLoading) return; if (modalState.confirmLoading) return;
const hide = message.loading(t('common.loading'), 0); const hide = message.loading(t('common.loading'), 0);
modalState.confirmLoading = true; modalState.confirmLoading = true;
getTenant(deptId).then(res => { getDept(tenantId).then(res => {
modalState.confirmLoading = false; modalState.confirmLoading = false;
hide(); hide();
if (res.code === RESULT_CODE_SUCCESS && res.data) { if (res.code === RESULT_CODE_SUCCESS && res.data) {
if (res.data.parentId === '0') { if (res.data.parentId === '0') {
modalState.treeData = [ modalState.treeData = [
{ deptId: '0', parentId: '0', deptName: t('views.system.dept.node') }, {
tenantId: '0',
parentId: '0',
tenantName: t('views.system.dept.node'),
},
]; ];
} else { } else {
modalState.treeData = treeDataAll; //modalState.treeData = treeDataAll;
} }
modalState.from = Object.assign(modalState.from, res.data); modalState.from = Object.assign(modalState.from, res.data);
modalState.title = t('views.system.dept.classInfo'); 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 * @param parentId 上级部门id
*/ */
function fnModalVisibleByEdit( function fnModalVisibleByEdit(
deptId?: string | number, tenantId?: string | number,
parentId?: string | number parentId?: string | number
) { ) {
if (!deptId) { if (!tenantId) {
modalStateFrom.resetFields(); modalStateFrom.resetFields();
if (parentId) { if (parentId) {
modalState.from.parentId = parentId; modalState.from.parentId = parentId;
@@ -268,7 +283,7 @@ function fnModalVisibleByEdit(
const hide = message.loading(t('common.loading'), 0); const hide = message.loading(t('common.loading'), 0);
modalState.confirmLoading = true; modalState.confirmLoading = true;
// 获取部门信息同时查询部门列表(排除节点) // 获取部门信息同时查询部门列表(排除节点)
Promise.all([getTenant(deptId), listDeptExcludeChild(deptId)]) Promise.all([getDept(tenantId), listDeptExcludeChild(tenantId)])
.then(resArr => { .then(resArr => {
if (resArr[0].code === RESULT_CODE_SUCCESS && resArr[0].data) { if (resArr[0].code === RESULT_CODE_SUCCESS && resArr[0].data) {
modalState.from = Object.assign(modalState.from, resArr[0].data); modalState.from = Object.assign(modalState.from, resArr[0].data);
@@ -279,13 +294,17 @@ function fnModalVisibleByEdit(
if (resArr[1].data.length === 0) { if (resArr[1].data.length === 0) {
modalState.treeData = [ modalState.treeData = [
{ {
deptId: '0', tenantId: '0',
parentId: '0', parentId: '0',
deptName: t('views.system.dept.node'), tenantName: t('views.system.dept.node'),
}, },
]; ];
} else { } 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 = modalState.title =
@@ -312,7 +331,8 @@ function fnModalOk() {
.then(() => { .then(() => {
modalState.confirmLoading = true; modalState.confirmLoading = true;
const from = toRaw(modalState.from); 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); const hide = message.loading(t('common.loading'), 0);
dept dept
.then(res => { .then(res => {
@@ -323,7 +343,7 @@ function fnModalOk() {
}); });
modalState.visibleByEdit = false; modalState.visibleByEdit = false;
// 新增时清空上级部门树重新获取 // 新增时清空上级部门树重新获取
if (!from.deptId) { if (!from.tenantId) {
treeDataAll = []; treeDataAll = [];
} }
modalStateFrom.resetFields(); 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({ Modal.confirm({
title: t('common.tipTitle'), title: t('common.tipTitle'),
content: t('views.system.dept.delSure', { deptId: deptId }), content: t('views.system.dept.delSure', { tenantId: tenantId }),
onOk() { onOk() {
const hide = message.loading(t('common.loading'), 0); const hide = message.loading(t('common.loading'), 0);
delDept(deptId).then(res => { delDept(tenantId).then(res => {
hide(); hide();
if (res.code === RESULT_CODE_SUCCESS) { if (res.code === RESULT_CODE_SUCCESS) {
message.success({ message.success({
@@ -390,13 +410,20 @@ function fnGetList() {
tableState.loading = true; tableState.loading = true;
listDept(toRaw(queryParams)).then(res => { listDept(toRaw(queryParams)).then(res => {
if (res.code === RESULT_CODE_SUCCESS && Array.isArray(res.data)) { 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 // 初始上级部门和展开编号key
if (treeDataAll.length <= 0) { if (treeDataAll.length <= 0) {
// 转换树状数据 // 转换树状数据
treeDataAll = treeData; treeDataAll = treeData;
// 展开编号key // 展开编号key
expandedRowKeys = [...new Set(res.data.map(item => item.parentId))]; expandedRowKeys = [...new Set(a.map((item:any) => item.parentId))];
fnTableExpandedRowsAll(tableState.expandedRowAll); fnTableExpandedRowsAll(tableState.expandedRowAll);
} }
tableState.data = treeData; tableState.data = treeData;
@@ -430,10 +457,10 @@ onMounted(() => {
<a-col :lg="6" :md="12" :xs="24"> <a-col :lg="6" :md="12" :xs="24">
<a-form-item <a-form-item
:label="t('views.system.dept.className')" :label="t('views.system.dept.className')"
name="deptName" name="tenantName"
> >
<a-input <a-input
v-model:value="queryParams.deptName" v-model:value="queryParams.tenantName"
allow-clear allow-clear
></a-input> ></a-input>
</a-form-item> </a-form-item>
@@ -538,7 +565,7 @@ onMounted(() => {
<!-- 表格列表 --> <!-- 表格列表 -->
<a-table <a-table
class="table" class="table"
row-key="deptId" row-key="tenantId"
:columns="tableColumns" :columns="tableColumns"
:loading="tableState.loading" :loading="tableState.loading"
:data-source="tableState.data" :data-source="tableState.data"
@@ -553,13 +580,13 @@ onMounted(() => {
<template v-if="column.key === 'status'"> <template v-if="column.key === 'status'">
<DictTag :options="dict.sysNormalDisable" :value="record.status" /> <DictTag :options="dict.sysNormalDisable" :value="record.status" />
</template> </template>
<template v-if="column.key === 'deptId'"> <template v-if="column.key === 'tenantId'">
<a-space :size="8" align="center"> <a-space :size="8" align="center">
<a-tooltip> <a-tooltip>
<template #title>{{ t('common.viewText') }}</template> <template #title>{{ t('common.viewText') }}</template>
<a-button <a-button
type="link" type="link"
@click.prevent="fnModalVisibleByVive(record.deptId)" @click.prevent="fnModalVisibleByVive(record.tenantId)"
v-perms:has="['system:dept:query']" v-perms:has="['system:dept:query']"
> >
<template #icon><ProfileOutlined /></template> <template #icon><ProfileOutlined /></template>
@@ -569,7 +596,7 @@ onMounted(() => {
<template #title>{{ t('common.editText') }}</template> <template #title>{{ t('common.editText') }}</template>
<a-button <a-button
type="link" type="link"
@click.prevent="fnModalVisibleByEdit(record.deptId)" @click.prevent="fnModalVisibleByEdit(record.tenantId)"
v-perms:has="['system:dept:edit']" v-perms:has="['system:dept:edit']"
> >
<template #icon><FormOutlined /></template> <template #icon><FormOutlined /></template>
@@ -579,7 +606,7 @@ onMounted(() => {
<template #title>{{ t('common.deleteText') }}</template> <template #title>{{ t('common.deleteText') }}</template>
<a-button <a-button
type="link" type="link"
@click.prevent="fnRecordDelete(record.deptId)" @click.prevent="fnRecordDelete(record.tenantId)"
v-perms:has="['system:dept:remove']" v-perms:has="['system:dept:remove']"
> >
<template #icon><DeleteOutlined /></template> <template #icon><DeleteOutlined /></template>
@@ -592,7 +619,7 @@ onMounted(() => {
<a-button <a-button
type="link" type="link"
@click.prevent=" @click.prevent="
fnModalVisibleByEdit(undefined, record.deptId) fnModalVisibleByEdit(undefined, record.tenantId)
" "
v-perms:has="['system:dept:add']" v-perms:has="['system:dept:add']"
> >
@@ -625,10 +652,10 @@ onMounted(() => {
:tree-data="modalState.treeData" :tree-data="modalState.treeData"
:field-names="{ :field-names="{
children: 'children', children: 'children',
label: 'deptName', label: 'tenantName',
value: 'deptId', value: 'tenantId',
}" }"
tree-node-label-prop="deptName" tree-node-label-prop="tenantName"
> >
<template #suffixIcon></template> <template #suffixIcon></template>
</a-tree-select> </a-tree-select>
@@ -637,9 +664,9 @@ onMounted(() => {
<a-col :lg="12" :md="12" :xs="24"> <a-col :lg="12" :md="12" :xs="24">
<a-form-item <a-form-item
:label="t('views.system.dept.className')" :label="t('views.system.dept.className')"
name="deptName" name="tenantName"
> >
{{ modalState.from.deptName }} {{ modalState.from.tenantName }}
</a-form-item> </a-form-item>
</a-col> </a-col>
<a-col :lg="12" :md="12" :xs="24"> <a-col :lg="12" :md="12" :xs="24">
@@ -662,8 +689,11 @@ onMounted(() => {
</a-form-item> </a-form-item>
</a-col> </a-col>
<a-col :lg="12" :md="12" :xs="24"> <a-col :lg="12" :md="12" :xs="24">
<a-form-item :label="t('views.system.dept.classId')" name="deptId"> <a-form-item
{{ modalState.from.deptId }} :label="t('views.system.dept.classId')"
name="tenantId"
>
{{ modalState.from.tenantId }}
</a-form-item> </a-form-item>
</a-col> </a-col>
</a-row> </a-row>
@@ -718,11 +748,11 @@ onMounted(() => {
:tree-data="modalState.treeData" :tree-data="modalState.treeData"
:field-names="{ :field-names="{
children: 'children', children: 'children',
label: 'deptName', label: 'tenantName',
value: 'deptId', value: 'tenantId',
}" }"
tree-node-label-prop="deptName" tree-node-label-prop="tenantName"
tree-node-filter-prop="deptName" tree-node-filter-prop="tenantName"
style="width: 100%" style="width: 100%"
:dropdown-style="{ maxHeight: '400px', overflow: 'auto' }" :dropdown-style="{ maxHeight: '400px', overflow: 'auto' }"
> >
@@ -731,13 +761,13 @@ onMounted(() => {
<a-form-item <a-form-item
:label="t('views.system.dept.className')" :label="t('views.system.dept.className')"
name="deptName" name="tenantName"
v-bind="modalStateFrom.validateInfos.deptName" v-bind="modalStateFrom.validateInfos.tenantName"
:label-col="{ span: 3 }" :label-col="{ span: 3 }"
:labelWrap="true" :labelWrap="true"
> >
<a-input <a-input
v-model:value="modalState.from.deptName" v-model:value="modalState.from.tenantName"
allow-clear allow-clear
:maxlength="30" :maxlength="30"
></a-input> ></a-input>