index.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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.username"
  31. placeholder="用户名"
  32. clearable
  33. @blur="loadData(true)"
  34. class="wd150 mr10">
  35. </el-input>
  36. <el-input
  37. v-model="state.formQuery.nickname"
  38. placeholder="昵称"
  39. clearable
  40. @blur="loadData(true)"
  41. class="wd150 mr10">
  42. </el-input>
  43. <el-input
  44. v-model="state.formQuery.mobilePhone"
  45. placeholder="手机号"
  46. clearable
  47. @blur="loadData(true)"
  48. class="wd150 mr10">
  49. </el-input>
  50. <ext-d-select
  51. v-model="state.formQuery.status"
  52. placeholder="状态"
  53. type="AdminUser.status"
  54. clearable
  55. @on-change="loadData(true)"
  56. class="wd150 mr10"/>
  57. <!-- <el-input-->
  58. <!-- v-model="state.formQuery.status"-->
  59. <!-- placeholder="状态"-->
  60. <!-- clearable-->
  61. <!-- @blur="loadData(true)"-->
  62. <!-- class="wd150 mr10">-->
  63. <!-- </el-input>-->
  64. <el-button class="ml10" plain size="default" type="success" @click="loadData(true)">
  65. <SvgIcon name="ele-Search"/>
  66. 查询
  67. </el-button>
  68. <el-button v-auth="'user.add'" size="default" plain type="success" class="ml10" @click="onRowClick('add',null)">
  69. <SvgIcon name="ele-FolderAdd"/>
  70. 新增
  71. </el-button>
  72. </el-form>
  73. <el-table
  74. border
  75. stripe="stripe"
  76. :height="state.tableData.height"
  77. highlight-current-row
  78. current-row-key="id"
  79. row-key="id"
  80. :data="state.tableData.data"
  81. v-loading="state.tableData.loading"
  82. @selection-change="handleTableSelectionChange"
  83. @sort-change="handleTableSortChange">
  84. <template #empty>
  85. <el-empty></el-empty>
  86. </template>
  87. <el-table-column
  88. v-for="field in state.tableData.columns"
  89. :key="field.prop"
  90. :label="field.label"
  91. :column-key="field.prop"
  92. :width="field.width"
  93. :min-width="field.minWidth"
  94. :fixed="field.fixed"
  95. :sortable="field.sortable"
  96. :show-overflow-tooltip="!field.fixed&&field.width>150"
  97. >
  98. <template #default="{row}">
  99. <template v-if="field.prop==='expand'">
  100. <p style="padding-left: 2em;" v-html="row[field.prop]"></p>
  101. </template>
  102. <template v-else-if="'status'===field.prop">
  103. <ext-d-label type="AdminUser.status" v-model="row[field.prop]"/>
  104. </template>
  105. <template v-else-if="'action'===field.prop">
  106. <el-button v-auth="'user.modify'" size="small" plain type="warning" @click="onRowClick('edit',row)">编辑</el-button>
  107. <!-- <el-button v-auth="'user.delete'" size="small" plain type="danger" @click="onRowDel(row)">删除</el-button>-->
  108. </template>
  109. <template v-else>
  110. <div>{{row[field.prop]}}</div>
  111. </template>
  112. </template>
  113. </el-table-column>
  114. </el-table>
  115. <ext-page class="page-pager" v-model:value="state.pageQuery" @change="loadData(false)"/>
  116. </el-card>
  117. </div>
  118. <AdminUserDialog ref="adminUserDialogRef" @refresh="loadData(true)"/>
  119. </template>
  120. <script setup lang="ts" name="AdminUserList">
  121. import {defineAsyncComponent, reactive, onMounted, onBeforeMount, ref, getCurrentInstance, nextTick, onBeforeUnmount} from 'vue';
  122. import {$body,$get} from "/@/utils/request";
  123. import {Msg} from "/@/utils/message";
  124. import ExtPage from '/@/components/form/ExtPage.vue'
  125. import mittBus from '/@/utils/mitt';
  126. import ExtDSelect from "/@/components/form/ExtDSelect.vue";
  127. import ExtDLabel from "/@/components/form/ExtDLabel.vue";
  128. const AdminUserDialog = defineAsyncComponent(() => import("/@/views/admin/user/dialog.vue"));
  129. //定义引用
  130. const queryRef = ref();
  131. const adminUserDialogRef = ref();
  132. //定义变量
  133. const state = reactive({
  134. formQuery: {},
  135. pageQuery: {
  136. pageNum: 1,
  137. pageSize: 10,
  138. total: 0
  139. },
  140. tableData: {
  141. height: 500,
  142. data: [] as Array < any >,
  143. loading: false,
  144. columns: [
  145. {label: '用户名', prop: 'username',width:120, resizable: true, fixed: 'left'},
  146. {label: '昵称', prop: 'nickname',width:180, resizable: true},
  147. {label: '手机号', prop: 'mobilePhone', width:130,resizable: true},
  148. {label: '状态', prop: 'status', sortable: 'custom', width:130,align: 'center'},
  149. {label: '最后登录时间', prop: 'lastLoginTime', width:180,sortable: 'custom', resizable: true},
  150. {label: '创建时间', prop: 'createTime', width:180,sortable: 'custom', resizable: true},
  151. {
  152. label: '操作', prop: 'action', width: 180, align: 'center', fixed: 'right',
  153. }
  154. ],
  155. },
  156. })
  157. // 监听双向绑定 modelValue 的变化
  158. // watch(
  159. // () => state.pageNum,
  160. // () => {
  161. //
  162. // }
  163. // );
  164. //生命周期钩子
  165. onBeforeMount(() => {
  166. })
  167. onMounted(() => {
  168. loadData();
  169. nextTick(() => {
  170. let bodyHeight = document.body.clientHeight;
  171. let queryHeight = queryRef.value.$el.clientHeight;
  172. state.tableData.height = bodyHeight - queryHeight - 320
  173. })
  174. mittBus.on("adminUser.refresh", () => {
  175. loadData();
  176. })
  177. });
  178. onBeforeUnmount(() => {
  179. mittBus.off("adminUser.refresh")
  180. })
  181. //region 方法区
  182. // 初始化表格数据
  183. const loadData = (refresh: boolean = false) => {
  184. if (refresh) {
  185. state.pageQuery.pageNum = 1;
  186. }
  187. state.tableData.loading = true;
  188. $get(`/admin-user/list`, {...state.formQuery, ...state.pageQuery}).then((res: any) => {
  189. let {list, total} = res;
  190. state.tableData.data = list;
  191. state.pageQuery.total = total;
  192. state.tableData.loading = false;
  193. }).catch(e => {
  194. //console.error(e)
  195. state.tableData.loading = false;
  196. })
  197. };
  198. // 打开修改用户弹窗
  199. const onRowClick = (type: string, row: any) => {
  200. adminUserDialogRef.value.open(type, row);
  201. };
  202. // 删除用户
  203. const onRowDel = (row: any) => {
  204. Msg.confirm(`此操作将永久删除:『${row.username}』,是否继续?`).then(() => {
  205. $get(`/admin-user/delete/${row.id}`).then(() => {
  206. Msg.message("删除成功", 'success')
  207. }).catch(() => {
  208. Msg.message("删除失败", 'error')
  209. })
  210. });
  211. };
  212. const handleTableSelectionChange = (selection: any) => {
  213. //console.log("handleTableSelectionChange>>", selection)
  214. // emit("on-check-change", selection)
  215. }
  216. const handleTableSortChange = (column, prop, order) => {
  217. //console.log("handleTableSortChange>>", column, prop, order)
  218. // emit("on-sort-change", column)
  219. }
  220. //endregion
  221. // 暴露变量
  222. // defineExpose({
  223. // loadData,
  224. // });
  225. </script>