tenant.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <template>
  2. <page-wrapper>
  3. <el-card :bordered="false" class="mb-3 proCard">
  4. <el-space align="center">
  5. <el-input
  6. :style="{ width: '320px' }"
  7. v-model="params.tenantName"
  8. clearable
  9. placeholder="请输入租户名称"
  10. @keyup.enter="reloadTable"
  11. />
  12. <el-button type="primary" @click="reloadTable">
  13. <template #icon>
  14. <el-icon>
  15. <SearchOutlined />
  16. </el-icon>
  17. </template>
  18. 查询
  19. </el-button>
  20. </el-space>
  21. </el-card>
  22. <el-card :bordered="false" class="proCard">
  23. <BasicTable
  24. :columns="columns"
  25. :dataSource="tenantItems"
  26. :row-key="(row) => row.id"
  27. ref="tableRef"
  28. :actionColumn="actionColumn"
  29. @update:checked-row-keys="onCheckedRow"
  30. >
  31. <template #tableTitle>
  32. <el-button type="primary" @click="openCreateDrawer">
  33. <template #icon>
  34. <el-icon>
  35. <FileAddOutlined />
  36. </el-icon>
  37. </template>
  38. 添加租户
  39. </el-button>
  40. </template>
  41. <template #action>
  42. <TableAction />
  43. </template>
  44. </BasicTable>
  45. </el-card>
  46. <CreateDrawer
  47. ref="createDrawerRef"
  48. :title="drawerTitle"
  49. :permissionList="treeData"
  50. @change="reloadTable"
  51. />
  52. </page-wrapper>
  53. </template>
  54. <script lang="ts" setup>
  55. import { reactive, ref, unref, h, onMounted } from 'vue';
  56. import { ElMessage } from 'element-plus';
  57. import { BasicTable, TableAction, BasicColumn } from '@/components/Table';
  58. import { tenantList, deleteTenant } from '@/api/tenant/index';
  59. import { columns } from './columns';
  60. import { FileAddOutlined, SearchOutlined } from '@vicons/antd';
  61. import CreateDrawer from './CreateDrawer.vue';
  62. const message = ElMessage;
  63. const tableRef = ref();
  64. const createDrawerRef = ref();
  65. const drawerTitle = ref('添加租户');
  66. const treeData = ref([]);
  67. const tenantItems = ref<any[]>([]);
  68. const params = reactive({
  69. tenantName: '',
  70. tenantCode: '',
  71. });
  72. const actionColumn: BasicColumn = reactive({
  73. width: 150,
  74. title: '操作',
  75. prop: 'action',
  76. fixed: 'right',
  77. render(record) {
  78. return h(TableAction as any, {
  79. style: 'button',
  80. actions: [
  81. {
  82. label: '删除',
  83. isConfirm: true,
  84. popConfirm: {
  85. onConfirm: handleDelete.bind(null, record.row),
  86. title: '您确定要删除吗?',
  87. confirmButtonText: '确定',
  88. cancelButtonText: '取消',
  89. },
  90. },
  91. {
  92. label: '编辑',
  93. onClick: handleEdit.bind(null, record.row),
  94. },
  95. ],
  96. });
  97. },
  98. });
  99. const loadDataTable = async (res?: any) => {
  100. let _params = {
  101. ...unref(params),
  102. ...res,
  103. };
  104. const list = await tenantList(_params);
  105. tenantItems.value = list;
  106. };
  107. function openCreateDrawer() {
  108. const { openDrawer } = createDrawerRef.value;
  109. openDrawer();
  110. }
  111. function onCheckedRow(rowKeys: any[]) {
  112. console.log(rowKeys);
  113. }
  114. function reloadTable() {
  115. // tableRef.value.reload();
  116. loadDataTable();
  117. }
  118. function handleEdit(record: Recordable) {
  119. console.log('点击了编辑', record);
  120. drawerTitle.value = '编辑租户';
  121. const { openDrawer } = createDrawerRef.value;
  122. openDrawer(record.tenantId);
  123. }
  124. function handleDelete(record: Recordable) {
  125. deleteTenant({ id: record.tenantId }).then(() => {
  126. message.success('删除成功');
  127. reloadTable();
  128. });
  129. }
  130. onMounted(async () => {
  131. loadDataTable();
  132. });
  133. </script>
  134. <style lang="scss" scoped></style>