Commit 8992f64eb4b785fa83bb32215f49c73a94fbb963

Authored by YunaiV
1 parent 051f4b85

bpm:完善流程分配任务的弹窗

yudao-ui-admin-vue3/src/api/bpm/taskAssignRule/index.ts
1 import request from '@/config/axios' 1 import request from '@/config/axios'
2 -import { TaskAssignVO } from './types' 2 +
  3 +export type TaskAssignVO = {
  4 + id: number
  5 + modelId: string
  6 + processDefinitionId: string
  7 + taskDefinitionKey: string
  8 + taskDefinitionName: string
  9 + options: string[]
  10 + type: number
  11 +}
3 12
4 export const getTaskAssignRuleList = async (params) => { 13 export const getTaskAssignRuleList = async (params) => {
5 return await request.get({ url: '/bpm/task-assign-rule/list', params }) 14 return await request.get({ url: '/bpm/task-assign-rule/list', params })
yudao-ui-admin-vue3/src/api/bpm/taskAssignRule/types.ts deleted
1 -export type TaskAssignVO = {  
2 - id: number  
3 - modelId: string  
4 - processDefinitionId: string  
5 - taskDefinitionKey: string  
6 - taskDefinitionName: string  
7 - options: string[]  
8 - type: number  
9 -}  
yudao-ui-admin-vue3/src/views/bpm/group/index.vue
@@ -77,7 +77,7 @@ @@ -77,7 +77,7 @@
77 type="primary" 77 type="primary"
78 :title="t('action.save')" 78 :title="t('action.save')"
79 :loading="actionLoading" 79 :loading="actionLoading"
80 - @click="submitForm()" 80 + @click="submitForm"
81 /> 81 />
82 <!-- 按钮:关闭 --> 82 <!-- 按钮:关闭 -->
83 <XButton :loading="actionLoading" :title="t('dialog.close')" @click="dialogVisible = false" /> 83 <XButton :loading="actionLoading" :title="t('dialog.close')" @click="dialogVisible = false" />
@@ -90,7 +90,7 @@ import { onMounted, ref } from &#39;vue&#39; @@ -90,7 +90,7 @@ import { onMounted, ref } from &#39;vue&#39;
90 // 业务相关的 import 90 // 业务相关的 import
91 import * as UserGroupApi from '@/api/bpm/userGroup' 91 import * as UserGroupApi from '@/api/bpm/userGroup'
92 import { getListSimpleUsersApi, UserVO } from '@/api/system/user' 92 import { getListSimpleUsersApi, UserVO } from '@/api/system/user'
93 -import { allSchemas } from './group.data' 93 +import { allSchemas, rules } from './group.data'
94 import { FormExpose } from '@/components/Form' 94 import { FormExpose } from '@/components/Form'
95 95
96 const { t } = useI18n() // 国际化 96 const { t } = useI18n() // 国际化
yudao-ui-admin-vue3/src/views/bpm/taskAssignRule/index.vue
@@ -9,29 +9,28 @@ @@ -9,29 +9,28 @@
9 </template> 9 </template>
10 <!-- 操作 --> 10 <!-- 操作 -->
11 <template #actionbtns_default="{ row }" v-if="modelId"> 11 <template #actionbtns_default="{ row }" v-if="modelId">
12 - <vxe-button  
13 - type="text"  
14 - status="primary"  
15 - content="修改"  
16 - icon="vxe-icon-edit" 12 + <!-- 操作:修改 -->
  13 + <XTextButton
  14 + preIcon="ep:edit"
  15 + :title="t('action.edit')"
  16 + v-hasPermi="['bpm:task-assign-rule:update']"
17 @click="handleUpdate(row)" 17 @click="handleUpdate(row)"
18 /> 18 />
19 </template> 19 </template>
20 </XTable> 20 </XTable>
21 21
22 <!-- 添加/修改弹窗 --> 22 <!-- 添加/修改弹窗 -->
23 - <XModal v-model="openVisible" title="修改任务规则" width="800" height="35%" resize> 23 + <XModal v-model="dialogVisible" title="修改任务规则" width="800" height="35%">
24 <el-form 24 <el-form
25 - ref="xForm" 25 + ref="formRef"
26 :model="formData" 26 :model="formData"
27 - :rules="formRules" 27 + :rules="rules"
28 label-width="120px" 28 label-width="120px"
29 - class="demo-ruleForm"  
30 size="default" 29 size="default"
31 status-icon 30 status-icon
32 > 31 >
33 <el-form-item label="任务名称" prop="taskDefinitionName"> 32 <el-form-item label="任务名称" prop="taskDefinitionName">
34 - <el-input -model="formData.taskDefinitionName" placeholder="请输入流标标识" disabled /> 33 + <el-input v-model="formData.taskDefinitionName" placeholder="请输入流标标识" disabled />
35 </el-form-item> 34 </el-form-item>
36 <el-form-item label="任务标识" prop="taskDefinitionKey"> 35 <el-form-item label="任务标识" prop="taskDefinitionKey">
37 <el-input v-model="formData.taskDefinitionKey" placeholder="请输入任务标识" disabled /> 36 <el-input v-model="formData.taskDefinitionKey" placeholder="请输入任务标识" disabled />
@@ -39,7 +38,7 @@ @@ -39,7 +38,7 @@
39 <el-form-item label="规则类型" prop="type"> 38 <el-form-item label="规则类型" prop="type">
40 <el-select v-model="formData.type" clearable style="width: 100%"> 39 <el-select v-model="formData.type" clearable style="width: 100%">
41 <el-option 40 <el-option
42 - v-for="dict in taskAssignRuleTypeDictDatas" 41 + v-for="dict in getDictOptions(DICT_TYPE.BPM_TASK_ASSIGN_RULE_TYPE)"
43 :key="parseInt(dict.value)" 42 :key="parseInt(dict.value)"
44 :label="dict.label" 43 :label="dict.label"
45 :value="parseInt(dict.value)" 44 :value="parseInt(dict.value)"
@@ -118,9 +117,21 @@ @@ -118,9 +117,21 @@
118 </el-select> 117 </el-select>
119 </el-form-item> 118 </el-form-item>
120 </el-form> 119 </el-form>
  120 + <!-- 操作按钮 -->
121 <template #footer> 121 <template #footer>
122 - <XButton type="primary" title="保存" :loading="loading" @click="submitEvent(xForm)" />  
123 - <XButton title="关闭" @click="resetEvent(xForm)" /> 122 + <!-- 按钮:保存 -->
  123 + <XButton
  124 + type="primary"
  125 + :title="t('action.save')"
  126 + :loading="actionLoading"
  127 + @click="submitForm"
  128 + />
  129 + <!-- 按钮:关闭 -->
  130 + <XButton
  131 + :loading="actionLoading"
  132 + :title="t('dialog.close')"
  133 + @click="dialogVisible = false"
  134 + />
124 </template> 135 </template>
125 </XModal> 136 </XModal>
126 </ContentWrap> 137 </ContentWrap>
@@ -128,28 +139,31 @@ @@ -128,28 +139,31 @@
128 <script setup lang="ts" name="TaskAssignRule"> 139 <script setup lang="ts" name="TaskAssignRule">
129 // 全局相关的 import 140 // 全局相关的 import
130 import type { FormInstance } from 'element-plus' 141 import type { FormInstance } from 'element-plus'
131 -  
132 // 业务相关的 import 142 // 业务相关的 import
133 -import { allSchemas } from './taskAssignRule.data'  
134 import * as TaskAssignRuleApi from '@/api/bpm/taskAssignRule' 143 import * as TaskAssignRuleApi from '@/api/bpm/taskAssignRule'
135 import { listSimpleRolesApi } from '@/api/system/role' 144 import { listSimpleRolesApi } from '@/api/system/role'
136 -import { handleTree, defaultProps } from '@/utils/tree'  
137 import { listSimplePostsApi } from '@/api/system/post' 145 import { listSimplePostsApi } from '@/api/system/post'
138 import { getListSimpleUsersApi } from '@/api/system/user' 146 import { getListSimpleUsersApi } from '@/api/system/user'
139 import { listSimpleUserGroupsApi } from '@/api/bpm/userGroup' 147 import { listSimpleUserGroupsApi } from '@/api/bpm/userGroup'
140 import { listSimpleDeptApi } from '@/api/system/dept' 148 import { listSimpleDeptApi } from '@/api/system/dept'
141 import { DICT_TYPE, getDictOptions } from '@/utils/dict' 149 import { DICT_TYPE, getDictOptions } from '@/utils/dict'
142 -// import {useI18n} from "@/hooks/web/useI18n";  
143 -// import {useMessage} from "@/hooks/web/useMessage";  
144 -import { useRoute } from 'vue-router' 150 +import { handleTree, defaultProps } from '@/utils/tree'
  151 +import { allSchemas, rules } from './taskAssignRule.data'
145 152
146 -// const { t } = useI18n() // 国际化  
147 -// const message = useMessage() // 消息弹窗  
148 -// const router = useRouter() // 路由 153 +const { t } = useI18n() // 国际化
  154 +const message = useMessage() // 消息弹窗
149 const { query } = useRoute() 155 const { query } = useRoute()
150 156
151 // ========== 列表相关 ========== 157 // ========== 列表相关 ==========
152 158
  159 +const roleOptions = ref() // 角色列表
  160 +const deptOptions = ref() // 部门列表
  161 +const deptTreeOptions = ref()
  162 +const postOptions = ref() // 岗位列表
  163 +const userOptions = ref() // 用户列表
  164 +const userGroupOptions = ref() // 用户组列表
  165 +const taskAssignScriptDictDatas = getDictOptions(DICT_TYPE.BPM_TASK_ASSIGN_SCRIPT)
  166 +
153 // 流程模型的编号。如果 modelId 非空,则用于流程模型的查看与配置 167 // 流程模型的编号。如果 modelId 非空,则用于流程模型的查看与配置
154 const modelId = query.modelId 168 const modelId = query.modelId
155 // 流程定义的编号。如果 processDefinitionId 非空,则用于流程定义的查看,不支持配置 169 // 流程定义的编号。如果 processDefinitionId 非空,则用于流程定义的查看,不支持配置
@@ -159,68 +173,14 @@ const queryParams = reactive({ @@ -159,68 +173,14 @@ const queryParams = reactive({
159 modelId: modelId, 173 modelId: modelId,
160 processDefinitionId: processDefinitionId 174 processDefinitionId: processDefinitionId
161 }) 175 })
162 -const [registerTable] = useXTable({ 176 +const [registerTable, { reload }] = useXTable({
163 allSchemas: allSchemas, 177 allSchemas: allSchemas,
164 params: queryParams, 178 params: queryParams,
165 getListApi: TaskAssignRuleApi.getTaskAssignRuleList, 179 getListApi: TaskAssignRuleApi.getTaskAssignRuleList,
166 isList: true 180 isList: true
167 }) 181 })
168 -// 修改任务责任表单  
169 -const xForm = ref<FormInstance>()  
170 -const formData = ref()  
171 -const formRules = reactive({  
172 - type: [{ required: true, message: '规则类型不能为空', trigger: 'change' }],  
173 - roleIds: [{ required: true, message: '指定角色不能为空', trigger: 'change' }],  
174 - deptIds: [{ required: true, message: '指定部门不能为空', trigger: 'change' }],  
175 - postIds: [{ required: true, message: '指定岗位不能为空', trigger: 'change' }],  
176 - userIds: [{ required: true, message: '指定用户不能为空', trigger: 'change' }],  
177 - userGroupIds: [{ required: true, message: '指定用户组不能为空', trigger: 'change' }],  
178 - scripts: [{ required: true, message: '指定脚本不能为空', trigger: 'change' }]  
179 -})  
180 -const loading = ref(false)  
181 -  
182 -const roleOptions = ref() // 角色列表  
183 -const deptOptions = ref() // 部门列表  
184 -const deptTreeOptions = ref()  
185 -const postOptions = ref() // 岗位列表  
186 -const userOptions = ref() // 用户列表  
187 -const userGroupOptions = ref() // 用户组列表  
188 -const taskAssignScriptDictDatas = getDictOptions(DICT_TYPE.BPM_TASK_ASSIGN_SCRIPT)  
189 -const taskAssignRuleTypeDictDatas = getDictOptions(DICT_TYPE.BPM_TASK_ASSIGN_RULE_TYPE)  
190 -  
191 -// 修改任务分配规则  
192 -const openVisible = ref(false)  
193 -  
194 -// 添加修改弹窗提交修改  
195 -const submitEvent = async (formEl: FormInstance | undefined) => {  
196 - console.log('确认')  
197 - if (!formEl) return  
198 - loading.value = true  
199 - await formEl.validate((valid, fields) => {  
200 - if (valid) {  
201 - console.log('submit!')  
202 - loading.value = false  
203 - openVisible.value = false  
204 - } else {  
205 - console.log('error submit!', fields)  
206 - loading.value = false  
207 - }  
208 - })  
209 -}  
210 182
211 -const resetEvent = (formEl: FormInstance | undefined) => {  
212 - if (!formEl) return  
213 - formEl.resetFields()  
214 - openVisible.value = false  
215 -}  
216 -  
217 -// 修改任务分配规则  
218 -const handleUpdate = (row) => {  
219 - console.log(row, '修改i数据')  
220 - openVisible.value = true  
221 - formData.value = { ...row }  
222 -}  
223 -// 类型字典 183 +// 翻译规则范围
224 const getAssignRuleOptionName = (type, option) => { 184 const getAssignRuleOptionName = (type, option) => {
225 if (type === 10) { 185 if (type === 10) {
226 for (const roleOption of roleOptions.value) { 186 for (const roleOption of roleOptions.value) {
@@ -263,6 +223,103 @@ const getAssignRuleOptionName = (type, option) =&gt; { @@ -263,6 +223,103 @@ const getAssignRuleOptionName = (type, option) =&gt; {
263 return '未知(' + option + ')' 223 return '未知(' + option + ')'
264 } 224 }
265 225
  226 +// ========== 修改相关 ==========
  227 +
  228 +// 修改任务责任表单
  229 +const actionLoading = ref(false) // 遮罩层
  230 +const dialogVisible = ref(false) // 是否显示弹出层
  231 +const formRef = ref<FormInstance>()
  232 +const formData = ref() // 表单数据
  233 +
  234 +// 提交按钮
  235 +const submitForm = async () => {
  236 + const elForm = unref(formRef)?.getElFormRef()
  237 + if (!elForm) return
  238 + elForm.validate(async (valid) => {
  239 + if (valid) {
  240 + // 构建表单
  241 + let form = {
  242 + ...formData.value,
  243 + taskDefinitionName: undefined
  244 + }
  245 + // 将 roleIds 等选项赋值到 options 中
  246 + if (form.type === 10) {
  247 + form.options = form.roleIds
  248 + } else if (form.type === 20 || form.type === 21) {
  249 + form.options = form.deptIds
  250 + } else if (form.type === 22) {
  251 + form.options = form.postIds
  252 + } else if (form.type === 30 || form.type === 31 || form.type === 32) {
  253 + form.options = form.userIds
  254 + } else if (form.type === 40) {
  255 + form.options = form.userGroupIds
  256 + } else if (form.type === 50) {
  257 + form.options = form.scripts
  258 + }
  259 + form.roleIds = undefined
  260 + form.deptIds = undefined
  261 + form.postIds = undefined
  262 + form.userIds = undefined
  263 + form.userGroupIds = undefined
  264 + form.scripts = undefined
  265 + // 设置提交中
  266 + actionLoading.value = true
  267 + // 提交请求
  268 + try {
  269 + const data = form as TaskAssignRuleApi.TaskAssignVO
  270 + // 新增
  271 + if (!data.id) {
  272 + await TaskAssignRuleApi.createTaskAssignRule(data)
  273 + message.success(t('common.createSuccess'))
  274 + // 修改
  275 + } else {
  276 + await TaskAssignRuleApi.updateTaskAssignRule(data)
  277 + message.success(t('common.updateSuccess'))
  278 + }
  279 + dialogVisible.value = false
  280 + } finally {
  281 + actionLoading.value = false
  282 + // 刷新列表
  283 + await reload()
  284 + }
  285 + }
  286 + })
  287 +}
  288 +
  289 +// 修改任务分配规则
  290 +const handleUpdate = (row) => {
  291 + // 1. 先重置表单
  292 + formData.value = {}
  293 + // 2. 再设置表单
  294 + formData.value = {
  295 + ...row,
  296 + options: [],
  297 + roleIds: [],
  298 + deptIds: [],
  299 + postIds: [],
  300 + userIds: [],
  301 + userGroupIds: [],
  302 + scripts: []
  303 + }
  304 + // 将 options 赋值到对应的 roleIds 等选项
  305 + if (row.type === 10) {
  306 + formData.value.roleIds.push(...row.options)
  307 + } else if (row.type === 20 || row.type === 21) {
  308 + formData.value.deptIds.push(...row.options)
  309 + } else if (row.type === 22) {
  310 + formData.value.postIds.push(...row.options)
  311 + } else if (row.type === 30 || row.type === 31 || row.type === 32) {
  312 + formData.value.userIds.push(...row.options)
  313 + } else if (row.type === 40) {
  314 + formData.value.userGroupIds.push(...row.options)
  315 + } else if (row.type === 50) {
  316 + formData.value.scripts.push(...row.options)
  317 + }
  318 + // 打开弹窗
  319 + dialogVisible.value = true
  320 + actionLoading.value = false
  321 +}
  322 +
266 // ========== 初始化 ========== 323 // ========== 初始化 ==========
267 onMounted(() => { 324 onMounted(() => {
268 // 获得角色列表 325 // 获得角色列表
yudao-ui-admin-vue3/src/views/bpm/taskAssignRule/taskAssignRule.data.ts
1 import { VxeCrudSchema } from '@/hooks/web/useVxeCrudSchemas' 1 import { VxeCrudSchema } from '@/hooks/web/useVxeCrudSchemas'
2 2
  3 +// 表单校验
  4 +export const rules = reactive({
  5 + type: [{ required: true, message: '规则类型不能为空', trigger: 'change' }],
  6 + roleIds: [{ required: true, message: '指定角色不能为空', trigger: 'change' }],
  7 + deptIds: [{ required: true, message: '指定部门不能为空', trigger: 'change' }],
  8 + postIds: [{ required: true, message: '指定岗位不能为空', trigger: 'change' }],
  9 + userIds: [{ required: true, message: '指定用户不能为空', trigger: 'change' }],
  10 + userGroupIds: [{ required: true, message: '指定用户组不能为空', trigger: 'change' }],
  11 + scripts: [{ required: true, message: '指定脚本不能为空', trigger: 'change' }]
  12 +})
  13 +
3 // CrudSchema 14 // CrudSchema
4 const crudSchemas = reactive<VxeCrudSchema>({ 15 const crudSchemas = reactive<VxeCrudSchema>({
5 primaryKey: 'id', 16 primaryKey: 'id',
@@ -17,7 +28,7 @@ const crudSchemas = reactive&lt;VxeCrudSchema&gt;({ @@ -17,7 +28,7 @@ const crudSchemas = reactive&lt;VxeCrudSchema&gt;({
17 }, 28 },
18 { 29 {
19 title: '规则类型', 30 title: '规则类型',
20 - field: 'category', 31 + field: 'type',
21 dictType: DICT_TYPE.BPM_TASK_ASSIGN_RULE_TYPE, 32 dictType: DICT_TYPE.BPM_TASK_ASSIGN_RULE_TYPE,
22 dictClass: 'number' 33 dictClass: 'number'
23 }, 34 },