Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 | 1x 1x 1x | <template> <u-linear-layout mode="inline"> <u-button v-for="item in permissionDetails" :key="item.name" :color="getColor(item)" @click="onClickButton(item)"> {{ item.showText }} </u-button> <u-modal v-if="currentItem" :title="currentItem.showText" :visible="!!currentItem" ref="modal" @close="currentItem = undefined"> <u-form label-layout="block" ref="form"> <u-form-item :label="$tt('approvalComments')" :required="currentItem.opinionsEnable" :rules="currentItem.opinionsEnable?'required':''" v-if="currentItem.name !== 'transfer'"> <u-textarea v-model="model.comment" size="normal full" :placeholder="$tt('placeholder')"> </u-textarea> </u-form-item> <u-form-item :label="$tt('selectTransfer')" required rules="required" v-if="currentItem.name === 'transfer'"> <u-input v-model="model.userName" size="normal full" :placeholder="$tt('placeholder')"> </u-input> </u-form-item> </u-form> <template #foot> <u-linear-layout justify="end"> <u-button @click="close()">{{ $tt('cancel') }}</u-button> <u-button color="primary" @click="onSubmit()">{{ $tt('submit') }}</u-button> </u-linear-layout> </template> </u-modal> <u-link ref="link" :destination="destination" :target="target" :link="link"></u-link> </u-linear-layout> </template> <script> import i18nMixin from '../../mixins/i18n'; export default { name: 'u-process-button', mixins: [i18nMixin('u-process-button')], props: { target: { type: String, default: '_self' }, destination: String, link: [String, Function], }, data() { return { model: { comment: '', userName: '', }, currentItem: undefined, taskId: undefined, permissionDetails: [], }; }, created() { location.search.replace('?', '').split('&').forEach((item) => { const [key, value] = item.split('='); if (key === 'taskId') { this.taskId = value; } }); if (this.taskId) { this.getTaskOptPermission(); } }, methods: { async getTaskOptPermission() { if (this.$processV2) { const res = await this.$processV2.taskOptPermission({ body: { taskId: this.taskId, }, }); this.permissionDetails = res.data; } }, getColor(item) { if (['approve', 'submit'].includes(item.name)) { return 'primary'; } return undefined; }, close() { this.currentItem = undefined; this.$refs.modal.close(); }, async onSubmit() { const validateResult = await this.$refs.form.validate(); if (validateResult.valid) { this.submit(); this.$refs.modal.close(); } }, async submit() { if (!this.$processV2) { return; } const { name } = this.currentItem; const operate = `${name}Task`; const body = { taskId: this.taskId, }; const dynamicRenderContainer = document.getElementById('dynamicRenderContainer'); if (dynamicRenderContainer && dynamicRenderContainer.__vue__) { body.data = dynamicRenderContainer.__vue__.processDetailFormData; } if (name === 'transfer') { body.userName = this.model.userName; } else { body.comment = this.model.comment; } await this.$processV2.setTaskInstance({ path: { operate, }, body, }); this.refresh(); }, refresh() { if (this.destination || this.link) { this.$refs.link.$el.click(); } else { window.location.reload(); } }, async onClickButton(item) { if (item.name === 'revert') { return this.revertOperator(); } if (item.name === 'withdraw') { return this.withdrawOperator(); } // 表单验证后打开弹窗 const dynamicRenderContainer = document.getElementById('dynamicRenderContainer'); if (dynamicRenderContainer && dynamicRenderContainer.__vue__) { const formRefName = dynamicRenderContainer.getAttribute('ref-name'); if (formRefName) { const formRef = dynamicRenderContainer.__vue__.$refs[formRefName]; if (formRef && formRef.validate) { const validateResult = await formRef.validate(); if (validateResult.valid) { this.openModal(item); } } } else { this.openModal(item); } } else { this.openModal(item); } }, openModal(item) { this.currentItem = item; Object.assign(this.model, { comment: '', userName: '', }); }, /** * 回退 */ revertOperator() { return this.$confirm({ title: this.$tt('revertTitle'), content: this.$tt('revertContent'), okButton: this.$tt('revertOK'), cancelButton: this.$tt('revertCancel'), }).then(async () => { if (this.$processV2) { await this.$processV2.revertTask({ body: { taskId: this.taskId, }, }); this.refresh(); } }).catch(() => { // do nothing console.log('error'); }); }, /** * 撤回 */ withdrawOperator() { return this.$confirm({ title: this.$tt('withdrawTitle'), content: this.$tt('withdrawContent'), okButton: this.$tt('withdrawOK'), cancelButton: this.$tt('withdrawCancel'), }).then(async () => { if (this.$processV2) { await this.$processV2.withdrawTask({ body: { taskId: this.taskId, }, }); this.refresh(); } }).catch(() => { // do nothing }); }, }, }; </script> |