|
| 1 | +import {FlowButton} from "@/components/flow/types"; |
| 2 | +import {FlowSubmitResultParser, FlowTrySubmitResultParser} from "@/components/flow/domain/FlowResultParser"; |
| 3 | +import {FlowEventContext} from "@/components/flow/domain/FlowEventContext"; |
| 4 | +import {FlowStateContext} from "./FlowStateContext"; |
| 5 | +import {message} from "antd"; |
| 6 | + |
| 7 | +// 流程按钮事件点击触发器 |
| 8 | +export class FlowButtonClickContext { |
| 9 | + |
| 10 | + private readonly flowEventContext: FlowEventContext; |
| 11 | + private readonly flowStateContext: FlowStateContext; |
| 12 | + |
| 13 | + constructor(flowEventContext: FlowEventContext, |
| 14 | + flowStateContext: FlowStateContext) { |
| 15 | + this.flowEventContext = flowEventContext; |
| 16 | + this.flowStateContext = flowStateContext; |
| 17 | + } |
| 18 | + |
| 19 | + |
| 20 | + /** |
| 21 | + * 触发刷新动作 |
| 22 | + */ |
| 23 | + handlerReload(){ |
| 24 | + this.flowEventContext?.reloadFlow(); |
| 25 | + } |
| 26 | + |
| 27 | + /** |
| 28 | + * 触发保存动作 |
| 29 | + */ |
| 30 | + handlerSave(){ |
| 31 | + if (this.flowStateContext?.hasRecordId()) { |
| 32 | + this.flowEventContext?.saveFlow(() => { |
| 33 | + message.info('流程保存成功').then(); |
| 34 | + }) |
| 35 | + } else { |
| 36 | + this.flowEventContext?.startFlow(() => { |
| 37 | + this.flowEventContext?.saveFlow(() => { |
| 38 | + message.info('流程保存成功').then(); |
| 39 | + }) |
| 40 | + }); |
| 41 | + } |
| 42 | + } |
| 43 | + |
| 44 | + /** |
| 45 | + * 触发发起动作 |
| 46 | + */ |
| 47 | + handlerStart(){ |
| 48 | + if (this.flowStateContext?.hasRecordId()) { |
| 49 | + message.info('流程已发起,无需重复发起').then(); |
| 50 | + } else { |
| 51 | + this.flowEventContext?.startFlow((res) => { |
| 52 | + message.info('流程发起成功.').then(); |
| 53 | + }) |
| 54 | + } |
| 55 | + } |
| 56 | + |
| 57 | + /** |
| 58 | + * 指定人提交流程 |
| 59 | + * @param approvalState 审批状态 同意为true 驳回为false |
| 60 | + * @param operatorIds 流程操作人员id |
| 61 | + */ |
| 62 | + handlerSpecifyOperatorSubmit(approvalState:boolean,operatorIds:number[]){ |
| 63 | + this.flowEventContext?.submitFlow(true, (res) => { |
| 64 | + const flowSubmitResultParser = new FlowSubmitResultParser(res.data); |
| 65 | + this.flowStateContext.setResult(flowSubmitResultParser.parser()); |
| 66 | + }, operatorIds); |
| 67 | + } |
| 68 | + |
| 69 | + /** |
| 70 | + * 触发指定人提交动作 |
| 71 | + */ |
| 72 | + handlerSpecifySubmit(){ |
| 73 | + const trySpecifySubmitHandler = ()=>{ |
| 74 | + this.flowEventContext?.trySubmitFlow((res) => { |
| 75 | + const operators = res.data.operators; |
| 76 | + const userIds = operators.map((item: any) => { |
| 77 | + return item.userId; |
| 78 | + }); |
| 79 | + this.flowStateContext?.setUserSelectMode({ |
| 80 | + userSelectType: 'nextNodeUser', |
| 81 | + multiple: true, |
| 82 | + specifyUserIds: userIds, |
| 83 | + }); |
| 84 | + }); |
| 85 | + } |
| 86 | + if (this.flowStateContext?.hasRecordId()) { |
| 87 | + trySpecifySubmitHandler(); |
| 88 | + }else { |
| 89 | + this.flowEventContext?.startFlow(() => { |
| 90 | + trySpecifySubmitHandler(); |
| 91 | + }); |
| 92 | + } |
| 93 | + } |
| 94 | + |
| 95 | + /** |
| 96 | + * 触发提交动作 |
| 97 | + */ |
| 98 | + handlerSubmit(){ |
| 99 | + const submitHandler = ()=>{ |
| 100 | + this.flowEventContext?.submitFlow(true, (res) => { |
| 101 | + const flowSubmitResultParser = new FlowSubmitResultParser(res.data); |
| 102 | + this.flowStateContext?.setResult(flowSubmitResultParser.parser()); |
| 103 | + }) |
| 104 | + } |
| 105 | + if (this.flowStateContext?.hasRecordId()) { |
| 106 | + submitHandler(); |
| 107 | + } else { |
| 108 | + this.flowEventContext?.startFlow(() => { |
| 109 | + submitHandler(); |
| 110 | + }); |
| 111 | + } |
| 112 | + } |
| 113 | + |
| 114 | + /** |
| 115 | + * 触发驳回动作 |
| 116 | + */ |
| 117 | + handlerReject(){ |
| 118 | + if (this.flowStateContext?.hasRecordId()) { |
| 119 | + this.flowEventContext?.submitFlow(false, (res) => { |
| 120 | + const flowSubmitResultParser = new FlowSubmitResultParser(res.data); |
| 121 | + this.flowStateContext?.setResult(flowSubmitResultParser.parser()); |
| 122 | + }) |
| 123 | + } else { |
| 124 | + message.info('流程尚未发起,无法操作').then(); |
| 125 | + } |
| 126 | + } |
| 127 | + |
| 128 | + /** |
| 129 | + * 触发尝试提交动作 |
| 130 | + */ |
| 131 | + handlerTrySubmit(){ |
| 132 | + const trySubmitHandler = ()=>{ |
| 133 | + this.flowEventContext?.trySubmitFlow((res) => { |
| 134 | + const flowTrySubmitResultParser = new FlowTrySubmitResultParser(res.data); |
| 135 | + this.flowStateContext?.setResult(flowTrySubmitResultParser.parser()); |
| 136 | + }); |
| 137 | + } |
| 138 | + if (this.flowStateContext?.hasRecordId()) { |
| 139 | + trySubmitHandler(); |
| 140 | + }else { |
| 141 | + this.flowEventContext?.startFlow(() => { |
| 142 | + trySubmitHandler(); |
| 143 | + }); |
| 144 | + } |
| 145 | + } |
| 146 | + |
| 147 | + /** |
| 148 | + * 触发撤回动作 |
| 149 | + */ |
| 150 | + handlerRecall(){ |
| 151 | + this.flowEventContext?.recallFlow(() => { |
| 152 | + this.flowStateContext?.setResult({ |
| 153 | + state: 'success', |
| 154 | + closeable: true, |
| 155 | + title: '流程撤回成功', |
| 156 | + }); |
| 157 | + }); |
| 158 | + } |
| 159 | + |
| 160 | + /** |
| 161 | + * 触发删除动作 |
| 162 | + */ |
| 163 | + handlerRemove(){ |
| 164 | + if (this.flowStateContext?.hasRecordId()) { |
| 165 | + this.flowEventContext?.removeFlow(() => { |
| 166 | + this.flowStateContext?.setResult({ |
| 167 | + state: 'success', |
| 168 | + closeable: true, |
| 169 | + title: '流程删除成功', |
| 170 | + }); |
| 171 | + }); |
| 172 | + } else { |
| 173 | + message.info('流程尚未发起,无法删除').then(); |
| 174 | + } |
| 175 | + } |
| 176 | + |
| 177 | + /** |
| 178 | + * 触发催办动作 |
| 179 | + */ |
| 180 | + handlerUrge(){ |
| 181 | + this.flowEventContext?.urgeFlow(() => { |
| 182 | + this.flowStateContext?.setResult({ |
| 183 | + state: 'success', |
| 184 | + closeable: true, |
| 185 | + title: '催办提醒已发送', |
| 186 | + }); |
| 187 | + }); |
| 188 | + } |
| 189 | + |
| 190 | + /** |
| 191 | + * 触发延期动作 |
| 192 | + */ |
| 193 | + handlerPostponed(){ |
| 194 | + if (this.flowStateContext?.hasRecordId()) { |
| 195 | + this.flowStateContext?.setPostponedVisible(true); |
| 196 | + }else { |
| 197 | + message.info('流程尚未发起,无法操作').then(); |
| 198 | + } |
| 199 | + } |
| 200 | + |
| 201 | + /** |
| 202 | + * 触发转办动作 |
| 203 | + */ |
| 204 | + handlerTransfer(){ |
| 205 | + if (this.flowStateContext?.hasRecordId()) { |
| 206 | + this.flowStateContext?.setUserSelectMode({ |
| 207 | + userSelectType: 'transfer', |
| 208 | + multiple: false, |
| 209 | + }); |
| 210 | + }else { |
| 211 | + message.info('流程尚未发起,无法操作').then(); |
| 212 | + } |
| 213 | + } |
| 214 | + |
| 215 | + /** |
| 216 | + * 触发自定义接口动作 |
| 217 | + * @param buttonId 自定义按钮的id |
| 218 | + */ |
| 219 | + handlerCustom(buttonId:string){ |
| 220 | + const customHandler = ()=>{ |
| 221 | + this.flowEventContext?.customFlow(buttonId, (res) => { |
| 222 | + const customMessage = res.data; |
| 223 | + this.flowStateContext?.setResult({ |
| 224 | + state: customMessage.resultState.toLowerCase(), |
| 225 | + ...customMessage |
| 226 | + }); |
| 227 | + }); |
| 228 | + } |
| 229 | + if (this.flowStateContext?.hasRecordId()) { |
| 230 | + customHandler(); |
| 231 | + } else { |
| 232 | + this.flowEventContext?.startFlow((res) => { |
| 233 | + customHandler(); |
| 234 | + }); |
| 235 | + } |
| 236 | + } |
| 237 | + |
| 238 | + /** |
| 239 | + * 触发自定义前端动作 |
| 240 | + * @param eventKey 自定义按钮的事件key |
| 241 | + */ |
| 242 | + handlerView(eventKey:string){ |
| 243 | + const viewHandler = ()=>{ |
| 244 | + this.flowEventContext?.triggerEvent(eventKey); |
| 245 | + } |
| 246 | + |
| 247 | + if (this.flowStateContext?.hasRecordId()) { |
| 248 | + viewHandler(); |
| 249 | + }else { |
| 250 | + this.flowEventContext?.startFlow((res) => { |
| 251 | + viewHandler(); |
| 252 | + }); |
| 253 | + } |
| 254 | + } |
| 255 | + |
| 256 | + /** |
| 257 | + * 处理按钮点击事件 |
| 258 | + * @param button |
| 259 | + */ |
| 260 | + handlerClick(button: FlowButton) { |
| 261 | + if (button.type === "RELOAD") { |
| 262 | + this.handlerReload(); |
| 263 | + } |
| 264 | + |
| 265 | + if (button.type === 'SAVE') { |
| 266 | + this.handlerSave(); |
| 267 | + } |
| 268 | + |
| 269 | + if (button.type === "START") { |
| 270 | + this.handlerStart(); |
| 271 | + } |
| 272 | + if (button.type === 'SPECIFY_SUBMIT') { |
| 273 | + this.handlerSpecifySubmit(); |
| 274 | + } |
| 275 | + |
| 276 | + if (button.type === 'SUBMIT') { |
| 277 | + this.handlerSubmit(); |
| 278 | + } |
| 279 | + |
| 280 | + if (button.type === 'REJECT') { |
| 281 | + this.handlerReject(); |
| 282 | + } |
| 283 | + |
| 284 | + if (button.type === 'TRY_SUBMIT') { |
| 285 | + this.handlerTrySubmit(); |
| 286 | + } |
| 287 | + |
| 288 | + if (button.type === 'RECALL') { |
| 289 | + this.handlerRecall(); |
| 290 | + } |
| 291 | + |
| 292 | + if (button.type === 'REMOVE') { |
| 293 | + this.handlerRemove(); |
| 294 | + } |
| 295 | + |
| 296 | + if (button.type === 'URGE') { |
| 297 | + this.handlerUrge() |
| 298 | + } |
| 299 | + |
| 300 | + if (button.type === 'POSTPONED') { |
| 301 | + this.handlerPostponed(); |
| 302 | + } |
| 303 | + |
| 304 | + if (button.type === 'TRANSFER') { |
| 305 | + this.handlerTransfer(); |
| 306 | + } |
| 307 | + |
| 308 | + if (button.type === "CUSTOM") { |
| 309 | + this.handlerCustom(button.id); |
| 310 | + } |
| 311 | + |
| 312 | + if (button.type === 'VIEW') { |
| 313 | + this.handlerView(button.eventKey); |
| 314 | + } |
| 315 | + } |
| 316 | +} |
0 commit comments