Commit ff88dfbb by qlintonger xeno

Merge branch 'master' of 122.112.146.86:pangchong/vue3_onlineEditor

parents 9a133f87 1838dc67
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
<!--Arbortext, Inc., 1988-2013, v.4002--> <!--Arbortext, Inc., 1988-2013, v.4002-->
<!DOCTYPE JOBCARD PUBLIC "-//CEA-TEXT//DTD JOBCARD-VER1//EN" "JOBCARD.dtd" [ <!DOCTYPE JOBCARD PUBLIC "-//CEA-TEXT//DTD JOBCARD-VER1//EN" "JOBCARD.dtd" [
<!ENTITY nbsp "&#160;"> <!ENTITY nbsp "&#160;">
<!ENTITY rsquo "&#8217;"> <!ENTITY rsquo "&#8217;">
]> ]>
<JOBCARD> <JOBCARD>
<EOTK-HEADER></EOTK-HEADER> <EOTK-HEADER></EOTK-HEADER>
...@@ -26,19 +26,6 @@ ...@@ -26,19 +26,6 @@
</NOTE> </NOTE>
<SIGNOFF/> <SIGNOFF/>
</STEP> </STEP>
<STEP CK-LEVEL="C">
<EFFECT EFFRG="001999"></EFFECT>
<RECORD-LINE>
<PARAC>发动机序号</PARAC>
<PARA>Engine SN</PARA>
<RECORD></RECORD>
</RECORD-LINE>
<NOTE>
<PARAC>开始工作前请记录。</PARAC>
<PARA>Please record before starting work.</PARA>
</NOTE>
<SIGNOFF/>
</STEP>
</TOPIC> </TOPIC>
<TOPIC CK-LEVEL="C"> <TOPIC CK-LEVEL="C">
<TITLEC>工作准备</TITLEC> <TITLEC>工作准备</TITLEC>
......
...@@ -11,14 +11,14 @@ ...@@ -11,14 +11,14 @@
<div class="choose-row bg-progressRailColor" ref="chooseRowRef"></div> <div class="choose-row bg-progressRailColor" ref="chooseRowRef"></div>
<GlobalEditor <GlobalEditor
ref="compareLeftRef" ref="compareLeftRef"
v-model="compareLeftData" v-model="compareData.xmlContentOld"
editorId="compareLeft" editorId="compareLeft"
:editorConfig="{ readOnly: true }" :editorConfig="{ readOnly: true }"
@handleScrollTop="handleScrollTopLeft" @handleScrollTop="handleScrollTopLeft"
/> />
<GlobalEditor <GlobalEditor
ref="compareRightRef" ref="compareRightRef"
v-model="compareRightData" v-model="compareData.xmlContentNew"
editorId="compareRight" editorId="compareRight"
:editorConfig="{ readOnly: true }" :editorConfig="{ readOnly: true }"
@handleScrollTop="handleScrollTopRight" @handleScrollTop="handleScrollTopRight"
...@@ -28,15 +28,7 @@ ...@@ -28,15 +28,7 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { import { showCompare, compareLeftRef, compareRightRef, compareContainerRef, chooseRowRef, compareData } from '../constants/compare'
showCompare,
compareLeftRef,
compareRightRef,
compareLeftData,
compareRightData,
compareContainerRef,
chooseRowRef
} from '../constants/compare'
import { handleScrollTopLeft, handleScrollTopRight } from '../functions/compare' import { handleScrollTopLeft, handleScrollTopRight } from '../functions/compare'
</script> </script>
<style lang="less" scoped> <style lang="less" scoped>
......
import { NewTreeModification, OldTreeModification, TreeRenderResult } from '@/lib/XMLProcessor/src/typing'
export const showCompare = ref(false) export const showCompare = ref(false)
export const compareLeftRef = ref() export const compareLeftRef = ref()
export const compareRightRef = ref() export const compareRightRef = ref()
export const compareLeftData = ref('')
export const compareRightData = ref('')
export const compareContainerRef = ref() export const compareContainerRef = ref()
export const chooseRowRef = ref() export const chooseRowRef = ref()
export const compareData = reactive<{
dataForNew: NewTreeModification
dataForOld: OldTreeModification
domOld: Document
domNew: Document
treeOld: TreeRenderResult[]
treeNew: TreeRenderResult[]
xmlContentOld: string
xmlContentNew: string
}>({
dataForNew: { Added: [] },
dataForOld: { Deleted: [] },
domOld: null as any,
domNew: null as any,
treeOld: [],
treeNew: [],
xmlContentOld: '',
xmlContentNew: ''
})
import { NewTreeModification, OldTreeModification, TreeRenderResult } from '@/lib/XMLProcessor/src/typing' import { TreeRenderResult } from '@/lib/XMLProcessor/src/typing'
import { chooseRowRef, compareContainerRef, compareLeftRef, compareRightRef, showCompare } from '../constants/compare' import { chooseRowRef, compareContainerRef, compareData, compareLeftRef, compareRightRef, showCompare } from '../constants/compare'
import { uniqBy } from 'lodash' import { uniqBy } from 'lodash'
export const handleClickDom = (event: any) => { export const handleClickDom = (event: any) => {
...@@ -22,60 +22,64 @@ export const handleScrollTopRight = (event: Event) => { ...@@ -22,60 +22,64 @@ 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 handleLeftDifferent = (dataForOld: OldTreeModification, treeNew: TreeRenderResult[]) => { export const handleLeftDifferent = () => {
nextTick(() => { nextTick(() => {
const containerLeft = compareLeftRef.value?.editorRef.getEditableContainer() const containerLeft = compareLeftRef.value?.editorRef.getEditableContainer()
const containerRight = compareRightRef.value?.editorRef.getEditableContainer() const containerRight = compareRightRef.value?.editorRef.getEditableContainer()
//新增 const Added = compareData.dataForNew.Added.map((item) => compareNodeAllParent(compareData.treeNew, item.key))
uniqBy(dataForOld.Deleted, 'key').map((item: any) => { uniqBy(compareData.dataForOld.Deleted, 'key').map((item: any) => {
debugger
const allParent = compareNodeAllParent(compareData.treeOld, item.key)
const node = containerLeft!.querySelector(`[data-key="${item.key}"]`) const node = containerLeft!.querySelector(`[data-key="${item.key}"]`)
//处理左边
node.classList.add('bg-errorColorSuppl')
//处理右边
const parentPath = item.chained.slice(0, item.chained.length - 1) const parentPath = item.chained.slice(0, item.chained.length - 1)
const index = item.chained[item.chained.length - 1] const index = item.chained[item.chained.length - 1]
const parentData = findNodeByChained(treeNew, parentPath) const parentData = findNodeByChained(compareData.treeNew, parentPath)
const parentNode = containerRight!.querySelector(`[data-key="${parentData?.key}"]`) const parentNode = containerRight!.querySelector(`[data-key="${parentData?.key}"]`)
// 创建一个新节点 if (Added.some((item) => JSON.stringify(item) === JSON.stringify(allParent))) {
const newDiv = document.createElement('div') //修改
newDiv.style.height = `${node.offsetHeight}px` const node = containerLeft!.querySelector(`[data-key="${item.key}"]`)
newDiv.classList.add('bg-dividerColor') if (node.childNodes.length == 1 && node.childNodes[0].nodeName == 'SPAN') {
parentNode && parentNode.insertBefore(newDiv, parentNode.childNodes[index]) node.classList.add('bg-warningColorSuppl')
}) }
//修改 } else {
dataForOld.Changed.map((item) => { //处理左边
const node = containerLeft!.querySelector(`[data-key="${item.key}"]`) node.classList.add('bg-errorColorSuppl')
if (node.childNodes.length == 1 && node.childNodes[0].nodeName == 'SPAN') { //处理右边
node.classList.add('bg-warningColorSuppl') const newDiv = document.createElement('div')
newDiv.style.height = `${node.offsetHeight}px`
newDiv.classList.add('bg-dividerColor')
parentNode && parentNode.insertBefore(newDiv, parentNode.childNodes[index])
} }
}) })
}) })
} }
export const handleRightDifferent = (dataForNew: NewTreeModification, treeOld: TreeRenderResult[]) => { export const handleRightDifferent = () => {
nextTick(() => { nextTick(() => {
const containerLeft = compareLeftRef.value?.editorRef.getEditableContainer() const containerLeft = compareLeftRef.value?.editorRef.getEditableContainer()
const containerRight = compareRightRef.value?.editorRef.getEditableContainer() const containerRight = compareRightRef.value?.editorRef.getEditableContainer()
//新增 const Deleted = compareData.dataForOld.Deleted.map((item) => compareNodeAllParent(compareData.treeOld, item.key))
uniqBy(dataForNew.Added, 'key').map((item: any) => { uniqBy(compareData.dataForNew.Added, 'key').map((item) => {
const allParent = compareNodeAllParent(compareData.treeNew, item.key)
const node = containerRight!.querySelector(`[data-key="${item.key}"]`) const node = containerRight!.querySelector(`[data-key="${item.key}"]`)
//处理右边
node.classList.add('bg-errorColorSuppl')
//处理左边
const parentPath = item.chained.slice(0, item.chained.length - 1) const parentPath = item.chained.slice(0, item.chained.length - 1)
const index = item.chained[item.chained.length - 1] const index = item.chained[item.chained.length - 1]
const parentData = findNodeByChained(treeOld, parentPath) const parentData = findNodeByChained(compareData.treeOld, parentPath)
const parentNode = containerLeft!.querySelector(`[data-key="${parentData?.key}"]`) const parentNode = containerLeft!.querySelector(`[data-key="${parentData?.key}"]`)
// 创建一个新节点 if (Deleted.some((item) => JSON.stringify(item) === JSON.stringify(allParent))) {
const newDiv = document.createElement('div') //修改
newDiv.style.height = `${node.offsetHeight}px` const node = containerRight!.querySelector(`[data-key="${item.key}"]`)
newDiv.classList.add('bg-dividerColor') if (node.childNodes.length == 1 && node.childNodes[0].nodeName == 'SPAN') {
parentNode && parentNode.insertBefore(newDiv, parentNode.childNodes[index]) node.classList.add('bg-warningColorSuppl')
}) }
//修改 } else {
dataForNew.Changed.map((item: any) => { //新增
const node = containerRight!.querySelector(`[data-key="${item.key}"]`) //处理右边
if (node.childNodes.length == 1 && node.childNodes[0].nodeName == 'SPAN') { node.classList.add('bg-errorColorSuppl')
node.classList.add('bg-warningColorSuppl') //处理左边
const newDiv = document.createElement('div')
newDiv.style.height = `${node.offsetHeight}px`
newDiv.classList.add('bg-dividerColor')
parentNode && parentNode.insertBefore(newDiv, parentNode.childNodes[index])
} }
}) })
}) })
...@@ -110,3 +114,21 @@ export const findNodeByChained = (data: TreeRenderResult[], targetChained: numbe ...@@ -110,3 +114,21 @@ export const findNodeByChained = (data: TreeRenderResult[], targetChained: numbe
} }
return null // 没有找到目标节点 return null // 没有找到目标节点
} }
//根据节点的key获取所有父节点的集合
export const compareNodeAllParent = (root: TreeRenderResult[], key: string) => {
function traverse(node: TreeRenderResult, currentPath: string[]): string[] | null {
currentPath.push(node.label)
if (node.key === key) {
return [...currentPath]
}
if (node.children) {
for (const child of node.children) {
const result = traverse(child, [...currentPath])
if (result) return result
}
}
return null
}
const result = traverse(root[0], [])
return result || []
}
...@@ -3,7 +3,7 @@ import { IDomEditor } from '@wangeditor/editor' ...@@ -3,7 +3,7 @@ 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 { compareLeftData, compareRightData, showCompare } from '../constants/compare' import { compareData, 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'
...@@ -102,10 +102,8 @@ export const compareXml = () => { ...@@ -102,10 +102,8 @@ export const compareXml = () => {
const xmlProcessing = useXMLProcessing() const xmlProcessing = useXMLProcessing()
const res = xmlProcessing.dualCompareFromString(TextA, TextB, nodeSet, contentHoldNode) const res = xmlProcessing.dualCompareFromString(TextA, TextB, nodeSet, contentHoldNode)
console.log(res) console.log(res)
//渲染数据 Object.assign(compareData, res)
compareLeftData.value = res.xmlContentOld
compareRightData.value = res.xmlContentNew
//比较数据 //比较数据
handleLeftDifferent(res.dataForOld, res.treeNew) handleLeftDifferent()
handleRightDifferent(res.dataForNew, res.treeOld) handleRightDifferent()
} }
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