|
|
@@ -1,149 +1,196 @@
|
|
|
<template>
|
|
|
- <page-wrapper>
|
|
|
- <el-card :bordered="false" class="mb-3 proCard">
|
|
|
- <el-space align="center">
|
|
|
- <el-input
|
|
|
- :style="{ width: '320px' }"
|
|
|
- v-model="params.tenantName"
|
|
|
- clearable
|
|
|
- placeholder="请输入租户名称"
|
|
|
- @keyup.enter="reloadTable"
|
|
|
- />
|
|
|
- <el-button type="primary" @click="reloadTable">
|
|
|
- <template #icon>
|
|
|
- <el-icon>
|
|
|
- <SearchOutlined />
|
|
|
- </el-icon>
|
|
|
- </template>
|
|
|
- 查询
|
|
|
- </el-button>
|
|
|
- </el-space>
|
|
|
- </el-card>
|
|
|
- <el-card :bordered="false" class="proCard">
|
|
|
- <BasicTable
|
|
|
- :columns="columns"
|
|
|
- :dataSource="tenantItems"
|
|
|
- :row-key="(row) => row.id"
|
|
|
- ref="tableRef"
|
|
|
- :actionColumn="actionColumn"
|
|
|
- @update:checked-row-keys="onCheckedRow"
|
|
|
- >
|
|
|
- <template #tableTitle>
|
|
|
- <el-button type="primary" @click="openCreateDrawer">
|
|
|
- <template #icon>
|
|
|
- <el-icon>
|
|
|
- <FileAddOutlined />
|
|
|
- </el-icon>
|
|
|
- </template>
|
|
|
- 添加租户
|
|
|
- </el-button>
|
|
|
+ <div class="tenantPage">
|
|
|
+ <div class="search-bar">
|
|
|
+ <el-input
|
|
|
+ v-model="searchParams.tenantName"
|
|
|
+ clearable
|
|
|
+ placeholder="请输入租户名称"
|
|
|
+ @keyup.enter="loadTenantTable"
|
|
|
+ />
|
|
|
+ <el-button type="primary" @click="loadTenantTable">
|
|
|
+ <template #icon>
|
|
|
+ <el-icon>
|
|
|
+ <SearchOutlined />
|
|
|
+ </el-icon>
|
|
|
</template>
|
|
|
+ 查询
|
|
|
+ </el-button>
|
|
|
+ </div>
|
|
|
|
|
|
- <template #action>
|
|
|
- <TableAction />
|
|
|
+ <div class="tenant-content">
|
|
|
+ <el-button type="primary" @click="openAddTenantDrawer('add')">
|
|
|
+ <template #icon>
|
|
|
+ <el-icon>
|
|
|
+ <FileAddOutlined />
|
|
|
+ </el-icon>
|
|
|
</template>
|
|
|
- </BasicTable>
|
|
|
- </el-card>
|
|
|
-
|
|
|
- <CreateDrawer
|
|
|
- ref="createDrawerRef"
|
|
|
- :title="drawerTitle"
|
|
|
- :permissionList="treeData"
|
|
|
- @change="reloadTable"
|
|
|
- />
|
|
|
- </page-wrapper>
|
|
|
+ 添加租户
|
|
|
+ </el-button>
|
|
|
+
|
|
|
+ <el-table :data="tenantTable" class="tenant-info-table" row-key="id" default-expand-all>
|
|
|
+ <el-table-column prop="tenantCode" align="center" label="租户编码" />
|
|
|
+ <el-table-column prop="tenantName" align="center" width="200" label="租户名称" />
|
|
|
+ <el-table-column align="center" width="100" label="状态">
|
|
|
+ <template #default="scope">
|
|
|
+ <div class="">
|
|
|
+ {{ TENANT_STATUS_LABEL[scope.row.isDisabled] }}
|
|
|
+ </div>
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ <el-table-column prop="startTime" align="center" width="200" label="生效时间" />
|
|
|
+ <el-table-column prop="endTime" align="center" width="200" label="失效时间" />
|
|
|
+ <el-table-column align="center" label="操作">
|
|
|
+ <template #default="scope">
|
|
|
+ <div class="operations">
|
|
|
+ <el-button type="primary" @click="openAddTenantDrawer('add', scope.row)">
|
|
|
+ 添加下一级
|
|
|
+ </el-button>
|
|
|
+ <el-button type="primary" @click="openAddTenantDrawer('edit', scope.row)">
|
|
|
+ 编辑
|
|
|
+ </el-button>
|
|
|
+ <el-button type="primary" @click="handleDelete(scope.row.id)"> 删除 </el-button>
|
|
|
+ </div>
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ </el-table>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <AddTenantDrawer
|
|
|
+ :showAddTenantDrawer="showAddTenantDrawer"
|
|
|
+ :mode="tenantDrawerMode"
|
|
|
+ :tenantForm="tenantForm"
|
|
|
+ @closeDrawer="closeTenantDrawer"
|
|
|
+ @loadTenantTable="loadTenantTable"
|
|
|
+ />
|
|
|
</template>
|
|
|
|
|
|
<script lang="ts" setup>
|
|
|
- import { reactive, ref, unref, h, onMounted } from 'vue';
|
|
|
- import { ElMessage } from 'element-plus';
|
|
|
- import { BasicTable, TableAction, BasicColumn } from '@/components/Table';
|
|
|
- import { tenantList, deleteTenant } from '@/api/tenant/index';
|
|
|
- import { columns } from './columns';
|
|
|
+ import { reactive, ref, onMounted } from 'vue';
|
|
|
+ import { ElInput, ElButton, ElIcon, ElTable, ElTableColumn } from 'element-plus';
|
|
|
+ import { ElMessageBox, ElMessage } from 'element-plus';
|
|
|
import { FileAddOutlined, SearchOutlined } from '@vicons/antd';
|
|
|
- import CreateDrawer from './CreateDrawer.vue';
|
|
|
-
|
|
|
- const message = ElMessage;
|
|
|
- const tableRef = ref();
|
|
|
- const createDrawerRef = ref();
|
|
|
- const drawerTitle = ref('添加租户');
|
|
|
- const treeData = ref([]);
|
|
|
+ import {
|
|
|
+ TenantInfoTreeType,
|
|
|
+ TENANT_STATUS_LABEL,
|
|
|
+ tenantDrawerModeType,
|
|
|
+ tenantFormType,
|
|
|
+ } from '@/types/tenant/type';
|
|
|
+ import AddTenantDrawer from './components/AddTenantDrawer.vue';
|
|
|
+ import { queryTenantTreeApi, deleteTenantApi } from '@/api/tenant/index';
|
|
|
|
|
|
- const tenantItems = ref<any[]>([]);
|
|
|
+ const tenantTable = ref<TenantInfoTreeType>();
|
|
|
|
|
|
- const params = reactive({
|
|
|
+ // drawer相关变量
|
|
|
+ const showAddTenantDrawer = ref<boolean>(false);
|
|
|
+ const tenantDrawerMode = ref<tenantDrawerModeType>('add');
|
|
|
+ // 添加/编辑租户的表单
|
|
|
+ const tenantForm = reactive<tenantFormType>({
|
|
|
+ parentId: 0,
|
|
|
+ parentName: '',
|
|
|
tenantName: '',
|
|
|
tenantCode: '',
|
|
|
+ startTime: '',
|
|
|
+ endTime: '',
|
|
|
});
|
|
|
|
|
|
- const actionColumn: BasicColumn = reactive({
|
|
|
- width: 150,
|
|
|
- title: '操作',
|
|
|
- prop: 'action',
|
|
|
- fixed: 'right',
|
|
|
- render(record) {
|
|
|
- return h(TableAction as any, {
|
|
|
- style: 'button',
|
|
|
- actions: [
|
|
|
- {
|
|
|
- label: '删除',
|
|
|
- isConfirm: true,
|
|
|
- popConfirm: {
|
|
|
- onConfirm: handleDelete.bind(null, record.row),
|
|
|
- title: '您确定要删除吗?',
|
|
|
- confirmButtonText: '确定',
|
|
|
- cancelButtonText: '取消',
|
|
|
- },
|
|
|
- },
|
|
|
- {
|
|
|
- label: '编辑',
|
|
|
- onClick: handleEdit.bind(null, record.row),
|
|
|
- },
|
|
|
- ],
|
|
|
- });
|
|
|
- },
|
|
|
+ // 搜索租户变量
|
|
|
+ const searchParams = reactive({
|
|
|
+ tenantName: '',
|
|
|
+ tenantCode: '',
|
|
|
});
|
|
|
|
|
|
- const loadDataTable = async (res?: any) => {
|
|
|
- let _params = {
|
|
|
- ...unref(params),
|
|
|
- ...res,
|
|
|
- };
|
|
|
- const list = await tenantList(_params);
|
|
|
- tenantItems.value = list;
|
|
|
- };
|
|
|
-
|
|
|
- function openCreateDrawer() {
|
|
|
- const { openDrawer } = createDrawerRef.value;
|
|
|
- openDrawer();
|
|
|
+ function loadTenantTable() {
|
|
|
+ queryTenantTreeApi(searchParams).then((res) => {
|
|
|
+ tenantTable.value = res;
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
- function onCheckedRow(rowKeys: any[]) {
|
|
|
- console.log(rowKeys);
|
|
|
+ function handleDelete(tenantId: number) {
|
|
|
+ ElMessageBox.confirm('是否删除租户,删除后该租户无法继续使用平台!', '删除租户', {
|
|
|
+ confirmButtonText: '确定',
|
|
|
+ cancelButtonText: '取消',
|
|
|
+ type: 'warning',
|
|
|
+ }).then(() => {
|
|
|
+ deleteTenantApi(tenantId).then(() => {
|
|
|
+ loadTenantTable();
|
|
|
+ ElMessage({
|
|
|
+ type: 'success',
|
|
|
+ message: '删除成功',
|
|
|
+ });
|
|
|
+ });
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
- function reloadTable() {
|
|
|
- // tableRef.value.reload();
|
|
|
- loadDataTable();
|
|
|
+ function openAddTenantDrawer(newTenantDrawerMode: tenantDrawerModeType, row?) {
|
|
|
+ showAddTenantDrawer.value = true;
|
|
|
+ tenantDrawerMode.value = newTenantDrawerMode;
|
|
|
+ // 添加子租户
|
|
|
+ if (newTenantDrawerMode === 'add' && row) {
|
|
|
+ tenantForm.parentId = row.id;
|
|
|
+ tenantForm.parentName = row.tenantName;
|
|
|
+ } else if (newTenantDrawerMode === 'edit') {
|
|
|
+ tenantForm.id = row.id;
|
|
|
+ tenantForm.parentId = undefined;
|
|
|
+ tenantForm.parentName = undefined;
|
|
|
+ tenantForm.tenantName = row.tenantName;
|
|
|
+ tenantForm.tenantCode = row.tenantCode;
|
|
|
+ tenantForm.startTime = row.startTime;
|
|
|
+ tenantForm.endTime = row.endTime;
|
|
|
+ }
|
|
|
+ // 添加父租户
|
|
|
+ else {
|
|
|
+ tenantForm.parentId = 0; //0表示顶层父租户
|
|
|
+ tenantForm.parentName = '顶级租户';
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- function handleEdit(record: Recordable) {
|
|
|
- console.log('点击了编辑', record);
|
|
|
- drawerTitle.value = '编辑租户';
|
|
|
- const { openDrawer } = createDrawerRef.value;
|
|
|
- openDrawer(record.tenantId);
|
|
|
+ function resetTenantForm() {
|
|
|
+ tenantForm.id = 0;
|
|
|
+ tenantForm.parentId = 0;
|
|
|
+ tenantForm.parentName = '';
|
|
|
+ tenantForm.tenantName = '';
|
|
|
+ tenantForm.tenantCode = '';
|
|
|
+ tenantForm.startTime = '';
|
|
|
+ tenantForm.endTime = '';
|
|
|
}
|
|
|
|
|
|
- function handleDelete(record: Recordable) {
|
|
|
- deleteTenant({ id: record.tenantId }).then(() => {
|
|
|
- message.success('删除成功');
|
|
|
- reloadTable();
|
|
|
- });
|
|
|
+ function closeTenantDrawer() {
|
|
|
+ showAddTenantDrawer.value = false;
|
|
|
+ resetTenantForm();
|
|
|
}
|
|
|
|
|
|
- onMounted(async () => {
|
|
|
- loadDataTable();
|
|
|
+ onMounted(() => {
|
|
|
+ loadTenantTable();
|
|
|
});
|
|
|
</script>
|
|
|
|
|
|
-<style lang="scss" scoped></style>
|
|
|
+<style lang="scss" scoped>
|
|
|
+ .tenantPage {
|
|
|
+ height: calc(100vh - 100px);
|
|
|
+ .search-bar {
|
|
|
+ margin-bottom: 10px;
|
|
|
+ padding: 16px;
|
|
|
+ background-color: #fff;
|
|
|
+ .el-input {
|
|
|
+ width: 320px;
|
|
|
+ margin-right: 8px;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ .tenant-content {
|
|
|
+ min-height: calc(100% - 60px);
|
|
|
+ padding: 16px;
|
|
|
+ background-color: #fff;
|
|
|
+
|
|
|
+ .el-button {
|
|
|
+ margin-bottom: 10px;
|
|
|
+ }
|
|
|
+ .tenant-info-table {
|
|
|
+ // .el-button {
|
|
|
+ // width: 30px;
|
|
|
+ // }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+</style>
|