UNIVPLMDataIntegration/Web/src/views/system/org/index.vue

224 lines
8.5 KiB
Vue
Raw Normal View History

2024-06-15 13:02:35 +08:00
<template>
2024-07-01 00:26:53 +08:00
<div class="sys-org-container" v-loading="options.loading">
<el-row :gutter="5" style="width: 100%; height: 100%">
<el-col :span="4" :xs="24" style="display: flex; height: 100%">
<OrgTree ref="orgTreeRef" @node-click="handleNodeChange" />
2024-06-15 13:02:35 +08:00
</el-col>
2024-07-01 00:26:53 +08:00
<el-col :span="20" :xs="24" style="display: flex; flex-direction: column; height: 100%">
<el-card shadow="hover" :body-style="{ padding: '5px 5px 0 5px', display: 'flex', width: '100%', height: '100%', alignItems: 'start' }">
<el-form :model="state.queryParams" ref="queryForm" :show-message="false" :inlineMessage="true" label-width="auto" style="flex: 1 1 0%">
2024-07-01 00:26:53 +08:00
<el-row :gutter="10">
<el-col class="mb5" :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
<el-form-item label="机构名称" prop="name">
<el-input v-model="state.queryParams.name" placeholder="机构名称" clearable @keyup.enter.native="handleQuery" />
</el-form-item>
</el-col>
<el-col class="mb5" :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
<el-form-item label="机构编码" prop="code">
<el-input v-model="state.queryParams.code" placeholder="机构编码" clearable @keyup.enter.native="handleQuery" />
</el-form-item>
</el-col>
<el-col class="mb5" :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
<el-form-item label="机构类型" prop="type">
<el-select v-model="state.queryParams.type" filterable clearable class="w100" @clear="state.queryParams.type = undefined">
<el-option v-for="item in state.orgTypeList" :key="item.value" :label="item.value" :value="item.code" />
</el-select>
</el-form-item>
</el-col>
</el-row>
</el-form>
<el-divider style="height: calc(100% - 5px); margin: 0 10px" direction="vertical" />
<el-row>
<el-col>
2024-06-15 13:02:35 +08:00
<el-button-group>
2024-07-01 00:26:53 +08:00
<el-button type="primary" icon="ele-Search" @click="handleQuery" :loading="options.loading"> 查询 </el-button>
<el-button icon="ele-Refresh" @click="resetQuery" :loading="options.loading"> 重置 </el-button>
2024-06-15 13:02:35 +08:00
</el-button-group>
2024-07-01 00:26:53 +08:00
</el-col>
</el-row>
2024-06-15 13:02:35 +08:00
</el-card>
2024-07-01 00:26:53 +08:00
<el-card class="full-table" shadow="hover" style="margin-top: 5px; flex: 1">
<vxe-grid ref="xGrid" class="xGrid-style" v-bind="options" :tree-config="{}">
<template #toolbar_buttons>
<el-button type="primary" icon="ele-Plus" @click="handleAdd" v-auth="'sysOrg:add'"> 新增 </el-button>
<el-button-group style="padding-left: 12px">
<el-button type="primary" icon="ele-Expand" @click="handleExpand"> 全部展开 </el-button>
<el-button type="primary" icon="ele-Fold" @click="handleFold"> 全部折叠 </el-button>
</el-button-group>
</template>
<template #toolbar_tools> </template>
<template #empty>
<el-empty :image-size="200" />
</template>
<template #row_status="{ row }">
<el-tag v-if="row.status === 1" type="success">启用</el-tag>
<el-tag v-else type="danger">禁用</el-tag>
</template>
<template #row_record="{ row }">
<ModifyRecord :data="row" />
</template>
<template #row_buttons="{ row }">
<el-tooltip content="编辑" placement="top">
<el-button icon="ele-Edit" size="small" text type="primary" @click="handleEdit(row)" v-auth="'sysOrg:update'"></el-button>
</el-tooltip>
<el-tooltip content="删除" placement="top">
<el-button icon="ele-Delete" size="small" text type="danger" @click="handleDelete(row)" v-auth="'sysOrg:delete'"></el-button>
</el-tooltip>
</template>
</vxe-grid>
2024-06-15 13:02:35 +08:00
</el-card>
</el-col>
</el-row>
2024-07-01 00:26:53 +08:00
<EditOrg ref="editOrgRef" :title="state.title" :orgData="state.treeData" @reload="handleQuery" />
2024-06-15 13:02:35 +08:00
</div>
</template>
<script lang="ts" setup name="sysOrg">
2024-07-01 00:26:53 +08:00
import { onMounted, reactive, ref, nextTick } from 'vue';
2024-06-15 13:02:35 +08:00
import { ElMessageBox, ElMessage } from 'element-plus';
2024-07-01 00:26:53 +08:00
import { auth } from '/@/utils/authFunction';
import { VxeGridInstance } from 'vxe-table';
import { useVxeTable } from '/@/hooks/vxeTableOptionsHook';
2024-06-15 13:02:35 +08:00
import OrgTree from '/@/views/system/org/component/orgTree.vue';
import EditOrg from '/@/views/system/org/component/editOrg.vue';
import ModifyRecord from '/@/components/table/modifyRecord.vue';
import { getAPI } from '/@/utils/axios-utils';
2024-07-01 00:26:53 +08:00
import { SysDictDataApi, SysOrgApi } from '/@/api-services';
2024-06-15 13:02:35 +08:00
import { SysOrg } from '/@/api-services/models';
2024-07-01 00:26:53 +08:00
const xGrid = ref<VxeGridInstance>();
2024-06-15 13:02:35 +08:00
const editOrgRef = ref<InstanceType<typeof EditOrg>>();
const orgTreeRef = ref<InstanceType<typeof OrgTree>>();
const state = reactive({
2024-07-01 00:26:53 +08:00
treeData: [] as Array<SysOrg>, // 机构树所有数据
2024-06-15 13:02:35 +08:00
queryParams: {
id: 0,
name: undefined,
code: undefined,
type: undefined,
},
2024-07-01 00:26:53 +08:00
title: '',
2024-06-15 13:02:35 +08:00
orgTypeList: [] as any,
});
2024-07-01 00:26:53 +08:00
// 表格参数配置
const options = useVxeTable<SysOrg>(
{
id: 'sysOrg',
name: '机构',
columns: [
// { type: 'checkbox', width: 40, fixed: 'left' },
{ type: 'seq', title: '序号', width: 60, fixed: 'left' },
{ field: 'name', title: '机构名称', minWidth: 200, showOverflow: 'tooltip', treeNode: true },
{ field: 'code', title: '机构编码', minWidth: 200, showOverflow: 'tooltip' },
{ field: 'level', title: '级别', minWidth: 70, showOverflow: 'tooltip' },
{ field: 'type', title: '机构类型', minWidth: 80, formatter: ({ cellValue }: any) => state.orgTypeList.find((u: any) => u.code == cellValue)?.value, showOverflow: 'tooltip' },
{ field: 'orderNo', title: '排序', width: 80, showOverflow: 'tooltip' },
{ field: 'status', title: '状态', width: 80, showOverflow: 'tooltip', slots: { default: 'row_status' } },
{ field: '', title: '修改记录', width: 100, showOverflow: 'tooltip', slots: { default: 'row_record' } },
{ title: '操作', fixed: 'right', width: 100, showOverflow: true, slots: { default: 'row_buttons' } },
],
enableExport: auth('sysOrg:export'),
searchCallback: () => handleQuery(),
queryAllCallback: () => fetchData({ pageSize: 99999 }),
},
{ stripe: false, checkboxConfig: { range: false } }
);
2024-06-15 13:02:35 +08:00
2024-07-01 00:26:53 +08:00
// 页面初始化
onMounted(async () => {
await handleQuery();
2024-06-15 13:02:35 +08:00
let resDicData = await getAPI(SysDictDataApi).apiSysDictDataDataListCodeGet('org_type');
state.orgTypeList = resDicData.data.result;
2024-07-01 00:26:53 +08:00
// 展开表格所有数据,数据量大时请勿开启
nextTick(async () => {
if (state.treeData?.length < 100) await xGrid.value?.setAllTreeExpand(true);
});
2024-06-15 13:02:35 +08:00
});
// 查询操作
const handleQuery = async (updateTree: boolean = false) => {
2024-07-01 00:26:53 +08:00
options.loading = true;
var res = await fetchData(null);
xGrid.value?.loadData(res.data.result ?? []);
options.loading = false;
2024-06-15 13:02:35 +08:00
// 是否更新左侧机构列表树
if (updateTree == true) {
2024-07-01 00:26:53 +08:00
const data = await orgTreeRef.value?.fetchTreeData();
state.treeData = data ?? [];
2024-06-15 13:02:35 +08:00
}
// 若无选择节点并且查询条件为空时,更新编辑页面机构列表树
2024-06-16 02:40:42 +08:00
if (state.queryParams.id == 0 && state.queryParams.name == undefined && state.queryParams.code == undefined && state.queryParams.type == undefined && updateTree == false)
2024-07-01 00:26:53 +08:00
state.treeData = res.data.result ?? [];
};
2024-07-01 02:47:16 +08:00
// 获取数据
2024-07-01 00:26:53 +08:00
const fetchData = async (tableParams: any) => {
let params = Object.assign(state.queryParams, tableParams);
return getAPI(SysOrgApi).apiSysOrgListGet(params.id, params.name, params.code, params.type);
2024-06-15 13:02:35 +08:00
};
// 重置操作
2024-07-01 00:26:53 +08:00
const resetQuery = async () => {
2024-06-15 13:02:35 +08:00
state.queryParams.id = 0;
state.queryParams.name = undefined;
state.queryParams.code = undefined;
state.queryParams.type = undefined;
2024-07-01 00:26:53 +08:00
await handleQuery();
2024-06-15 13:02:35 +08:00
};
// 打开新增页面
2024-07-01 00:26:53 +08:00
const handleAdd = () => {
state.title = '添加机构';
2024-06-15 13:02:35 +08:00
editOrgRef.value?.openDialog({ status: 1, orderNo: 100 });
};
// 打开编辑页面
2024-07-01 00:26:53 +08:00
const handleEdit = (row: any) => {
state.title = '编辑机构';
2024-06-15 13:02:35 +08:00
editOrgRef.value?.openDialog(row);
};
// 删除
2024-07-01 00:26:53 +08:00
const handleDelete = (row: any) => {
2024-06-15 13:02:35 +08:00
ElMessageBox.confirm(`确定删除机构:【${row.name}】?`, '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
})
.then(async () => {
await getAPI(SysOrgApi).apiSysOrgDeletePost({ id: row.id });
ElMessage.success('删除成功');
2024-07-01 00:26:53 +08:00
await handleQuery(true);
2024-06-15 13:02:35 +08:00
})
.catch(() => {});
};
// 树组件点击
2024-07-01 00:26:53 +08:00
const handleNodeChange = async (node: any) => {
2024-06-15 13:02:35 +08:00
state.queryParams.id = node.id;
state.queryParams.name = undefined;
state.queryParams.code = undefined;
state.queryParams.type = undefined;
2024-07-01 00:26:53 +08:00
orgTreeRef?.value?.setCurrentKey();
await handleQuery();
};
// 全部展开
const handleExpand = () => {
xGrid.value?.setAllTreeExpand(true);
2024-06-15 13:02:35 +08:00
};
2024-07-01 00:26:53 +08:00
// 全部折叠
const handleFold = () => {
xGrid.value?.clearTreeExpand();
2024-06-15 13:02:35 +08:00
};
</script>