Commit 09a08709 by qlintonger xeno

Merge remote-tracking branch 'origin/master'

parents 823fc252 ec8fe382
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { DomEditor, IDomEditor, IEditorConfig } from '@wangeditor/editor' import { IDomEditor, IEditorConfig } from '@wangeditor/editor'
// @ts-ignore // @ts-ignore
import { Editor, Toolbar } from '@wangeditor/editor-for-vue' import { Editor, Toolbar } from '@wangeditor/editor-for-vue'
import { isNumber } from 'lodash' import { isNumber } from 'lodash'
......
...@@ -19,20 +19,11 @@ ...@@ -19,20 +19,11 @@
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { realComposableData, searchKey, treeData, xmlContent, xmlDOM, treeSelectedKeys, treeRef } from '../constants' import { realComposableData, searchKey, treeSelectedKeys, treeRef } from '../constants'
import { nodeSet } from '@/views/editor/constants/nodeParsed.ts'
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'
const xmlProcessing = useXMLProcessing()
const expandedKeys = ref<string[]>([]) const expandedKeys = ref<string[]>([])
onMounted(function () {
// const res = xmlProcessing.processXML(FileXML, nodeSet)
// treeData.value = res.treeData
// xmlDOM.value = res.xmlDOM
// xmlContent.value = res.xmlContent
})
function getAllKeys(item: TreeOption[]) { function getAllKeys(item: TreeOption[]) {
return item.reduce(function (q, w) { return item.reduce(function (q, w) {
......
import { IDomEditor, SlateTransforms } from '@wangeditor/editor' import { IDomEditor } from '@wangeditor/editor'
import { editorRef, showLoading, treeData, treeRef, treeSelectedKeys, xmlContent, xmlDOM } from '../constants' import { editorRef, formData, showLoading, treeData, treeRef, treeSelectedKeys, xmlContent, xmlDOM } from '../constants'
import { TreeOption } from 'naive-ui' import { TreeOption } from 'naive-ui'
import { nodeSet } from '../constants/nodeParsed' import { nodeSet } from '../constants/nodeParsed'
import { UUID } from 'uuidjs'
export const handleEditor = (editor: IDomEditor) => { export const handleEditor = (editor: IDomEditor) => {
if (editor.getHtml() == '<p><br></p>') return if (editor.getHtml() == '<p><br></p>') return
console.log(editor.getHtml())
const xmlProcessing = useXMLProcessing() const xmlProcessing = useXMLProcessing()
const res = xmlProcessing.processXML(editor.getHtml(), nodeSet) const res = xmlProcessing.processXML(editor.getHtml().replace(/<p><br><\/p>/g, ''), nodeSet)
treeData.value = res.treeData treeData.value = res.treeData
xmlDOM.value = res.xmlDOM
xmlContent.value = res.xmlContent
} }
export const handleClick = (key: string) => { export const handleClick = (key: string) => {
treeRef.value?.scrollTo({ key }) treeRef.value?.scrollTo({ key })
treeSelectedKeys.value = [key] treeSelectedKeys.value = [key]
setEditorActive(key)
} }
export const handleContextSelect = (key: string) => { export const handleContextSelect = (key: string) => {
if (key == 'TaskTitle') { if (key == 'TaskTitle') {
const node = { type: 'TaskTitle', dataKey: 'fasdfasdf', children: [{ text: 'TaskTitle' }] } const node = { type: 'TaskTitle', dataKey: 'g-' + UUID.generate(), children: [{ text: 'TaskTitle' }] }
editorRef.value?.editorRef?.insertNode(node) editorRef.value?.editorRef?.insertNode(node)
} else if (key == 'TopicTitle') { } else if (key == 'TopicTitle') {
const node = { type: 'TopicTitle', children: [{ text: 'TopicTitle' }] } const node = { type: 'TopicTitle', dataKey: 'g-' + UUID.generate(), children: [{ text: 'TopicTitle' }] }
editorRef.value?.editorRef?.insertNode(node) editorRef.value?.editorRef?.insertNode(node)
} }
} }
let lastFocusedId = ''
export const nodeProps = ({ option }: { option: TreeOption }) => { export const nodeProps = ({ option }: { option: TreeOption }) => {
return { return {
onClick() { onClick() {
const container = editorRef.value?.editorRef.getEditableContainer() setEditorActive(option.key as string, (id: string) => {
const id = container.querySelector(`[data-key="${option.key}"]`)?.getAttribute('id') editorRef.value?.editorRef.scrollToElem([id])
editorRef.value?.editorRef.scrollToElem([id]) })
if (container) {
if (lastFocusedId) {
container.querySelector(`#${lastFocusedId}`)?.classList.remove('focus')
}
lastFocusedId = option.key as string
container.querySelector(`#${lastFocusedId}`)?.classList.add('focus')
}
} }
} }
} }
let lastFocusedId = ''
export const setEditorActive = (key: string, callBack?: Function) => {
const container = editorRef.value?.editorRef.getEditableContainer()
const id = container.querySelector(`[data-key="${key}"]`)?.getAttribute('id')
if (container) {
if (lastFocusedId) {
container.querySelector(`#${lastFocusedId}`)?.classList.remove('bg-primaryColorHover')
}
lastFocusedId = id
container.querySelector(`#${id}`)?.classList.add('bg-primaryColorHover')
}
if (callBack) callBack(id)
}
export const uploadXml = async () => { export const uploadXml = async () => {
const input = document.createElement('input') const input = document.createElement('input')
input.type = 'file' input.type = 'file'
...@@ -59,10 +65,7 @@ export const uploadXml = async () => { ...@@ -59,10 +65,7 @@ export const uploadXml = async () => {
showLoading.value = true showLoading.value = true
const res = await xmlProcessing.processFile(file, nodeSet) const res = await xmlProcessing.processFile(file, nodeSet)
showLoading.value = false showLoading.value = false
treeData.value = res.treeData formData.html = res.xmlContent
xmlDOM.value = res.xmlDOM
xmlContent.value = res.xmlContent
editorRef.value?.editorRef?.setHtml(xmlContent.value)
} }
}) })
} }
...@@ -29,8 +29,4 @@ onMounted(() => { ...@@ -29,8 +29,4 @@ onMounted(() => {
// }) // })
}) })
</script> </script>
<style lang="less" scoped> <style lang="less" scoped></style>
:deep(.focus) {
background: red;
}
</style>
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