8
0

user.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. <template>
  2. <hc-body split>
  3. <template #left>
  4. <hc-card title="部门树" scrollbar>
  5. <template #extra>
  6. <el-button hc-btn type="primary" :disabled="isNullES(searchForm.deptId)" @click="clearSearchDeptId">清空选择</el-button>
  7. </template>
  8. <hc-lazy-tree ref="lazyTreeRef" :is-root-expand="false" :h-props="treeProps" tree-key="id" @load="treeLoadNode" @node-tap="treeNodeTap">
  9. <template #default="{ node }">{{ node.label }}</template>
  10. </hc-lazy-tree>
  11. </hc-card>
  12. </template>
  13. <hc-card w-to="1800">
  14. <template #headerToSearch>
  15. <div class="w-140px">
  16. <el-select v-model="searchForm.type" placeholder="用户平台" filterable clearable block>
  17. <el-option v-for="item in userTypeData" :key="item.value" :label="item.label" :value="item.value" />
  18. </el-select>
  19. </div>
  20. <div class="ml-2 w-340px">
  21. <hc-search-input v-model="searchFormName" placeholder="请输入关键字" @search="searchClick">
  22. <template #prepend>
  23. <el-select v-model="searchFormType" placeholder="类型" clearable style="width: 100px">
  24. <el-option label="登录账号" value="account" />
  25. <el-option label="用户姓名" value="realName" />
  26. </el-select>
  27. </template>
  28. </hc-search-input>
  29. </div>
  30. </template>
  31. <template #extraToHeader>
  32. <el-button hc-btn type="primary" @click="addUserClick">新增</el-button>
  33. <el-button hc-btn type="danger">删除</el-button>
  34. <el-button hc-btn type="info">角色配置</el-button>
  35. <el-button hc-btn type="warning">密码重置</el-button>
  36. <el-button hc-btn type="info">平台配置</el-button>
  37. <el-button hc-btn type="danger">账号封禁</el-button>
  38. <el-button hc-btn type="success">账号解封</el-button>
  39. <el-button hc-btn type="success" plain>导入</el-button>
  40. <el-button hc-btn type="warning" plain>导出</el-button>
  41. </template>
  42. <hc-table
  43. :column="tableColumn" :datas="tableData" :loading="tableLoading" :index-style="{ width: 60 }"
  44. is-check :check-style="{ width: 29 }" @selection-change="tableCheckChange"
  45. >
  46. <template #action="{ row }">
  47. <el-link type="warning" @click="editRowClick(row)">修改</el-link>
  48. <el-link v-del-com:[delRowClick]="row" type="danger">删除</el-link>
  49. </template>
  50. </hc-table>
  51. <template #action>
  52. <hc-pages :pages="searchForm" @change="pageChange" />
  53. </template>
  54. </hc-card>
  55. <!-- 新增编辑 -->
  56. <HcDataDialog v-model="isUserDataShow" :info="userItem" @finish="getTableData" />
  57. </hc-body>
  58. </template>
  59. <script setup>
  60. import { onActivated, ref } from 'vue'
  61. import { getArrValue, isNullES } from 'js-fast-way'
  62. import { getDictionaryData } from '~uti/tools'
  63. import HcDataDialog from './modules/user/data.vue'
  64. import deptApi from '~api/system/dept'
  65. import mainApi from '~api/system/user'
  66. onActivated(()=> {
  67. getUserTypeData()
  68. searchClick()
  69. })
  70. //搜索表单
  71. const searchFormType = ref('account')
  72. const searchFormName = ref('')
  73. const searchForm = ref({ deptId: null, current: 1, size: 30, total: 0 })
  74. //获取用户平台
  75. const userTypeData = ref([])
  76. const getUserTypeData = async () => {
  77. userTypeData.value = await getDictionaryData('user_type')
  78. }
  79. //数据格式
  80. const lazyTreeRef = ref(null)
  81. const treeProps = {
  82. label: 'title',
  83. children: 'children',
  84. isLeaf: (item) => {
  85. return !item.hasChildren
  86. },
  87. }
  88. const treeLoadNode = async ({ item, level }, resolve) => {
  89. const parentId = level === 0 ? 0 : item.id
  90. const { data } = await deptApi.getDeptLazyTree(parentId)
  91. resolve(getArrValue(data))
  92. }
  93. //树节点被点击
  94. const treeNodeTap = ({ data }) => {
  95. searchForm.value.deptId = data.id
  96. searchClick()
  97. }
  98. //清空树节点选择
  99. const clearSearchDeptId = () => {
  100. searchForm.value.deptId = null
  101. lazyTreeRef.value?.treeRef?.setCurrentKey(null)
  102. searchClick()
  103. }
  104. //搜索
  105. const searchClick = () => {
  106. searchForm.value.current = 1
  107. getTableData()
  108. }
  109. //分页
  110. const pageChange = ({ current, size }) => {
  111. searchForm.value.current = current
  112. searchForm.value.size = size
  113. getTableData()
  114. }
  115. //表格数据
  116. const tableColumn = ref([
  117. { key: 'account', name: '登录账号', width: 140, align: 'center' },
  118. { key: 'tenantName', name: '所属租户', width: 100, align: 'center' },
  119. { key: 'realName', name: '用户姓名', width: 100, align: 'center' },
  120. { key: 'roleName', name: '所属角色', width: 180, align: 'center' },
  121. { key: 'deptName', name: '所属部门' },
  122. { key: 'userTypeName', name: '用户平台' },
  123. { key: 'action', name: '操作', width: 100, align: 'center' },
  124. ])
  125. const tableData = ref([])
  126. //获取用户数据
  127. const tableLoading = ref(false)
  128. const getTableData = async () => {
  129. tableData.value = []
  130. tableLoading.value = true
  131. const form = {
  132. ...searchForm.value,
  133. total: null,
  134. }
  135. if (searchFormName.value) {
  136. form[searchFormType.value] = searchFormName.value
  137. }
  138. const { data } = await mainApi.page(form)
  139. tableLoading.value = false
  140. tableData.value = getArrValue(data?.records)
  141. searchForm.value.total = data?.total ?? 0
  142. }
  143. //表格被选择
  144. const tableCheckKeys = ref([])
  145. const tableCheckChange = (rows) => {
  146. tableCheckKeys.value = rows
  147. }
  148. //新增修改用户
  149. const isUserDataShow = ref(false)
  150. const userItem = ref({})
  151. //新增用户
  152. const addUserClick = () => {
  153. userItem.value = {}
  154. isUserDataShow.value = true
  155. }
  156. //修改账号
  157. const editRowClick = (row) => {
  158. userItem.value = row
  159. isUserDataShow.value = true
  160. }
  161. //删除账号
  162. const delRowClick = async ({ item }, resolve) => {
  163. await delUserData(item.id)
  164. resolve()
  165. }
  166. //删除用户
  167. const delUserData = async (id) => {
  168. const { isRes } = await mainApi.del(id)
  169. if (!isRes) return
  170. window.$message.success('删除成功')
  171. }
  172. </script>