UNPKG

@aidiruanjian/doc-helper

Version:

UOS环境下使用的wps的web插件

2 lines (1 loc) 2.89 kB
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("vue")):"function"==typeof define&&define.amd?define(["vue"],t):(e="undefined"!=typeof globalThis?globalThis:e||self).DocHelper=t(e.Vue)}(this,(function(e){"use strict";const t=class{constructor(e,t={}){this.application=e,t.onBeforeSave&&(this.application.registerEvent("DIID_ApplicationEvents4","DocumentBeforeSave","onBeforeSave"),window.onBeforeSave=()=>{t.onBeforeSave()})}createDocument(){this.application.createDocument("wps"),this.application.setToolbarAllVisible(!0)}openRemote(e,t=!1){try{this.application.openDocumentRemote(e,t)}catch(o){alert("文档打开失败")}!0===t&&this.application.setToolbarAllVisible(!1)}saveRemote(e,t){this.application.saveURL(e,t)}enableProtect(e){this.application.enableProtect(e)}},o=class{constructor(e){this.application=e}openRemote(e){this.download(e).then((e=>{this.application.setAttribute("src",e),this.refresh()}),(e=>{}))}refresh(){let e=this.application.parentNode;e.removeChild(this.application),e.appendChild(this.application)}download(e){return new Promise(((t,o)=>{try{var n=new XMLHttpRequest;n.open("GET",e,!0),n.setRequestHeader("Content-Type","application/pdf"),n.responseType="blob",n.onload=function(e){if(200==this.status){var o=this.response,n=new Blob([o],{type:"application/pdf"}),i=URL.createObjectURL(n);t(i)}else alert("PDF加载失败"),console.error(e)},n.onerror=e=>{alert("PDF加载失败"),console.error(e)},n.send()}catch(i){console.error(i),o()}}))}};const n={class:"plugin-container",style:{height:"100%",width:"100%"}},i={key:0,class:"wps-plugin",style:{height:"100%",width:"100%"},ref:"plugin",type:"application/x-wps"},l={key:1,class:"wps-plugin",style:{height:"100%",width:"100%"},ref:"plugin2",type:"application/x-et"},s={key:2,class:"wps-plugin",style:{height:"100%",width:"100%"},ref:"plugin3"};return((e,t)=>{const o=e.__vccOpts||e;for(const[n,i]of t)o[n]=i;return o})({data:()=>({type:null,application:null,controller:null}),methods:{switchType(e,n){this.type=e,this.$nextTick((()=>{let i=this.$refs.plugin;if("word"==e){let e=i.Application;this.controller=new t(e,{onBeforeSave:()=>{this.$emit("beforeSave")}})}else"excel"==e||"pdf"==e&&(this.controller=new o(i));n&&n()}))},createDocument(e){this.switchType(e,(()=>{this.controller.createDocument()}))},openRemote(e,t,o=!0){this.switchType(e,(()=>{this.controller.openRemote(t,o)}))},saveRemote(e,t){this.controller.saveRemote&&this.controller.saveRemote(e,t)}}},[["render",function(t,o,r,c,p,a){return e.openBlock(),e.createElementBlock("div",n,["word"==p.type?(e.openBlock(),e.createElementBlock("embed",i,null,512)):e.createCommentVNode("",!0),"excel"==p.type?(e.openBlock(),e.createElementBlock("embed",l,null,512)):e.createCommentVNode("",!0),"pdf"==p.type?(e.openBlock(),e.createElementBlock("embed",s,null,512)):e.createCommentVNode("",!0)])}]])}));