UserTask.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. <template>
  2. <el-form label-width="100px">
  3. <el-form-item label="规则类型" prop="candidateStrategy">
  4. <el-select
  5. v-model="userTaskForm.candidateStrategy"
  6. clearable
  7. style="width: 100%"
  8. @change="changeCandidateStrategy"
  9. >
  10. <el-option
  11. v-for="dict in getIntDictOptions(DICT_TYPE.BPM_TASK_CANDIDATE_STRATEGY)"
  12. :key="dict.value"
  13. :label="dict.label"
  14. :value="dict.value"
  15. />
  16. </el-select>
  17. </el-form-item>
  18. <el-form-item
  19. v-if="userTaskForm.candidateStrategy == 10"
  20. label="指定角色"
  21. prop="candidateParam"
  22. >
  23. <el-select
  24. v-model="userTaskForm.candidateParam"
  25. clearable
  26. multiple
  27. style="width: 100%"
  28. @change="updateElementTask"
  29. >
  30. <el-option v-for="item in roleOptions" :key="item.id" :label="item.name" :value="item.id" />
  31. </el-select>
  32. </el-form-item>
  33. <el-form-item
  34. v-if="userTaskForm.candidateStrategy == 20 || userTaskForm.candidateStrategy == 21"
  35. label="指定部门"
  36. prop="candidateParam"
  37. span="24"
  38. >
  39. <el-tree-select
  40. ref="treeRef"
  41. v-model="userTaskForm.candidateParam"
  42. :data="deptTreeOptions"
  43. :props="defaultProps"
  44. empty-text="加载中,请稍后"
  45. multiple
  46. node-key="id"
  47. show-checkbox
  48. @change="updateElementTask"
  49. />
  50. </el-form-item>
  51. <el-form-item
  52. v-if="userTaskForm.candidateStrategy == 22"
  53. label="指定岗位"
  54. prop="candidateParam"
  55. span="24"
  56. >
  57. <el-select
  58. v-model="userTaskForm.candidateParam"
  59. clearable
  60. multiple
  61. style="width: 100%"
  62. @change="updateElementTask"
  63. >
  64. <el-option v-for="item in postOptions" :key="item.id" :label="item.name" :value="item.id" />
  65. </el-select>
  66. </el-form-item>
  67. <el-form-item
  68. v-if="userTaskForm.candidateStrategy == 30"
  69. label="指定用户"
  70. prop="candidateParam"
  71. span="24"
  72. >
  73. <el-select
  74. v-model="userTaskForm.candidateParam"
  75. clearable
  76. multiple
  77. style="width: 100%"
  78. @change="updateElementTask"
  79. >
  80. <el-option
  81. v-for="item in userOptions"
  82. :key="item.id"
  83. :label="item.nickname"
  84. :value="item.id"
  85. />
  86. </el-select>
  87. </el-form-item>
  88. <el-form-item
  89. v-if="userTaskForm.candidateStrategy === 40"
  90. label="指定用户组"
  91. prop="candidateParam"
  92. >
  93. <el-select
  94. v-model="userTaskForm.candidateParam"
  95. clearable
  96. multiple
  97. style="width: 100%"
  98. @change="updateElementTask"
  99. >
  100. <el-option
  101. v-for="item in userGroupOptions"
  102. :key="item.id"
  103. :label="item.name"
  104. :value="item.id"
  105. />
  106. </el-select>
  107. </el-form-item>
  108. <el-form-item
  109. v-if="userTaskForm.candidateStrategy === 60"
  110. label="流程表达式"
  111. prop="candidateParam"
  112. >
  113. <el-input
  114. type="textarea"
  115. v-model="userTaskForm.candidateParam[0]"
  116. clearable
  117. style="width: 72%"
  118. @change="updateElementTask"
  119. />
  120. <el-button class="ml-5px" size="small" type="success" @click="openProcessExpressionDialog"
  121. >选择表达式</el-button
  122. >
  123. <!-- 选择弹窗 -->
  124. <ProcessExpressionDialog ref="processExpressionDialogRef" @select="selectProcessExpression" />
  125. </el-form-item>
  126. </el-form>
  127. </template>
  128. <script lang="ts" setup>
  129. import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
  130. import { defaultProps, handleTree } from '@/utils/tree'
  131. import * as RoleApi from '@/api/system/role'
  132. import * as DeptApi from '@/api/system/dept'
  133. import * as PostApi from '@/api/system/post'
  134. import * as UserApi from '@/api/system/user'
  135. import * as UserGroupApi from '@/api/bpm/userGroup'
  136. import ProcessExpressionDialog from './ProcessExpressionDialog.vue'
  137. defineOptions({ name: 'UserTask' })
  138. const props = defineProps({
  139. id: String,
  140. type: String
  141. })
  142. const userTaskForm = ref({
  143. candidateStrategy: undefined, // 分配规则
  144. candidateParam: [] // 分配选项
  145. })
  146. const bpmnElement = ref()
  147. const bpmnInstances = () => (window as any)?.bpmnInstances
  148. const roleOptions = ref<RoleApi.RoleVO[]>([]) // 角色列表
  149. const deptTreeOptions = ref() // 部门树
  150. const postOptions = ref<PostApi.PostVO[]>([]) // 岗位列表
  151. const userOptions = ref<UserApi.UserVO[]>([]) // 用户列表
  152. const userGroupOptions = ref<UserGroupApi.UserGroupVO[]>([]) // 用户组列表
  153. const resetTaskForm = () => {
  154. const businessObject = bpmnElement.value.businessObject
  155. if (!businessObject) {
  156. return
  157. }
  158. if (businessObject.candidateStrategy != undefined) {
  159. userTaskForm.value.candidateStrategy = parseInt(businessObject.candidateStrategy) as any
  160. } else {
  161. userTaskForm.value.candidateStrategy = undefined
  162. }
  163. if (businessObject.candidateParam && businessObject.candidateParam.length > 0) {
  164. if (userTaskForm.value.candidateStrategy === 60) {
  165. // 特殊:流程表达式,只有一个 input 输入框
  166. userTaskForm.value.candidateParam = [businessObject.candidateParam]
  167. } else {
  168. userTaskForm.value.candidateParam = businessObject.candidateParam
  169. .split(',')
  170. .map((item) => +item)
  171. }
  172. } else {
  173. userTaskForm.value.candidateParam = []
  174. }
  175. }
  176. /** 更新 candidateStrategy 字段时,需要清空 candidateParam,并触发 bpmn 图更新 */
  177. const changeCandidateStrategy = () => {
  178. userTaskForm.value.candidateParam = []
  179. updateElementTask()
  180. }
  181. /** 选中某个 options 时候,更新 bpmn 图 */
  182. const updateElementTask = () => {
  183. bpmnInstances().modeling.updateProperties(toRaw(bpmnElement.value), {
  184. candidateStrategy: userTaskForm.value.candidateStrategy,
  185. candidateParam: userTaskForm.value.candidateParam.join(',')
  186. })
  187. }
  188. // 打开监听器弹窗
  189. const processExpressionDialogRef = ref()
  190. const openProcessExpressionDialog = async () => {
  191. processExpressionDialogRef.value.open()
  192. }
  193. const selectProcessExpression = (expression) => {
  194. userTaskForm.value.candidateParam = [expression.expression]
  195. }
  196. watch(
  197. () => props.id,
  198. () => {
  199. bpmnElement.value = bpmnInstances().bpmnElement
  200. nextTick(() => {
  201. resetTaskForm()
  202. })
  203. },
  204. { immediate: true }
  205. )
  206. onMounted(async () => {
  207. // 获得角色列表
  208. roleOptions.value = await RoleApi.getSimpleRoleList()
  209. // 获得部门列表
  210. const deptOptions = await DeptApi.getSimpleDeptList()
  211. deptTreeOptions.value = handleTree(deptOptions, 'id')
  212. // 获得岗位列表
  213. postOptions.value = await PostApi.getSimplePostList()
  214. // 获得用户列表
  215. userOptions.value = await UserApi.getSimpleUserList()
  216. // 获得用户组列表
  217. userGroupOptions.value = await UserGroupApi.getUserGroupSimpleList()
  218. })
  219. onBeforeUnmount(() => {
  220. bpmnElement.value = null
  221. })
  222. </script>