news 2026/4/16 19:01:06

机械设计系统如何通过wangEditor控件导入三维模型截图?

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
机械设计系统如何通过wangEditor控件导入三维模型截图?

《大三程序猿的CMS升级记:Word一键转存+公式高清显示,99元预算搞大事!》

一、背景

“师弟,你这CMS新闻系统能直接粘贴Word里的表格和公式吗?”
“不能啊师姐,现在编辑器只能粘贴纯文本…”
“那毕业论文里的MathType公式咋办?总不能让我手动敲LaTeX吧?”

被师姐灵魂拷问后,我摸着秃了一半的脑袋,决定用99元预算给wangEditor加个"黑科技"按钮,实现:

  1. Word/Excel/PPT/PDF一键导入,图片自动上传OSS
  2. LaTeX/MathType公式自动转MathML,多端高清显示
  3. 表格/字体/颜色/形状样式全保留
  4. 跨平台支持(Windows/macOS/Linux全家桶)
二、技术选型(白嫖版)
组件方案成本
编辑器wangEditor + 自定义插件免费
文档解析mammoth.js(Word)+ pdf.js(PDF)免费
公式转换MathJax(LaTeX→MathML)免费
文件上传阿里云OSS SDK免费
后端接口PHP原生(拒绝Laravel臃肿)免费
调试工具Postman + Chrome DevTools免费

总预算:99元(预留给OSS流量费)

三、前端实现(Vue2 + wangEditor)
1. 安装依赖
npminstallwangeditor mammoth pdf-lib mathjax-full --save
2. 自定义编辑器插件
// src/plugins/WordPastePlugin.jsimportEditorfrom'wangeditor'importmammothfrom'mammoth'import{PDFDocument}from'pdf-lib'exportdefaultclassWordPastePlugin{constructor(editor,ossConfig){this.editor=editorthis.ossConfig=ossConfigthis.initButton()}initButton(){const{editor}=thiseditor.config.menus=[...editor.config.menus,'wordPaste']editor.config.customUploadImg=async(files,insertFn)=>{// 多图上传OSS逻辑(省略)}editor.config.customPaste=(e)=>{constitems=(e.clipboardData||window.clipboardData).itemsfor(letitemofitems){if(item.type.indexOf('office')>-1){this.handleOfficePaste(item.getAsFile())e.preventDefault()break}}}}asynchandleOfficePaste(file){if(file.name.endsWith('.docx')){constresult=awaitmammoth.extractRawText({arrayBuffer:awaitfile.arrayBuffer()})this.parseWordContent(result.value)}elseif(file.name.endsWith('.pdf')){constpdf=awaitPDFDocument.load(awaitfile.arrayBuffer())// PDF解析逻辑(需自行实现)}}parseWordContent(html){// 1. 替换Word生成的垃圾标签letcleanHtml=html.replace(/<\/o:p>/g,'')// 2. 公式转换(调用后端API)cleanHtml=cleanHtml.replace(/\$\$(.*?)\$\$/g,(match,latex)=>{return`${latex}`})this.editor.cmd.do('insertHTML',cleanHtml)}}
3. 集成到Vue组件
import Editor from 'wangeditor' import WordPastePlugin from './plugins/WordPastePlugin' export default { data() { return { editor: null, ossConfig: { region: 'oss-cn-hangzhou', accessKeyId: 'your-key', accessKeySecret: 'your-secret', bucket: 'your-bucket' } } }, mounted() { this.editor = new Editor({ selector: [this.$refs.editorMenu, this.$refs.editorContent], onChange: () => console.log('内容变化') }) new WordPastePlugin(this.editor, this.ossConfig) this.editor.create() } }
四、后端实现(PHP)
1. OSS上传接口
// api/upload.phpputObject($bucket,$object,fopen($file['tmp_name'],'r'));echojson_encode(['url'=>"https://{$bucket}.{$endpoint}/{$object}",'name'=>$file['name']]);
2. 公式转换接口
// api/convert-math.phpE=m c2EOD;header('Content-Type: application/xml');echo$mathml;
五、部署优化
  1. 跨域问题:在阿里云OSS配置CORS规则
[{"AllowedOrigin":["*"],"AllowedMethod":["GET","POST","PUT"],"AllowedHeader":["*"]}]
  1. 性能优化

    • 使用CDN加速MathJax资源
    • 对大文件分片上传
    • 启用OSS图片处理(缩略图/水印)
  2. 安全加固

    • 接口添加JWT验证
    • 限制上传文件类型
    • 对LaTeX公式进行XSS过滤
六、求职彩蛋

"师姐,我们外包群现在搞活动:

  1. 加入QQ群:223813913 领1-99元红包
  2. 推荐客户拿20%提成(黄金会员50%!)
  3. 内推简历优先处理(群主在字节/阿里/腾讯都有HR资源)

PS:群文件有完整源码+部署文档,支持Vue2/Vue3无缝迁移,PHP后端可直接部署到宝塔面板!"


最终效果
(师姐把论文公式粘进来后:“这比Word还爽!”)

复制插件文件


安装jquery

npm install jquery

导入组件

importEfrom'wangeditor'const{$,BtnMenu,DropListMenu,PanelMenu,DropList,Panel,Tooltip}=Eimport{WordPaster}from'../../static/WordPaster/js/w'import{zyCapture}from'../../static/zyCapture/z'import{zyOffice}from'../../static/zyOffice/js/o'

初始化组件

//zyCapture ButtonclasszyCaptureBtnextendsBtnMenu{constructor(editor){const$elem=E.$(`<div class="w-e-menu">`)super($elem,editor)}clickHandler(){window.zyCapture.setEditor(this.editor).Capture();}tryChangeActive(){this.active()}}//zyOffice ButtonclassimportWordBtnextendsBtnMenu{constructor(editor){const$elem=E.$(`<div class="w-e-menu">`)super($elem,editor)}clickHandler(){window.zyOffice.SetEditor(this.editor).api.openDoc();}tryChangeActive(){this.active()}}//zyOffice ButtonclassexportWordBtnextendsBtnMenu{constructor(editor){const$elem=E.$(`<div class="w-e-menu">`)super($elem,editor)}clickHandler(){window.zyOffice.SetEditor(this.editor).api.exportWord();}tryChangeActive(){this.active()}}//zyOffice ButtonclassimportPdfBtnextendsBtnMenu{constructor(editor){const$elem=E.$(`<div class="w-e-menu">`)super($elem,editor)}clickHandler(){window.zyOffice.SetEditor(this.editor).api.openPdf();}tryChangeActive(){this.active()}}//WordPaster ButtonclassWordPasterBtnextendsBtnMenu{constructor(editor){const$elem=E.$(`<div class="w-e-menu">`)super($elem,editor)}clickHandler(){WordPaster.getInstance().SetEditor(this.editor).Paste();}tryChangeActive(){this.active()}}//wordImport ButtonclassWordImportBtnextendsBtnMenu{constructor(editor){const$elem=E.$(`<div class="w-e-menu">`)super($elem,editor)}clickHandler(){WordPaster.getInstance().SetEditor(this.editor).importWord();}tryChangeActive(){this.active()}}//excelImport ButtonclassExcelImportBtnextendsBtnMenu{constructor(editor){const$elem=E.$(`<div class="w-e-menu">`)super($elem,editor)}clickHandler(){WordPaster.getInstance().SetEditor(this.editor).importExcel();}tryChangeActive(){this.active()}}//ppt paster ButtonclassPPTImportBtnextendsBtnMenu{constructor(editor){const$elem=E.$(`<div class="w-e-menu">`)super($elem,editor)}clickHandler(){WordPaster.getInstance().SetEditor(this.editor).importPPT();}tryChangeActive(){this.active()}}//pdf paster ButtonclassPDFImportBtnextendsBtnMenu{constructor(editor){const$elem=E.$(`<div class="w-e-menu">`)super($elem,editor)}clickHandler(){WordPaster.getInstance().SetEditor(this.editor);WordPaster.getInstance().ImportPDF();}tryChangeActive(){this.active()}}//importWordToImg ButtonclassImportWordToImgBtnextendsBtnMenu{constructor(editor){const$elem=E.$(`<div class="w-e-menu">`)super($elem,editor)}clickHandler(){WordPaster.getInstance().SetEditor(this.editor).importWordToImg();}tryChangeActive(){this.active()}}//network paster ButtonclassNetImportBtnextendsBtnMenu{constructor(editor){const$elem=E.$(`<div class="w-e-menu">`)super($elem,editor)}clickHandler(){WordPaster.getInstance().SetEditor(this.editor);WordPaster.getInstance().UploadNetImg();}tryChangeActive(){this.active()}}exportdefault{name:'HelloWorld',data(){return{msg:'Welcome to Your Vue.js App'}},mounted(){vareditor=newE('#editor');WordPaster.getInstance({//上传接口:http://www.ncmem.com/doc/view.aspx?id=d88b60a2b0204af1ba62fa66288203edPostUrl:"http://localhost:8891/upload.aspx",License2:"",//为图片地址增加域名:http://www.ncmem.com/doc/view.aspx?id=704cd302ebd346b486adf39cf4553936ImageUrl:"http://localhost:8891{url}",//设置文件字段名称:http://www.ncmem.com/doc/view.aspx?id=c3ad06c2ae31454cb418ceb2b8da7c45FileFieldName:"file",//提取图片地址:http://www.ncmem.com/doc/view.aspx?id=07e3f323d22d4571ad213441ab8530d1ImageMatch:''});zyCapture.getInstance({config:{PostUrl:"http://localhost:8891/upload.aspx",License2:'',FileFieldName:"file",Fields:{uname:"test"},ImageUrl:'http://localhost:8891{url}'}})// zyoffice,// 使用前请在服务端部署zyoffice,// http://www.ncmem.com/doc/view.aspx?id=82170058de824b5c86e2e666e5be319czyOffice.getInstance({word:'http://localhost:13710/zyoffice/word/convert',wordExport:'http://localhost:13710/zyoffice/word/export',pdf:'http://localhost:13710/zyoffice/pdf/upload'})// 注册菜单E.registerMenu("zyCaptureBtn",zyCaptureBtn)E.registerMenu("WordPasterBtn",WordPasterBtn)E.registerMenu("ImportWordToImgBtn",ImportWordToImgBtn)E.registerMenu("NetImportBtn",NetImportBtn)E.registerMenu("WordImportBtn",WordImportBtn)E.registerMenu("ExcelImportBtn",ExcelImportBtn)E.registerMenu("PPTImportBtn",PPTImportBtn)E.registerMenu("PDFImportBtn",PDFImportBtn)E.registerMenu("importWordBtn",importWordBtn)E.registerMenu("exportWordBtn",exportWordBtn)E.registerMenu("importPdfBtn",importPdfBtn)//挂载粘贴事件editor.txt.eventHooks.pasteEvents.length=0;editor.txt.eventHooks.pasteEvents.push(function(){WordPaster.getInstance().SetEditor(editor).Paste();e.preventDefault();});editor.create();varedt2=newE('#editor2');//挂载粘贴事件edt2.txt.eventHooks.pasteEvents.length=0;edt2.txt.eventHooks.pasteEvents.push(function(){WordPaster.getInstance().SetEditor(edt2).Paste();e.preventDefault();return;});edt2.create();}}h1,h2{font-weight:normal;}ul{list-style-type:none;padding:0;}li{display:inline-block;margin:010px;}a{color:#42b983;}

测试前请配置图片上传接口并测试成功
接口测试
接口返回JSON格式参考

为编辑器添加按钮

components:{Editor,Toolbar},data(){return{editor:null,html:'dd',toolbarConfig:{insertKeys:{index:0,keys:['zycapture','wordpaster','pptimport','pdfimport','netimg','importword','exportword','importpdf']}},editorConfig:{placeholder:''},mode:'default'// or 'simple'}},

整合效果

导入Word文档,支持doc,docx

导入Excel文档,支持xls,xlsx

粘贴Word

一键粘贴Word内容,自动上传Word中的图片,保留文字样式。

Word转图片

一键导入Word文件,并将Word文件转换成图片上传到服务器中。

导入PDF

一键导入PDF文件,并将PDF转换成图片上传到服务器中。

导入PPT

一键导入PPT文件,并将PPT转换成图片上传到服务器中。

上传网络图片

一键自动上传网络图片,自动下载远程服务器图片,自动上传远程服务器图片

下载示例

点击下载完整示例

版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/4/15 14:54:03

2026财务人新出路:别只做账房先生,用数据分析打开高薪通道

2026财务人员转型方向传统财务岗位的职责正在被自动化工具取代&#xff0c;财务人员需要掌握数据分析技能才能保持竞争力。数据分析能力可以帮助财务人员从基础核算转向战略决策支持&#xff0c;提升职业价值。传统财务岗位局限数据分析转型优势重复性高&#xff0c;易被自动化…

作者头像 李华
网站建设 2026/4/15 12:52:03

GWY系列钢材弯曲试验机

GWY系列钢材弯曲试验机 一、概述&#xff1a; GWY系列钢材弯曲试验机用于进行圆钢、棒材、板材、建筑螺纹钢、钢管的弯曲实验&#xff0c;可以进行正弯与反弯试验&#xff0c;测定其弯曲塑性弯形能力&#xff0c;是一款多功能钢材弯曲试验机。弯曲试样最大规格可选&#xff…

作者头像 李华
网站建设 2026/4/16 8:58:36

RDCMan:远程桌面管理的效率革命

RDCMan&#xff1a;远程桌面管理的效率革命 【免费下载链接】RDCMan Remote Desktop Connection Manager (微软RDP远程桌面管理工具) reflect 项目地址: https://gitcode.com/gh_mirrors/rd/RDCMan 在现代IT架构中&#xff0c;远程桌面管理已成为运维工作的核心环节。随…

作者头像 李华
网站建设 2026/4/16 10:39:55

医院HIS系统如何解决wangEditor粘贴Word表格变形?

《苏州程序员の暑假奇遇记&#xff1a;Word图片转存大作战》 日期&#xff1a;2023年7月15日 星期五 苏州 暴雨转晴&#xff08;适合宅家敲代码&#xff09; 第一章&#xff1a;需求诞生——从“懒癌晚期”到“技术狂魔” “客户爸爸说&#xff0c;他们每天要从Word里抠100张…

作者头像 李华