Commit d6f197bf by pangchong

feat: 对比优化

parent 475e297c
...@@ -13,6 +13,7 @@ declare module 'vue' { ...@@ -13,6 +13,7 @@ declare module 'vue' {
NCard: typeof import('naive-ui')['NCard'] NCard: typeof import('naive-ui')['NCard']
NConfigProvider: typeof import('naive-ui')['NConfigProvider'] NConfigProvider: typeof import('naive-ui')['NConfigProvider']
NDropdown: typeof import('naive-ui')['NDropdown'] NDropdown: typeof import('naive-ui')['NDropdown']
NEmpty: typeof import('naive-ui')['NEmpty']
NInput: typeof import('naive-ui')['NInput'] NInput: typeof import('naive-ui')['NInput']
NLayout: typeof import('naive-ui')['NLayout'] NLayout: typeof import('naive-ui')['NLayout']
NLayoutContent: typeof import('naive-ui')['NLayoutContent'] NLayoutContent: typeof import('naive-ui')['NLayoutContent']
...@@ -21,6 +22,7 @@ declare module 'vue' { ...@@ -21,6 +22,7 @@ declare module 'vue' {
NMessageProvider: typeof import('naive-ui')['NMessageProvider'] NMessageProvider: typeof import('naive-ui')['NMessageProvider']
NModalProvider: typeof import('naive-ui')['NModalProvider'] NModalProvider: typeof import('naive-ui')['NModalProvider']
NSpace: typeof import('naive-ui')['NSpace'] NSpace: typeof import('naive-ui')['NSpace']
NSpin: typeof import('naive-ui')['NSpin']
NTree: typeof import('naive-ui')['NTree'] NTree: typeof import('naive-ui')['NTree']
RouterLink: typeof import('vue-router')['RouterLink'] RouterLink: typeof import('vue-router')['RouterLink']
RouterView: typeof import('vue-router')['RouterView'] RouterView: typeof import('vue-router')['RouterView']
......
<template> <template>
<n-modal v-bind="$attrs" v-model:show="showModal" :preset="preset" :type="type"> <n-modal v-bind="$attrs" v-model:show="showModal" :preset="preset" :type="type">
<template #title> <template #header>
<slot name="title"></slot> <slot name="title"></slot>
</template> </template>
<n-spin class="w-full h-full" content-class="w-full h-full" :show="loading" :description="description"> <n-spin class="w-full h-full" content-class="w-full h-full" :show="loading" :description="description">
......
...@@ -9,7 +9,7 @@ const renderElem = (type: string, style = { display: 'block' }) => { ...@@ -9,7 +9,7 @@ const renderElem = (type: string, style = { display: 'block' }) => {
const modifyType = (elem as any).modifyType const modifyType = (elem as any).modifyType
Object.assign(style, { Object.assign(style, {
// @ts-ignore // @ts-ignore
paddingLeft: Number(elem.dataIndent) * 10 + 'px' textIndent: Number(elem.dataIndent) * 10 + 'px'
}) })
return h( return h(
type, type,
......
...@@ -2,11 +2,23 @@ ...@@ -2,11 +2,23 @@
<GlobalModal <GlobalModal
v-model="showCompare" v-model="showCompare"
content-class="h-full overflow-hidden !p-0" content-class="h-full overflow-hidden !p-0"
title="XML对比"
style="width: 99vw; height: 99vh" style="width: 99vw; height: 99vh"
preset="card" preset="card"
:showFooter="false" :showFooter="false"
> >
<template #title>
<div class="flex items-center justify-between">
<n-space>
XML对比
<n-button @click="uploadLeftXml">上传左边文件</n-button>
<n-button @click="clearLeftXml">清除左边文件</n-button>
</n-space>
<n-space>
<n-button @click="uploadRightXml">上传右边文件</n-button>
<n-button @click="clearRightXml">清除右边文件</n-button>
</n-space>
</div>
</template>
<div class="flex h-full relative" ref="compareContainerRef"> <div class="flex h-full relative" ref="compareContainerRef">
<div class="choose-row bg-progressRailColor" ref="chooseRowRef"></div> <div class="choose-row bg-progressRailColor" ref="chooseRowRef"></div>
<GlobalEditor <GlobalEditor
...@@ -28,8 +40,26 @@ ...@@ -28,8 +40,26 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { showCompare, compareLeftRef, compareRightRef, compareContainerRef, chooseRowRef, compareData } from '../constants/compare' import { contentHoldNode, nodeSet } from '@/configs/node.config'
import { handleScrollTopLeft, handleScrollTopRight } from '../functions/compare' import {
showCompare,
compareLeftRef,
compareRightRef,
compareContainerRef,
chooseRowRef,
compareData,
compareLeftContent,
compareRightContent
} from '../constants/compare'
import { clearLeftXml, clearRightXml, handleScrollTopLeft, handleScrollTopRight, uploadLeftXml, uploadRightXml } from '../functions/compare'
watchEffect(() => {
if (compareLeftContent.value && compareRightContent.value) {
const xmlProcessing = useXMLProcessing()
const res = xmlProcessing.dualCompareFromString(compareLeftContent.value, compareRightContent.value, nodeSet, contentHoldNode)
Object.assign(compareData, res)
}
})
</script> </script>
<style lang="less"> <style lang="less">
[data-modify-type='removed'] { [data-modify-type='removed'] {
...@@ -39,8 +69,9 @@ import { handleScrollTopLeft, handleScrollTopRight } from '../functions/compare' ...@@ -39,8 +69,9 @@ import { handleScrollTopLeft, handleScrollTopRight } from '../functions/compare'
background-color: var(--success-color-suppl); background-color: var(--success-color-suppl);
} }
[data-modify-type='placeholder'] { [data-modify-type='placeholder'] {
visibility: hidden; opacity: 0.1;
background-color: var(--warning-color-suppl); background-color: var(--warning-color-suppl);
color: var(--warning-color-suppl);
} }
[data-modify-type='null-blank'] { [data-modify-type='null-blank'] {
display: none !important; display: none !important;
......
...@@ -3,6 +3,8 @@ export const compareLeftRef = ref() ...@@ -3,6 +3,8 @@ export const compareLeftRef = ref()
export const compareRightRef = ref() export const compareRightRef = ref()
export const compareContainerRef = ref() export const compareContainerRef = ref()
export const chooseRowRef = ref() export const chooseRowRef = ref()
export const compareLeftContent = ref()
export const compareRightContent = ref()
export const compareData = reactive<{ export const compareData = reactive<{
treeOld: string treeOld: string
treeNew: string treeNew: string
......
import { chooseRowRef, compareContainerRef, compareLeftRef, compareRightRef, showCompare } from '../constants/compare' import { contentHoldNode, nodeSet } from '@/configs/node.config'
import {
chooseRowRef,
compareContainerRef,
compareData,
compareLeftContent,
compareLeftRef,
compareRightContent,
compareRightRef,
showCompare
} from '../constants/compare'
export const handleClickDom = (event: any) => { export const handleClickDom = (event: any) => {
if (!showCompare.value) return if (!showCompare.value) return
...@@ -20,3 +30,49 @@ export const handleScrollTopRight = (event: Event) => { ...@@ -20,3 +30,49 @@ export const handleScrollTopRight = (event: Event) => {
compareLeftRef.value?.handleScrollTop(scrollTop) compareLeftRef.value?.handleScrollTop(scrollTop)
chooseRowRef.value.style.height = '0px' chooseRowRef.value.style.height = '0px'
} }
export const uploadLeftXml = async () => {
const input = document.createElement('input')
input.type = 'file'
input.accept = 'application/xml,text/xml'
input.multiple = false
input.click()
input.addEventListener('change', async (event: Event) => {
const files = (event.target as HTMLInputElement).files
if (files && files.length > 0) {
const file = files[0]
const xmlProcessing = useXMLProcessing()
const res = await xmlProcessing.processFile(file, nodeSet, contentHoldNode)
compareLeftContent.value = res.xmlContent
compareData.treeOld = res.xmlContent
}
input.remove()
})
}
export const uploadRightXml = async () => {
const input = document.createElement('input')
input.type = 'file'
input.accept = 'application/xml,text/xml'
input.multiple = false
input.click()
input.addEventListener('change', async (event: Event) => {
const files = (event.target as HTMLInputElement).files
if (files && files.length > 0) {
const file = files[0]
const xmlProcessing = useXMLProcessing()
const res = await xmlProcessing.processFile(file, nodeSet, contentHoldNode)
compareRightContent.value = res.xmlContent
compareData.treeNew = res.xmlContent
}
input.remove()
})
}
export const clearLeftXml = () => {
compareData.treeNew = compareRightContent.value
compareLeftContent.value = ''
compareData.treeOld = ''
}
export const clearRightXml = () => {
compareData.treeOld = compareLeftContent.value
compareRightContent.value = ''
compareData.treeNew = ''
}
...@@ -3,11 +3,10 @@ import { IDomEditor } from '@wangeditor/editor' ...@@ -3,11 +3,10 @@ import { IDomEditor } from '@wangeditor/editor'
import { treeData, treeRef, treeSelectedKeys } from '../constants/tree' import { treeData, treeRef, treeSelectedKeys } from '../constants/tree'
import { dropdownConfig, editorRef, editorHtml } from '../constants' import { dropdownConfig, editorRef, editorHtml } from '../constants'
import { getUUID } from '@/utils' import { getUUID } from '@/utils'
import { compareData, showCompare } from '../constants/compare' import { compareData, compareLeftContent, compareRightContent, showCompare } from '../constants/compare'
import TextA from '@/assets/file/CES-QEC-V250-A.xml?raw' import TextA from '@/assets/file/CES-QEC-V250-A.xml?raw'
import TextB from '@/assets/file/Trans-Convert.xml?raw' import TextB from '@/assets/file/Trans-Convert.xml?raw'
import { nodeSet, contentHoldNode } from '@/configs/node.config' import { nodeSet, contentHoldNode } from '@/configs/node.config'
import { handleLeftDifferent, handleRightDifferent } from './compare'
export const handleCreated = (editor: IDomEditor) => { export const handleCreated = (editor: IDomEditor) => {
editorRef.value = editor editorRef.value = editor
...@@ -99,11 +98,8 @@ export const uploadXml = async () => { ...@@ -99,11 +98,8 @@ export const uploadXml = async () => {
//xml对比 //xml对比
export const compareXml = () => { export const compareXml = () => {
showCompare.value = true showCompare.value = true
const xmlProcessing = useXMLProcessing() compareData.treeOld = ''
const res = xmlProcessing.dualCompareFromString(TextA, TextB, nodeSet, contentHoldNode) compareData.treeNew = ''
console.log(res) compareLeftContent.value = ''
Object.assign(compareData, res) compareRightContent.value = ''
//比较数据
// handleLeftDifferent()
// handleRightDifferent()
} }
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
<Toolbar :editor="editorRef" editorId="wangeEditor-1" class="border-b border-solid border-borderColor" /> <Toolbar :editor="editorRef" editorId="wangeEditor-1" class="border-b border-solid border-borderColor" />
</div> </div>
<n-space class="bg-baseColor"> <n-space class="bg-baseColor">
<n-button @click="uploadXml" class="h-full" type="error">上传XML</n-button> <n-button @click="uploadXml" class="h-full">上传XML</n-button>
<n-button @click="compareXml" class="h-full">XML对比</n-button> <n-button @click="compareXml" class="h-full">XML对比</n-button>
</n-space> </n-space>
</div> </div>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment