UserTask.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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. import { ProcessExpressionVO } from '@/api/bpm/processExpression'
  138. defineOptions({ name: 'UserTask' })
  139. const props = defineProps({
  140. id: String,
  141. type: String
  142. })
  143. const userTaskForm = ref({
  144. candidateStrategy: undefined, // 分配规则
  145. candidateParam: [] // 分配选项
  146. })
  147. const bpmnElement = ref()
  148. const bpmnInstances = () => (window as any)?.bpmnInstances
  149. const roleOptions = ref<RoleApi.RoleVO[]>([]) // 角色列表
  150. const deptTreeOptions = ref() // 部门树
  151. const postOptions = ref<PostApi.PostVO[]>([]) // 岗位列表
  152. const userOptions = ref<UserApi.UserVO[]>([]) // 用户列表
  153. const userGroupOptions = ref<UserGroupApi.UserGroupVO[]>([]) // 用户组列表
  154. const resetTaskForm = () => {
  155. const businessObject = bpmnElement.value.businessObject
  156. if (!businessObject) {
  157. return
  158. }
  159. if (businessObject.candidateStrategy != undefined) {
  160. userTaskForm.value.candidateStrategy = parseInt(businessObject.candidateStrategy) as any
  161. } else {
  162. userTaskForm.value.candidateStrategy = undefined
  163. }
  164. if (businessObject.candidateParam && businessObject.candidateParam.length > 0) {
  165. if (userTaskForm.value.candidateStrategy === 60) {
  166. // 特殊:流程表达式,只有一个 input 输入框
  167. userTaskForm.value.candidateParam = [businessObject.candidateParam]
  168. } else {
  169. userTaskForm.value.candidateParam = businessObject.candidateParam
  170. .split(',')
  171. .map((item) => +item)
  172. }
  173. } else {
  174. userTaskForm.value.candidateParam = []
  175. }
  176. }
  177. /** 更新 candidateStrategy 字段时,需要清空 candidateParam,并触发 bpmn 图更新 */
  178. const changeCandidateStrategy = () => {
  179. userTaskForm.value.candidateParam = []
  180. updateElementTask()
  181. }
  182. /** 选中某个 options 时候,更新 bpmn 图 */
  183. const updateElementTask = () => {
  184. bpmnInstances().modeling.updateProperties(toRaw(bpmnElement.value), {
  185. candidateStrategy: userTaskForm.value.candidateStrategy,
  186. candidateParam: userTaskForm.value.candidateParam.join(',')
  187. })
  188. }
  189. // 打开监听器弹窗
  190. const processExpressionDialogRef = ref()
  191. const openProcessExpressionDialog = async () => {
  192. processExpressionDialogRef.value.open()
  193. }
  194. const selectProcessExpression = (expression: ProcessExpressionVO) => {
  195. userTaskForm.value.candidateParam = [expression.expression]
  196. updateElementTask()
  197. }
  198. watch(
  199. () => props.id,
  200. () => {
  201. bpmnElement.value = bpmnInstances().bpmnElement
  202. nextTick(() => {
  203. resetTaskForm()
  204. })
  205. },
  206. { immediate: true }
  207. )
  208. onMounted(async () => {
  209. // 获得角色列表
  210. roleOptions.value = await RoleApi.getSimpleRoleList()
  211. // 获得部门列表
  212. const deptOptions = await DeptApi.getSimpleDeptList()
  213. deptTreeOptions.value = handleTree(deptOptions, 'id')
  214. // 获得岗位列表
  215. postOptions.value = await PostApi.getSimplePostList()
  216. // 获得用户列表
  217. userOptions.value = await UserApi.getSimpleUserList()
  218. // 获得用户组列表
  219. userGroupOptions.value = await UserGroupApi.getUserGroupSimpleList()
  220. })
  221. onBeforeUnmount(() => {
  222. bpmnElement.value = null
  223. })
  224. </script>