cnhis-design-vue 3.2.11-beta.0 → 3.2.11-release.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
|
|
1
|
-
import t from"axios";import{cloneDeep as e,isArray as i}from"lodash-es";import{IdentityVerificationDialog as r,PreviewDialog as s}from"./dialog.js";import{isIReport as a,getFileUrl as n,useBrowserPrint as o}from"./browserPrint.js";import{getCurrentInstance as l}from"vue";import{uuidGenerator as c}from"../../../../shared/utils/index.js";import{format as h}from"date-fns";import{io as p}from"socket.io-client";const u=String(navigator.platform).toLowerCase().includes("linux"),m=t.create({timeout:6e4,withCredentials:!1}),d=`${window.location.protocol}//${window.location.host}`,g=`${d}/fdp-api/print/assembly/printIReport`,y=`${d}/bi-api/reprot/print/open/client/printIReportForBase64`,f=`${d}/bi-api/reprot/print/open/client/printIReportForHex`,w=`${d}/bi-api/reprot/print/open/client/previewIReport`,v=`${d}/bi-api/reprot/print/open/client/getRemote`,P=`${d}/printService/file`;let _=null;class I{constructor(){var t,e,i;if(this.webview=null,this.dialog=new r,this.dialogPreview=new s,this.instance=null,this.downloadPath="",this.printOrigin="http://127.0.0.1:11111",this.printDomesticOrigin="http://127.0.0.1:17521",this.isRemote=!1,this.CMonitor=null,this.queryServicesParams=null,this.isConnectHiPrint=!1,this.clientInfo=null,this.printerList=[],this.hiPrintSocket=null,this.base64Fragment="",this._successCallbackFn=null,this._errorCallbackFn=null,this._cancelCallbackFn=null,this.messageHandlerQueue=[],this.getIReportFormatId=(t,e)=>t?e.split("_")[1]:e,_)return _;_=this;const a=window;this.CMonitor=a.$CMonitor;try{this.webview=a.top?null==(t=a.top.chrome)?void 0:t.webview:null==(e=a.chrome)?void 0:e.webview}catch(t){console.log(t),this.webview=null==(i=a.chrome)?void 0:i.webview}if(this.webview){this.currentMessageHandler=this.messageHandler.bind(this),this.webview.addEventListener("message",this.currentMessageHandler);try{this.webview.postMessage({exec:"config",data:""})}catch(t){const e="当前浏览器版本不支持获取配置接口";this._handleMonitorNotify(e),console.log("非封装浏览器或者"+e)}}}messageHandler(t){var e;if(console.log("打印事件message",t),!t)return this._handleMonitorNotify("接收到空的浏览器事件,"+t),console.log("当前回执",t,"接收到空的浏览器事件");let i;try{i=JSON.parse(t.data||"{}")}catch(e){console.log("解析e.data失败,"+e),this._handleMonitorNotify("解析e.data失败,"+t)}if(["print","pdf","resetprint"].includes(null==i?void 0:i.cmd)){console.log("打印命令执行了",i);const e=this.messageHandlerQueue.shift();if(!e)return console.log("当前回执",t,"没有可用的handler");const{resolve:r,reject:s}=e;try{if("resetprint"===(null==i?void 0:i.cmd))return void r({result:(null==i?void 0:i.res)?"success":"fail"});r(i.res||"")}catch(t){s(t)}}else"config"===(null==i?void 0:i.exec)&&(this.downloadPath=(null==(e=i.res)?void 0:e.downloadpath)||"")}_initDomesticSystem(t){try{if(this.hiPrintSocket)return this.isConnectHiPrint;this.hiPrintSocket=p(this.printDomesticOrigin,{reconnection:!1,transports:["websocket"],auth:{token:"no-use-vue-plugin-hiprint"}}),this.hiPrintSocket&&(this.hiPrintSocket.on("connect",(()=>{this.isConnectHiPrint=!0})),this.hiPrintSocket.on("disconnect",(()=>{this.isConnectHiPrint=!1,this.hiPrintSocket=null})),this.hiPrintSocket.on("clientInfo",(t=>{console.log("获取到客户端信息>>>>>",t),t.clientUrl&&(this.clientInfo=t)})),this.hiPrintSocket.on("printerList",(e=>{console.log("获取到打印机列表信息>>>>>",e),this.printerList=e,t&&t(!0)})),this.hiPrintSocket.on("success",(t=>{console.log("打印成功>>>>>",t),this.base64Fragment="",this._successCallbackFn&&this._successCallbackFn(t)})),this.hiPrintSocket.on("replayPrinterTemplate",(t=>{console.log("获取到数据的回复>>>>>",t),t&&this.hiPrintSocket.emit("news",t)})),this.hiPrintSocket.on("error",(t=>{console.log("打印失败>>>>>",t),this.base64Fragment="","cancel"==(null==t?void 0:t.result)?this._cancelCallbackFn&&this._cancelCallbackFn(t):this._errorCallbackFn&&this._errorCallbackFn(t)})))}catch(e){console.log("ihoPrint系统连接失败",e),t&&t(!1)}}async getPicAndUpload(t){try{const e=t=>"[object Object]"===Object.prototype.toString.call(t);if("success"===(null==t?void 0:t.result)&&"Y"==(null==t?void 0:t.uploadTemplateFlag)&&!(null==t?void 0:t.filebase64)&&this.queryServicesParams){const t=e(this.queryServicesParams.params)?this.queryServicesParams.params:JSON.parse(this.queryServicesParams.params);t.uploadTemplateFlag="Y",this.queryServicesParams.params=JSON.stringify(t),this.queryServicesParams.cmdid="7",this.queryServicesParams.print={print:1,type:6,zip:0},this.queryServicesParams.paramsArr=[{params:JSON.stringify(t)}];await this._queryBase64ServicesPrint(this.queryServicesParams)}}catch(t){console.log(t)}finally{this.queryServicesParams=null}}async postMessage(t,e=0){if(!this.webview)return Promise.reject();const i=c();return e&&e>0?this.messageCollectAndNotifyFail(i,t,e):this.messageCollect(i,t)}messageCollect(t,e){return new Promise(((i,r)=>{this.messageHandlerQueue.push({resolve:i,reject:r,id:t}),this.webview.postMessage(e)}))}messageCollectAndNotifyFail(t,e,i){return Promise.race([new Promise(((i,r)=>{this.messageHandlerQueue.push({resolve:i,reject:r,id:t}),this.webview.postMessage(e)})),new Promise(((e,r)=>{setTimeout((()=>{const e=this.messageHandlerQueue.findIndex((e=>e.id===t));e>-1&&this.messageHandlerQueue.splice(e,1),r({type:"timeout"})}),i)}))])}destroy(){}show(...t){return this.dialog.show(...t)}showPreview(...t){return this.dialogPreview.show(...t)}_testDomesticSystemConnection(){return new Promise((t=>{m({url:`${this.printDomesticOrigin}/test`,method:"get",withCredentials:!1,params:{}}).then((({data:e})=>{e.status?t(!0):t(!1)})).catch((e=>{t(!1)}))}))}_testConnection(){return this.webview?Promise.resolve(!0):new Promise((t=>{m({url:`${this.printOrigin}/test`,method:"get",withCredentials:!1,params:{inputdata:{result:"success"}}}).then((({data:e})=>{"success"===e.result?t(!0):t(!1)})).catch((e=>{t(!1)}))}))}async resetPrinter(t,e){const i=a(t),r=this.getIReportFormatId(i,t);if(i&&(u||2==e)){return await this._testDomesticSystemConnection()?m({url:`${this.printDomesticOrigin}/resetPrint`,method:"get",withCredentials:!1,params:{formatId:r}}).then((({data:t})=>t.status?{type:"resetSuccess",result:"success",message:null==t?void 0:t.message}:{type:"resetError",result:"error",message:null==t?void 0:t.message})).catch((t=>({type:"resetError",result:"error",message:"重置打印机错误"}))):{type:"notInstalledApp",result:"error",message:"请开启ihoPrint客户端"}}return this.webview?this.postMessage({exec:"resetprint",data:{formatID:r}}):m({url:`${this.printOrigin}/services/printset`,method:"get",withCredentials:!1,params:{inputdata:r}}).then((({data:t})=>t))}_queryServicesPrint(e){return this.webview?this.postMessage({exec:"print",data:{inputData:e}},null==e?void 0:e.messageTimeout):t({url:this.printOrigin+"/services/print",method:"get",params:{inputData:JSON.stringify(e)}}).then((({data:t})=>t))}_queryBase64ServicesPrint(t){return this.webview?this.postMessage({exec:"print",data:{inputData:t}}):m({url:this.printOrigin+"/services/Printqueue",method:"get",params:{inputData:JSON.stringify(t)}}).then((({data:t})=>t))}_callPrintWithFile(t){const e={cmdid:"7",flag:"1"},i={inputData:JSON.stringify(Object.assign({},e,t))};return this.webview?this.postMessage({exec:"print",data:r(i)}):m({url:this.printOrigin+"/PrintLocal",method:"post",data:i,transformRequest:[r]}).then((({data:t})=>t));function r(t){let e="";for(const i in t)e+=encodeURIComponent(i)+"="+encodeURIComponent(t[i])+"&";return e=e.slice(0,-1),e}}_handleMonitorNotify(t){var e,i;null==(i=null==(e=this.CMonitor)?void 0:e.notify)||i.call(e,{name:"custom_info",message:t,businessName:"打印sdk"})}_handleResult(t,e,i){if(!t){const t="打印命令返回空数据";return this._handleMonitorNotify(""),null==e||e({type:"printError",message:t,result:"error",errinfo:t}),!1}if("success"!==t.result){const r=t.message||t.Message;this._handleMonitorNotify(r);const s={type:"printError",message:r,result:t.result,errinfo:t.errinfo};return"cancel"==t.result?(i&&i({type:"printCancel",message:r,result:t.result,errinfo:t.errinfo}),!1):(null==e||e(s),!1)}return t}_handleResultTest(t,e){return!!t||(console.log("notInstalledApp"),null==e||e({type:"notInstalledApp",message:"请打开打印服务器插件",result:"error"}),!1)}async _handleEventQueryPrintData(t,e,i,r,s){const a={templateId:t,formatId:e,params:i,cmdid:"7",messageTimeout:r},n=await this._queryServicesPrint(a);return this._handleQueryPrintDataResult(n,e,s)}_handleQueryPrintDataResult(t,e,i){if(!(null==t?void 0:t.file)){try{const e=t.message||t.Message;console.log(e),null==i||i({result:"error",type:"queryPrintDataFailure",message:e})}catch(t){console.log(t)}return!1}return{file:t.file,printerName:t.defprinter,pageCount:t.pagecount,formatId:e}}async _handleEventDirect({templateId:t,formatId:e,svrUpdateIp:i,params:r,paramsArr:s,cmdid:a,print:n,signature:o,copies:l,printdlgshow:c="0",nobillnode:p="1",btnprint:u="1",messageTimeout:m=0}){const d={templateId:t,formatId:e,svrUpdateIp:i,params:r,cmdid:a,nobillnode:p,printdlgshow:c,btnprint:u,copies:l,messageTimeout:m,...o?{signature:o}:{}};if(s&&(d.paramsArr=s),n){try{n=JSON.parse(n)}catch(t){}d.print=n}else if(this.isRemote){const t=h(new Date,"yyyyMMddHHmmss");d.print={print:"1",type:"1",zip:"0",filename:`F:\\WorkSpace\\crmweb\\web\\${t}\\${t}`}}return this.queryServicesParams=d,await this._queryServicesPrint(d)}async _handleEventEditFormat({templateId:t,formatId:e="",params:i="",token:r,messageTimeout:s=0}){const a={};let n={};try{n=Object.assign({},a,JSON.parse(i))}catch(t){n=a}const o={templateId:t,formatId:e,cmdid:"9",token:r,params:JSON.stringify(n),messageTimeout:s};return await this._queryServicesPrint(o)}async _queryProxyOrigin(){if(this.isRemote)return;const{data:t}=await m({method:"get",url:v})||{},{map:e={}}=t;e.isRemote&&(this.printOrigin=d+"/printService",this.isRemote=!0)}async _queryPrintFile(t,e=""){const{data:i}=await m({method:"post",url:g,responseType:"blob",params:{formatId:t.split("_")[1],params:e}})||{};return i}paramsSerializer(t){return Object.keys(t).forEach((e=>{const i=t[e];t[e]=i,"biParams"==e&&(t[e]=encodeURIComponent(i))})),t}async _queryPrintForBase64(t,e,i="",r){const s="object"==typeof i?i:JSON.parse(i),{data:a}=await m({method:"post",url:y,params:{id:t,formatId:e,params:this.paramsSerializer(s),authorizationKey:r}})||{};return a}async _queryPrintForBase16(t,e,i="",r){const s="object"==typeof i?i:JSON.parse(i),{data:a}=await m({method:"post",url:f,params:{id:t,formatId:e,params:this.paramsSerializer(s),authorizationKey:r}})||{};return a}async _queryPrintForPdf(t,e,i="",r){const s="object"==typeof i?i:JSON.parse(i),{data:a}=await m({method:"post",url:w,responseType:"blob",params:{id:t,formatId:e,params:this.paramsSerializer(s),authorizationKey:r}})||{};return a}async _browserPrint(t,e){if(this.isRemote){const{filedir:i}=t,r=JSON.parse(i)[0].replace(/\\/g,"/").split("/"),s=r[r.length-2],a=r[r.length-1],l=await n(`${P}/${s}/${a}`),c=o(null,e,l);if("preview"===e)return c}}_base64ToBlob(t,e){const i=window.atob(t);let r=i.length;const s=new Uint8Array(r);for(;r--;)s[r]=i.charCodeAt(r);return new Blob([s],{type:e})}async preview({iReportExecuteMode:t,templateId:e,formatId:i,params:r="",paramsArr:s,authorizationKey:n,signature:c,btnprint:h,messageTimeout:p=0},m,d){const g=a(i),y=this.getIReportFormatId(g,i);if(g&&(u||2==t)){const t=await this._queryPrintForPdf(e,y,r,n);if(!t)return null==d?void 0:d({type:"queryPrintDataFailure",result:"error",message:"获取文件失败!"});const i=o(t,"preview");return this.instance||(this.instance=l()),this.showPreview(this.instance,i),null==m?void 0:m({result:"success",message:"",file:t})}await this._queryProxyOrigin();const f=await this._testConnection();if(!this._handleResultTest(f,d))return!1;try{const t=await this._handleEventDirect({templateId:e,formatId:y,params:r,paramsArr:s,cmdid:this.isRemote?"7":"8",signature:c,btnprint:h,messageTimeout:p}),i=this._handleResult(t,d);if(!i)return!1;if(this.isRemote){const t=await this._browserPrint(i,"preview");this.instance||(this.instance=l()),this.showPreview(this.instance,t)}await this.getPicAndUpload(i),null==m||m(i)}catch(t){const e="预览失败",i="timeout"===(null==t?void 0:t.type)?{...t,message:e,result:"error"}:{message:e,result:"error"};null==d||d(i),this._handleMonitorNotify(i)}}async printSync(t,e,i){const r=t.map((t=>{const e={params:"",printdlgshow:"0",nobillnode:"1",btnprint:"1",...t,cmdid:"7",...t.signature?{signature:t.signature}:{}};if(e.print)try{e.print=JSON.parse(e.print)}catch(t){}return{inputData:e}}));try{const t=c(),s=await this.messageCollect(t,{exec:"printA",data:r});if(s&&Array.isArray(s)){s.some((t=>"success"===t.res.result))?null==e||e(s):(null==i||i(s),this._handleMonitorNotify(s))}else{const t="打印命令返回无效数据";this._handleMonitorNotify(s||""),null==i||i({type:"printError",message:t,result:"error",errinfo:t})}}catch(t){const e={error:t,result:"error",message:"打印失败"};null==i||i(e),this._handleMonitorNotify(e)}}async printDirect({iReportExecuteMode:t,templateId:e,formatId:i,params:r="",paramsArr:s,authorizationKey:n,print:o,signature:l,printdlgshow:c,nobillnode:h,copies:p,svrUpdateIp:m,isDownloadFile:d=!0,messageTimeout:g=0},y,f,w,v="printDirect"){const P=a(i),_=this.getIReportFormatId(P,i);if(P&&(u||2==t)){if(!await this._testDomesticSystemConnection())return void f({type:"notInstalledApp",result:"error",message:"请开启ihoPrint客户端"});return void(this._initDomesticSystem((async t=>{t?await this.printToHiPrint({templateId:e,formatId:_,params:r,authorizationKey:n},y,f,w):f({type:"notInstalledApp",result:"error",message:"连接ihoPrint客户端失败"})}))&&await this.printToHiPrint({templateId:e,formatId:_,params:r,authorizationKey:n},y,f,w))}await this._queryProxyOrigin();const I=await this._testConnection();if(!this._handleResultTest(I,f))return!1;try{const t=await this._handleEventDirect({templateId:e,formatId:_,params:r,paramsArr:s,cmdid:"7",print:o,signature:l,printdlgshow:c,nobillnode:h,copies:p,svrUpdateIp:m,messageTimeout:g}),i=this._handleResult(t,f,w);if(!i)return!1;d&&["downloadPDF"].includes(v)&&await this._browserPrint(i,v),null==y||y(i)}catch(t){const e="printDirect"===v?"打印失败":"下载失败",i="timeout"===(null==t?void 0:t.type)?{...t,message:e,result:"error"}:{message:e,result:"error"};null==f||f(i),this._handleMonitorNotify(i)}}async printToHiPrint({templateId:t,formatId:e,params:i,authorizationKey:r},s,a,n){const o=await this._queryPrintForBase64(t,e,i,r);if(!o.success)return a({message:o.resultMsg,result:"error"});const{base64:l,formatId:c}=o.map;this.base64Fragment=l,this._successCallbackFn=s,this._errorCallbackFn=a,n&&(this._cancelCallbackFn=n),this.hiPrintSocket.emit("news",{printerList:this.printerList,type:"askPrinterTemplate",markTemplateId:c,pdf_stream:this.base64Fragment})}_downloadPDF(t){return this.webview?this.postMessage({exec:"pdf",data:{file:t}}):m.get(this.printOrigin+"/download",{params:{inputData:t}}).then((({data:t})=>t))}async downloadPDF(t,r,s){var n;const o=e(t);if(this.webview&&this.downloadPath&&(Reflect.has(o,"print")||Reflect.set(o,"print",{print:"1",type:"1"}),!o.print.filename)){const t=h(new Date,"yyyy-MM-dd"),e=c(),i=h(new Date,"yyyyMMddHHmmss")+e;o.print.filename=`${this.downloadPath}/${t}/${i}/${i}`.replace(/\\/g,"/")}const l=a(o.formatId);if(o.formatId=this.getIReportFormatId(l,o.formatId),l&&(u||2==o.iReportExecuteMode)){const t=await this._queryPrintForBase16(o.templateId||"",o.formatId,o.params||"",o.authorizationKey);return(null==t?void 0:t.success)?r({filebase64:null==(n=null==t?void 0:t.map)?void 0:n.hex,isIreport:!0}):null==s?void 0:s({type:"queryPrintDataFailure",result:"error",message:"获取文件失败!"})}this.printDirect(o,(async t=>{t||s({result:"error",message:""});const e=this,a=await async function(t){const r=[],s=JSON.parse(t);if(!i(s))return await e._downloadPDF("");if(1===s.length)return await e._downloadPDF(s[0]||"");for(let t=0,i=s.length;t<i;t++)r.push(await e._downloadPDF(s[t]||""));return r}(t.filedir);r(a,t)}),(t=>s(t)),(t=>{console.log(t)}),"downloadPDF")}async print({templateId:t,formatId:e,params:i="",messageTimeout:r=0},s,a){const n=await this._testConnection();if(!this._handleResultTest(n,a))return!1;const o=await this.queryPrintData({templateId:t,formatId:e,params:i,messageTimeout:r},void 0,a);if(!o)return!1;const l=this.printFileData({formatId:e,file:o.file,printerName:o.printerName},void 0,a);if(!l)return!1;s&&s(l)}async queryPrintData({templateId:t,formatId:e,params:i="",messageTimeout:r=0},s,a){const n=await this._testConnection();if(!this._handleResultTest(n,a))return!1;const o=await this._handleEventQueryPrintData(t,e,i,r,a);return!!o&&(s&&s(o),o)}async printFileData({formatId:t,file:e,printerName:i="Default"},r,s){const a=await this._testConnection();if(!this._handleResultTest(a,s))return!1;const n=await this._callPrintWithFile({formatId:t,printname:i,file:e}),o=this._handleResult(n,s);return!!o&&(r&&r(o),o)}async editPrintFormat({templateId:t,formatId:e,params:i,token:r,messageTimeout:s=0},a,n){const o=await this._testConnection();if(!this._handleResultTest(o,n))return!1;const l=await this._handleEventEditFormat({templateId:t,formatId:e,params:i,token:r,messageTimeout:s}),c=this._handleResult(l,n);if(!c)return!1;a&&a(c)}async addPrintFormat({templateId:t,params:e,token:i},r,s){const a=await this._testConnection();if(!this._handleResultTest(a,s))return!1;const n=await this._handleEventEditFormat({templateId:t,params:e,token:i}),o=this._handleResult(n,s);if(!o)return!1;r&&r(o)}}export{I as Print};
|
1
|
+
import t from"axios";import{cloneDeep as e,isArray as i}from"lodash-es";import{IdentityVerificationDialog as r,PreviewDialog as s}from"./dialog.js";import{isIReport as a,getFileUrl as n,useBrowserPrint as o}from"./browserPrint.js";import{getCurrentInstance as l}from"vue";import{uuidGenerator as c}from"../../../../shared/utils/index.js";import{format as h}from"date-fns";import{io as p}from"socket.io-client";const u=String(navigator.platform).toLowerCase().includes("linux"),m=t.create({timeout:6e4,withCredentials:!1}),d=`${window.location.protocol}//${window.location.host}`,g=`${d}/fdp-api/print/assembly/printIReport`,y=`${d}/bi-api/reprot/print/open/client/printIReportForBase64`,f=`${d}/bi-api/reprot/print/open/client/printIReportForHex`,w=`${d}/bi-api/reprot/print/open/client/previewIReport`,v=`${d}/bi-api/reprot/print/open/client/getRemote`,P=`${d}/printService/file`;let _=null;class b{constructor(){var t,e,i;if(this.webview=null,this.dialog=new r,this.dialogPreview=new s,this.instance=null,this.downloadPath="",this.printOrigin="http://127.0.0.1:11111",this.printDomesticOrigin="http://127.0.0.1:17521",this.isRemote=!1,this.CMonitor=null,this.queryServicesParams=null,this.isConnectHiPrint=!1,this.clientInfo=null,this.printerList=[],this.hiPrintSocket=null,this.base64Fragment="",this._successCallbackFn=null,this._errorCallbackFn=null,this._cancelCallbackFn=null,this.messageHandlerQueue=[],this.getIReportFormatId=(t,e)=>t?e.split("_")[1]:e,_)return _;_=this;const a=window;this.CMonitor=a.$CMonitor;try{this.webview=a.top?null==(t=a.top.chrome)?void 0:t.webview:null==(e=a.chrome)?void 0:e.webview}catch(t){console.log(t),this.webview=null==(i=a.chrome)?void 0:i.webview}if(this.webview){this.currentMessageHandler=this.messageHandler.bind(this),this.webview.addEventListener("message",this.currentMessageHandler);try{this.webview.postMessage({exec:"config",data:""})}catch(t){const e="当前浏览器版本不支持获取配置接口";this._handleMonitorNotify(e),console.log("非封装浏览器或者"+e)}}}messageHandler(t){var e;if(console.log("打印事件message",t),!t)return this._handleMonitorNotify("接收到空的浏览器事件,"+t),console.log("当前回执",t,"接收到空的浏览器事件");let i;try{i=JSON.parse(t.data||"{}")}catch(e){console.log("解析e.data失败,"+e),this._handleMonitorNotify("解析e.data失败,"+t)}if(["print","pdf","resetprint"].includes(null==i?void 0:i.cmd)){console.log("打印命令执行了",i);const e=this.messageHandlerQueue.shift();if(!e)return console.log("当前回执",t,"没有可用的handler");const{resolve:r,reject:s}=e;try{if("resetprint"===(null==i?void 0:i.cmd))return void r({result:(null==i?void 0:i.res)?"success":"fail"});r(i.res||"")}catch(t){s(t)}}else"config"===(null==i?void 0:i.exec)&&(this.downloadPath=(null==(e=i.res)?void 0:e.downloadpath)||"")}_initDomesticSystem(t){try{if(this.hiPrintSocket)return this.isConnectHiPrint;this.hiPrintSocket=p(this.printDomesticOrigin,{reconnection:!1,transports:["websocket"],auth:{token:"no-use-vue-plugin-hiprint"}}),this.hiPrintSocket&&(this.hiPrintSocket.on("connect",(()=>{this.isConnectHiPrint=!0})),this.hiPrintSocket.on("disconnect",(()=>{this.isConnectHiPrint=!1,this.hiPrintSocket=null})),this.hiPrintSocket.on("clientInfo",(t=>{console.log("获取到客户端信息>>>>>",t),t.clientUrl&&(this.clientInfo=t)})),this.hiPrintSocket.on("printerList",(e=>{console.log("获取到打印机列表信息>>>>>",e),this.printerList=e,t&&t(!0)})),this.hiPrintSocket.on("success",(t=>{console.log("打印成功>>>>>",t),this.base64Fragment="",this._successCallbackFn&&this._successCallbackFn(t)})),this.hiPrintSocket.on("replayPrinterTemplate",(t=>{console.log("获取到数据的回复>>>>>",t),t&&this.hiPrintSocket.emit("news",t)})),this.hiPrintSocket.on("error",(t=>{console.log("打印失败>>>>>",t),this.base64Fragment="","cancel"==(null==t?void 0:t.result)?this._cancelCallbackFn&&this._cancelCallbackFn(t):this._errorCallbackFn&&this._errorCallbackFn(t)})))}catch(e){console.log("ihoPrint系统连接失败",e),t&&t(!1)}}async getPicAndUpload(t){try{const e=t=>"[object Object]"===Object.prototype.toString.call(t);if("success"===(null==t?void 0:t.result)&&"Y"==(null==t?void 0:t.uploadTemplateFlag)&&!(null==t?void 0:t.filebase64)&&this.queryServicesParams){const t=e(this.queryServicesParams.params)?this.queryServicesParams.params:JSON.parse(this.queryServicesParams.params);t.uploadTemplateFlag="Y",this.queryServicesParams.params=JSON.stringify(t),this.queryServicesParams.cmdid="7",this.queryServicesParams.print={print:1,type:6,zip:0},this.queryServicesParams.paramsArr=[{params:JSON.stringify(t)}];await this._queryBase64ServicesPrint(this.queryServicesParams)}}catch(t){console.log(t)}finally{this.queryServicesParams=null}}async postMessage(t,e=0){if(!this.webview)return Promise.reject();const i=c();return e&&e>0?this.messageCollectAndNotifyFail(i,t,e):this.messageCollect(i,t)}messageCollect(t,e){return new Promise(((i,r)=>{this.messageHandlerQueue.push({resolve:i,reject:r,id:t}),this.webview.postMessage(e)}))}messageCollectAndNotifyFail(t,e,i){return Promise.race([new Promise(((i,r)=>{this.messageHandlerQueue.push({resolve:i,reject:r,id:t}),this.webview.postMessage(e)})),new Promise(((e,r)=>{setTimeout((()=>{const e=this.messageHandlerQueue.findIndex((e=>e.id===t));e>-1&&this.messageHandlerQueue.splice(e,1),r({type:"timeout"})}),i)}))])}destroy(){}show(...t){return this.dialog.show(...t)}showPreview(...t){return this.dialogPreview.show(...t)}_testDomesticSystemConnection(){return new Promise((t=>{m({url:`${this.printDomesticOrigin}/test`,method:"get",withCredentials:!1,params:{}}).then((({data:e})=>{e.status?t(!0):t(!1)})).catch((e=>{t(!1)}))}))}_testConnection(){return this.webview?Promise.resolve(!0):new Promise((t=>{m({url:`${this.printOrigin}/test`,method:"get",withCredentials:!1,params:{inputdata:{result:"success"}}}).then((({data:e})=>{"success"===e.result?t(!0):t(!1)})).catch((e=>{t(!1)}))}))}async resetPrinter(t,e){const i=a(t),r=this.getIReportFormatId(i,t);if(i&&(u||2==e)){return await this._testDomesticSystemConnection()?m({url:`${this.printDomesticOrigin}/resetPrint`,method:"get",withCredentials:!1,params:{formatId:r}}).then((({data:t})=>t.status?{type:"resetSuccess",result:"success",message:null==t?void 0:t.message}:{type:"resetError",result:"error",message:null==t?void 0:t.message})).catch((t=>({type:"resetError",result:"error",message:"重置打印机错误"}))):{type:"notOpenedApp",result:"error",message:"请开启ihoPrint客户端"}}return this.webview?this.postMessage({exec:"resetprint",data:{formatID:r}}):m({url:`${this.printOrigin}/services/printset`,method:"get",withCredentials:!1,params:{inputdata:r}}).then((({data:t})=>t))}_queryServicesPrint(e){return this.webview?this.postMessage({exec:"print",data:{inputData:e}},null==e?void 0:e.messageTimeout):t({url:this.printOrigin+"/services/print",method:"get",params:{inputData:JSON.stringify(e)}}).then((({data:t})=>t))}_queryBase64ServicesPrint(t){return this.webview?this.postMessage({exec:"print",data:{inputData:t}}):m({url:this.printOrigin+"/services/Printqueue",method:"get",params:{inputData:JSON.stringify(t)}}).then((({data:t})=>t))}_callPrintWithFile(t){const e={cmdid:"7",flag:"1"},i={inputData:JSON.stringify(Object.assign({},e,t))};return this.webview?this.postMessage({exec:"print",data:r(i)}):m({url:this.printOrigin+"/PrintLocal",method:"post",data:i,transformRequest:[r]}).then((({data:t})=>t));function r(t){let e="";for(const i in t)e+=encodeURIComponent(i)+"="+encodeURIComponent(t[i])+"&";return e=e.slice(0,-1),e}}_handleMonitorNotify(t){var e,i;null==(i=null==(e=this.CMonitor)?void 0:e.notify)||i.call(e,{name:"custom_info",message:t,businessName:"打印sdk"})}_handleResult(t,e,i){if(!t){const t="打印命令返回空数据";return this._handleMonitorNotify(""),null==e||e({type:"printError",message:t,result:"error",errinfo:t}),!1}if("success"!==t.result){const r=t.message||t.Message;this._handleMonitorNotify(r);const s={type:"printError",message:r,result:t.result,errinfo:t.errinfo};return"cancel"==t.result?(i&&i({type:"printCancel",message:r,result:t.result,errinfo:t.errinfo}),!1):(null==e||e(s),!1)}return t}_handleResultTest(t,e){return!!t||(console.log("notInstalledApp"),null==e||e({type:"notInstalledApp",message:"请打开打印服务器插件",result:"error"}),!1)}async _handleEventQueryPrintData(t,e,i,r,s){const a={templateId:t,formatId:e,params:i,cmdid:"7",messageTimeout:r},n=await this._queryServicesPrint(a);return this._handleQueryPrintDataResult(n,e,s)}_handleQueryPrintDataResult(t,e,i){if(!(null==t?void 0:t.file)){try{const e=t.message||t.Message;console.log(e),null==i||i({result:"error",type:"queryPrintDataFailure",message:e})}catch(t){console.log(t)}return!1}return{file:t.file,printerName:t.defprinter,pageCount:t.pagecount,formatId:e}}async _handleEventDirect({templateId:t,formatId:e,svrUpdateIp:i,params:r,paramsArr:s,cmdid:a,print:n,signature:o,copies:l,printdlgshow:c="0",nobillnode:p="1",btnprint:u="1",messageTimeout:m=0}){const d={templateId:t,formatId:e,svrUpdateIp:i,params:r,cmdid:a,nobillnode:p,printdlgshow:c,btnprint:u,copies:l,messageTimeout:m,...o?{signature:o}:{}};if(s&&(d.paramsArr=s),n){try{n=JSON.parse(n)}catch(t){}d.print=n}else if(this.isRemote){const t=h(new Date,"yyyyMMddHHmmss");d.print={print:"1",type:"1",zip:"0",filename:`F:\\WorkSpace\\crmweb\\web\\${t}\\${t}`}}return this.queryServicesParams=d,await this._queryServicesPrint(d)}async _handleEventEditFormat({templateId:t,formatId:e="",params:i="",token:r,messageTimeout:s=0}){const a={};let n={};try{n=Object.assign({},a,JSON.parse(i))}catch(t){n=a}const o={templateId:t,formatId:e,cmdid:"9",token:r,params:JSON.stringify(n),messageTimeout:s};return await this._queryServicesPrint(o)}async _queryProxyOrigin(){if(this.isRemote)return;const{data:t}=await m({method:"get",url:v})||{},{map:e={}}=t;e.isRemote&&(this.printOrigin=d+"/printService",this.isRemote=!0)}async _queryPrintFile(t,e=""){const{data:i}=await m({method:"post",url:g,responseType:"blob",params:{formatId:t.split("_")[1],params:e}})||{};return i}paramsSerializer(t){return Object.keys(t).forEach((e=>{const i=t[e];t[e]=i,"biParams"==e&&(t[e]=encodeURIComponent(i))})),t}async _queryPrintForBase64(t,e,i="",r){const s="object"==typeof i?i:JSON.parse(i),{data:a}=await m({method:"post",url:y,params:{id:t,formatId:e,params:this.paramsSerializer(s),authorizationKey:r}})||{};return a}async _queryPrintForBase16(t,e,i="",r){const s="object"==typeof i?i:JSON.parse(i),{data:a}=await m({method:"post",url:f,params:{id:t,formatId:e,params:this.paramsSerializer(s),authorizationKey:r}})||{};return a}async _queryPrintForPdf(t,e,i="",r){const s="object"==typeof i?i:JSON.parse(i),{data:a}=await m({method:"post",url:w,responseType:"blob",params:{id:t,formatId:e,params:this.paramsSerializer(s),authorizationKey:r}})||{};return a}async _browserPrint(t,e){if(this.isRemote){const{filedir:i}=t,r=JSON.parse(i)[0].replace(/\\/g,"/").split("/"),s=r[r.length-2],a=r[r.length-1],l=await n(`${P}/${s}/${a}`),c=o(null,e,l);if("preview"===e)return c}}_base64ToBlob(t,e){const i=window.atob(t);let r=i.length;const s=new Uint8Array(r);for(;r--;)s[r]=i.charCodeAt(r);return new Blob([s],{type:e})}async preview({iReportExecuteMode:t,templateId:e,formatId:i,params:r="",paramsArr:s,authorizationKey:n,signature:c,btnprint:h,messageTimeout:p=0},m,d){const g=a(i),y=this.getIReportFormatId(g,i);if(g&&(u||2==t)){const t=await this._queryPrintForPdf(e,y,r,n);if(!t)return null==d?void 0:d({type:"queryPrintDataFailure",result:"error",message:"获取文件失败!"});const i=o(t,"preview");return this.instance||(this.instance=l()),this.showPreview(this.instance,i),null==m?void 0:m({result:"success",message:"",file:t})}await this._queryProxyOrigin();const f=await this._testConnection();if(!this._handleResultTest(f,d))return!1;try{const t=await this._handleEventDirect({templateId:e,formatId:y,params:r,paramsArr:s,cmdid:this.isRemote?"7":"8",signature:c,btnprint:h,messageTimeout:p}),i=this._handleResult(t,d);if(!i)return!1;if(this.isRemote){const t=await this._browserPrint(i,"preview");this.instance||(this.instance=l()),this.showPreview(this.instance,t)}await this.getPicAndUpload(i),null==m||m(i)}catch(t){const e="预览失败",i="timeout"===(null==t?void 0:t.type)?{...t,message:e,result:"error"}:{message:e,result:"error"};null==d||d(i),this._handleMonitorNotify(i)}}async printSync(t,e,i){const r=t.map((t=>{const e={params:"",printdlgshow:"0",nobillnode:"1",btnprint:"1",...t,cmdid:"7",...t.signature?{signature:t.signature}:{}};if(e.print)try{e.print=JSON.parse(e.print)}catch(t){}return{inputData:e}}));try{const t=c(),s=await this.messageCollect(t,{exec:"printA",data:r});if(s&&Array.isArray(s)){s.some((t=>"success"===t.res.result))?null==e||e(s):(null==i||i(s),this._handleMonitorNotify(s))}else{const t="打印命令返回无效数据";this._handleMonitorNotify(s||""),null==i||i({type:"printError",message:t,result:"error",errinfo:t})}}catch(t){const e={error:t,result:"error",message:"打印失败"};null==i||i(e),this._handleMonitorNotify(e)}}async printDirect({iReportExecuteMode:t,templateId:e,formatId:i,params:r="",paramsArr:s,authorizationKey:n,print:o,signature:l,printdlgshow:c,nobillnode:h,copies:p,svrUpdateIp:m,isDownloadFile:d=!0,messageTimeout:g=0},y,f,w,v="printDirect"){const P=a(i),_=this.getIReportFormatId(P,i);if(P&&(u||2==t)){if(!await this._testDomesticSystemConnection())return void f({type:"notOpenedApp",result:"error",message:"请开启ihoPrint客户端"});return void(this._initDomesticSystem((async t=>{t?await this.printToHiPrint({templateId:e,formatId:_,params:r,authorizationKey:n},y,f,w):f({type:"connectAppFail",result:"error",message:"连接ihoPrint客户端失败"})}))&&await this.printToHiPrint({templateId:e,formatId:_,params:r,authorizationKey:n},y,f,w))}await this._queryProxyOrigin();const b=await this._testConnection();if(!this._handleResultTest(b,f))return!1;try{const t=await this._handleEventDirect({templateId:e,formatId:_,params:r,paramsArr:s,cmdid:"7",print:o,signature:l,printdlgshow:c,nobillnode:h,copies:p,svrUpdateIp:m,messageTimeout:g}),i=this._handleResult(t,f,w);if(!i)return!1;d&&["downloadPDF"].includes(v)&&await this._browserPrint(i,v),null==y||y(i)}catch(t){const e="printDirect"===v?"打印失败":"下载失败",i="timeout"===(null==t?void 0:t.type)?{...t,message:e,result:"error"}:{message:e,result:"error"};null==f||f(i),this._handleMonitorNotify(i)}}async printToHiPrint({templateId:t,formatId:e,params:i,authorizationKey:r},s,a,n){const o=await this._queryPrintForBase64(t,e,i,r);if(!o.success)return a({message:o.resultMsg,result:"error"});const{base64:l,formatId:c}=o.map;this.base64Fragment=l,this._successCallbackFn=s,this._errorCallbackFn=a,n&&(this._cancelCallbackFn=n),this.hiPrintSocket.emit("news",{printerList:this.printerList,type:"askPrinterTemplate",markTemplateId:c,pdf_stream:this.base64Fragment})}_downloadPDF(t){return this.webview?this.postMessage({exec:"pdf",data:{file:t}}):m.get(this.printOrigin+"/download",{params:{inputData:t}}).then((({data:t})=>t))}async downloadPDF(t,r,s){var n;const o=e(t);if(this.webview&&this.downloadPath&&(Reflect.has(o,"print")||Reflect.set(o,"print",{print:"1",type:"1"}),!o.print.filename)){const t=h(new Date,"yyyy-MM-dd"),e=c(),i=h(new Date,"yyyyMMddHHmmss")+e;o.print.filename=`${this.downloadPath}/${t}/${i}/${i}`.replace(/\\/g,"/")}const l=a(o.formatId);if(o.formatId=this.getIReportFormatId(l,o.formatId),l&&(u||2==o.iReportExecuteMode)){const t=await this._queryPrintForBase16(o.templateId||"",o.formatId,o.params||"",o.authorizationKey);return(null==t?void 0:t.success)?r({filebase64:null==(n=null==t?void 0:t.map)?void 0:n.hex,isIreport:!0}):null==s?void 0:s({type:"queryPrintDataFailure",result:"error",message:"获取文件失败!"})}this.printDirect(o,(async t=>{t||s({result:"error",message:""});const e=this,a=await async function(t){const r=[],s=JSON.parse(t);if(!i(s))return await e._downloadPDF("");if(1===s.length)return await e._downloadPDF(s[0]||"");for(let t=0,i=s.length;t<i;t++)r.push(await e._downloadPDF(s[t]||""));return r}(t.filedir);r(a,t)}),(t=>s(t)),(t=>{console.log(t)}),"downloadPDF")}async print({templateId:t,formatId:e,params:i="",messageTimeout:r=0},s,a){const n=await this._testConnection();if(!this._handleResultTest(n,a))return!1;const o=await this.queryPrintData({templateId:t,formatId:e,params:i,messageTimeout:r},void 0,a);if(!o)return!1;const l=this.printFileData({formatId:e,file:o.file,printerName:o.printerName},void 0,a);if(!l)return!1;s&&s(l)}async queryPrintData({templateId:t,formatId:e,params:i="",messageTimeout:r=0},s,a){const n=await this._testConnection();if(!this._handleResultTest(n,a))return!1;const o=await this._handleEventQueryPrintData(t,e,i,r,a);return!!o&&(s&&s(o),o)}async printFileData({formatId:t,file:e,printerName:i="Default"},r,s){const a=await this._testConnection();if(!this._handleResultTest(a,s))return!1;const n=await this._callPrintWithFile({formatId:t,printname:i,file:e}),o=this._handleResult(n,s);return!!o&&(r&&r(o),o)}async editPrintFormat({templateId:t,formatId:e,params:i,token:r,messageTimeout:s=0},a,n){const o=await this._testConnection();if(!this._handleResultTest(o,n))return!1;const l=await this._handleEventEditFormat({templateId:t,formatId:e,params:i,token:r,messageTimeout:s}),c=this._handleResult(l,n);if(!c)return!1;a&&a(c)}async addPrintFormat({templateId:t,params:e,token:i},r,s){const a=await this._testConnection();if(!this._handleResultTest(a,s))return!1;const n=await this._handleEventEditFormat({templateId:t,params:e,token:i}),o=this._handleResult(n,s);if(!o)return!1;r&&r(o)}}export{b as Print};
|
@@ -1 +1 @@
|
|
1
|
-
import{fabric as t}from"../../../../../shared/utils/fabricjs/index.js";import{drawLine as e,drawArrow as n,drawPoint as i,defaultStyle as o,drawText as r,defaultTextStyle as l,drawTextAndIconGroup as s,defaultRectStyle as a}from"../useDraw.js";import{useGrid as c}from"../useGrid.js";import{useBirthProcessCumputedPoint as u}from"../useCumputedPoint.js";import"../useEvent.js";import{getScaleInfo as d,drawScaleNumber as h,drawScaleLine as f}from"../useScaleColumn.js";import{useCommon as p}from"../useCommon.js";import"vue";import{getIndex as g,isEffectiveNode as m,getTime as v,getScaleNumberList as y}from"../../utils/index.js";import{cloneDeep as k,last as b,range as x}from"lodash-es";import"../temperature/useShadow.js";import"@vueuse/shared";import{format as w}from"date-fns";import"naive-ui";import"@vueuse/core";function S(S,C,j,P,I){const{computedX:E,computedY:T,getXValue:X,getYValue:A}=u(C),{getEqualXTypes:L,handleAddPrevent:Y,isGridLimit:M,setPrevAndNextPoint:H,getPointEventProps:z}=p(S,j,C),{xAxis:G,grid:W,originX:D,originY:N,xCellWidth:O,endY:R,startTime:V,leftAddAreaWidth:B,leftScales:F,rightScales:$,yCellHeight:q,endX:J,scaleValues:K,canvasWidth:Q,borderStyle:U,rightAddAreaWidth:Z,event:_,originYCervix:tt,other:et,canvasHeight:nt,scalebarBorder:it}=C,ot=k(K),rt=new Set;function lt(){ot.filter((({showData:t=!0})=>t)).forEach(((t,s)=>{var a;const c=[],u=[],d=[];null==(a=t.data)||a.forEach(((a,h)=>{!function(a,h,f){let p,g;const{pointAttr:m={},lineAttr:v={},title:y="",key:k,type:b="circle",childbirthStyle:x={}}=t,w=t.data[f+1],C=dt(w,t);if(a&&C&&!h.breakpoint)g=e([...a,...C],{...v});else if(a&&!C&&!h.breakpoint){const n=dt(w,t);g=n?e([...a,...n],{...v}):null}let I,E;if(h.childbirth){const{type:t="arrow",style:e={}}=x;if("arrow"===t){const t=a[1]+q;I=n([a[0],a[1],t],e)}else I=i(t,{left:a[0],top:a[1],...e,...o,hoverCursor:"default"});E=r([a[0]+O/2,a[1]+q/2],{value:String(h.childbirth),...l,originX:"left",originY:"center",fill:e.stroke||e.fill,fontSize:e.fontSize||l.fontSize}),I&&d.push(I),d.push(E)}const T=u[f-1],L={origin:{data:h,title:y,key:k||"",dataIndex:s,index:f},leftLine:T,rightLine:g,childbirthIcon:I,childbirthText:E,...m,...z()};a&&(T||(L.leftLine=null),p=i(b,{left:a[0],top:a[1],...L}));u.push(g),p&&(!function(t){_.hovered&&(t.on("mouseover",(()=>{ut(t,"hover")})),t.on("mouseout",(()=>{P.show=!1})));if(t.lockMovementX&&t.lockMovementY)return;t.on("moving",(()=>{ct(t),function(t){var e,n,i,o;null==(e=t.leftLine)||e.setCoords().set({x2:t.left,y2:t.top}),null==(n=t.rightLine)||n.setCoords().set({x1:t.left,y1:t.top}),null==(i=t.childbirthIcon)||i.setCoords().set({left:t.left,top:t.top}),null==(o=t.childbirthText)||o.setCoords().set({left:t.left+O/2,top:t.top+q/2})}(t),_.hovered&&ut(t)})),t.on("mouseup",(e=>{if(P.show=!1,1===e.button){const{key:e}=t.origin,n={...t.origin,data:{...t.origin.data,time:X(t.left),value:A(e,t.top)}};S.value.discardActiveObject(),j("change",n),st(n,"change")}}))}(p),c.push(p),rt.add(p))}(dt(a,t),a,h)})),Promise.all(c).then((t=>{const e=u.filter((t=>t));H(t),Promise.all(d).then((n=>{S.value.add(...e,...t,...n),t.forEach((t=>{null==t||t.bringToFront();const{childbirthIcon:e}=t;e&&Reflect.has(e,"zIndex")&&e.zIndex>0&&e.bringToFront()}))}))}))}))}function st(t,e="add"){const{dataIndex:n,data:i,index:o,key:r}=t,l=ot.find((t=>t.key===r));switch(e){case"remove":l.data.splice(o,1);break;case"change":l.data[o]=i;break;default:{const t=g(i.time,l.data);l.data.splice(t,0,i);break}}at()}function at(){var t;rt.size&&(null==(t=S.value)||t.remove(...function(t){const e=[];return t.forEach((t=>{t&&e.push(t),(null==t?void 0:t.leftLine)&&e.push(null==t?void 0:t.leftLine),(null==t?void 0:t.rightLine)&&e.push(null==t?void 0:t.rightLine),(null==t?void 0:t.childbirthIcon)&&e.push(null==t?void 0:t.childbirthIcon),(null==t?void 0:t.childbirthText)&&e.push(null==t?void 0:t.childbirthText)})),e}([...rt]))),rt.clear(),lt()}function ct(t){const e=t.prevPoint?t.prevPoint.left:D,n=t.nextPoint?t.nextPoint.left:J;t.setCoords(),["cervix","fetalPresentation"].includes(t.origin.key)&&t.top<tt&&t.set("top",tt),t.top<N&&t.set("top",N),t.top>R&&t.set("top",R),t.left<e&&t.set("left",e),t.left>n&&t.set("left",n)}function ut(t,e="moving"){const{title:n,key:i,data:o}=t.origin;P.point={x:t.left,y:t.top},P.list=[`${n} ${"hover"===e?o.value:A(i,t.top)}`,`时间 ${X(t.left).slice(-5)}`],P.show=!0}function dt(t,e){if(m(t)&&function(t){const e=V+864e5,n=v(t);return n>=V&&n<=e}(t.time)){const n=E(t.time),i=T(e.key,e.range,t.value);return[n,i<N?N:i>R?R:i]}}function ht(t,e){return t+1>e[1]?e[0]:t+1}return c(S,C),function(){const e=it?{width:Q-B-Z-1,left:B}:{width:J-D
|
1
|
+
import{fabric as t}from"../../../../../shared/utils/fabricjs/index.js";import{drawLine as e,drawArrow as n,drawPoint as i,defaultStyle as o,drawText as r,defaultTextStyle as l,drawTextAndIconGroup as s,defaultRectStyle as a}from"../useDraw.js";import{useGrid as c}from"../useGrid.js";import{useBirthProcessCumputedPoint as u}from"../useCumputedPoint.js";import"../useEvent.js";import{getScaleInfo as d,drawScaleNumber as h,drawScaleLine as f}from"../useScaleColumn.js";import{useCommon as p}from"../useCommon.js";import"vue";import{getIndex as g,isEffectiveNode as m,getTime as v,getScaleNumberList as y}from"../../utils/index.js";import{cloneDeep as k,last as b,range as x}from"lodash-es";import"../temperature/useShadow.js";import"@vueuse/shared";import{format as w}from"date-fns";import"naive-ui";import"@vueuse/core";function S(S,C,j,P,I){const{computedX:E,computedY:T,getXValue:X,getYValue:A}=u(C),{getEqualXTypes:L,handleAddPrevent:Y,isGridLimit:M,setPrevAndNextPoint:H,getPointEventProps:z}=p(S,j,C),{xAxis:G,grid:W,originX:D,originY:N,xCellWidth:O,endY:R,startTime:V,leftAddAreaWidth:B,leftScales:F,rightScales:$,yCellHeight:q,endX:J,scaleValues:K,canvasWidth:Q,borderStyle:U,rightAddAreaWidth:Z,event:_,originYCervix:tt,other:et,canvasHeight:nt,scalebarBorder:it}=C,ot=k(K),rt=new Set;function lt(){ot.filter((({showData:t=!0})=>t)).forEach(((t,s)=>{var a;const c=[],u=[],d=[];null==(a=t.data)||a.forEach(((a,h)=>{!function(a,h,f){let p,g;const{pointAttr:m={},lineAttr:v={},title:y="",key:k,type:b="circle",childbirthStyle:x={}}=t,w=t.data[f+1],C=dt(w,t);if(a&&C&&!h.breakpoint)g=e([...a,...C],{...v});else if(a&&!C&&!h.breakpoint){const n=dt(w,t);g=n?e([...a,...n],{...v}):null}let I,E;if(h.childbirth){const{type:t="arrow",style:e={}}=x;if("arrow"===t){const t=a[1]+q;I=n([a[0],a[1],t],e)}else I=i(t,{left:a[0],top:a[1],...e,...o,hoverCursor:"default"});E=r([a[0]+O/2,a[1]+q/2],{value:String(h.childbirth),...l,originX:"left",originY:"center",fill:e.stroke||e.fill,fontSize:e.fontSize||l.fontSize}),I&&d.push(I),d.push(E)}const T=u[f-1],L={origin:{data:h,title:y,key:k||"",dataIndex:s,index:f},leftLine:T,rightLine:g,childbirthIcon:I,childbirthText:E,...m,...z()};a&&(T||(L.leftLine=null),p=i(b,{left:a[0],top:a[1],...L}));u.push(g),p&&(!function(t){_.hovered&&(t.on("mouseover",(()=>{ut(t,"hover")})),t.on("mouseout",(()=>{P.show=!1})));if(t.lockMovementX&&t.lockMovementY)return;t.on("moving",(()=>{ct(t),function(t){var e,n,i,o;null==(e=t.leftLine)||e.setCoords().set({x2:t.left,y2:t.top}),null==(n=t.rightLine)||n.setCoords().set({x1:t.left,y1:t.top}),null==(i=t.childbirthIcon)||i.setCoords().set({left:t.left,top:t.top}),null==(o=t.childbirthText)||o.setCoords().set({left:t.left+O/2,top:t.top+q/2})}(t),_.hovered&&ut(t)})),t.on("mouseup",(e=>{if(P.show=!1,1===e.button){const{key:e}=t.origin,n={...t.origin,data:{...t.origin.data,time:X(t.left),value:A(e,t.top)}};S.value.discardActiveObject(),j("change",n),st(n,"change")}}))}(p),c.push(p),rt.add(p))}(dt(a,t),a,h)})),Promise.all(c).then((t=>{const e=u.filter((t=>t));H(t),Promise.all(d).then((n=>{S.value.add(...e,...t,...n),t.forEach((t=>{null==t||t.bringToFront();const{childbirthIcon:e}=t;e&&Reflect.has(e,"zIndex")&&e.zIndex>0&&e.bringToFront()}))}))}))}))}function st(t,e="add"){const{dataIndex:n,data:i,index:o,key:r}=t,l=ot.find((t=>t.key===r));switch(e){case"remove":l.data.splice(o,1);break;case"change":l.data[o]=i;break;default:{const t=g(i.time,l.data);l.data.splice(t,0,i);break}}at()}function at(){var t;rt.size&&(null==(t=S.value)||t.remove(...function(t){const e=[];return t.forEach((t=>{t&&e.push(t),(null==t?void 0:t.leftLine)&&e.push(null==t?void 0:t.leftLine),(null==t?void 0:t.rightLine)&&e.push(null==t?void 0:t.rightLine),(null==t?void 0:t.childbirthIcon)&&e.push(null==t?void 0:t.childbirthIcon),(null==t?void 0:t.childbirthText)&&e.push(null==t?void 0:t.childbirthText)})),e}([...rt]))),rt.clear(),lt()}function ct(t){const e=t.prevPoint?t.prevPoint.left:D,n=t.nextPoint?t.nextPoint.left:J;t.setCoords(),["cervix","fetalPresentation"].includes(t.origin.key)&&t.top<tt&&t.set("top",tt),t.top<N&&t.set("top",N),t.top>R&&t.set("top",R),t.left<e&&t.set("left",e),t.left>n&&t.set("left",n)}function ut(t,e="moving"){const{title:n,key:i,data:o}=t.origin;P.point={x:t.left,y:t.top},P.list=[`${n} ${"hover"===e?o.value:A(i,t.top)}`,`时间 ${X(t.left).slice(-5)}`],P.show=!0}function dt(t,e){if(m(t)&&function(t){const e=V+864e5,n=v(t);return n>=V&&n<=e}(t.time)){const n=E(t.time),i=T(e.key,e.range,t.value);return[n,i<N?N:i>R?R:i]}}function ht(t,e){return t+1>e[1]?e[0]:t+1}return c(S,C),function(){const e=it?{width:Q-B-Z-1,left:B}:{width:J-D,left:D},n=new t.Rect({...U,height:R-1,top:0,fill:"transparent",...e});S.value.add(n)}(),function(){function e(e,n="left"){let i="left"===n?B:J;e.forEach(((e,n)=>{const{range:s,spaceValue:c,width:u,title:p,titleStyle:g,key:m,position:v="center",spaceGridNumber:k=1,showNumber:b,showMaxMinNumber:x}=e,w=[],C=[],j=i+u/2,P=y(s,c),I=P.length,{lineXMain:E,lineXSub:T,textLeft:X}=d(v,i,u);P.forEach(((t,n)=>{const i=R-n*q*k,o=0===n?R-8:n!==P.length-1||N||tt&&"FHR"!==m?i:N+8;!b||(0===n||n===I-1)&&!x||w.push(h(String(t),e,X,o)),C.push(...f(e,n,E,T,i,q,N,I,1))}));const A=[],L=it?new t.Rect({...a,strokeWidth:.5,width:u,height:R,left:j,top:R/2}):null;L&&A.push(L);const Y=r([j,N>0?N-q/2:q/2],{value:String(p),...l,...g});Y&&A.push(Y);const M=new t.Group([...C,...w,...A],{objectCaching:!1,...o});S.value.add(M),M.sendToBack(),i+=u}))}e(F),e($,"right")}(),function(){const{show:e,startTime:n,range:i=[0,23],position:s="top",style:a}=G.time,{show:c,range:u=[0,23],position:d,style:h={}}=G.processTime;if(e||c){const f=[],p=x(u[0],u[1]+1),g=[],m=[],v=q/2;for(let t=0;t<W.mainXCell;t++){if(e){const{textAlign:e="center"}=a,o=D+("center"===e?O/2:0),c=0===t&&"center"!==e?o+5:o,u=0===t?+n.slice(11,13):ht(b(f),i);f.push(u);const d="top"===s?N-v:R+v;g.push(r([c+t*O,d],{value:String(u),...l,...a})),t===W.mainXCell-1&&"center"!==e&&g.push(r([J-1,d],{value:String(ht(b(f),i)),...l,...a,originX:"center"!==e?"right":"center"}))}if(c&&t<=p.length){const{textAlign:e="center"}=h,n=D+("center"===e?O/2:0),i=0===t&&"center"!==e?n+5:n,o="top"===d?v:nt-v;m.push(r([i+t*O,o],{value:String(p[t]),...l,...h})),t===W.mainXCell-1&&"center"!==e&&m.push(r([J-1,o],{value:String(b(p)),...l,...a,originX:"center"!==e?"right":"center"}))}}const y=new t.Group([...g,...m],{objectCaching:!1,...o});S.value.add(y),S.value.sendToBack(y)}}(),function(){var t;const n=Object.values(et),i=[],o={},r=ot.find((t=>"cervix"===t.key&&t.show)),l=null==(t=null==r?void 0:r.data)?void 0:t.find((t=>3==+t.value));function s(t,e){const{key:n,range:i}=r||{},o=T(n,i,10),l=[0,e],s=[-e/t,0],a=[(R-o-e)/t,R-o],c=[J-D,t*(J-D)+e];let u=[],d=[];function h([n,i]){return Math.abs(i-t*n-e)<=1}function f([t,e]){const[n,i]=[...p([t,e])];return n>=D&&n<=J&&i>=o&&i<=R}function p([t,e]){return[D+t,R-e]}return h(l)&&f(l)&&(u=p(l)),h(s)&&f(s)&&(u=p(s)),h(a)&&f(a)&&(d=p(a)),h(c)&&f(c)&&(d=p(c)),[...u,...d]}n.forEach((t=>{if(!t.show)return;const{key:n}=t;switch(n){case"fetalPresentation":{const{range:o,show:r}=ot.find((t=>t.key===n));if(r){const r=T(n,o,0);i.push(e([D,r,J,r],{...t}))}break}case"alert":if(l){const{key:n,range:a}=r||{},c=216e5,u={time:w(new Date(v(l.time)+c),"yyyy-MM-dd HH:mm"),value:10},[d,h]=[E(l.time)-D,R-T(n,a,l.value)],[f,p]=[E(u.time)-D,R-T(n,a,u.value)],g=(p-h)/(f-d),m=h-d*g,y=s(g,m);y.length>0&&(i.push(e(y,{...t})),Object.assign(o,{k:g,b:m}))}break;case"handling":if(l){const{k:n,b:r}=o,a=144e5,c=s(n,r-(E(w(new Date(v(l.time)+a),"yyyy-MM-dd HH:mm"))-E(l.time))*n);c.length>0&&i.push(e(c,{...t}))}}})),S.value.add(...i)}(),lt(),function(){function t(t,e){const n=ot.findIndex((e=>e.key===t.key));return{renderItem:()=>t.title,origin:{title:t.title,unit:t.unit,dataIndex:n,key:t.key},pointer:e}}C.event.evented&&S.value.on("mouse:up",(e=>{if(3===e.button){const{x:n=0,y:i=0}=e.pointer||{};n>=D&&n<=J&&i>=N&&i<=R&&(I.point={x:n,y:i},I.show=!0,e.target?(I.target=e.target,I.list=["删除节点"],[...rt].forEach((t=>{t.origin&&t.left===e.target.left&&t.top===e.target.top&&I.list.push({renderItem:()=>t.origin.title,origin:{...t.origin},mode:"remove",pointer:e.pointer})}))):(I.target=null,I.list=["新增节点"],ot.filter((t=>t.show)).forEach((o=>{if(!L([...rt],n,"key").includes(o.key)){if(["cervix","fetalPresentation"].includes(o.key)&&i<tt)return;I.list.push(t(o,e.pointer))}})),1===I.list.length&&(I.show=!1,Y("repeat"),console.log("当前时间段内无可新增节点"))))}}))}(),function(){const t=Q-Z/2;function e(t,e){if(!t.length)return;let i=N;const o=[];t.forEach((t=>{const n=t.title.split("").join("\n"),r=K.findIndex((e=>e.key===t.key)),{text:l,icon:a}=s(n,t,{text:{originY:"top",left:e,top:i},icon:{left:e,topY:i,originY:"top",origin:{type:t.type,dataIndex:r},...C.event}},"vertical");var c;i+=l.height+a.height+15,(c=a).on("moving",(()=>{c.set("originY","center"),M(c)?(ct(c),ut(c)):P.show=!1})),c.on("mouseup:before",(t=>{if(P.show=!1,0===t.e.button&&M(c))if(L([...rt],c.left,"key").includes(c.origin.key))Y("repeat");else{const t={data:{time:X(c.left),value:A(c.origin.key,c.top)},...c.origin};j("add",t),st(t)}!function(t){t.setCoords().set({originY:"top",left:t.originLeft,top:t.originTop})}(c)})),o.push(l,a)})),n(o),S.value.add(...o)}function n(t){const e=b(t),n=(R-N)/2,i=(e.height+e.top-N)/2;t.forEach((t=>{const e=t.top+n-i;t.set({top:e,originTop:e})}))}e(F,B/2),e($,t)}(),{clickMenu:function({item:t,target:e}){const n={...t.origin};"remove"===t.mode?(j("remove",n),st(n,"remove")):(Object.assign(n,{data:{time:X(t.pointer.x),value:A(t.origin.key,t.pointer.y)}}),j("add",n),st(n))},redrawPoints:at}}export{S as useBirthProcess};
|
@@ -1 +1 @@
|
|
1
|
-
var e="@cnhis-design-vue/shared",
|
1
|
+
var e="@cnhis-design-vue/shared",s="3.2.11-release.0",i="index.ts",n={"naive-ui":"^2.30.0",vue:"^3.2.0"},a={"@vicons/ionicons5":"^0.12.0","lodash-es":"^4.17.21",moment:"^2.29.1","video.js":"^7.19.2","videojs-contrib-hls":"^5.15.0",viewerjs:"^1.10.5","xe-utils":"^3.5.4"},d={name:e,version:"3.2.11-release.0",private:!0,main:"index.ts",peerDependencies:n,dependencies:a};export{d as default,a as dependencies,i as main,e as name,n as peerDependencies,s as version};
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "cnhis-design-vue",
|
3
|
-
"version": "3.2.11-
|
3
|
+
"version": "3.2.11-release.0",
|
4
4
|
"license": "ISC",
|
5
5
|
"module": "./es/components/index.js",
|
6
6
|
"main": "./es/components/index.js",
|
@@ -72,5 +72,5 @@
|
|
72
72
|
"iOS 7",
|
73
73
|
"last 3 iOS versions"
|
74
74
|
],
|
75
|
-
"gitHead": "
|
75
|
+
"gitHead": "5a5fa0af389665218fe05c7d011f562deb70d590"
|
76
76
|
}
|