Commit df7be9ee by qlintonger xeno

feat: AI格式化processing+4

parent 35ba9b8b
...@@ -7,10 +7,16 @@ import { UUID } from 'uuidjs'; ...@@ -7,10 +7,16 @@ import { UUID } from 'uuidjs';
export class Processing { export class Processing {
// 私有属性,用于解析 XML 字符串为 DOM 对象 // 私有属性,用于解析 XML 字符串为 DOM 对象
private domParser: DOMParser; private domParser: DOMParser;
private xmlSerializer: XMLSerializer
// 构造函数,初始化 DOMParser 实例 // 构造函数,初始化 DOMParser 实例
constructor() { constructor() {
this.domParser = new DOMParser(); this.domParser = new DOMParser();
this.xmlSerializer = new XMLSerializer();
}
serializeXML(xmlDOM: Document): string {
return this.xmlSerializer.serializeToString(xmlDOM);
} }
// 处理 XML 字符串的方法,返回树形数据和 XML DOM 对象 // 处理 XML 字符串的方法,返回树形数据和 XML DOM 对象
...@@ -64,7 +70,7 @@ export class Processing { ...@@ -64,7 +70,7 @@ export class Processing {
private innerHandle(domNode: Element, handledNode: string[]): TreeRenderResult[] { private innerHandle(domNode: Element, handledNode: string[]): TreeRenderResult[] {
let treeData: TreeRenderResult[] = []; let treeData: TreeRenderResult[] = [];
// 生成唯一的 key // 生成唯一的 key
const targetKey = UUID.generate(); const targetKey = 'g-' + UUID.generate();
// 创建树形数据项 // 创建树形数据项
const treeItem: TreeRenderResult = { const treeItem: TreeRenderResult = {
key: targetKey, key: targetKey,
...@@ -101,7 +107,7 @@ export class Processing { ...@@ -101,7 +107,7 @@ export class Processing {
} }
realIndex++; realIndex++;
// 生成唯一的 key // 生成唯一的 key
const targetKey = UUID.generate(); const targetKey ='g-' + UUID.generate();
// 创建树形数据项 // 创建树形数据项
const treeItem: TreeRenderResult = { const treeItem: TreeRenderResult = {
key: targetKey, key: targetKey,
......
...@@ -17,11 +17,10 @@ ...@@ -17,11 +17,10 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { searchKey, treeData, realComposableData, xmlDOM } from '../constants' import { realComposableData, searchKey, treeData, xmlDOM } from '../constants'
import FileXML from '@/assets/file/CES-QEC-V250-A.xml?raw' import FileXML from '@/assets/file/CES-QEC-V250-A.xml?raw'
import type { TreeOption } from 'naive-ui' import type { TreeOption } from 'naive-ui'
import { nodeProps } from '../functions' import { nodeProps } from '../functions'
import {contentDummy} from '@/views/editor/constants/dummy.ts'
const xmlProcessing = useXMLProcessing() const xmlProcessing = useXMLProcessing()
const nodeSet = [ const nodeSet = [
...@@ -53,7 +52,6 @@ onMounted(function () { ...@@ -53,7 +52,6 @@ onMounted(function () {
const res = xmlProcessing.processXML(FileXML, nodeSet) const res = xmlProcessing.processXML(FileXML, nodeSet)
treeData.value = res.treeData treeData.value = res.treeData
xmlDOM.value = res.xmlDOM xmlDOM.value = res.xmlDOM
console.log('dummy-ts',contentDummy, xmlProcessing.processXML(contentDummy, nodeSet))
}) })
function getAllKeys(item: TreeOption[]) { function getAllKeys(item: TreeOption[]) {
return item.reduce(function (q, w) { return item.reduce(function (q, w) {
......
...@@ -3,7 +3,7 @@ import { editorRef } from '../constants' ...@@ -3,7 +3,7 @@ import { editorRef } from '../constants'
import { TreeOption } from 'naive-ui' import { TreeOption } from 'naive-ui'
export const handleEditor = (editor: IDomEditor) => { export const handleEditor = (editor: IDomEditor) => {
console.log(editor.getHtml())
// console.log(editor.getElemsByTypePrefix('JOBCARD')) // console.log(editor.getElemsByTypePrefix('JOBCARD'))
// console.log(editor) // console.log(editor)
// const headers = editor.getElemsByTypePrefix('header') // const headers = editor.getElemsByTypePrefix('header')
......
...@@ -4,7 +4,7 @@ import { IDomEditor, IModuleConf, SlateElement } from '@wangeditor/editor' ...@@ -4,7 +4,7 @@ import { IDomEditor, IModuleConf, SlateElement } from '@wangeditor/editor'
const renderElem = (type: string, style = { display: 'block' }) => { const renderElem = (type: string, style = { display: 'block' }) => {
return (elem: SlateElement, children: VNode[] | null, editor: IDomEditor): VNode => { return (elem: SlateElement, children: VNode[] | null, editor: IDomEditor): VNode => {
const dataKey = (elem as any).dataKey const dataKey = (elem as any).dataKey
return h(type, { style, attrs: { dataKey: dataKey } }, children) return h(type, { style, attrs: { dataKey: dataKey, id: dataKey } }, children)
} }
} }
const createRenderConfig = (types: string | string[]) => { const createRenderConfig = (types: string | string[]) => {
......
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