Vue3 重构:流程模型的各种操作

This commit is contained in:
YunaiV 2023-03-26 01:36:27 +08:00
parent e83d5914f0
commit b587d7634c
2 changed files with 116 additions and 122 deletions

View File

@ -1,153 +1,137 @@
<template> <template>
<ContentWrap> <Dialog title="导入流程" v-model="modelVisible" width="400">
<!-- 列表 --> <div>
<XTable @register="registerTable"> <el-upload
<template #toolbar_buttons> ref="uploadRef"
<!-- 操作导入 --> :action="importUrl"
<XButton :headers="uploadHeaders"
type="warning" :data="formData"
preIcon="ep:upload" name="bpmnFile"
:title="'导入流程'" v-model:file-list="fileList"
@click="handleImport" :drag="true"
style="margin-left: 10px" :auto-upload="false"
/> accept=".bpmn, .xml"
</template> :limit="1"
</XTable> :on-exceed="handleExceed"
:on-success="submitFormSuccess"
<!-- 导入流程 --> :on-error="submitFormError"
<XModal v-model="importDialogVisible" width="400" title="导入流程"> :disabled="formLoading"
<div> >
<el-upload <Icon class="el-icon--upload" icon="ep:upload-filled" />
ref="uploadRef" <div class="el-upload__text"> 将文件拖到此处 <em>点击上传</em> </div>
:action="importUrl" <template #tip>
:headers="uploadHeaders" <div class="el-upload__tip" style="color: red">
:drag="true" 提示仅允许导入bpmxml格式文件
:limit="1" </div>
:multiple="true" <div>
:show-file-list="true" <el-form ref="formRef" :model="formData" :rules="formRules" label-width="120px">
:disabled="uploadDisabled" <el-form-item label="流程标识" prop="key">
:on-exceed="handleExceed" <el-input
:on-success="handleFileSuccess" v-model="formData.key"
:on-error="excelUploadError" placeholder="请输入流标标识"
:auto-upload="false" style="width: 250px"
accept=".bpmn, .xml" />
name="bpmnFile" </el-form-item>
:data="importForm" <el-form-item label="流程名称" prop="name">
> <el-input v-model="formData.name" placeholder="请输入流程名称" clearable />
<Icon class="el-icon--upload" icon="ep:upload-filled" /> </el-form-item>
<div class="el-upload__text"> 将文件拖到此处 <em>点击上传</em> </div> <el-form-item label="流程描述" prop="description">
<template #tip> <el-input type="textarea" v-model="formData.description" clearable />
<div class="el-upload__tip" style="color: red"> </el-form-item>
提示仅允许导入bpmxml格式文件 </el-form>
</div> </div>
<div> </template>
<el-form </el-upload>
ref="importFormRef" </div>
:model="importForm" <template #footer>
:rules="rules" <el-button @click="submitForm" type="primary" :disabled="formLoading"> </el-button>
label-width="120px" <el-button @click="modelVisible = false"> </el-button>
status-icon </template>
> </Dialog>
<el-form-item label="流程标识" prop="key">
<el-input
v-model="importForm.key"
placeholder="请输入流标标识"
style="width: 250px"
/>
</el-form-item>
<el-form-item label="流程名称" prop="name">
<el-input v-model="importForm.name" placeholder="请输入流程名称" clearable />
</el-form-item>
<el-form-item label="流程描述" prop="description">
<el-input type="textarea" v-model="importForm.description" clearable />
</el-form-item>
</el-form>
</div>
</template>
</el-upload>
</div>
<template #footer>
<!-- 按钮保存 -->
<XButton
type="warning"
preIcon="ep:upload-filled"
:title="t('action.save')"
@click="submitFileForm"
/>
<XButton title="取 消" @click="uploadClose" />
</template>
</XModal>
</ContentWrap>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { getAccessToken, getTenantId } from '@/utils/auth' import { getAccessToken, getTenantId } from '@/utils/auth'
const { t } = useI18n() //
const message = useMessage() // const message = useMessage() //
const router = useRouter() //
// ========== ========== const modelVisible = ref(false) //
const uploadRef = ref<UploadInstance>() const formLoading = ref(false) //
let importUrl = import.meta.env.VITE_BASE_URL + import.meta.env.VITE_API_URL + '/bpm/model/import' const formData = ref({
const uploadHeaders = ref()
const importDialogVisible = ref(false)
const uploadDisabled = ref(false)
const importFormRef = ref<FormInstance>()
const importForm = ref({
key: '', key: '',
name: '', name: '',
description: '' description: ''
}) })
const formRules = reactive({
key: [{ required: true, message: '流程标识不能为空', trigger: 'blur' }],
name: [{ required: true, message: '流程名称不能为空', trigger: 'blur' }]
})
const formRef = ref() // Ref
const uploadRef = ref() // Ref
const importUrl = import.meta.env.VITE_BASE_URL + import.meta.env.VITE_API_URL + '/bpm/model/import'
const uploadHeaders = ref() // Header
const fileList = ref([]) //
// /** 打开弹窗 */
const handleImport = () => { const open = async () => {
importDialogVisible.value = true modelVisible.value = true
} resetForm()
//
const handleExceed = (): void => {
message.error('最多只能上传一个文件!')
}
//
const excelUploadError = (): void => {
message.error('导入流程失败,请您重新上传!')
} }
defineExpose({ open }) // open
// /** 重置表单 */
const submitFileForm = () => { const submitForm = async () => {
//
if (!formRef) return
const valid = await formRef.value.validate()
if (!valid) return
if (fileList.value.length == 0) {
message.error('请上传文件')
return
}
//
uploadHeaders.value = { uploadHeaders.value = {
Authorization: 'Bearer ' + getAccessToken(), Authorization: 'Bearer ' + getAccessToken(),
'tenant-id': getTenantId() 'tenant-id': getTenantId()
} }
uploadDisabled.value = true formLoading.value = true
uploadRef.value!.submit() uploadRef.value!.submit()
} }
//
const handleFileSuccess = async (response: any): Promise<void> => { /** 文件上传成功 */
const emit = defineEmits(['success']) // success
const submitFormSuccess = async (response: any): Promise<void> => {
if (response.code !== 0) { if (response.code !== 0) {
message.error(response.msg) message.error(response.msg)
formLoading.value = false
return return
} }
// //
uploadClose()
//
message.success('导入流程成功!请点击【设计流程】按钮,进行编辑保存后,才可以进行【发布流程】') message.success('导入流程成功!请点击【设计流程】按钮,进行编辑保存后,才可以进行【发布流程】')
await reload() //
emit('success')
} }
//
const uploadClose = () => { /** 上传错误提示 */
// const submitFormError = (): void => {
importDialogVisible.value = false message.error('导入流程失败,请您重新上传!')
formLoading.value = false
}
/** 重置表单 */
const resetForm = () => {
// //
uploadDisabled.value = false formLoading.value = false
uploadRef.value!.clearFiles() uploadRef.value?.clearFiles()
// //
importForm.value = { formData.value = {
key: '', key: '',
name: '', name: '',
description: '' description: ''
} }
importFormRef.value?.resetFields() formRef.value?.resetFields()
}
/** 文件数超出提示 */
const handleExceed = (): void => {
message.error('最多只能上传一个文件!')
} }
</script> </script>

View File

@ -52,7 +52,7 @@
> >
<Icon icon="ep:plus" class="mr-5px" /> 新建流程 <Icon icon="ep:plus" class="mr-5px" /> 新建流程
</el-button> </el-button>
<el-button type="success" plain @click="handleImport()" v-hasPermi="['bpm:model:import']"> <el-button type="success" plain @click="openImportForm" v-hasPermi="['bpm:model:import']">
<Icon icon="ep:upload" class="mr-5px" /> 导入流程 <Icon icon="ep:upload" class="mr-5px" /> 导入流程
</el-button> </el-button>
</el-form-item> </el-form-item>
@ -196,9 +196,12 @@
/> />
</ContentWrap> </ContentWrap>
<!-- 表单弹窗添加/修改 --> <!-- 表单弹窗添加/修改流程 -->
<ModelForm ref="formRef" @success="getList" /> <ModelForm ref="formRef" @success="getList" />
<!-- 表单弹窗导入流程 -->
<ModelImportForm ref="importFormRef" @success="getList" />
<!-- 弹窗表单详情 --> <!-- 弹窗表单详情 -->
<Dialog title="表单详情" v-model="formDetailVisible" width="800"> <Dialog title="表单详情" v-model="formDetailVisible" width="800">
<form-create :rule="formDetailPreview.rule" :option="formDetailPreview.option" /> <form-create :rule="formDetailPreview.rule" :option="formDetailPreview.option" />
@ -222,6 +225,7 @@ import { dateFormatter, formatDate } from '@/utils/formatTime'
import * as ModelApi from '@/api/bpm/model' import * as ModelApi from '@/api/bpm/model'
import * as FormApi from '@/api/bpm/form' import * as FormApi from '@/api/bpm/form'
import ModelForm from './ModelForm.vue' import ModelForm from './ModelForm.vue'
import ModelImportForm from '@/views/bpm/model/ModelImportForm.vue'
import { setConfAndFields2 } from '@/utils/formCreate' import { setConfAndFields2 } from '@/utils/formCreate'
const message = useMessage() // const message = useMessage() //
const { t } = useI18n() // const { t } = useI18n() //
@ -269,6 +273,12 @@ const openForm = (type: string, id?: number) => {
formRef.value.open(type, id) formRef.value.open(type, id)
} }
/** 添加/修改操作 */
const importFormRef = ref()
const openImportForm = () => {
importFormRef.value.open()
}
/** 删除按钮操作 */ /** 删除按钮操作 */
const handleDelete = async (id: number) => { const handleDelete = async (id: number) => {
try { try {