index.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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"
  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 class="dept-table">
  53. <el-table
  54. v-loading="loading"
  55. :data="list"
  56. row-key="id"
  57. :default-expand-all="isExpandAll"
  58. v-if="refreshTable"
  59. :height="calculateTableHeight(310)"
  60. >
  61. <el-table-column prop="name" label="部门名称" width="360" />
  62. <el-table-column prop="leader" label="负责人" width="100">
  63. <template #default="scope">
  64. {{ userList.find((user) => user.id === scope.row.leaderUserId)?.nickname }}
  65. </template>
  66. </el-table-column>
  67. <el-table-column prop="deptLeaderUserId" label="分管领导" width="100">
  68. <template #default="scope">
  69. {{ userList.find((user) => user.id === scope.row.deptLeaderUserId)?.nickname }}
  70. </template>
  71. </el-table-column>
  72. <el-table-column prop="sort" label="排序" width="80" align="center" />
  73. <el-table-column prop="status" label="状态" width="100" align="center">
  74. <template #default="scope">
  75. <dict-tag :type="DICT_TYPE.COMMON_STATUS" :value="scope.row.status" />
  76. </template>
  77. </el-table-column>
  78. <el-table-column
  79. label="创建时间"
  80. align="center"
  81. prop="createTime"
  82. width="240"
  83. :formatter="dateFormatter"
  84. />
  85. <el-table-column label="操作" align="center" class-name="fixed-width">
  86. <template #default="scope">
  87. <el-button
  88. link
  89. type="primary"
  90. @click="openForm('update', scope.row.id)"
  91. v-hasPermi="['system:dept:update']"
  92. >
  93. 修改
  94. </el-button>
  95. <el-button
  96. link
  97. type="danger"
  98. @click="handleDelete(scope.row.id)"
  99. v-hasPermi="['system:dept:delete']"
  100. >
  101. 删除
  102. </el-button>
  103. </template>
  104. </el-table-column>
  105. </el-table>
  106. </ContentWrap>
  107. <!-- 表单弹窗:添加/修改 -->
  108. <DeptForm ref="formRef" @success="getList" />
  109. </template>
  110. <script lang="ts" setup>
  111. import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
  112. import { dateFormatter } from '@/utils/formatTime'
  113. import { handleTree } from '@/utils/tree'
  114. import * as DeptApi from '@/api/system/dept'
  115. import DeptForm from './DeptForm.vue'
  116. import * as UserApi from '@/api/system/user'
  117. import { calculateTableHeight } from '@/utils/tool'
  118. defineOptions({ name: 'SystemDept' })
  119. const message = useMessage() // 消息弹窗
  120. const { t } = useI18n() // 国际化
  121. const loading = ref(true) // 列表的加载中
  122. const list = ref() // 列表的数据
  123. const queryParams = reactive({
  124. title: '',
  125. name: undefined,
  126. status: undefined,
  127. pageNo: 1,
  128. pageSize: 100
  129. })
  130. const queryFormRef = ref() // 搜索的表单
  131. const isExpandAll = ref(true) // 是否展开,默认全部展开
  132. const refreshTable = ref(true) // 重新渲染表格状态
  133. const userList = ref<UserApi.UserVO[]>([]) // 用户列表
  134. /** 查询部门列表 */
  135. const getList = async () => {
  136. loading.value = true
  137. try {
  138. const data = await DeptApi.getDeptPage(queryParams)
  139. list.value = handleTree(data)
  140. } finally {
  141. loading.value = false
  142. }
  143. }
  144. /** 展开/折叠操作 */
  145. const toggleExpandAll = () => {
  146. refreshTable.value = false
  147. isExpandAll.value = !isExpandAll.value
  148. nextTick(() => {
  149. refreshTable.value = true
  150. })
  151. }
  152. /** 搜索按钮操作 */
  153. const handleQuery = () => {
  154. getList()
  155. }
  156. /** 重置按钮操作 */
  157. const resetQuery = () => {
  158. queryParams.pageNo = 1
  159. queryFormRef.value.resetFields()
  160. handleQuery()
  161. }
  162. /** 添加/修改操作 */
  163. const formRef = ref()
  164. const openForm = (type: string, id?: number) => {
  165. formRef.value.open(type, id)
  166. }
  167. /** 删除按钮操作 */
  168. const handleDelete = async (id: number) => {
  169. try {
  170. // 删除的二次确认
  171. await message.delConfirm()
  172. // 发起删除
  173. await DeptApi.deleteDept(id)
  174. message.success(t('common.delSuccess'))
  175. // 刷新列表
  176. await getList()
  177. } catch {}
  178. }
  179. /** 初始化 **/
  180. onMounted(async () => {
  181. await getList()
  182. // 获取用户列表
  183. userList.value = await UserApi.getSimpleUserList()
  184. })
  185. </script>
  186. <style>
  187. .dept-table {
  188. padding-bottom: 0 !important;
  189. margin-bottom: 0 !important;
  190. }
  191. </style>