Commit ff6336ef by pangchong

feat: 提交上传

parent 92b01eb2
...@@ -7,6 +7,7 @@ export {} ...@@ -7,6 +7,7 @@ export {}
declare module 'vue' { declare module 'vue' {
export interface GlobalComponents { export interface GlobalComponents {
NButton: typeof import('naive-ui')['NButton']
NCard: typeof import('naive-ui')['NCard'] NCard: typeof import('naive-ui')['NCard']
NConfigProvider: typeof import('naive-ui')['NConfigProvider'] NConfigProvider: typeof import('naive-ui')['NConfigProvider']
NInput: typeof import('naive-ui')['NInput'] NInput: typeof import('naive-ui')['NInput']
...@@ -15,7 +16,10 @@ declare module 'vue' { ...@@ -15,7 +16,10 @@ declare module 'vue' {
NLayoutFooter: typeof import('naive-ui')['NLayoutFooter'] NLayoutFooter: typeof import('naive-ui')['NLayoutFooter']
NLayoutHeader: typeof import('naive-ui')['NLayoutHeader'] NLayoutHeader: typeof import('naive-ui')['NLayoutHeader']
NMessageProvider: typeof import('naive-ui')['NMessageProvider'] NMessageProvider: typeof import('naive-ui')['NMessageProvider']
NResult: typeof import('naive-ui')['NResult']
NSpace: typeof import('naive-ui')['NSpace']
NTree: typeof import('naive-ui')['NTree'] NTree: typeof import('naive-ui')['NTree']
NUpload: typeof import('naive-ui')['NUpload']
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>
<div class="z-10 h-full flex flex-col"> <div class="z-10 h-full flex flex-col">
<!-- 工具栏 --> <!-- 工具栏 -->
<Toolbar :editor="editorRef" :editorId="editorId" class="border-b border-solid border-borderColor" /> <Toolbar :editor="editorRef" :editorId="editorId" :defaultConfig="toolbarConfig" class="border-b border-solid border-borderColor" />
<!-- 编辑器 --> <!-- 编辑器 -->
<div class="p-[15px] flex flex-1 overflow-hidden"> <div class="p-[15px] flex flex-1 overflow-hidden">
<slot name="left"></slot> <slot name="left"></slot>
...@@ -28,6 +28,7 @@ import { Boot, IModuleConf } from '@wangeditor/editor' ...@@ -28,6 +28,7 @@ import { Boot, IModuleConf } from '@wangeditor/editor'
import renderElemConf from '../functions/render-elem' import renderElemConf from '../functions/render-elem'
import elemToHtmlConf from '../functions/elem-to-html' import elemToHtmlConf from '../functions/elem-to-html'
import parseHtmlConf from '../functions/parse-elem-html' import parseHtmlConf from '../functions/parse-elem-html'
import myMenuConf from '../functions/extra-menu'
const module: Partial<IModuleConf> = { const module: Partial<IModuleConf> = {
renderElems: renderElemConf, renderElems: renderElemConf,
...@@ -35,6 +36,33 @@ const module: Partial<IModuleConf> = { ...@@ -35,6 +36,33 @@ const module: Partial<IModuleConf> = {
parseElemsHtml: parseHtmlConf parseElemsHtml: parseHtmlConf
} }
Boot.registerModule(module) Boot.registerModule(module)
Boot.registerMenu(myMenuConf) // 注册菜单
//菜单配置
const toolbarConfig = {
toolbarKeys: [
'headerSelect',
'bold',
'italic',
'underline',
'through',
'color',
'fontSize',
'lineHeight',
'bulletedList',
'numberedList',
'justifyLeft',
'justifyCenter',
'justifyRight',
'undo',
'redo',
'uploadImage',
'insertLink',
'fullScreen',
'clearStyle',
'XML'
]
}
type InsertFnType = (url: string, alt: string, href: string) => void type InsertFnType = (url: string, alt: string, href: string) => void
const ps = defineProps({ const ps = defineProps({
......
...@@ -10,7 +10,6 @@ ...@@ -10,7 +10,6 @@
:data="realComposableData" :data="realComposableData"
:node-props="nodeProps" :node-props="nodeProps"
v-model:selected-keys="treeSelectedKeys" v-model:selected-keys="treeSelectedKeys"
:render-label="nodeProps.renderLabel"
:pattern="searchKey" :pattern="searchKey"
block-line block-line
/> />
...@@ -24,22 +23,15 @@ import { nodeSet } from '@/views/editor/constants/nodeParsed.ts' ...@@ -24,22 +23,15 @@ import { nodeSet } from '@/views/editor/constants/nodeParsed.ts'
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 {editorRef} from '../constants'
const xmlProcessing = useXMLProcessing() const xmlProcessing = useXMLProcessing()
watchEffect(function() {
console.log('the keys', treeSelectedKeys.value, editorRef.value?.editorRef?.getEditableContainer())
})
const treeRef = ref() const treeRef = ref()
const expandedKeys = ref<string[]>([]) const expandedKeys = ref<string[]>([])
onMounted(function () { 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
xmlContent.value = res.xmlContent // xmlContent.value = res.xmlContent
}) })
function getAllKeys(item: TreeOption[]) { function getAllKeys(item: TreeOption[]) {
......
import { IButtonMenu, IDomEditor } from '@wangeditor/editor'
import { uploadXml } from '.'
class XMLMenu implements IButtonMenu {
title: string
tag: string
constructor() {
this.title = '上传XML' // 自定义菜单标题
this.tag = 'button' // 菜单的标签,默认是button
}
getValue(editor: IDomEditor): string | boolean {
// 获取菜单执行时的 value,用不到则返回空字符串或 false
return ''
}
isActive(editor: IDomEditor): boolean {
// 菜单是否需要激活,用不到则返回 false
return false
}
isDisabled(editor: IDomEditor): boolean {
// 菜单是否需要禁用,用不到则返回 false
return false
}
async exec(editor: IDomEditor, value: string | boolean) {
// 点击菜单时触发的函数
if (this.isDisabled(editor)) return
const arrFileHandle = await (window as any).showOpenFilePicker({
types: [
{
accept: {
'XML/*': ['.xml']
}
}
]
})
const file = await arrFileHandle[0].getFile()
uploadXml(file)
}
}
export default {
key: 'XML', // 定义 menu key,要保证唯一、不重复
factory() {
return new XMLMenu() // 返回定义的菜单类实例
}
}
import { IDomEditor } from '@wangeditor/editor' import { IDomEditor } from '@wangeditor/editor'
import { editorRef } from '../constants' import { editorRef, treeData, xmlContent, xmlDOM } from '../constants'
import { TreeOption } from 'naive-ui' import { TreeOption } from 'naive-ui'
import { nodeSet } from '../constants/nodeParsed'
export const handleEditor = (editor: IDomEditor) => { export const handleEditor = (editor: IDomEditor) => {
// 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')
...@@ -34,3 +34,10 @@ export const nodeProps = ({ option }: { option: TreeOption }) => { ...@@ -34,3 +34,10 @@ export const nodeProps = ({ option }: { option: TreeOption }) => {
} }
} }
} }
const xmlProcessing = useXMLProcessing()
export const uploadXml = async (file: File) => {
const res = await xmlProcessing.processFile(file, nodeSet)
treeData.value = res.treeData
xmlDOM.value = res.xmlDOM
xmlContent.value = res.xmlContent
}
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