<!-- 租户管理 --> <script lang="ts" setup name="EdgeDeviceList"> import type { Ref } from 'vue' import { ref } from 'vue' import { ElMessage, ElMessageBox } from 'element-plus' import type { IList, IListQuery } from './multiTenant-interface' import EditDialog from './editDialog.vue' import type { TableColumn } from '@/components/NormalTable/table_interface' import { delTenant, getTenantList } from '@/api/system/multiTenant' const editDialogRef = ref() // 组件 const loading = ref(false) // 默认查询条件 const listQuery: Ref<IListQuery> = ref({ keywords: '', tenantName: '', offset: 1, limit: 20, }) // 表格表头 const columns: Ref<TableColumn[]> = ref([ { text: '租户编号', value: 'tenantCode', align: 'center' }, { text: '租户名称', value: 'tenantName', align: 'center' }, { text: '联系人', value: 'linkPerson', align: 'center' }, { text: '联系电话', value: 'tel', align: 'center' }, ]) const total = ref(0) // 数据条数 const list = ref<IList[]>([]) // 数据条数 const checkoutList = ref<IList[]>([]) // 数据条数 // 查询数据 const fetchData = () => { loading.value = true getTenantList(listQuery.value).then((res: any) => { list.value = res.data.rows total.value = res.data.total loading.value = false }) loading.value = false } // 搜索重置 const reset = () => { listQuery.value = { keywords: '', tenantName: '', offset: 1, limit: 20, } fetchData() } // 搜索按钮 const search = () => { fetchData() } // 新增 function add() { editDialogRef.value.initDialog('add') } // 编辑 const edit = (row: IList) => { editDialogRef.value.initDialog('edit', row) } // 详情 const detail = (row: IList) => { editDialogRef.value.initDialog('detail', row) } // 删除 const del = (row: IList) => { ElMessageBox.confirm( `确定要删除${row.tenantName}吗?`, '确认删除', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning', }, ).then(() => { delTenant({ tenantId: row.id }).then(() => { ElMessage.success('删除成功') fetchData() }) }) } // 页数发生变化后的操作,可能是页码变化,可能是每页容量变化,此函数必写 function changePage(val: { size: number; page: number }) { if (val && val.size) { listQuery.value.limit = val.size } if (val && val.page) { listQuery.value.offset = val.page } fetchData() } onMounted(() => { fetchData() }) </script> <template> <app-container> <search-area :need-clear="true" @search="search" @clear="reset"> <search-item> <el-input v-model="listQuery.tenantName" placeholder="租户名称" clearable style="width: 200px;" @change="search" /> </search-item> </search-area> <table-container> <template #btns-right> <icon-button icon="icon-add" title="新增" @click="add" /> </template> <normal-table :query="listQuery" :list-loading="loading" :columns="columns" :data="list" :total="total" :border="false" @change="changePage"> <template #columns> <el-table-column label="操作" width="220" align="center"> <template #default="scope"> <el-button type="primary" link size="small" class="table-text-button" @click="detail(scope.row)"> 详情 </el-button> <el-button type="primary" link size="small" class="table-text-button" @click="edit(scope.row)"> 编辑 </el-button> <el-button type="danger" link size="small" class="table-text-button" @click="del(scope.row)"> 删除 </el-button> </template> </el-table-column> </template> </normal-table> </table-container> <edit-dialog ref="editDialogRef" @close-refresh="search" /> </app-container> </template>