|
| 1 | +<template> |
| 2 | + <ContentWrap> |
| 3 | + <!-- 列表 --> |
| 4 | + <XTable @register="registerTable"> |
| 5 | + <template #toolbar_buttons> |
| 6 | + <!-- 操作:导入 --> |
| 7 | + <XButton |
| 8 | + type="warning" |
| 9 | + preIcon="ep:upload" |
| 10 | + :title="'导入流程'" |
| 11 | + @click="handleImport" |
| 12 | + style="margin-left: 10px" |
| 13 | + /> |
| 14 | + </template> |
| 15 | + </XTable> |
| 16 | + |
| 17 | + <!-- 导入流程 --> |
| 18 | + <XModal v-model="importDialogVisible" width="400" title="导入流程"> |
| 19 | + <div> |
| 20 | + <el-upload |
| 21 | + ref="uploadRef" |
| 22 | + :action="importUrl" |
| 23 | + :headers="uploadHeaders" |
| 24 | + :drag="true" |
| 25 | + :limit="1" |
| 26 | + :multiple="true" |
| 27 | + :show-file-list="true" |
| 28 | + :disabled="uploadDisabled" |
| 29 | + :on-exceed="handleExceed" |
| 30 | + :on-success="handleFileSuccess" |
| 31 | + :on-error="excelUploadError" |
| 32 | + :auto-upload="false" |
| 33 | + accept=".bpmn, .xml" |
| 34 | + name="bpmnFile" |
| 35 | + :data="importForm" |
| 36 | + > |
| 37 | + <Icon class="el-icon--upload" icon="ep:upload-filled" /> |
| 38 | + <div class="el-upload__text"> 将文件拖到此处,或 <em>点击上传</em> </div> |
| 39 | + <template #tip> |
| 40 | + <div class="el-upload__tip" style="color: red"> |
| 41 | + 提示:仅允许导入“bpm”或“xml”格式文件! |
| 42 | + </div> |
| 43 | + <div> |
| 44 | + <el-form |
| 45 | + ref="importFormRef" |
| 46 | + :model="importForm" |
| 47 | + :rules="rules" |
| 48 | + label-width="120px" |
| 49 | + status-icon |
| 50 | + > |
| 51 | + <el-form-item label="流程标识" prop="key"> |
| 52 | + <el-input |
| 53 | + v-model="importForm.key" |
| 54 | + placeholder="请输入流标标识" |
| 55 | + style="width: 250px" |
| 56 | + /> |
| 57 | + </el-form-item> |
| 58 | + <el-form-item label="流程名称" prop="name"> |
| 59 | + <el-input v-model="importForm.name" placeholder="请输入流程名称" clearable /> |
| 60 | + </el-form-item> |
| 61 | + <el-form-item label="流程描述" prop="description"> |
| 62 | + <el-input type="textarea" v-model="importForm.description" clearable /> |
| 63 | + </el-form-item> |
| 64 | + </el-form> |
| 65 | + </div> |
| 66 | + </template> |
| 67 | + </el-upload> |
| 68 | + </div> |
| 69 | + <template #footer> |
| 70 | + <!-- 按钮:保存 --> |
| 71 | + <XButton |
| 72 | + type="warning" |
| 73 | + preIcon="ep:upload-filled" |
| 74 | + :title="t('action.save')" |
| 75 | + @click="submitFileForm" |
| 76 | + /> |
| 77 | + <XButton title="取 消" @click="uploadClose" /> |
| 78 | + </template> |
| 79 | + </XModal> |
| 80 | + |
| 81 | + </ContentWrap> |
| 82 | +</template> |
| 83 | + |
| 84 | +<script setup lang="ts"> |
| 85 | +import { getAccessToken, getTenantId } from '@/utils/auth' |
| 86 | +
|
| 87 | +const { t } = useI18n() // 国际化 |
| 88 | +const message = useMessage() // 消息弹窗 |
| 89 | +const router = useRouter() // 路由 |
| 90 | +
|
| 91 | +// ========== 导入流程 ========== |
| 92 | +const uploadRef = ref<UploadInstance>() |
| 93 | +let importUrl = import.meta.env.VITE_BASE_URL + import.meta.env.VITE_API_URL + '/bpm/model/import' |
| 94 | +const uploadHeaders = ref() |
| 95 | +const importDialogVisible = ref(false) |
| 96 | +const uploadDisabled = ref(false) |
| 97 | +const importFormRef = ref<FormInstance>() |
| 98 | +const importForm = ref({ |
| 99 | + key: '', |
| 100 | + name: '', |
| 101 | + description: '' |
| 102 | +}) |
| 103 | +
|
| 104 | +// 导入流程弹窗显示 |
| 105 | +const handleImport = () => { |
| 106 | + importDialogVisible.value = true |
| 107 | +} |
| 108 | +// 文件数超出提示 |
| 109 | +const handleExceed = (): void => { |
| 110 | + message.error('最多只能上传一个文件!') |
| 111 | +} |
| 112 | +// 上传错误提示 |
| 113 | +const excelUploadError = (): void => { |
| 114 | + message.error('导入流程失败,请您重新上传!') |
| 115 | +} |
| 116 | +
|
| 117 | +// 提交文件上传 |
| 118 | +const submitFileForm = () => { |
| 119 | + uploadHeaders.value = { |
| 120 | + Authorization: 'Bearer ' + getAccessToken(), |
| 121 | + 'tenant-id': getTenantId() |
| 122 | + } |
| 123 | + uploadDisabled.value = true |
| 124 | + uploadRef.value!.submit() |
| 125 | +} |
| 126 | +// 文件上传成功 |
| 127 | +const handleFileSuccess = async (response: any): Promise<void> => { |
| 128 | + if (response.code !== 0) { |
| 129 | + message.error(response.msg) |
| 130 | + return |
| 131 | + } |
| 132 | + // 重置表单 |
| 133 | + uploadClose() |
| 134 | + // 提示,并刷新 |
| 135 | + message.success('导入流程成功!请点击【设计流程】按钮,进行编辑保存后,才可以进行【发布流程】') |
| 136 | + await reload() |
| 137 | +} |
| 138 | +// 关闭文件上传 |
| 139 | +const uploadClose = () => { |
| 140 | + // 关闭弹窗 |
| 141 | + importDialogVisible.value = false |
| 142 | + // 重置上传状态和文件 |
| 143 | + uploadDisabled.value = false |
| 144 | + uploadRef.value!.clearFiles() |
| 145 | + // 重置表单 |
| 146 | + importForm.value = { |
| 147 | + key: '', |
| 148 | + name: '', |
| 149 | + description: '' |
| 150 | + } |
| 151 | + importFormRef.value?.resetFields() |
| 152 | +} |
| 153 | +</script> |
0 commit comments