index.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. <template>
  2. <ContentWrap>
  3. <!-- 列表 -->
  4. <XTable @register="registerTable">
  5. <template #toolbar_buttons>
  6. <!-- 操作:新增 -->
  7. <XButton
  8. type="primary"
  9. preIcon="ep:zoom-in"
  10. :title="t('action.add')"
  11. v-hasPermi="['bpm:user-group:create']"
  12. @click="handleCreate()"
  13. />
  14. </template>
  15. <template #memberUserIds_default="{ row }">
  16. <span v-for="userId in row.memberUserIds" :key="userId">
  17. {{ getUserNickname(userId) }} &nbsp;
  18. </span>
  19. </template>
  20. <template #actionbtns_default="{ row }">
  21. <!-- 操作:修改 -->
  22. <XTextButton
  23. preIcon="ep:edit"
  24. :title="t('action.edit')"
  25. v-hasPermi="['bpm:user-group:update']"
  26. @click="handleUpdate(row.id)"
  27. />
  28. <!-- 操作:详情 -->
  29. <XTextButton
  30. preIcon="ep:view"
  31. :title="t('action.detail')"
  32. v-hasPermi="['bpm:user-group:query']"
  33. @click="handleDetail(row.id)"
  34. />
  35. <!-- 操作:删除 -->
  36. <XTextButton
  37. preIcon="ep:delete"
  38. :title="t('action.del')"
  39. v-hasPermi="['bpm:user-group:delete']"
  40. @click="deleteData(row.id)"
  41. />
  42. </template>
  43. </XTable>
  44. </ContentWrap>
  45. <XModal v-model="dialogVisible" :title="dialogTitle" :mask-closable="false">
  46. <!-- 对话框(添加 / 修改) -->
  47. <Form
  48. v-if="['create', 'update'].includes(actionType)"
  49. :schema="allSchemas.formSchema"
  50. :rules="rules"
  51. ref="formRef"
  52. >
  53. <template #memberUserIds="form">
  54. <el-select v-model="form.memberUserIds" multiple>
  55. <el-option v-for="item in users" :key="item.id" :label="item.nickname" :value="item.id" />
  56. </el-select>
  57. </template>
  58. </Form>
  59. <!-- 对话框(详情) -->
  60. <Descriptions
  61. v-if="actionType === 'detail'"
  62. :schema="allSchemas.detailSchema"
  63. :data="detailData"
  64. >
  65. <template #memberUserIds="{ row }">
  66. <span v-for="userId in row.memberUserIds" :key="userId">
  67. {{ getUserNickname(userId) }} &nbsp;
  68. </span>
  69. </template>
  70. </Descriptions>
  71. <!-- 操作按钮 -->
  72. <template #footer>
  73. <!-- 按钮:保存 -->
  74. <XButton
  75. v-if="['create', 'update'].includes(actionType)"
  76. type="primary"
  77. :title="t('action.save')"
  78. :loading="actionLoading"
  79. @click="submitForm"
  80. />
  81. <!-- 按钮:关闭 -->
  82. <XButton :loading="actionLoading" :title="t('dialog.close')" @click="dialogVisible = false" />
  83. </template>
  84. </XModal>
  85. </template>
  86. <script setup lang="ts">
  87. // 业务相关的 import
  88. import * as UserGroupApi from '@/api/bpm/userGroup'
  89. import { getListSimpleUsersApi, UserVO } from '@/api/system/user'
  90. import { allSchemas, rules } from './group.data'
  91. import { FormExpose } from '@/components/Form'
  92. const { t } = useI18n() // 国际化
  93. const message = useMessage() // 消息弹窗
  94. // 列表相关的变量
  95. const [registerTable, { reload, deleteData }] = useXTable({
  96. allSchemas: allSchemas,
  97. getListApi: UserGroupApi.getUserGroupPageApi,
  98. deleteApi: UserGroupApi.deleteUserGroupApi
  99. })
  100. // 用户列表
  101. const users = ref<UserVO[]>([])
  102. const getUserNickname = (userId) => {
  103. for (const user of users.value) {
  104. if (user.id === userId) {
  105. return user.nickname
  106. }
  107. }
  108. return '未知(' + userId + ')'
  109. }
  110. // ========== CRUD 相关 ==========
  111. const actionLoading = ref(false) // 遮罩层
  112. const actionType = ref('') // 操作按钮的类型
  113. const dialogVisible = ref(false) // 是否显示弹出层
  114. const dialogTitle = ref('edit') // 弹出层标题
  115. const formRef = ref<FormExpose>() // 表单 Ref
  116. const detailData = ref() // 详情 Ref
  117. // 设置标题
  118. const setDialogTile = (type: string) => {
  119. dialogTitle.value = t('action.' + type)
  120. actionType.value = type
  121. dialogVisible.value = true
  122. }
  123. // 新增操作
  124. const handleCreate = () => {
  125. setDialogTile('create')
  126. }
  127. // 修改操作
  128. const handleUpdate = async (rowId: number) => {
  129. setDialogTile('update')
  130. // 设置数据
  131. const res = await UserGroupApi.getUserGroupApi(rowId)
  132. unref(formRef)?.setValues(res)
  133. }
  134. // 详情操作
  135. const handleDetail = async (rowId: number) => {
  136. setDialogTile('detail')
  137. detailData.value = await UserGroupApi.getUserGroupApi(rowId)
  138. }
  139. // 提交按钮
  140. const submitForm = async () => {
  141. const elForm = unref(formRef)?.getElFormRef()
  142. if (!elForm) return
  143. elForm.validate(async (valid) => {
  144. if (valid) {
  145. actionLoading.value = true
  146. // 提交请求
  147. try {
  148. const data = unref(formRef)?.formModel as UserGroupApi.UserGroupVO
  149. if (actionType.value === 'create') {
  150. await UserGroupApi.createUserGroupApi(data)
  151. message.success(t('common.createSuccess'))
  152. } else {
  153. await UserGroupApi.updateUserGroupApi(data)
  154. message.success(t('common.updateSuccess'))
  155. }
  156. dialogVisible.value = false
  157. } finally {
  158. actionLoading.value = false
  159. // 刷新列表
  160. await reload()
  161. }
  162. }
  163. })
  164. }
  165. // ========== 初始化 ==========
  166. onMounted(() => {
  167. getListSimpleUsersApi().then((data) => {
  168. users.value = data
  169. })
  170. })
  171. </script>