index.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. <style scoped lang="scss">
  2. .system-container {
  3. :deep(.el-card__body) {
  4. display: flex;
  5. flex-direction: column;
  6. justify-content: space-between;
  7. flex: 1;
  8. overflow: auto;
  9. .el-table {
  10. flex: 1;
  11. }
  12. }
  13. }
  14. .page-content {
  15. margin-bottom: 20px;
  16. }
  17. .page-pager {
  18. background-color: #fff;
  19. height: 24px;
  20. }
  21. </style>
  22. <template>
  23. <div class="system-container layout-padding">
  24. <el-card shadow="hover" class="layout-padding-auto">
  25. <el-form
  26. :model="state.formQuery"
  27. ref="queryRef"
  28. size="default" label-width="0px" class="mt5 mb5">
  29. <el-input
  30. v-model="state.formQuery.roleName"
  31. placeholder="角色名"
  32. clearable
  33. @blur="loadData(true)"
  34. class="wd150 mr10">
  35. </el-input>
  36. <el-button class="ml10" plain size="default" type="success" @click="loadData(true)">
  37. <SvgIcon name="ele-Search"/>
  38. 查询
  39. </el-button>
  40. </el-form>
  41. <el-table
  42. :header-cell-style="{background:'#eef1f6',color:'#606266'}"
  43. border
  44. stripe="stripe"
  45. :height="state.tableData.height"
  46. highlight-current-row
  47. current-row-key="id"
  48. row-key="id"
  49. :data="state.tableData.data"
  50. v-loading="state.tableData.loading"
  51. @selection-change="handleTableSelectionChange"
  52. @sort-change="handleTableSortChange">
  53. <template #empty>
  54. <el-empty></el-empty>
  55. </template>
  56. <el-table-column
  57. v-for="field in state.tableData.columns"
  58. :key="field.prop"
  59. :label="field.label"
  60. :column-key="field.prop"
  61. :width="field.width"
  62. :min-width="field.minWidth"
  63. :fixed="field.fixed"
  64. :sortable="field.sortable"
  65. :show-overflow-tooltip="!field.fixed&&field.width>150"
  66. >
  67. <template #default="{row}">
  68. <template v-if="field.prop==='expand'">
  69. <p style="padding-left: 2em;" v-html="row[field.prop]"></p>
  70. </template>
  71. <template v-else>
  72. <div>{{row[field.prop]}}</div>
  73. </template>
  74. </template>
  75. </el-table-column>
  76. </el-table>
  77. <!-- <ext-page class="page-pager" v-model:value="state.pageQuery" @change="loadData(false)"/>-->
  78. </el-card>
  79. </div>
  80. <!-- <RoleDialog ref="roleDialogRef" @refresh="loadData(true)"/>-->
  81. </template>
  82. <script setup lang="ts" name="RoleList">
  83. import {defineAsyncComponent, reactive, onMounted, onBeforeMount, ref, getCurrentInstance, nextTick, onBeforeUnmount} from 'vue';
  84. import {$body,$get} from "/@/utils/request";
  85. import {Msg} from "/@/utils/message";
  86. import ExtPage from '/@/components/form/ExtPage.vue'
  87. import mittBus from '/@/utils/mitt';
  88. // const RoleDialog = defineAsyncComponent(() => import("/@/views/page/RoleDialog.vue"));
  89. //定义引用
  90. const queryRef = ref();
  91. const roleDialogRef = ref();
  92. //定义变量
  93. const state = reactive({
  94. formQuery: {},
  95. pageQuery: {
  96. pageNum: 1,
  97. pageSize: 10,
  98. total: 0
  99. },
  100. tableData: {
  101. height: 500,
  102. data: [] as Array < any >,
  103. loading: false,
  104. columns: [
  105. {label: '角色名', prop: 'roleName', resizable: true},
  106. {label: '角色描述', prop: 'roleDesc', resizable: true},
  107. {label: '角色列表', prop: 'permissions', resizable: true},
  108. {label: '创建时间', prop: 'createTime', sortable: 'custom', resizable: true},
  109. {label: '更新时间', prop: 'updateTime', sortable: 'custom', resizable: true},
  110. {
  111. label: '操作', prop: 'action', width: 180, align: 'center', fixed: 'right',
  112. }
  113. ],
  114. },
  115. })
  116. // 监听双向绑定 modelValue 的变化
  117. // watch(
  118. // () => state.pageIndex,
  119. // () => {
  120. //
  121. // }
  122. // );
  123. //生命周期钩子
  124. onBeforeMount(() => {
  125. })
  126. onMounted(() => {
  127. loadData();
  128. nextTick(() => {
  129. let bodyHeight = document.body.clientHeight;
  130. let queryHeight = queryRef.value.$el.clientHeight;
  131. state.tableData.height = bodyHeight - queryHeight - 220
  132. })
  133. mittBus.on("role.refresh", () => {
  134. loadData();
  135. })
  136. });
  137. onBeforeUnmount(() => {
  138. mittBus.off("role.refresh")
  139. })
  140. //region 方法区
  141. // 初始化表格数据
  142. const loadData = (refresh: boolean = false) => {
  143. if (refresh) {
  144. state.pageQuery.pageNum = 1;
  145. }
  146. state.tableData.loading = true;
  147. $get(`/admin-user/listRole`, {...state.formQuery, ...state.pageQuery}).then((res: any) => {
  148. // let {list, total} = res;
  149. state.tableData.data = res;
  150. // state.pageQuery.total = total;
  151. state.tableData.loading = false;
  152. }).catch(e => {
  153. console.error(e)
  154. state.tableData.loading = false;
  155. })
  156. };
  157. // 打开修改用户弹窗
  158. const onRowClick = (type: string, row: any) => {
  159. roleDialogRef.value.open(type, row);
  160. };
  161. // 删除用户
  162. const onRowDel = (row: any) => {
  163. Msg.confirm(`此操作将永久删除:『${row.name}』,是否继续?`).then(() => {
  164. $get(`/role/delete/${row.id}`).then(() => {
  165. Msg.message("删除成功", 'success')
  166. }).catch(() => {
  167. Msg.message("删除失败", 'error')
  168. })
  169. });
  170. };
  171. const handleTableSelectionChange = (selection: any) => {
  172. console.log("handleTableSelectionChange>>", selection)
  173. // emit("on-check-change", selection)
  174. }
  175. const handleTableSortChange = (column, prop, order) => {
  176. console.log("handleTableSortChange>>", column, prop, order)
  177. // emit("on-sort-change", column)
  178. }
  179. //endregion
  180. // 暴露变量
  181. // defineExpose({
  182. // loadData,
  183. // });
  184. </script>