fix: 流程定义xml预览问题 & 重构代码

This commit is contained in:
dap 2024-05-16 08:18:54 +08:00
parent ed66231d19
commit 3062c46b49
2 changed files with 16 additions and 50 deletions

View File

@ -1,12 +1,10 @@
<template> <template>
<el-dialog v-model="data.visible" title="预览" width="70%" append-to-body> <el-dialog v-model="data.visible" title="预览" width="70%" append-to-body destroy-on-close>
<div v-if="data.type === 'png' && data.xmlStr" style="align: center"> <div v-if="data.type === 'bpmn' && data.xmlStr">
<BpmnViewer ref="bpmnViewerRef"></BpmnViewer> <BpmnViewer ref="bpmnViewerRef"></BpmnViewer>
</div> </div>
<div v-if="data.type === 'xml'" class="xml-data"> <div v-if="data.type === 'xml' && data.xmlStr">
<div v-for="(xml, index) in data.url" :key="index"> <highlightjs language="xml" :code="data.xmlStr" />
<pre class="font">{{ xml }}</pre>
</div>
</div> </div>
<template #footer> <template #footer>
<span v-if="data.type === 'xml'" class="dialog-footer"> </span> <span v-if="data.type === 'xml'" class="dialog-footer"> </span>
@ -19,20 +17,19 @@ import BpmnViewer from '@/components/BpmnView/index.vue';
const data = reactive({ const data = reactive({
visible: false, visible: false,
url: new Array<string>(),
type: '', type: '',
xmlStr: '' xmlStr: ''
}); });
const bpmnViewerRef = ref<InstanceType<typeof BpmnViewer>>(); const bpmnViewerRef = ref<InstanceType<typeof BpmnViewer>>();
type PreviewType = 'xml' | 'bpmn';
// //
const openDialog = (url: string[], type: string) => { const openDialog = (xmlStr: string, type: PreviewType) => {
data.visible = true; data.visible = true;
data.url = url; data.xmlStr = xmlStr;
data.type = type; data.type = type;
/** 流程图 */ /** 流程图 */
if (type === 'png') { if (type === 'bpmn') {
data.xmlStr = url.join('\n');
/** 必须放在nextTick 否则第一次打开为空 */ /** 必须放在nextTick 否则第一次打开为空 */
nextTick(() => { nextTick(() => {
bpmnViewerRef.value?.initXml(data.xmlStr); bpmnViewerRef.value?.initXml(data.xmlStr);
@ -46,23 +43,3 @@ defineExpose({
openDialog openDialog
}); });
</script> </script>
<style>
.xml-data {
background-color: #2b2b2b;
border-radius: 5px;
color: #c6c6c6;
word-break: break-all;
overflow-y: scroll;
overflow-x: hidden;
box-sizing: border-box;
padding: 8px 0px;
height: 500px;
width: inherit;
line-height: 1px;
overflow: auto;
}
.font {
font-family: '幼圆';
font-weight: 500;
}
</style>

View File

@ -61,12 +61,12 @@
</el-table-column> </el-table-column>
<el-table-column align="center" prop="resourceName" label="流程XML" width="100" :show-overflow-tooltip="true"> <el-table-column align="center" prop="resourceName" label="流程XML" width="100" :show-overflow-tooltip="true">
<template #default="scope"> <template #default="scope">
<el-link type="primary" @click="clickPreviewXML(scope.row.id)">{{ scope.row.resourceName }}</el-link> <el-link type="primary" @click="clickPreview(scope.row.id, 'xml')">{{ scope.row.resourceName }}</el-link>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column align="center" prop="diagramResourceName" label="流程图片" width="100" :show-overflow-tooltip="true"> <el-table-column align="center" prop="diagramResourceName" label="流程图片" width="100" :show-overflow-tooltip="true">
<template #default="scope"> <template #default="scope">
<el-link type="primary" @click="clickPreviewImg(scope.row.id)">{{ scope.row.diagramResourceName }}</el-link> <el-link type="primary" @click="clickPreview(scope.row.id, 'bpmn')">{{ scope.row.diagramResourceName }}</el-link>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column align="center" prop="suspensionState" label="状态" width="80"> <el-table-column align="center" prop="suspensionState" label="状态" width="80">
@ -293,7 +293,6 @@ const total = ref(0);
const uploadDialogLoading = ref(false); const uploadDialogLoading = ref(false);
const processDefinitionList = ref<ProcessDefinitionVO[]>([]); const processDefinitionList = ref<ProcessDefinitionVO[]>([]);
const processDefinitionHistoryList = ref<ProcessDefinitionVO[]>([]); const processDefinitionHistoryList = ref<ProcessDefinitionVO[]>([]);
const url = ref<string[]>([]);
const categoryOptions = ref<CategoryOption[]>([]); const categoryOptions = ref<CategoryOption[]>([]);
const categoryName = ref(''); const categoryName = ref('');
/** 部署文件分类选择 */ /** 部署文件分类选择 */
@ -400,28 +399,18 @@ const getProcessDefinitionHitoryList = async (id: string, key: string) => {
loading.value = false; loading.value = false;
}; };
// type PreviewType = 'xml' | 'bpmn';
const clickPreviewImg = async (id: string) => { //
const clickPreview = async (id: string, type: PreviewType) => {
loading.value = true; loading.value = true;
const resp = await definitionXml(id); const resp = await definitionXml(id);
if (previewRef.value) { if (previewRef.value) {
url.value = []; const xmlStr = resp.data.xmlStr;
url.value = resp.data.xml;
loading.value = false; loading.value = false;
previewRef.value.openDialog(url.value, 'png'); previewRef.value.openDialog(xmlStr, type);
}
};
//xml
const clickPreviewXML = async (id: string) => {
loading.value = true;
const resp = await definitionXml(id);
if (previewRef.value) {
url.value = [];
url.value = resp.data.xml;
loading.value = false;
previewRef.value.openDialog(url.value, 'xml');
} }
}; };
/** 删除按钮操作 */ /** 删除按钮操作 */
const handleDelete = async (row?: ProcessDefinitionVO) => { const handleDelete = async (row?: ProcessDefinitionVO) => {
const id = row?.id || ids.value; const id = row?.id || ids.value;