index.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. <template>
  2. <!-- 搜索工作栏 -->
  3. <ContentWrap>
  4. <el-form
  5. class="-mb-15px"
  6. :model="queryParams"
  7. ref="queryFormRef"
  8. :inline="true"
  9. label-width="68px"
  10. >
  11. <el-form-item label="部门名称" prop="title">
  12. <el-input
  13. v-model="queryParams.name"
  14. placeholder="请输入部门名称"
  15. clearable
  16. class="!w-240px"
  17. />
  18. </el-form-item>
  19. <el-form-item label="部门状态" prop="status">
  20. <el-select
  21. v-model="queryParams.status"
  22. placeholder="请选择部门状态"
  23. clearable
  24. class="!w-240px"
  25. >
  26. <el-option
  27. v-for="dict in getIntDictOptions(DICT_TYPE.COMMON_STATUS)"
  28. :key="dict.value as number"
  29. :label="dict.label"
  30. :value="dict.value"
  31. />
  32. </el-select>
  33. </el-form-item>
  34. <el-form-item>
  35. <el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
  36. <el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
  37. <el-button
  38. type="primary"
  39. plain
  40. @click="openForm('create')"
  41. v-hasPermi="['system:dept:create']"
  42. >
  43. <Icon icon="ep:plus" class="mr-5px" /> 新增
  44. </el-button>
  45. <el-button type="danger" plain @click="toggleExpandAll">
  46. <Icon icon="ep:sort" class="mr-5px" /> 展开/折叠
  47. </el-button>
  48. </el-form-item>
  49. </el-form>
  50. </ContentWrap>
  51. <!-- 列表 -->
  52. <ContentWrap>
  53. <el-table
  54. v-loading="loading"
  55. :data="list"
  56. row-key="id"
  57. :default-expand-all="isExpandAll"
  58. v-if="refreshTable"
  59. >
  60. <el-table-column prop="name" label="部门名称" />
  61. <el-table-column prop="leader" label="负责人">
  62. <template #default="scope">
  63. {{ userList.find((user) => user.id === scope.row.leaderUserId)?.nickname }}
  64. </template>
  65. </el-table-column>
  66. <el-table-column prop="sort" label="排序" />
  67. <el-table-column prop="status" label="状态">
  68. <template #default="scope">
  69. <dict-tag :type="DICT_TYPE.COMMON_STATUS" :value="scope.row.status" />
  70. </template>
  71. </el-table-column>
  72. <el-table-column
  73. label="创建时间"
  74. align="center"
  75. prop="createTime"
  76. width="180"
  77. :formatter="dateFormatter"
  78. />
  79. <el-table-column label="操作" align="center">
  80. <template #default="scope">
  81. <el-button
  82. link
  83. type="primary"
  84. @click="openForm('update', scope.row.id)"
  85. v-hasPermi="['system:dept:update']"
  86. >
  87. 修改
  88. </el-button>
  89. <el-button
  90. link
  91. type="danger"
  92. @click="handleDelete(scope.row.id)"
  93. v-hasPermi="['system:dept:delete']"
  94. >
  95. 删除
  96. </el-button>
  97. </template>
  98. </el-table-column>
  99. </el-table>
  100. </ContentWrap>
  101. <!-- 表单弹窗:添加/修改 -->
  102. <DeptForm ref="formRef" @success="getList" />
  103. </template>
  104. <script lang="ts" setup>
  105. import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
  106. import { dateFormatter } from '@/utils/formatTime'
  107. import { handleTree } from '@/utils/tree'
  108. import * as DeptApi from '@/api/system/dept'
  109. import DeptForm from './DeptForm.vue'
  110. import * as UserApi from '@/api/system/user'
  111. defineOptions({ name: 'SystemDept' })
  112. const message = useMessage() // 消息弹窗
  113. const { t } = useI18n() // 国际化
  114. const loading = ref(true) // 列表的加载中
  115. const list = ref() // 列表的数据
  116. const queryParams = reactive({
  117. pageNo: 1,
  118. pageSize: 100,
  119. name: undefined,
  120. status: undefined
  121. })
  122. const queryFormRef = ref() // 搜索的表单
  123. const isExpandAll = ref(true) // 是否展开,默认全部展开
  124. const refreshTable = ref(true) // 重新渲染表格状态
  125. const userList = ref<UserApi.UserVO[]>([]) // 用户列表
  126. /** 查询部门列表 */
  127. const getList = async () => {
  128. loading.value = true
  129. try {
  130. const data = await DeptApi.getDeptPage(queryParams)
  131. list.value = handleTree(data)
  132. } finally {
  133. loading.value = false
  134. }
  135. }
  136. /** 展开/折叠操作 */
  137. const toggleExpandAll = () => {
  138. refreshTable.value = false
  139. isExpandAll.value = !isExpandAll.value
  140. nextTick(() => {
  141. refreshTable.value = true
  142. })
  143. }
  144. /** 搜索按钮操作 */
  145. const handleQuery = () => {
  146. getList()
  147. }
  148. /** 重置按钮操作 */
  149. const resetQuery = () => {
  150. queryParams.pageNo = 1
  151. queryFormRef.value.resetFields()
  152. handleQuery()
  153. }
  154. /** 添加/修改操作 */
  155. const formRef = ref()
  156. const openForm = (type: string, id?: number) => {
  157. formRef.value.open(type, id)
  158. }
  159. /** 删除按钮操作 */
  160. const handleDelete = async (id: number) => {
  161. try {
  162. // 删除的二次确认
  163. await message.delConfirm()
  164. // 发起删除
  165. await DeptApi.deleteDept(id)
  166. message.success(t('common.delSuccess'))
  167. // 刷新列表
  168. await getList()
  169. } catch {}
  170. }
  171. /** 初始化 **/
  172. onMounted(async () => {
  173. await getList()
  174. // 获取用户列表
  175. userList.value = await UserApi.getSimpleUserList()
  176. })
  177. </script>