index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. <template>
  2. <ContentWrap>
  3. <!-- 列表 -->
  4. <XTable @register="registerTable">
  5. <template #options_default="{ row }">
  6. <span :key="option" v-for="option in row.options">
  7. <el-tag>
  8. {{ getAssignRuleOptionName(row.type, option) }}
  9. </el-tag>
  10. &nbsp;
  11. </span>
  12. </template>
  13. <!-- 操作 -->
  14. <template #actionbtns_default="{ row }" v-if="modelId">
  15. <!-- 操作:修改 -->
  16. <XTextButton
  17. preIcon="ep:edit"
  18. :title="t('action.edit')"
  19. v-hasPermi="['bpm:task-assign-rule:update']"
  20. @click="handleUpdate(row)"
  21. />
  22. </template>
  23. </XTable>
  24. <!-- 添加/修改弹窗 -->
  25. <XModal v-model="dialogVisible" title="修改任务规则" width="800" height="35%">
  26. <el-form ref="formRef" :model="formData" :rules="rules" label-width="80px">
  27. <el-form-item label="任务名称" prop="taskDefinitionName">
  28. <el-input v-model="formData.taskDefinitionName" placeholder="请输入流标标识" disabled />
  29. </el-form-item>
  30. <el-form-item label="任务标识" prop="taskDefinitionKey">
  31. <el-input v-model="formData.taskDefinitionKey" placeholder="请输入任务标识" disabled />
  32. </el-form-item>
  33. <el-form-item label="规则类型" prop="type">
  34. <el-select v-model="formData.type" clearable style="width: 100%">
  35. <el-option
  36. v-for="dict in getDictOptions(DICT_TYPE.BPM_TASK_ASSIGN_RULE_TYPE)"
  37. :key="parseInt(dict.value)"
  38. :label="dict.label"
  39. :value="parseInt(dict.value)"
  40. />
  41. </el-select>
  42. </el-form-item>
  43. <el-form-item v-if="formData.type === 10" label="指定角色" prop="roleIds">
  44. <el-select v-model="formData.roleIds" multiple clearable style="width: 100%">
  45. <el-option
  46. v-for="item in roleOptions"
  47. :key="item.id"
  48. :label="item.name"
  49. :value="item.id"
  50. />
  51. </el-select>
  52. </el-form-item>
  53. <el-form-item
  54. label="指定部门"
  55. prop="deptIds"
  56. span="24"
  57. v-if="formData.type === 20 || formData.type === 21"
  58. >
  59. <el-tree-select
  60. ref="treeRef"
  61. v-model="formData.deptIds"
  62. node-key="id"
  63. show-checkbox
  64. :props="defaultProps"
  65. :data="deptTreeOptions"
  66. empty-text="加载中,请稍后"
  67. multiple
  68. />
  69. </el-form-item>
  70. <el-form-item label="指定岗位" prop="postIds" span="24" v-if="formData.type === 22">
  71. <el-select v-model="formData.postIds" multiple clearable style="width: 100%">
  72. <el-option
  73. v-for="item in postOptions"
  74. :key="parseInt(item.id)"
  75. :label="item.name"
  76. :value="parseInt(item.id)"
  77. />
  78. </el-select>
  79. </el-form-item>
  80. <el-form-item
  81. label="指定用户"
  82. prop="userIds"
  83. span="24"
  84. v-if="formData.type === 30 || formData.type === 31 || formData.type === 32"
  85. >
  86. <el-select v-model="formData.userIds" multiple clearable style="width: 100%">
  87. <el-option
  88. v-for="item in userOptions"
  89. :key="parseInt(item.id)"
  90. :label="item.nickname"
  91. :value="parseInt(item.id)"
  92. />
  93. </el-select>
  94. </el-form-item>
  95. <el-form-item label="指定用户组" prop="userGroupIds" v-if="formData.type === 40">
  96. <el-select v-model="formData.userGroupIds" multiple clearable style="width: 100%">
  97. <el-option
  98. v-for="item in userGroupOptions"
  99. :key="parseInt(item.id)"
  100. :label="item.name"
  101. :value="parseInt(item.id)"
  102. />
  103. </el-select>
  104. </el-form-item>
  105. <el-form-item label="指定脚本" prop="scripts" v-if="formData.type === 50">
  106. <el-select v-model="formData.scripts" multiple clearable style="width: 100%">
  107. <el-option
  108. v-for="dict in taskAssignScriptDictDatas"
  109. :key="parseInt(dict.value)"
  110. :label="dict.label"
  111. :value="parseInt(dict.value)"
  112. />
  113. </el-select>
  114. </el-form-item>
  115. </el-form>
  116. <!-- 操作按钮 -->
  117. <template #footer>
  118. <!-- 按钮:保存 -->
  119. <XButton
  120. type="primary"
  121. :title="t('action.save')"
  122. :loading="actionLoading"
  123. @click="submitForm"
  124. />
  125. <!-- 按钮:关闭 -->
  126. <XButton
  127. :loading="actionLoading"
  128. :title="t('dialog.close')"
  129. @click="dialogVisible = false"
  130. />
  131. </template>
  132. </XModal>
  133. </ContentWrap>
  134. </template>
  135. <script setup lang="ts" name="TaskAssignRule">
  136. // 全局相关的 import
  137. import { FormInstance } from 'element-plus'
  138. // 业务相关的 import
  139. import * as TaskAssignRuleApi from '@/api/bpm/taskAssignRule'
  140. import { listSimpleRolesApi } from '@/api/system/role'
  141. import { listSimplePostsApi } from '@/api/system/post'
  142. import { getListSimpleUsersApi } from '@/api/system/user'
  143. import { listSimpleUserGroupsApi } from '@/api/bpm/userGroup'
  144. import { listSimpleDeptApi } from '@/api/system/dept'
  145. import { DICT_TYPE, getDictOptions } from '@/utils/dict'
  146. import { handleTree, defaultProps } from '@/utils/tree'
  147. import { allSchemas, rules } from './taskAssignRule.data'
  148. const { t } = useI18n() // 国际化
  149. const message = useMessage() // 消息弹窗
  150. const { query } = useRoute()
  151. // ========== 列表相关 ==========
  152. const roleOptions = ref() // 角色列表
  153. const deptOptions = ref() // 部门列表
  154. const deptTreeOptions = ref()
  155. const postOptions = ref() // 岗位列表
  156. const userOptions = ref() // 用户列表
  157. const userGroupOptions = ref() // 用户组列表
  158. const taskAssignScriptDictDatas = getDictOptions(DICT_TYPE.BPM_TASK_ASSIGN_SCRIPT)
  159. // 流程模型的编号。如果 modelId 非空,则用于流程模型的查看与配置
  160. const modelId = query.modelId
  161. // 流程定义的编号。如果 processDefinitionId 非空,则用于流程定义的查看,不支持配置
  162. const processDefinitionId = query.processDefinitionId
  163. // 查询参数
  164. const queryParams = reactive({
  165. modelId: modelId,
  166. processDefinitionId: processDefinitionId
  167. })
  168. const [registerTable, { reload }] = useXTable({
  169. allSchemas: allSchemas,
  170. params: queryParams,
  171. getListApi: TaskAssignRuleApi.getTaskAssignRuleList,
  172. isList: true
  173. })
  174. // 翻译规则范围
  175. const getAssignRuleOptionName = (type, option) => {
  176. if (type === 10) {
  177. for (const roleOption of roleOptions.value) {
  178. if (roleOption.id === option) {
  179. return roleOption.name
  180. }
  181. }
  182. } else if (type === 20 || type === 21) {
  183. for (const deptOption of deptOptions.value) {
  184. if (deptOption.id === option) {
  185. return deptOption.name
  186. }
  187. }
  188. } else if (type === 22) {
  189. for (const postOption of postOptions.value) {
  190. if (postOption.id === option) {
  191. return postOption.name
  192. }
  193. }
  194. } else if (type === 30 || type === 31 || type === 32) {
  195. for (const userOption of userOptions.value) {
  196. if (userOption.id === option) {
  197. return userOption.nickname
  198. }
  199. }
  200. } else if (type === 40) {
  201. for (const userGroupOption of userGroupOptions.value) {
  202. if (userGroupOption.id === option) {
  203. return userGroupOption.name
  204. }
  205. }
  206. } else if (type === 50) {
  207. option = option + '' // 转换成 string
  208. for (const dictData of taskAssignScriptDictDatas) {
  209. if (dictData.value === option) {
  210. return dictData.label
  211. }
  212. }
  213. }
  214. return '未知(' + option + ')'
  215. }
  216. // ========== 修改相关 ==========
  217. // 修改任务责任表单
  218. const actionLoading = ref(false) // 遮罩层
  219. const dialogVisible = ref(false) // 是否显示弹出层
  220. const formRef = ref<FormInstance>()
  221. const formData = ref() // 表单数据
  222. // 提交按钮
  223. const submitForm = async () => {
  224. // 参数校验
  225. const elForm = unref(formRef)
  226. if (!elForm) return
  227. const valid = await elForm.validate()
  228. if (!valid) return
  229. // 构建表单
  230. let form = {
  231. ...formData.value,
  232. taskDefinitionName: undefined
  233. }
  234. // 将 roleIds 等选项赋值到 options 中
  235. if (form.type === 10) {
  236. form.options = form.roleIds
  237. } else if (form.type === 20 || form.type === 21) {
  238. form.options = form.deptIds
  239. } else if (form.type === 22) {
  240. form.options = form.postIds
  241. } else if (form.type === 30 || form.type === 31 || form.type === 32) {
  242. form.options = form.userIds
  243. } else if (form.type === 40) {
  244. form.options = form.userGroupIds
  245. } else if (form.type === 50) {
  246. form.options = form.scripts
  247. }
  248. form.roleIds = undefined
  249. form.deptIds = undefined
  250. form.postIds = undefined
  251. form.userIds = undefined
  252. form.userGroupIds = undefined
  253. form.scripts = undefined
  254. // 设置提交中
  255. actionLoading.value = true
  256. // 提交请求
  257. try {
  258. const data = form as TaskAssignRuleApi.TaskAssignVO
  259. // 新增
  260. if (!data.id) {
  261. await TaskAssignRuleApi.createTaskAssignRule(data)
  262. message.success(t('common.createSuccess'))
  263. // 修改
  264. } else {
  265. await TaskAssignRuleApi.updateTaskAssignRule(data)
  266. message.success(t('common.updateSuccess'))
  267. }
  268. dialogVisible.value = false
  269. } finally {
  270. actionLoading.value = false
  271. // 刷新列表
  272. await reload()
  273. }
  274. }
  275. // 修改任务分配规则
  276. const handleUpdate = (row) => {
  277. // 1. 先重置表单
  278. formData.value = {}
  279. // 2. 再设置表单
  280. formData.value = {
  281. ...row,
  282. modelId: modelId,
  283. options: [],
  284. roleIds: [],
  285. deptIds: [],
  286. postIds: [],
  287. userIds: [],
  288. userGroupIds: [],
  289. scripts: []
  290. }
  291. // 将 options 赋值到对应的 roleIds 等选项
  292. if (row.type === 10) {
  293. formData.value.roleIds.push(...row.options)
  294. } else if (row.type === 20 || row.type === 21) {
  295. formData.value.deptIds.push(...row.options)
  296. } else if (row.type === 22) {
  297. formData.value.postIds.push(...row.options)
  298. } else if (row.type === 30 || row.type === 31 || row.type === 32) {
  299. formData.value.userIds.push(...row.options)
  300. } else if (row.type === 40) {
  301. formData.value.userGroupIds.push(...row.options)
  302. } else if (row.type === 50) {
  303. formData.value.scripts.push(...row.options)
  304. }
  305. // 打开弹窗
  306. dialogVisible.value = true
  307. actionLoading.value = false
  308. }
  309. // ========== 初始化 ==========
  310. onMounted(() => {
  311. // 获得角色列表
  312. roleOptions.value = []
  313. listSimpleRolesApi().then((data) => {
  314. roleOptions.value.push(...data)
  315. })
  316. // 获得部门列表
  317. deptOptions.value = []
  318. deptTreeOptions.value = []
  319. listSimpleDeptApi().then((data) => {
  320. deptOptions.value.push(...data)
  321. deptTreeOptions.value.push(...handleTree(data, 'id'))
  322. })
  323. // 获得岗位列表
  324. postOptions.value = []
  325. listSimplePostsApi().then((data) => {
  326. postOptions.value.push(...data)
  327. })
  328. // 获得用户列表
  329. userOptions.value = []
  330. getListSimpleUsersApi().then((data) => {
  331. userOptions.value.push(...data)
  332. })
  333. // 获得用户组列表
  334. userGroupOptions.value = []
  335. listSimpleUserGroupsApi().then((data) => {
  336. userGroupOptions.value.push(...data)
  337. })
  338. })
  339. </script>