cnhis-design-vue 3.2.15-beta.12 → 3.2.15-beta.14

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.
@@ -46,6 +46,9 @@ declare const AiChat: SFCWithInstall<import("vue").DefineComponent<{
46
46
  }) => Promise<import("../../shared/types").AnyObject[]>;
47
47
  }>>;
48
48
  };
49
+ appId: {
50
+ type: StringConstructor;
51
+ };
49
52
  }, {
50
53
  cssVars: import("vue").ComputedRef<import("../../shared/types").AnyObject>;
51
54
  props: Readonly<import("@vue/shared").LooseRequired<Readonly<import("vue").ExtractPropTypes<{
@@ -95,6 +98,9 @@ declare const AiChat: SFCWithInstall<import("vue").DefineComponent<{
95
98
  }) => Promise<import("../../shared/types").AnyObject[]>;
96
99
  }>>;
97
100
  };
101
+ appId: {
102
+ type: StringConstructor;
103
+ };
98
104
  }>> & {
99
105
  "onButton-click"?: ((...args: any[]) => any) | undefined;
100
106
  }>>;
@@ -311,6 +317,9 @@ declare const AiChat: SFCWithInstall<import("vue").DefineComponent<{
311
317
  }) => Promise<import("../../shared/types").AnyObject[]>;
312
318
  }>>;
313
319
  };
320
+ appId: {
321
+ type: StringConstructor;
322
+ };
314
323
  }>> & {
315
324
  "onButton-click"?: ((...args: any[]) => any) | undefined;
316
325
  }, {
@@ -48,6 +48,9 @@ declare const _default: import("vue").DefineComponent<{
48
48
  }) => Promise<AnyObject[]>;
49
49
  }>>;
50
50
  };
51
+ appId: {
52
+ type: StringConstructor;
53
+ };
51
54
  }, {
52
55
  cssVars: import("vue").ComputedRef<AnyObject>;
53
56
  props: Readonly<import("@vue/shared").LooseRequired<Readonly<import("vue").ExtractPropTypes<{
@@ -97,6 +100,9 @@ declare const _default: import("vue").DefineComponent<{
97
100
  }) => Promise<AnyObject[]>;
98
101
  }>>;
99
102
  };
103
+ appId: {
104
+ type: StringConstructor;
105
+ };
100
106
  }>> & {
101
107
  "onButton-click"?: ((...args: any[]) => any) | undefined;
102
108
  }>>;
@@ -313,6 +319,9 @@ declare const _default: import("vue").DefineComponent<{
313
319
  }) => Promise<AnyObject[]>;
314
320
  }>>;
315
321
  };
322
+ appId: {
323
+ type: StringConstructor;
324
+ };
316
325
  }>> & {
317
326
  "onButton-click"?: ((...args: any[]) => any) | undefined;
318
327
  }, {
@@ -1 +1 @@
1
- import{defineComponent as e,reactive as t,provide as o,toRefs as r,computed as s,openBlock as a,createElementBlock as i,normalizeClass as n,normalizeStyle as u,unref as l,createVNode as d,withCtx as p,createBlock as m,createCommentVNode as c}from"vue";import{NMessageProvider as h}from"naive-ui";import y from"./components/ChatMain.js";import f from"./components/ChatFooter.vue.js";import{useTheme as v}from"../../../shared/hooks/useTheme.js";import"@vueuse/core";import"date-fns";import"lodash-es";import"@vue/shared";import{uuidGenerator as S}from"../../../shared/utils/index.js";import"@vueuse/shared";import"../../../shared/hooks/selectHooks/useSearchContent.js";import"@vicons/ionicons5";import"../../../shared/hooks/useScrollLoading.js";import{InjectionAIChat as x,InjectionAIChatEmits as j}from"./types/index.js";import k from"axios";const P=["id"];var g=e({__name:"Index",props:{token:{type:String,required:!0},userAvatar:{type:String},defaultShortcutList:{type:Array},shortcutList:{type:Array},queryData:{type:Function,reuired:!0},queryRecord:{type:Function,reuired:!0},hideInput:{type:Boolean},uiStyle:{type:String},audioTimed:{type:Number,default:10},commandList:{type:Array},queryPrompt:{type:Function},patientInfo:{type:Object}},emits:["button-click"],setup(e,{expose:g,emit:I}){const b=e,A=v(),C=k.create({headers:{Authorization:"bearer "+b.token}});C.interceptors.response.use((e=>{var t;return(null==(t=e.data)?void 0:t.success)?e.data:{success:!1,data:[]}}));const F=t({id:"ai-chat-"+S(),loading:!1,sending:!1,sendContent:"",selectedCommand:null,selectedPrompt:null,externalData:null,selectedPatient:null,selectedPatientLabel:"",selectedPatientForm:null,showPatient:!1});return o(x,{...r(b),state:F,isSmall:s((()=>"small"===b.uiStyle)),axiosInstance:C}),o(j,I),g({pushMessage:e=>{F.externalData=e},updatePatientInfo:e=>{F.selectedPatient=e}}),(t,o)=>(a(),i("div",{id:F.id,class:n(["ai-chat","small"===e.uiStyle?"ai-chat--small":""]),style:u(l(A))},[d(l(h),null,{default:p((()=>[d(l(y)),e.hideInput?c("v-if",!0):(a(),m(f,{key:0}))])),_:1})],14,P))}});export{g as default};
1
+ import{defineComponent as e,reactive as t,provide as o,toRefs as r,computed as s,openBlock as a,createElementBlock as i,normalizeClass as n,normalizeStyle as u,unref as l,createVNode as p,withCtx as d,createBlock as m,createCommentVNode as c}from"vue";import{NMessageProvider as h}from"naive-ui";import y from"./components/ChatMain.js";import f from"./components/ChatFooter.vue.js";import{useTheme as v}from"../../../shared/hooks/useTheme.js";import"@vueuse/core";import"date-fns";import"lodash-es";import"@vue/shared";import{uuidGenerator as S}from"../../../shared/utils/index.js";import"@vueuse/shared";import"../../../shared/hooks/selectHooks/useSearchContent.js";import"@vicons/ionicons5";import"../../../shared/hooks/useScrollLoading.js";import{InjectionAIChat as x,InjectionAIChatEmits as g}from"./types/index.js";import j from"axios";const k=["id"];var P=e({__name:"Index",props:{token:{type:String,required:!0},userAvatar:{type:String},defaultShortcutList:{type:Array},shortcutList:{type:Array},queryData:{type:Function,reuired:!0},queryRecord:{type:Function,reuired:!0},hideInput:{type:Boolean},uiStyle:{type:String},audioTimed:{type:Number,default:10},commandList:{type:Array},queryPrompt:{type:Function},patientInfo:{type:Object},appId:{type:String}},emits:["button-click"],setup(e,{expose:P,emit:I}){const b=e,A=v(),C=j.create({headers:{Authorization:"bearer "+b.token}});C.interceptors.response.use((e=>{var t;return(null==(t=e.data)?void 0:t.success)?e.data:{success:!1,data:[]}}));const F=t({id:"ai-chat-"+S(),loading:!1,sending:!1,sendContent:"",selectedCommand:null,selectedPrompt:null,externalData:null,selectedPatient:null,selectedPatientLabel:"",selectedPatientForm:null,showPatient:!1});return o(x,{...r(b),state:F,isSmall:s((()=>"small"===b.uiStyle)),axiosInstance:C}),o(g,I),P({pushMessage:e=>{F.externalData=e},updatePatientInfo:e=>{F.selectedPatient=e}}),(t,o)=>(a(),i("div",{id:F.id,class:n(["ai-chat","small"===e.uiStyle?"ai-chat--small":""]),style:u(l(A))},[p(l(h),null,{default:d((()=>[p(l(y)),e.hideInput?c("v-if",!0):(a(),m(f,{key:0}))])),_:1})],14,k))}});export{P as default};
@@ -1 +1 @@
1
- import{defineComponent as e,inject as t,ref as a,reactive as l,computed as n,watch as o,createVNode as i}from"vue";import{NForm as s,NFormItem as r,NInput as u,NIcon as d,NButton as c}from"naive-ui";import{InjectionAIChat as v}from"../types/index.js";import"../../../index.js";import{cloneDeep as m,isArray as p}from"lodash-es";import{isValidJSON as f}from"../utils/index.js";import{ChevronDown as g,ChevronForward as b}from"@vicons/ionicons5";import{useTheme as h}from"../../../../shared/hooks/useTheme.js";import"@vueuse/core";import"date-fns";import"@vue/shared";import"../../../../shared/utils/index.js";import"@vueuse/shared";import"../../../../shared/hooks/selectHooks/useSearchContent.js";import"../../../../shared/hooks/useScrollLoading.js";import y from"../../../form-render/index.js";import E from"../../../template-render/index.js";var I=e({name:"ChatCard",inheritAttrs:!1,props:{msgItem:{type:Object,default:()=>({})},selectParams:{type:Object},configs:{type:Object},msgId:{type:String}},emits:["button-click"],setup(e,{attrs:I,slots:k,emit:x}){const T={TEXT:"INPUT",NUMBER:"INPUT_NUMBER",DATETIME:"DATETIME-INPUT",MULTI_SELECT:"REMOTE_SEARCH",SELECT:"REMOTE_SEARCH"},_=h(),{patientInfo:C,state:P,axiosInstance:w,isSmall:O}=t(v),S=a([]),j=a(),R=a(),M=l({vaa05:""}),L=a(),N=n((()=>{var t,a;return!!(null==(a=null==(t=e.msgItem)?void 0:t.content)?void 0:a.body)})),q=e.msgItem.content,A={},U=l(m(q.data||{})),B={beforeRequest(e,t,a){(null==t?void 0:t.params)&&(t.params.vaa05=R.value.selectedPatient.vaa01),t&&Reflect.has(t,"configs")&&(t.configs=R.value.selectedPatient)}};function F(e){const{eventName:t,data:a}=e;t&&x("button-click",{buttonInfo:a,isBI:!0})}function K(e){U[e.button.id+"Disabled"]="1",x("button-click",{buttonInfo:e.button})}function H(){var t;if(!R.value)return null;function a(){e.msgItem.disabled||(P.showPatient=!0)}return i(s,{class:"form-render",ref:L,"require-mark-placement":"left",disabled:e.msgItem.disabled,model:M,rules:{vaa05:{required:R.value.required,message:R.value.name+((null==(t=window.getLanguageByCode)?void 0:t.call(window,"10010.1.146"))||"为必填"),trigger:["input"]}}},{default:()=>[i(r,{label:R.value.name,path:"vaa05",class:"form-render__formItem",style:"--n-feedback-height: 16px; --n-feedback-padding: 0px; --n-feedback-font-size: 12px"},{default:()=>{var e;return[i(u,{style:"--n-text-color-disabled: #000; --n-placeholder-color-disabled: #000;--n-padding-left: 8px; --n-padding-right: 8px",readonly:!0,value:M.vaa05,placeholder:(null==(e=window.getLanguageByCode)?void 0:e.call(window,"10010.1.147"))||"请选择",onClick:a},{suffix:()=>i(d,{color:"#c2c2c2",component:g},null)})]}})]})}async function J(t,a){var l,n;try{const o=a||j.value.getFormValues();await(null==(l=j.value)?void 0:l.validate()),q.body.items.forEach((e=>{var t;"vaa05"===e.code?(e._value=P.selectedPatientLabel,e.value=R.value.selectedPatient.vaa01||e.value):o[e.code]&&(e.value=o[e.code]),(null==(t=A[e.code])?void 0:t[0])&&(e.options=A[e.code])})),P.loading=!0,x("button-click",{values:o,buttonInfo:t,patient:(null==(n=R.value)?void 0:n.selectedPatient)||e.configs,isForm:!0})}catch(e){P.loading=!1}}function z(e){const{fieldInstance:t,context:a,value:l,fieldKey:n}=e;"REMOTE_SEARCH"===t.componentType&&(null==l?void 0:l.length)&&(A[n]=[null==a?void 0:a.currentOption])}function D(){x("button-click",{showMore:!0})}function V(){var e;if("1834043761964638208"!==(null==(e=q.settings)?void 0:e.id)||!q.data)return null;const t=JSON.parse(q.settings.setting),a=e=>{var t;let l="";for(let n=0;n<e.length;n++){const o=e[n];if(o.setting.scopeKey){l=o.setting.scopeKey;break}if((null==(t=o.childrens)?void 0:t.length)&&(l=a(o.childrens),l))break}return l},l=a(t.templates);return!l||!f(q.data[l])||JSON.parse(q.data[l]).length<=5?null:(f(U[l])&&(U[l]=JSON.parse(U[l]).slice(0,5)),i(c,{block:!0,text:!0,"icon-placement":"right",color:_.value["--c-primary-color"],style:"margin-top: 10px",onClick:D},{icon:()=>i(d,{component:b},null),default:()=>"查看更多"}))}return N.value&&(S.value=(q.body.items||[]).map((t=>{var a,l,n;if("vaa05"===t.code&&!O.value)return R.value={...t},t._value?M.vaa05=t._value:(null==(a=t.options)?void 0:a.length)&&t.value&&(M.vaa05=null==(l=t.options.find((e=>e.value===t.value)))?void 0:l.label,R.value.selectedPatient=e.configs),null;const o={html_type:T[t.type]||t.type,val_key:t.code,name:t.name,elem_width:12,default_val:t.value,lazyRequest:!0,requestCache:!0,urlConfig:{nameKey:null!=(n=t.labelField)?n:"label"},option:[],is_null:t.required?"0":"1",is_edit:e.msgItem.disabled?"0":"1",componentProps:{},multi_select:"MULTI_SELECT"===t.type?"0":"1"};if("REMOTE_SEARCH"===o.html_type){if(o.componentProps={fallbackOption:!1},o.option=t.options||[],o.default_val=null,t.value&&p(t.options)&&t.options.length>0){t.options.find((e=>(null==e?void 0:e.value)===t.value))&&(o.default_val=t.value)}if(Object.assign(o.urlConfig,{url:"/flow/api/instruction/parameter/getOptionsValues",method:"post",params:{...e.selectParams,code:t.code,source:O.value?"inner":"global",configs:C.value.info||P.selectedPatient},dependKey:[]}),t.dependencies){const e=t.dependencies.split(",");o.urlConfig.dependKey=e,e.includes("vaa05")&&(o.urlConfig.params.params={vaa05:""})}}return o})).filter((e=>!!e))),o((()=>P.showPatient),(t=>{!e.msgItem.disabled&&N.value&&!t&&P.selectedPatientLabel&&R.value&&(M.vaa05=P.selectedPatientLabel,R.value.selectedPatient={...P.selectedPatientForm})})),()=>{var t;return i("div",{class:"card"},[N.value?[i("p",null,[q.title||q.header.title]),i("div",{class:"form-box"},[[H(),i(y,{"request-instance":{get:w.get,post:w.post},"life-cycle":B,column:12,ref:j,"field-list":S.value,onFormChange:z},null)]]),q.footer.buttons.map((t=>function(t){const a={width:"100%","--n-height":"36px",fontSize:"15px",marginTop:"10px"},l=N.value?{...a,marginTop:"0"}:a;return i(c,{id:e.msgId,style:l,secondary:!0,class:"gradient",disabled:e.msgItem.disabled,onClick:async function(){var e;if(N.value){if(!j.value)return;try{R.value?null==(e=L.value)||e.validate((async e=>{var a,l;if(!e){const e=null==(l=(a=j.value).getFormValues)?void 0:l.call(a);Object.assign(e,{vaa05:R.value.selectedPatient.vaa01}),await J(t,e)}})):await J(t)}catch(e){}}else x("button-click")}},{default:()=>[N.value?null==t?void 0:t.text:q.buttonName]})}(t)))]:[i(E,{config:f(null==(t=q.settings)?void 0:t.setting)?JSON.parse(q.settings.setting):null,data:U,"onModule-click":F,"onButton-click":K},null),V()]])}}});export{I as default};
1
+ import{defineComponent as e,inject as t,ref as a,reactive as l,computed as n,watch as o,createVNode as i}from"vue";import{NForm as s,NFormItem as r,NInput as u,NIcon as d,NButton as c}from"naive-ui";import{InjectionAIChat as v}from"../types/index.js";import"../../../index.js";import{cloneDeep as p,isArray as m}from"lodash-es";import{isValidJSON as f}from"../utils/index.js";import{ChevronDown as g,ChevronForward as b}from"@vicons/ionicons5";import{useTheme as h}from"../../../../shared/hooks/useTheme.js";import"@vueuse/core";import"date-fns";import"@vue/shared";import"../../../../shared/utils/index.js";import"@vueuse/shared";import"../../../../shared/hooks/selectHooks/useSearchContent.js";import"../../../../shared/hooks/useScrollLoading.js";import y from"../../../form-render/index.js";import I from"../../../template-render/index.js";var E=e({name:"ChatCard",inheritAttrs:!1,props:{msgItem:{type:Object,default:()=>({})},selectParams:{type:Object},configs:{type:Object},msgId:{type:String}},emits:["button-click"],setup(e,{attrs:E,slots:k,emit:x}){const T={TEXT:"INPUT",NUMBER:"INPUT_NUMBER",DATETIME:"DATETIME-INPUT",MULTI_SELECT:"REMOTE_SEARCH",SELECT:"REMOTE_SEARCH"},_=h(),{patientInfo:C,state:P,axiosInstance:w,isSmall:O,appId:S}=t(v),j=a([]),R=a(),M=a(),L=l({vaa05:""}),N=a(),q=n((()=>{var t,a;return!!(null==(a=null==(t=e.msgItem)?void 0:t.content)?void 0:a.body)})),A=e.msgItem.content,U={},B=l(p(A.data||{})),F={beforeRequest(e,t,a){(null==t?void 0:t.params)&&(t.params.vaa05=M.value.selectedPatient.vaa01),t&&Reflect.has(t,"configs")&&(t.configs=M.value.selectedPatient)}};function K(e){const{eventName:t,data:a}=e;t&&x("button-click",{buttonInfo:a,isBI:!0})}function H(e){B[e.button.id+"Disabled"]="1",x("button-click",{buttonInfo:e.button})}function J(){var t;if(!M.value)return null;function a(){e.msgItem.disabled||(P.showPatient=!0)}return i(s,{class:"form-render",ref:N,"require-mark-placement":"left",disabled:e.msgItem.disabled,model:L,rules:{vaa05:{required:M.value.required,message:M.value.name+((null==(t=window.getLanguageByCode)?void 0:t.call(window,"10010.1.146"))||"为必填"),trigger:["input"]}}},{default:()=>[i(r,{label:M.value.name,path:"vaa05",class:"form-render__formItem",style:"--n-feedback-height: 16px; --n-feedback-padding: 0px; --n-feedback-font-size: 12px"},{default:()=>{var e;return[i(u,{style:"--n-text-color-disabled: #000; --n-placeholder-color-disabled: #000;--n-padding-left: 8px; --n-padding-right: 8px",readonly:!0,value:L.vaa05,placeholder:(null==(e=window.getLanguageByCode)?void 0:e.call(window,"10010.1.147"))||"请选择",onClick:a},{suffix:()=>i(d,{color:"#c2c2c2",component:g},null)})]}})]})}async function z(t,a){var l,n;try{const o=a||R.value.getFormValues();await(null==(l=R.value)?void 0:l.validate()),A.body.items.forEach((e=>{var t;"vaa05"===e.code?(e._value=P.selectedPatientLabel,e.value=M.value.selectedPatient.vaa01||e.value):o[e.code]&&(e.value=o[e.code]),(null==(t=U[e.code])?void 0:t[0])&&(e.options=U[e.code])})),P.loading=!0,x("button-click",{values:o,buttonInfo:t,patient:(null==(n=M.value)?void 0:n.selectedPatient)||e.configs,isForm:!0})}catch(e){P.loading=!1}}function D(e){const{fieldInstance:t,context:a,value:l,fieldKey:n}=e;"REMOTE_SEARCH"===t.componentType&&(null==l?void 0:l.length)&&(U[n]=[null==a?void 0:a.currentOption])}function V(){x("button-click",{showMore:!0})}function X(){var e;if("1834043761964638208"!==(null==(e=A.settings)?void 0:e.id)||!A.data)return null;const t=JSON.parse(A.settings.setting),a=e=>{var t;let l="";for(let n=0;n<e.length;n++){const o=e[n];if(o.setting.scopeKey){l=o.setting.scopeKey;break}if((null==(t=o.childrens)?void 0:t.length)&&(l=a(o.childrens),l))break}return l},l=a(t.templates);return!l||!f(A.data[l])||JSON.parse(A.data[l]).length<=5?null:(f(B[l])&&(B[l]=JSON.parse(B[l]).slice(0,5)),i(c,{block:!0,text:!0,"icon-placement":"right",color:_.value["--c-primary-color"],style:"margin-top: 10px",onClick:V},{icon:()=>i(d,{component:b},null),default:()=>"查看更多"}))}return q.value&&(j.value=(A.body.items||[]).map((t=>{var a,l,n;if("vaa05"===t.code&&!O.value)return M.value={...t},t._value?L.vaa05=t._value:(null==(a=t.options)?void 0:a.length)&&t.value&&(L.vaa05=null==(l=t.options.find((e=>e.value===t.value)))?void 0:l.label,M.value.selectedPatient=e.configs),null;const o={html_type:T[t.type]||t.type,val_key:t.code,name:t.name,elem_width:12,default_val:t.value,lazyRequest:!0,requestCache:!0,urlConfig:{nameKey:null!=(n=t.labelField)?n:"label"},option:[],is_null:t.required?"0":"1",is_edit:e.msgItem.disabled?"0":"1",componentProps:{},multi_select:"MULTI_SELECT"===t.type?"0":"1"};if("REMOTE_SEARCH"===o.html_type){if(o.componentProps={fallbackOption:!1},o.option=t.options||[],o.default_val=null,t.value&&m(t.options)&&t.options.length>0){t.options.find((e=>(null==e?void 0:e.value)===t.value))&&(o.default_val=t.value)}if(Object.assign(o.urlConfig,{url:"/flow/api/instruction/parameter/getOptionsValues",method:"post",params:{...e.selectParams,code:t.code,source:O.value?"inner":"global",...O.value?{appId:S.value}:{},configs:C.value.info||P.selectedPatient},dependKey:[]}),t.dependencies){const e=t.dependencies.split(",");o.urlConfig.dependKey=e,e.includes("vaa05")&&(o.urlConfig.params.params={vaa05:""})}}return o})).filter((e=>!!e))),o((()=>P.showPatient),(t=>{!e.msgItem.disabled&&q.value&&!t&&P.selectedPatientLabel&&M.value&&(L.vaa05=P.selectedPatientLabel,M.value.selectedPatient={...P.selectedPatientForm})})),()=>{var t;return i("div",{class:"card"},[q.value?[i("p",null,[A.title||A.header.title]),i("div",{class:"form-box"},[[J(),i(y,{"request-instance":{get:w.get,post:w.post},"life-cycle":F,column:12,ref:R,"field-list":j.value,onFormChange:D},null)]]),A.footer.buttons.map((t=>function(t){const a={width:"100%","--n-height":"36px",fontSize:"15px",marginTop:"10px"},l=q.value?{...a,marginTop:"0"}:a;return i(c,{id:e.msgId,style:l,secondary:!0,class:"gradient",disabled:e.msgItem.disabled,onClick:async function(){var e;if(q.value){if(!R.value)return;try{M.value?null==(e=N.value)||e.validate((async e=>{var a,l;if(!e){const e=null==(l=(a=R.value).getFormValues)?void 0:l.call(a);Object.assign(e,{vaa05:M.value.selectedPatient.vaa01}),await z(t,e)}})):await z(t)}catch(e){}}else x("button-click")}},{default:()=>[q.value?null==t?void 0:t.text:A.buttonName]})}(t)))]:[i(I,{config:f(null==(t=A.settings)?void 0:t.setting)?JSON.parse(A.settings.setting):null,data:B,"onModule-click":K,"onButton-click":H},null),X()]])}}});export{E as default};
@@ -28,6 +28,9 @@ export declare class Print {
28
28
  private postMessage;
29
29
  messageCollect(id: string, data: AnyObject): Promise<unknown>;
30
30
  messageCollectAndNotifyFail(id: string, data: AnyObject, messageTimeout: number): Promise<unknown>;
31
+ initConfigExec(): Promise<void>;
32
+ listenEvent(): void;
33
+ removeEvent(): void;
31
34
  destroy(): void;
32
35
  /**
33
36
  * @desc 调用实例方法打开弹窗
@@ -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 n,getFileUrl as a,useBrowserPrint as o}from"./browserPrint.js";import{getCurrentInstance as l}from"vue";import{uuidGenerator as c}from"../../../../shared/utils/index.js";import{format as d}from"date-fns";import{io as u}from"socket.io-client";const h=String(navigator.platform).toLowerCase().includes("linux"),p=t.create({timeout:6e4,withCredentials:!1}),m=`${window.location.protocol}//${window.location.host}`,g=`${m}/fdp-api/print/assembly/printIReport`,w=`${m}/bi-api/reprot/print/open/client/printIReportForBase64`,y=`${m}/bi-api/reprot/print/open/client/printIReportForHex`,f=`${m}/bi-api/reprot/print/open/client/previewIReport`,v=`${m}/bi-api/reprot/print/open/client/getRemote`,P=`${m}/printService/file`;let _=null;class I{constructor(){var t,e,i,n;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(((null==(n=window.getLanguageByCode)?void 0:n.call(window,"10010.1.494"))||"非封装浏览器或者")+e)}}}messageHandler(t){var e,i;if(console.log("打印事件message",t),!t)return this._handleMonitorNotify("接收到空的浏览器事件,"+t),console.log("当前回执",t,(null==(e=window.getLanguageByCode)?void 0:e.call(window,"10010.1.493"))||"接收到空的浏览器事件");let r;try{r=JSON.parse(t.data||"{}")}catch(e){console.log("解析e.data失败,"+e),this._handleMonitorNotify("解析e.data失败,"+t)}if(["print","pdf","resetprint"].includes(null==r?void 0:r.cmd)){console.log("打印命令执行了",r);const e=this.messageHandlerQueue.shift();if(!e)return console.log("当前回执",t,"没有可用的handler");const{resolve:i,reject:s}=e;try{if("resetprint"===(null==r?void 0:r.cmd))return void i({result:(null==r?void 0:r.res)?"success":"fail",message:(null==r?void 0:r.error)||""});i(r.res||"")}catch(t){s(t)}}else"config"===(null==r?void 0:r.exec)&&(this.downloadPath=(null==(i=r.res)?void 0:i.downloadpath)||"")}_initDomesticSystem(t){try{if(this.hiPrintSocket)return this.isConnectHiPrint;this.hiPrintSocket=u(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=>{p({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=>{p({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){var i;const r=n(t),s=this.getIReportFormatId(r,t);if(r&&(h||2==e)){return await this._testDomesticSystemConnection()?p({url:`${this.printDomesticOrigin}/resetPrint`,method:"get",withCredentials:!1,params:{formatId:s}}).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:(null==(i=window.getLanguageByCode)?void 0:i.call(window,"10010.1.496"))||"请开启ihoPrint客户端"}}return this.webview?this.postMessage({exec:"resetprint",data:{formatID:s}}):p({url:`${this.printOrigin}/services/printset`,method:"get",withCredentials:!1,params:{inputdata:s}}).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}}):p({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)}):p({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){var r;if(!t){const t=(null==(r=window.getLanguageByCode)?void 0:r.call(window,"10010.1.497"))||"打印命令返回空数据";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){var i;return!!t||(console.log("notInstalledApp"),null==e||e({type:"notInstalledApp",message:(null==(i=window.getLanguageByCode)?void 0:i.call(window,"10010.1.498"))||"请打开打印服务器插件",result:"error"}),!1)}async _handleEventQueryPrintData(t,e,i,r,s){const n={templateId:t,formatId:e,params:i,cmdid:"7",messageTimeout:r},a=await this._queryServicesPrint(n);return this._handleQueryPrintDataResult(a,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:n,print:a,signature:o,copies:l,printdlgshow:c="0",nobillnode:u="1",btnprint:h="1",messageTimeout:p=0}){const m={templateId:t,formatId:e,svrUpdateIp:i,params:r,cmdid:n,nobillnode:u,printdlgshow:c,btnprint:h,copies:l,messageTimeout:p,...o?{signature:o}:{}};if(s&&(m.paramsArr=s),a){try{a=JSON.parse(a)}catch(t){}m.print=a}else if(this.isRemote){const t=d(new Date,"yyyyMMddHHmmss");m.print={print:"1",type:"1",zip:"0",filename:`F:\\WorkSpace\\crmweb\\web\\${t}\\${t}`}}return this.queryServicesParams=m,await this._queryServicesPrint(m)}async _handleEventEditFormat({templateId:t,formatId:e="",params:i="",token:r,messageTimeout:s=0}){const n={};let a={};try{a=Object.assign({},n,JSON.parse(i))}catch(t){a=n}const o={templateId:t,formatId:e,cmdid:"9",token:r,params:JSON.stringify(a),messageTimeout:s};return await this._queryServicesPrint(o)}async _queryProxyOrigin(){if(this.isRemote)return;const{data:t}=await p({method:"get",url:v})||{},{map:e={}}=t;e.isRemote&&(this.printOrigin=m+"/printService",this.isRemote=!0)}async _queryPrintFile(t,e=""){const{data:i}=await p({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:n}=await p({method:"post",url:w,params:{id:t,formatId:e,params:this.paramsSerializer(s),authorizationKey:r}})||{};return n}async _queryPrintForBase16(t,e,i="",r){const s="object"==typeof i?i:JSON.parse(i),{data:n}=await p({method:"post",url:y,params:{id:t,formatId:e,params:this.paramsSerializer(s),authorizationKey:r}})||{};return n}async _queryPrintForPdf(t,e,i="",r){const s="object"==typeof i?i:JSON.parse(i),{data:n}=await p({method:"post",url:f,responseType:"blob",params:{id:t,formatId:e,params:this.paramsSerializer(s),authorizationKey:r}})||{};return n}async _browserPrint(t,e){if(this.isRemote){const{filedir:i}=t,r=JSON.parse(i)[0].replace(/\\/g,"/").split("/"),s=r[r.length-2],n=r[r.length-1],l=await a(`${P}/${s}/${n}`),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:a,signature:c,btnprint:d,messageTimeout:u=0},p,m){var g;const w=n(i),y=this.getIReportFormatId(w,i);if(w&&(h||2==t)){const t=await this._queryPrintForPdf(e,y,r,a);if(!t)return null==m?void 0:m({type:"queryPrintDataFailure",result:"error",message:"获取文件失败!"});const i=o(t,"preview");return this.instance||(this.instance=l()),this.showPreview(this.instance,i),null==p?void 0:p({result:"success",message:"",file:t})}await this._queryProxyOrigin();const f=await this._testConnection();if(!this._handleResultTest(f,m))return!1;try{const t=await this._handleEventDirect({templateId:e,formatId:y,params:r,paramsArr:s,cmdid:this.isRemote?"7":"8",signature:c,btnprint:d,messageTimeout:u}),i=this._handleResult(t,m);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==p||p(i)}catch(t){const e=(null==(g=window.getLanguageByCode)?void 0:g.call(window,"10010.1.499"))||"预览失败",i="timeout"===(null==t?void 0:t.type)?{...t,message:e,result:"error"}:{message:e,result:"error"};null==m||m(i),this._handleMonitorNotify(i)}}async printSync(t,e,i){var r,s;const n=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:n});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=(null==(r=window.getLanguageByCode)?void 0:r.call(window,"10010.1.500"))||"打印命令返回无效数据";this._handleMonitorNotify(s||""),null==i||i({type:"printError",message:t,result:"error",errinfo:t})}}catch(t){const e={error:t,result:"error",message:(null==(s=window.getLanguageByCode)?void 0:s.call(window,"10010.1.501"))||"打印失败"};null==i||i(e),this._handleMonitorNotify(e)}}async printDirect({iReportExecuteMode:t,templateId:e,formatId:i,params:r="",paramsArr:s,authorizationKey:a,print:o,signature:l,printdlgshow:c,nobillnode:d,copies:u,svrUpdateIp:p,isDownloadFile:m=!0,messageTimeout:g=0},w,y,f,v="printDirect"){var P,_,I;const b=n(i),S=this.getIReportFormatId(b,i);if(b&&(h||2==t)){if(!await this._testDomesticSystemConnection())return void y({type:"notInstalledApp",result:"error",message:(null==(P=window.getLanguageByCode)?void 0:P.call(window,"10010.1.496"))||"请开启ihoPrint客户端"});return void(this._initDomesticSystem((async t=>{var i;t?await this.printToHiPrint({templateId:e,formatId:S,params:r,authorizationKey:a},w,y,f):y({type:"notInstalledApp",result:"error",message:(null==(i=window.getLanguageByCode)?void 0:i.call(window,"10010.1.502"))||"连接ihoPrint客户端失败"})}))&&await this.printToHiPrint({templateId:e,formatId:S,params:r,authorizationKey:a},w,y,f))}await this._queryProxyOrigin();const C=await this._testConnection();if(!this._handleResultTest(C,y))return!1;try{const t=await this._handleEventDirect({templateId:e,formatId:S,params:r,paramsArr:s,cmdid:"7",print:o,signature:l,printdlgshow:c,nobillnode:d,copies:u,svrUpdateIp:p,messageTimeout:g}),i=this._handleResult(t,y,f);if(!i)return!1;m&&["downloadPDF"].includes(v)&&await this._browserPrint(i,v),null==w||w(i)}catch(t){const e="printDirect"===v?(null==(_=window.getLanguageByCode)?void 0:_.call(window,"10010.1.501"))||"打印失败":(null==(I=window.getLanguageByCode)?void 0:I.call(window,"10010.1.503"))||"下载失败",i="timeout"===(null==t?void 0:t.type)?{...t,message:e,result:"error"}:{message:e,result:"error"};null==y||y(i),this._handleMonitorNotify(i)}}async printToHiPrint({templateId:t,formatId:e,params:i,authorizationKey:r},s,n,a){const o=await this._queryPrintForBase64(t,e,i,r);if(!o.success)return n({message:o.resultMsg,result:"error"});const{base64:l,formatId:c}=o.map;this.base64Fragment=l,this._successCallbackFn=s,this._errorCallbackFn=n,a&&(this._cancelCallbackFn=a),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}}):p.get(this.printOrigin+"/download",{params:{inputData:t}}).then((({data:t})=>t))}async downloadPDF(t,r,s){var a;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=d(new Date,"yyyy-MM-dd"),e=c(),i=d(new Date,"yyyyMMddHHmmss")+e;o.print.filename=`${this.downloadPath}/${t}/${i}/${i}`.replace(/\\/g,"/")}const l=n(o.formatId);if(o.formatId=this.getIReportFormatId(l,o.formatId),l&&(h||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==(a=null==t?void 0:t.map)?void 0:a.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,n=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(n,t)}),(t=>s(t)),(t=>{console.log(t)}),"downloadPDF")}async print({templateId:t,formatId:e,params:i="",messageTimeout:r=0},s,n){const a=await this._testConnection();if(!this._handleResultTest(a,n))return!1;const o=await this.queryPrintData({templateId:t,formatId:e,params:i,messageTimeout:r},void 0,n);if(!o)return!1;const l=this.printFileData({formatId:e,file:o.file,printerName:o.printerName},void 0,n);if(!l)return!1;s&&s(l)}async queryPrintData({templateId:t,formatId:e,params:i="",messageTimeout:r=0},s,n){const a=await this._testConnection();if(!this._handleResultTest(a,n))return!1;const o=await this._handleEventQueryPrintData(t,e,i,r,n);return!!o&&(s&&s(o),o)}async printFileData({formatId:t,file:e,printerName:i="Default"},r,s){const n=await this._testConnection();if(!this._handleResultTest(n,s))return!1;const a=await this._callPrintWithFile({formatId:t,printname:i,file:e}),o=this._handleResult(a,s);return!!o&&(r&&r(o),o)}async editPrintFormat({templateId:t,formatId:e,params:i,token:r,messageTimeout:s=0},n,a){const o=await this._testConnection();if(!this._handleResultTest(o,a))return!1;const l=await this._handleEventEditFormat({templateId:t,formatId:e,params:i,token:r,messageTimeout:s}),c=this._handleResult(l,a);if(!c)return!1;n&&n(c)}async addPrintFormat({templateId:t,params:e,token:i},r,s){const n=await this._testConnection();if(!this._handleResultTest(n,s))return!1;const a=await this._handleEventEditFormat({templateId:t,params:e,token:i}),o=this._handleResult(a,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 s,PreviewDialog as r}from"./dialog.js";import{isIReport as n,getFileUrl as a,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 d}from"socket.io-client";const u=String(navigator.platform).toLowerCase().includes("linux"),m=t.create({timeout:6e4,withCredentials:!1}),p=`${window.location.protocol}//${window.location.host}`,g=`${p}/fdp-api/print/assembly/printIReport`,w=`${p}/bi-api/reprot/print/open/client/printIReportForBase64`,v=`${p}/bi-api/reprot/print/open/client/printIReportForHex`,y=`${p}/bi-api/reprot/print/open/client/previewIReport`,f=`${p}/bi-api/reprot/print/open/client/getRemote`,P=`${p}/printService/file`;let _=null;class I{constructor(){var t,e,i;if(this.webview=null,this.dialog=new s,this.dialogPreview=new r,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 n=window;this.CMonitor=n.$CMonitor;try{this.webview=n.top?null==(t=n.top.chrome)?void 0:t.webview:null==(e=n.chrome)?void 0:e.webview}catch(t){console.log(t),this.webview=null==(i=n.chrome)?void 0:i.webview}this.webview&&(this.currentMessageHandler=this.messageHandler.bind(this),this.initConfigExec())}messageHandler(t){var e,i;if(console.log("打印事件message",t),!t)return this._handleMonitorNotify("接收到空的浏览器事件,"+t),console.log("当前回执",t,(null==(e=window.getLanguageByCode)?void 0:e.call(window,"10010.1.493"))||"接收到空的浏览器事件");let s;try{s=JSON.parse(t.data||"{}")}catch(e){console.log("解析e.data失败,"+e),this._handleMonitorNotify("解析e.data失败,"+t)}if(["print","pdf","resetprint"].includes(null==s?void 0:s.cmd)){console.log("打印命令执行了",s);const e=this.messageHandlerQueue.shift();if(!e)return console.log("当前回执",t,"没有可用的handler");const{resolve:i,reject:r}=e;try{if("resetprint"===(null==s?void 0:s.cmd))return void i({result:(null==s?void 0:s.res)?"success":"fail",message:(null==s?void 0:s.error)||""});i(s.res||"")}catch(t){r(t)}}else"config"===(null==s?void 0:s.exec)&&(this.downloadPath=(null==(i=s.res)?void 0:i.downloadpath)||"")}_initDomesticSystem(t){try{if(this.hiPrintSocket)return this.isConnectHiPrint;this.hiPrintSocket=d(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,s)=>{this.messageHandlerQueue.push({resolve:i,reject:s,id:t}),this.webview.postMessage(e)}))}messageCollectAndNotifyFail(t,e,i){return Promise.race([new Promise(((i,s)=>{this.messageHandlerQueue.push({resolve:i,reject:s,id:t}),this.webview.postMessage(e)})),new Promise(((e,s)=>{setTimeout((()=>{const e=this.messageHandlerQueue.findIndex((e=>e.id===t));e>-1&&this.messageHandlerQueue.splice(e,1),s({type:"timeout"})}),i)}))])}async initConfigExec(){var t;try{this.listenEvent(),await this.postMessage({exec:"config",data:""}),this.removeEvent()}catch(e){const i="当前浏览器版本不支持获取配置接口";this._handleMonitorNotify(i),console.log(((null==(t=window.getLanguageByCode)?void 0:t.call(window,"10010.1.494"))||"非封装浏览器或者")+i),this.removeEvent()}}listenEvent(){this.webview&&this.currentMessageHandler&&this.webview.addEventListener("message",this.currentMessageHandler)}removeEvent(){this.webview&&this.currentMessageHandler&&this.webview.removeEventListener("message",this.currentMessageHandler)}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){var i;const s=n(t),r=this.getIReportFormatId(s,t);if(s&&(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:(null==(i=window.getLanguageByCode)?void 0:i.call(window,"10010.1.496"))||"请开启ihoPrint客户端"}}if(this.webview){this.listenEvent();const t=await this.postMessage({exec:"resetprint",data:{formatID:r}});return this.removeEvent(),t}return m({url:`${this.printOrigin}/services/printset`,method:"get",withCredentials:!1,params:{inputdata:r}}).then((({data:t})=>t))}async _queryServicesPrint(e){return this.webview?await 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))}async _queryBase64ServicesPrint(t){return this.webview?await this.postMessage({exec:"print",data:{inputData:t}}):m({url:this.printOrigin+"/services/Printqueue",method:"get",params:{inputData:JSON.stringify(t)}}).then((({data:t})=>t))}async _callPrintWithFile(t){const e={cmdid:"7",flag:"1"},i={inputData:JSON.stringify(Object.assign({},e,t))};return this.webview?await this.postMessage({exec:"print",data:s(i)}):m({url:this.printOrigin+"/PrintLocal",method:"post",data:i,transformRequest:[s]}).then((({data:t})=>t));function s(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){var s;if(!t){const t=(null==(s=window.getLanguageByCode)?void 0:s.call(window,"10010.1.497"))||"打印命令返回空数据";return this._handleMonitorNotify(""),this.removeEvent(),null==e||e({type:"printError",message:t,result:"error",errinfo:t}),!1}if("success"!==t.result){const s=t.message||t.Message;this._handleMonitorNotify(s);const r={type:"printError",message:s,result:t.result,errinfo:t.errinfo};return"cancel"==t.result?(this.removeEvent(),i&&i({type:"printCancel",message:s,result:t.result,errinfo:t.errinfo}),!1):(this.removeEvent(),null==e||e(r),!1)}return t}_handleResultTest(t,e){var i;return!!t||(console.log("notInstalledApp"),this.removeEvent(),null==e||e({type:"notInstalledApp",message:(null==(i=window.getLanguageByCode)?void 0:i.call(window,"10010.1.498"))||"请打开打印服务器插件",result:"error"}),!1)}async _handleEventQueryPrintData(t,e,i,s,r){const n={templateId:t,formatId:e,params:i,cmdid:"7",messageTimeout:s},a=await this._queryServicesPrint(n);return this._handleQueryPrintDataResult(a,e,r)}_handleQueryPrintDataResult(t,e,i){if(!(null==t?void 0:t.file)){try{const e=t.message||t.Message;console.log(e),this.removeEvent(),null==i||i({result:"error",type:"queryPrintDataFailure",message:e})}catch(t){this.removeEvent(),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:s,paramsArr:r,cmdid:n,print:a,signature:o,copies:l,printdlgshow:c="0",nobillnode:d="1",btnprint:u="1",messageTimeout:m=0}){const p={templateId:t,formatId:e,svrUpdateIp:i,params:s,cmdid:n,nobillnode:d,printdlgshow:c,btnprint:u,copies:l,messageTimeout:m,...o?{signature:o}:{}};if(r&&(p.paramsArr=r),a){try{a=JSON.parse(a)}catch(t){}p.print=a}else if(this.isRemote){const t=h(new Date,"yyyyMMddHHmmss");p.print={print:"1",type:"1",zip:"0",filename:`F:\\WorkSpace\\crmweb\\web\\${t}\\${t}`}}return this.queryServicesParams=p,await this._queryServicesPrint(p)}async _handleEventEditFormat({templateId:t,formatId:e="",params:i="",token:s,messageTimeout:r=0}){const n={};let a={};try{a=Object.assign({},n,JSON.parse(i))}catch(t){a=n}const o={templateId:t,formatId:e,cmdid:"9",token:s,params:JSON.stringify(a),messageTimeout:r};return await this._queryServicesPrint(o)}async _queryProxyOrigin(){if(this.isRemote)return;const{data:t}=await m({method:"get",url:f})||{},{map:e={}}=t;e.isRemote&&(this.printOrigin=p+"/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="",s){const r="object"==typeof i?i:JSON.parse(i),{data:n}=await m({method:"post",url:w,params:{id:t,formatId:e,params:this.paramsSerializer(r),authorizationKey:s}})||{};return n}async _queryPrintForBase16(t,e,i="",s){const r="object"==typeof i?i:JSON.parse(i),{data:n}=await m({method:"post",url:v,params:{id:t,formatId:e,params:this.paramsSerializer(r),authorizationKey:s}})||{};return n}async _queryPrintForPdf(t,e,i="",s){const r="object"==typeof i?i:JSON.parse(i),{data:n}=await m({method:"post",url:y,responseType:"blob",params:{id:t,formatId:e,params:this.paramsSerializer(r),authorizationKey:s}})||{};return n}async _browserPrint(t,e){if(this.isRemote){const{filedir:i}=t,s=JSON.parse(i)[0].replace(/\\/g,"/").split("/"),r=s[s.length-2],n=s[s.length-1],l=await a(`${P}/${r}/${n}`),c=o(null,e,l);if("preview"===e)return c}}_base64ToBlob(t,e){const i=window.atob(t);let s=i.length;const r=new Uint8Array(s);for(;s--;)r[s]=i.charCodeAt(s);return new Blob([r],{type:e})}async preview({iReportExecuteMode:t,templateId:e,formatId:i,params:s="",paramsArr:r,authorizationKey:a,signature:c,btnprint:h,messageTimeout:d=0},m,p){var g;const w=n(i),v=this.getIReportFormatId(w,i);if(w&&(u||2==t)){const t=await this._queryPrintForPdf(e,v,s,a);if(!t)return null==p?void 0:p({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})}this.listenEvent(),await this._queryProxyOrigin();const y=await this._testConnection();if(!this._handleResultTest(y,p))return!1;try{const t=await this._handleEventDirect({templateId:e,formatId:v,params:s,paramsArr:r,cmdid:this.isRemote?"7":"8",signature:c,btnprint:h,messageTimeout:d}),i=this._handleResult(t,p);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),this.removeEvent(),null==m||m(i)}catch(t){const e=(null==(g=window.getLanguageByCode)?void 0:g.call(window,"10010.1.499"))||"预览失败",i="timeout"===(null==t?void 0:t.type)?{...t,message:e,result:"error"}:{message:e,result:"error"};this.removeEvent(),null==p||p(i),this._handleMonitorNotify(i)}}async printSync(t,e,i){var s,r;const n=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(),r=await this.messageCollect(t,{exec:"printA",data:n});if(r&&Array.isArray(r)){r.some((t=>"success"===t.res.result))?null==e||e(r):(null==i||i(r),this._handleMonitorNotify(r))}else{const t=(null==(s=window.getLanguageByCode)?void 0:s.call(window,"10010.1.500"))||"打印命令返回无效数据";this._handleMonitorNotify(r||""),null==i||i({type:"printError",message:t,result:"error",errinfo:t})}}catch(t){const e={error:t,result:"error",message:(null==(r=window.getLanguageByCode)?void 0:r.call(window,"10010.1.501"))||"打印失败"};null==i||i(e),this._handleMonitorNotify(e)}}async printDirect({iReportExecuteMode:t,templateId:e,formatId:i,params:s="",paramsArr:r,authorizationKey:a,print:o,signature:l,printdlgshow:c,nobillnode:h,copies:d,svrUpdateIp:m,isDownloadFile:p=!0,messageTimeout:g=0},w,v,y,f="printDirect"){var P,_,I;const b=n(i),S=this.getIReportFormatId(b,i);if(b&&(u||2==t)){if(!await this._testDomesticSystemConnection())return void v({type:"notInstalledApp",result:"error",message:(null==(P=window.getLanguageByCode)?void 0:P.call(window,"10010.1.496"))||"请开启ihoPrint客户端"});return void(this._initDomesticSystem((async t=>{var i;t?await this.printToHiPrint({templateId:e,formatId:S,params:s,authorizationKey:a},w,v,y):v({type:"notInstalledApp",result:"error",message:(null==(i=window.getLanguageByCode)?void 0:i.call(window,"10010.1.502"))||"连接ihoPrint客户端失败"})}))&&await this.printToHiPrint({templateId:e,formatId:S,params:s,authorizationKey:a},w,v,y))}this.listenEvent(),await this._queryProxyOrigin();const C=await this._testConnection();if(!this._handleResultTest(C,v))return!1;try{const t=await this._handleEventDirect({templateId:e,formatId:S,params:s,paramsArr:r,cmdid:"7",print:o,signature:l,printdlgshow:c,nobillnode:h,copies:d,svrUpdateIp:m,messageTimeout:g}),i=this._handleResult(t,v,y);if(!i)return!1;p&&["downloadPDF"].includes(f)&&await this._browserPrint(i,f),this.removeEvent(),null==w||w(i)}catch(t){const e="printDirect"===f?(null==(_=window.getLanguageByCode)?void 0:_.call(window,"10010.1.501"))||"打印失败":(null==(I=window.getLanguageByCode)?void 0:I.call(window,"10010.1.503"))||"下载失败",i="timeout"===(null==t?void 0:t.type)?{...t,message:e,result:"error"}:{message:e,result:"error"};this.removeEvent(),null==v||v(i),this._handleMonitorNotify(i)}}async printToHiPrint({templateId:t,formatId:e,params:i,authorizationKey:s},r,n,a){const o=await this._queryPrintForBase64(t,e,i,s);if(!o.success)return n({message:o.resultMsg,result:"error"});const{base64:l,formatId:c}=o.map;this.base64Fragment=l,this._successCallbackFn=r,this._errorCallbackFn=n,a&&(this._cancelCallbackFn=a),this.hiPrintSocket.emit("news",{printerList:this.printerList,type:"askPrinterTemplate",markTemplateId:c,pdf_stream:this.base64Fragment})}async _downloadPDF(t){return this.webview?await this.postMessage({exec:"pdf",data:{file:t}}):m.get(this.printOrigin+"/download",{params:{inputData:t}}).then((({data:t})=>t))}async downloadPDF(t,s,r){var a;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=n(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)?s({filebase64:null==(a=null==t?void 0:t.map)?void 0:a.hex,isIreport:!0}):null==r?void 0:r({type:"queryPrintDataFailure",result:"error",message:"获取文件失败!"})}this.printDirect(o,(async t=>{t||r({result:"error",message:""}),this.listenEvent();const e=this,n=await async function(t){const s=[],r=JSON.parse(t);if(!i(r))return await e._downloadPDF("");if(1===r.length)return await e._downloadPDF(r[0]||"");for(let t=0,i=r.length;t<i;t++)s.push(await e._downloadPDF(r[t]||""));return s}(t.filedir);this.removeEvent(),s(n,t)}),(t=>r(t)),(t=>{console.log(t)}),"downloadPDF")}async print({templateId:t,formatId:e,params:i="",messageTimeout:s=0},r,n){const a=await this._testConnection();if(!this._handleResultTest(a,n))return!1;const o=await this.queryPrintData({templateId:t,formatId:e,params:i,messageTimeout:s},void 0,n);if(!o)return!1;const l=this.printFileData({formatId:e,file:o.file,printerName:o.printerName},void 0,n);if(!l)return!1;r&&r(l)}async queryPrintData({templateId:t,formatId:e,params:i="",messageTimeout:s=0},r,n){const a=await this._testConnection();if(this.listenEvent(),!this._handleResultTest(a,n))return!1;const o=await this._handleEventQueryPrintData(t,e,i,s,n);return!!o&&(this.removeEvent(),r&&r(o),o)}async printFileData({formatId:t,file:e,printerName:i="Default"},s,r){const n=await this._testConnection();if(this.listenEvent(),!this._handleResultTest(n,r))return!1;const a=await this._callPrintWithFile({formatId:t,printname:i,file:e}),o=this._handleResult(a,r);return!!o&&(this.removeEvent(),s&&s(o),o)}async editPrintFormat({templateId:t,formatId:e,params:i,token:s,messageTimeout:r=0},n,a){const o=await this._testConnection();if(this.listenEvent(),!this._handleResultTest(o,a))return!1;const l=await this._handleEventEditFormat({templateId:t,formatId:e,params:i,token:s,messageTimeout:r}),c=this._handleResult(l,a);if(!c)return!1;this.removeEvent(),n&&n(c)}async addPrintFormat({templateId:t,params:e,token:i},s,r){const n=await this._testConnection();if(this.listenEvent(),!this._handleResultTest(n,r))return!1;const a=await this._handleEventEditFormat({templateId:t,params:e,token:i}),o=this._handleResult(a,r);if(!o)return!1;this.removeEvent(),s&&s(o)}}export{I as Print};
@@ -1 +1 @@
1
- var e="@cnhis-design-vue/shared",i="3.2.15-beta.12",s="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.15-beta.12",private:!0,main:"index.ts",peerDependencies:n,dependencies:a};export{d as default,a as dependencies,s as main,e as name,n as peerDependencies,i as version};
1
+ var e="@cnhis-design-vue/shared",i="3.2.15-beta.14",s="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.15-beta.14",private:!0,main:"index.ts",peerDependencies:n,dependencies:a};export{d as default,a as dependencies,s as main,e as name,n as peerDependencies,i as version};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cnhis-design-vue",
3
- "version": "3.2.15-beta.12",
3
+ "version": "3.2.15-beta.14",
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": "b8a711b7f8cff1388b57de4ba789f0d7889dec41"
75
+ "gitHead": "12da9fbf3962a422034ae91a0b9e050d7fd2e4ec"
76
76
  }