index.vue 7.5 KB

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