cnhis-design-vue 3.2.10-release.1 → 3.2.10-release.2

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,42 +1,40 @@
1
1
  import { ComponentInternalInstance } from 'vue';
2
2
  import 'recorder-core/src/engine/mp3';
3
3
  import 'recorder-core/src/engine/mp3-engine';
4
- import { AnyObject } from '../../../shared/types';
5
4
  export default class AudioSDK {
5
+ static instance: AudioSDK | null;
6
+ static sendInterval: number;
7
+ private recordingModal;
8
+ private webSocket;
9
+ private messageHandlerQueue;
6
10
  private recorder;
7
- private recordingDialog;
8
11
  private contentRef;
9
- private realTimeRecognition;
10
- private allowPunctuationMark;
11
- private timed;
12
- private timer;
13
12
  private realTimeSendStartTime;
14
13
  private realTimeSendBytesChunks;
15
14
  private realTimeSendClearPrevBufferIdx;
16
- static instance: AudioSDK | null;
17
- static serverUrl: string;
18
- static sendInterval: number;
15
+ private timer;
16
+ private option;
17
+ private hasEventListener;
18
+ isReady: boolean;
19
19
  constructor();
20
- static create(option?: AnyObject): AudioSDK;
20
+ static create(): AudioSDK;
21
21
  private initRecorder;
22
- private takeoffEncodeChunk;
23
22
  private onProcess;
24
- private recorderOpen;
25
- recorderStart(instance: ComponentInternalInstance, { onStop, allowPunctuationMark, realTimeRecognition, timed }: {
26
- onStop: () => any;
23
+ private takeoffEncodeChunk;
24
+ run(instance: ComponentInternalInstance, handle: {
25
+ resolve: Function;
26
+ reject: Function;
27
+ }): void;
28
+ start(instance: ComponentInternalInstance, option?: {
27
29
  realTimeRecognition?: boolean;
28
30
  allowPunctuationMark?: boolean;
29
31
  timed?: number;
30
- }): Promise<{
31
- result: string;
32
- }>;
33
- recorderStop(): Promise<AnyObject>;
34
- private toAudioRecognition;
32
+ }): Promise<unknown>;
33
+ stop(): void;
34
+ private handleError;
35
+ private handleMessage;
36
+ private handleKeydown;
35
37
  private reset;
36
38
  destroy(): void;
37
- static audioRecognition(params: FormData): Promise<import("axios").AxiosResponse<any, any>>;
38
- static audioRevise(params: {
39
- file_id: string;
40
- audio_txt: string;
41
- }): Promise<import("axios").AxiosResponse<any, any>>;
39
+ static destroy(): void;
42
40
  }
@@ -1 +1 @@
1
- import{ref as e}from"vue";import t from"axios";import r from"recorder-core";import"recorder-core/src/engine/mp3";import"recorder-core/src/engine/mp3-engine";import{uuidGenerator as i}from"../../../shared/utils/index.js";import{RecordingDialog as s}from"./utils/recordingDialog.js";const n=class{constructor(){if(this.recorder=null,this.recordingDialog=new s,this.contentRef=e(""),this.realTimeRecognition=!1,this.allowPunctuationMark=!0,this.timed=0,this.timer=null,this.realTimeSendStartTime=0,this.realTimeSendBytesChunks=[],this.realTimeSendClearPrevBufferIdx=0,n.instance)return n.instance;n.instance=this}static create(e){return(null==e?void 0:e.serverUrl)&&(this.serverUrl=e.serverUrl),new n}initRecorder(){this.recorder=r({type:"mp3",sampleRate:16e3,bitRate:16,...this.realTimeRecognition?{onProcess:this.onProcess.bind(this),takeoffEncodeChunk:this.takeoffEncodeChunk.bind(this)}:{}})}async takeoffEncodeChunk(e){e&&this.realTimeSendBytesChunks.push(e);const t=Date.now();if(t-this.realTimeSendStartTime<n.sendInterval)return;this.realTimeSendStartTime=t;let r=0;for(let e=0;e<this.realTimeSendBytesChunks.length;e++)r+=this.realTimeSendBytesChunks[e].length;const i=new Uint8Array(r);for(let e=0,t=0;e<this.realTimeSendBytesChunks.length;e++){const r=this.realTimeSendBytesChunks[e];i.set(r,t),t+=r.length}if(this.realTimeSendBytesChunks=[],i.length>0){const e=new Blob([i],{type:"audio/mp3"}),{text:t}=await this.toAudioRecognition(e);this.contentRef.value+=t}}async onProcess(e,t,r,i,s){0===this.realTimeSendStartTime&&(this.realTimeSendStartTime=Date.now(),this.realTimeSendBytesChunks=[],this.realTimeSendClearPrevBufferIdx=0);for(let t=this.realTimeSendClearPrevBufferIdx;t<s;t++)e[t]=null;this.realTimeSendClearPrevBufferIdx=s}async recorderOpen(){return this.recorder||this.initRecorder(),new Promise(((e,t)=>{this.recorder.open((()=>{e({})}),((e,r)=>{t({result:"fail",msg:e,isUserNotAllow:r})}))}))}async recorderStart(e,{onStop:t,allowPunctuationMark:r=!0,realTimeRecognition:i=!1,timed:s=0}){this.realTimeRecognition=i,this.allowPunctuationMark=r,this.timed=1e3*s,this.timed&&(this.timer=setTimeout((()=>{t()}),this.timed));try{return await this.recorderOpen(),this.recorder.start(),this.recordingDialog.show(e,{contentRef:this.contentRef,after:()=>t()}),Promise.resolve({result:"success"})}catch(e){return Promise.reject(e)}}recorderStop(){return this.recorder?(this.recordingDialog.hide(),new Promise(((e,t)=>{if(this.realTimeRecognition){const t={file_id:"",text:this.contentRef.value};return e({result:"success",data:t}),void this.destroy()}this.recorder.stop((async(t,r)=>{const i=await this.toAudioRecognition(t);e({result:"success",duration:r,data:i}),this.destroy()}),(e=>{t({result:"fail",msg:e}),this.destroy()}))}))):Promise.reject({result:"fail",msg:"请先打开麦克风录音"})}async toAudioRecognition(e){var t;const r=new File([e],`${i()}.mp3`,{type:e.type}),s=new FormData;s.append("audio",r);const o={file_id:"",text:""};try{const{data:e}=await n.audioRecognition(s);!this.allowPunctuationMark&&"success"===e.msg&&(null==(t=e.data)?void 0:t.text)&&(e.data.text=e.data.text.replace(/[??,。,.\s]/g,""),Object.assign(o,e.data))}catch(e){console.log(e)}return o}reset(){this.realTimeSendStartTime=0,this.contentRef.value="",this.timer&&(clearTimeout(this.timer),this.timer=null),this.timed=0}destroy(){var e;null==(e=this.recorder)||e.close(),this.recorder=null,this.reset()}static async audioRecognition(e){return await t.post(`${this.serverUrl}/audio/recognition`,e,{headers:{"Content-Type":"multipart/form-data"}})}static async audioRevise(e){return await t.post(`${this.serverUrl}/audio/revise`,e)}};let o=n;o.serverUrl="",o.sendInterval=1500;export{o as default};
1
+ import{ref as e}from"vue";import t from"recorder-core";import"recorder-core/src/engine/mp3";import"recorder-core/src/engine/mp3-engine";import{RecordingModal as s}from"./utils/recordingModal.js";const i=class{constructor(){if(this.recordingModal=new s,this.webSocket=null,this.messageHandlerQueue=[],this.recorder=null,this.contentRef=e(""),this.realTimeSendStartTime=0,this.realTimeSendBytesChunks=[],this.realTimeSendClearPrevBufferIdx=0,this.timer=null,this.option={},this.hasEventListener=!1,this.isReady=!1,i.instance)return i.instance;i.instance=this}static create(){return new i}initRecorder(){this.recorder=t({type:"mp3",sampleRate:16e3,bitRate:16,...this.option.realTimeRecognition?{onProcess:this.onProcess.bind(this),takeoffEncodeChunk:this.takeoffEncodeChunk.bind(this)}:{}})}async onProcess(e,t,s,i,r){0===this.realTimeSendStartTime&&(this.realTimeSendStartTime=Date.now(),this.realTimeSendBytesChunks=[],this.realTimeSendClearPrevBufferIdx=0);for(let t=this.realTimeSendClearPrevBufferIdx;t<r;t++)e[t]=null;this.realTimeSendClearPrevBufferIdx=r}async takeoffEncodeChunk(e){var t;e&&this.realTimeSendBytesChunks.push(e);const s=Date.now();if(s-this.realTimeSendStartTime<i.sendInterval)return;this.realTimeSendStartTime=s;let r=0;for(let e=0;e<this.realTimeSendBytesChunks.length;e++)r+=this.realTimeSendBytesChunks[e].length;const n=new Uint8Array(r);for(let e=0,t=0;e<this.realTimeSendBytesChunks.length;e++){const s=this.realTimeSendBytesChunks[e];n.set(s,t),t+=s.length}if(this.realTimeSendBytesChunks=[],n.length>0){const e=new Blob([n],{type:"audio/wav"});null==(t=this.webSocket)||t.send(e)}}run(e,t){this.recorder||this.initRecorder(),this.messageHandlerQueue.push(t),this.option.timed&&(this.timer=setTimeout((()=>{this.stop()}),1e3*this.option.timed)),this.recorder.open((()=>{this.recorder.start(),this.recordingModal.show(e,{contentRef:this.contentRef,onClose:()=>this.stop()})}),((e,t)=>{this.handleError({msg:e,isUserNotAllow:t})}))}start(e,t={}){return Object.assign(this.option,t),new Promise(((t,s)=>{if(this.messageHandlerQueue.length>0)return void s({result:"fail",msg:"当前已存在正在录音的任务"});if(this.hasEventListener||(document.addEventListener("keydown",this.handleKeydown),this.hasEventListener=!0),!this.webSocket)return this.webSocket=new WebSocket("wss://emr-tl.cnhis.com/audio/socket"),this.webSocket.onopen=()=>{this.isReady=!0,this.run(e,{resolve:t,reject:s})},this.webSocket.onmessage=this.handleMessage.bind(this),this.webSocket.onerror=()=>console.log("WebSocket连接失败"),void(this.webSocket.binaryType="blob");const i=this;!async function r(n=0){if(n>5)return s({result:"fail",msg:"WebSocket连接失败"});i.isReady?i.run(e,{resolve:t,reject:s}):setTimeout((()=>{r(++n)}),100)}()}))}stop(){if(this.recordingModal.hide(),this.option.realTimeRecognition){const e=this.messageHandlerQueue.shift();if(!e)return;const{resolve:t,reject:s}=e;t({result:"success",data:{text:this.contentRef.value}}),this.reset()}else this.recorder.stop((async(e,t)=>{var s;null==(s=this.webSocket)||s.send(e)}),(e=>{this.handleError({msg:e})}),!0)}handleError(e){const t=this.messageHandlerQueue.shift();if(!t)return;const{resolve:s,reject:i}=t;i({result:"fail",...e}),this.reset()}handleMessage(e){const{data:t}=e||{};if(!function(e){try{return JSON.parse(e),!0}catch(e){return!1}}(t))return void this.handleError({msg:"接收数据不是一个有效SJON"});const s=JSON.parse(t);if("success"===s.msg)if(this.option.realTimeRecognition)this.contentRef.value+=s.data.text.replace(/[??,。,.\s]/g,"");else{const e=this.messageHandlerQueue.shift();if(!e)return;const{resolve:t,reject:i}=e;t({result:"success",data:s.data.text.replace(/[??,。,.\s]/g,"")}),this.reset()}else this.handleError({msg:s.msg})}handleKeydown(e){var t,s,r,n;if(" "===e.key||"Space"===e.code){if(!(null==(s=null==(t=i.instance)?void 0:t.recordingModal)?void 0:s.rendered)||0===(null==(r=i.instance)?void 0:r.messageHandlerQueue.length))return;e.preventDefault(),null==(n=i.instance)||n.stop()}}reset(){var e;null==(e=this.recorder)||e.close(),this.realTimeSendStartTime=0,this.contentRef.value="",this.timer&&(clearTimeout(this.timer),this.timer=null),this.option={realTimeRecognition:!1,allowPunctuationMark:!0,timed:5},this.messageHandlerQueue=[]}destroy(){this.webSocket&&(this.webSocket.close(),this.webSocket=null,this.isReady=!1),document.removeEventListener("keydown",this.handleKeydown),this.hasEventListener=!1,this.reset(),this.recorder=null}static destroy(){i.instance&&(i.instance.destroy(),i.instance=null)}};let r=i;r.sendInterval=1500;export{r as default};
@@ -1,8 +1,4 @@
1
1
  declare const _default: import("vue").DefineComponent<{
2
- visible: {
3
- type: BooleanConstructor;
4
- default: boolean;
5
- };
6
2
  content: {
7
3
  type: StringConstructor;
8
4
  default: string;
@@ -10,32 +6,26 @@ declare const _default: import("vue").DefineComponent<{
10
6
  }, {
11
7
  cssVars: import("vue").ComputedRef<import("../../../../shared/types").AnyObject>;
12
8
  props: Readonly<import("@vue/shared").LooseRequired<Readonly<import("vue").ExtractPropTypes<{
13
- visible: {
14
- type: BooleanConstructor;
15
- default: boolean;
16
- };
17
9
  content: {
18
10
  type: StringConstructor;
19
11
  default: string;
20
12
  };
21
- }>> & {}>>;
22
- showModal: import("vue").Ref<boolean>;
23
- handleKeydown: (event: KeyboardEvent) => void;
13
+ }>> & {
14
+ onClose?: ((...args: any[]) => any) | undefined;
15
+ }>>;
16
+ emit: (event: "close", ...args: any[]) => void;
24
17
  close: () => void;
25
18
  NModal: any;
26
19
  NIcon: any;
27
20
  Mic: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, import("vue").EmitsOptions, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{}>>, {}>;
28
- }, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{
29
- visible: {
30
- type: BooleanConstructor;
31
- default: boolean;
32
- };
21
+ }, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, "close"[], "close", import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{
33
22
  content: {
34
23
  type: StringConstructor;
35
24
  default: string;
36
25
  };
37
- }>>, {
38
- visible: boolean;
26
+ }>> & {
27
+ onClose?: ((...args: any[]) => any) | undefined;
28
+ }, {
39
29
  content: string;
40
30
  }>;
41
31
  export default _default;
@@ -0,0 +1 @@
1
+ import r from"./recording.vue2.js";import e from"../../../../_virtual/_plugin-vue_export-helper.js";var o=e(r,[["__file","recording.vue"]]);export{o as default};
@@ -0,0 +1 @@
1
+ import{defineComponent as o,openBlock as e,createBlock as s,unref as t,normalizeStyle as r,withCtx as i,createElementVNode as n,toDisplayString as c,createVNode as a}from"vue";import{NModal as p,NIcon as l}from"naive-ui";import{Mic as m}from"@vicons/ionicons5";import{useTheme as u}from"../../../../shared/hooks/useTheme.js";import"@vueuse/core";import"date-fns";import"lodash-es";import"@vue/shared";import"../../../../shared/utils/index.js";import"@vueuse/shared";import"../../../../shared/hooks/selectHooks/useSearchContent.js";import"../../../../shared/hooks/useScrollLoading.js";const d={class:"c-recording-wrapper"},f={class:"content"},h=n("div",{class:"animation"},null,-1),v=n("p",{class:"tip"},"按下空格键停止录音",-1);var k=o({__name:"recording",props:{content:{type:String,default:""}},emits:["close"],setup(o,{emit:k}){const g=u();function j(){k("close")}return(u,k)=>(e(),s(t(p),{style:r(t(g))},{default:i((()=>[n("div",d,[n("p",f,c(o.content||"正在聆听..."),1),h,n("div",{class:"icon-box",onClick:j},[a(t(l),{size:"60",color:"#fff",component:t(m)},null,8,["component"])]),v])])),_:1},8,["style"]))}});export{k as default};
@@ -0,0 +1,10 @@
1
+ import { ComponentInternalInstance, Ref } from 'vue';
2
+ export declare class RecordingModal {
3
+ rendered: boolean;
4
+ target: HTMLElement | null;
5
+ show(instance: ComponentInternalInstance, { contentRef, onClose }: {
6
+ contentRef: Ref<string>;
7
+ onClose: () => void;
8
+ }): void;
9
+ hide(): void;
10
+ }
@@ -0,0 +1 @@
1
+ import{ref as e,render as t,createVNode as n,withCtx as r,nextTick as o}from"vue";import{createProviderWrapper as s}from"../../../../shared/utils/index.js";import l from"../components/recording.vue.js";class i{constructor(){this.rendered=!1,this.target=null}show(i,{contentRef:d,onClose:a}){if(this.rendered)return;this.rendered=!0;const u=document.createElement("div"),h=e(!1),c=s(i);t(n(c,null,{default:r((()=>n(l,{to:u,content:d.value,show:h.value,"onUpdate:show":e=>h.value=e,onClose:()=>p(),onAfterLeave:()=>p()},null)),i)}),u);const m=this;var v;function p(){a()}v=u,document.body.appendChild(v),m.target=v,o((()=>h.value=!0))}hide(){var e;(null==(e=this.target)?void 0:e.parentElement)&&(this.rendered=!1,this.target.parentElement.removeChild(this.target),this.target=null)}}export{i as RecordingModal};
@@ -1 +1 @@
1
- var e="@cnhis-design-vue/shared",s="3.2.10-release.1",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.10-release.1",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};
1
+ var e="@cnhis-design-vue/shared",s="3.2.10-release.2",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.10-release.2",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.10-release.1",
3
+ "version": "3.2.10-release.2",
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": "c8e4970272f877aeba86a447b77801ddaa22362f"
75
+ "gitHead": "41b7974fd07cbe8e3852c3a2f037b983a1bd0ae2"
76
76
  }
@@ -1 +0,0 @@
1
- import r from"./recordingDialog.vue2.js";import e from"../../../../_virtual/_plugin-vue_export-helper.js";var o=e(r,[["__file","recordingDialog.vue"]]);export{o as default};
@@ -1 +0,0 @@
1
- import{defineComponent as e,ref as o,onMounted as s,watch as t,openBlock as n,createBlock as i,unref as r,normalizeStyle as a,withCtx as c,createElementVNode as l,toDisplayString as p,createVNode as u}from"vue";import{NModal as d,NIcon as m}from"naive-ui";import{Mic as v}from"@vicons/ionicons5";import{useTheme as f}from"../../../../shared/hooks/useTheme.js";import"@vueuse/core";import"date-fns";import"lodash-es";import"@vue/shared";import"../../../../shared/utils/index.js";import"@vueuse/shared";import"../../../../shared/hooks/selectHooks/useSearchContent.js";import"../../../../shared/hooks/useScrollLoading.js";const h={class:"c-recording-wrapper"},k={class:"content"},y=l("div",{class:"animation"},null,-1),w=l("p",{class:"tip"},"按下空格键停止录音",-1);var g=e({__name:"recordingDialog",props:{visible:{type:Boolean,default:!1},content:{type:String,default:""}},setup(e){const g=e,j=f(),S=o(!0);function b(e){" "!==e.key&&"Space"!==e.code||(e.preventDefault(),x())}function x(){S.value=!1,document.removeEventListener("keydown",b)}return s((()=>{document.addEventListener("keydown",b)})),t((()=>g.visible),(e=>{S.value=e})),(o,s)=>(n(),i(r(d),{show:S.value,"onUpdate:show":s[0]||(s[0]=e=>S.value=e),style:a(r(j)),onEsc:x,onMaskClick:x},{default:c((()=>[l("div",h,[l("p",k,p(e.content||"正在聆听..."),1),y,l("div",{class:"icon-box",onClick:x},[u(r(m),{size:"60",color:"#fff",component:r(v)},null,8,["component"])]),w])])),_:1},8,["show","style"]))}});export{g as default};
@@ -1,11 +0,0 @@
1
- import { ComponentInternalInstance, Ref } from 'vue';
2
- export declare class RecordingDialog {
3
- rendered: boolean;
4
- target: HTMLElement | null;
5
- static createMsg(message: string): string;
6
- show(instance: ComponentInternalInstance, { contentRef, after }: {
7
- contentRef: Ref<string>;
8
- after: () => void;
9
- }): Promise<string>;
10
- hide(): void;
11
- }
@@ -1 +0,0 @@
1
- import{ref as e,render as t,createVNode as r,withCtx as n,nextTick as i}from"vue";import{createProviderWrapper as s}from"../../../../shared/utils/index.js";import o from"../components/recordingDialog.vue.js";class a{constructor(){this.rendered=!1,this.target=null}static createMsg(e){return`[PreviewDialog] ${e}`}show(l,{contentRef:d,after:u}){return this.rendered?Promise.reject(a.createMsg("请勿重复打开弹窗")):new Promise(((a,c)=>{this.rendered=!0;const h=document.createElement("div"),m=e(!1),v=s(l);t(r(v,null,{default:n((()=>r(o,{to:h,content:d.value,visible:m.value,onAfterLeave:()=>function(e){if(!e.parentElement)return;g.hide(),u(),a("success")}(h)},null)),l)}),h);const g=this;var p;p=h,document.body.appendChild(p),g.target=p,i((()=>m.value=!0))}))}hide(){var e;(null==(e=this.target)?void 0:e.parentElement)&&(this.rendered=!1,this.target.parentElement.removeChild(this.target),this.target=null)}}export{a as RecordingDialog};