cnhis-design-vue 3.3.1-beta.6 → 3.3.1-beta.7
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{ref as e,nextTick as t}from"vue";import i from"recorder-core";import"recorder-core/src/engine/mp3";import"recorder-core/src/engine/mp3-engine";import{RecordingModal as s}from"./utils/recordingModal.js";import n from"axios";import{isString as r}from"lodash-es";const o=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.loading=!1,this.isReady=!1,o.instance)return o.instance;o.instance=this}static create(){return new o}initRecorder(){this.recorder=i({type:"mp3",sampleRate:16e3,bitRate:16,...this.option.realTimeRecognition?{onProcess:this.onProcess.bind(this),takeoffEncodeChunk:this.takeoffEncodeChunk.bind(this)}:{}})}async onProcess(e,t,i,s,n){0===this.realTimeSendStartTime&&(this.realTimeSendStartTime=Date.now(),this.realTimeSendBytesChunks=[],this.realTimeSendClearPrevBufferIdx=0);for(let t=this.realTimeSendClearPrevBufferIdx;t<n;t++)e[t]=null;this.realTimeSendClearPrevBufferIdx=n}async takeoffEncodeChunk(e){e&&this.realTimeSendBytesChunks.push(e);const t=Date.now();if(t-this.realTimeSendStartTime<o.sendInterval)return;this.realTimeSendStartTime=t;let i=0;for(let e=0;e<this.realTimeSendBytesChunks.length;e++)i+=this.realTimeSendBytesChunks[e].length;const s=new Uint8Array(i);for(let e=0,t=0;e<this.realTimeSendBytesChunks.length;e++){const i=this.realTimeSendBytesChunks[e];s.set(i,t),t+=i.length}if(this.realTimeSendBytesChunks=[],s.length>0){const e=new Blob([s],{type:"audio/mp3"});this.toSend(e)}}toSend(e){if((null==e?void 0:e.size)>0){const t=new FileReader;t.onloadend=()=>{var e,i;const s=null==(e=t.result)?void 0:e.toString().split(",")[1];s&&(null==(i=this.webSocket)||i.send(JSON.stringify({data:s})))},t.readAsDataURL(e)}}run(e){this.recorder||this.initRecorder(),this.messageHandlerQueue.push(e),this.option.timed&&(this.timer=setTimeout((()=>{this.stop()}),1e3*this.option.timed)),this.recorder.open((()=>{this.recorder.start(),this.recordingModal.show({instance:this.option.instance,onClose:()=>this.stop(),toEdit:()=>this.toEdit(),props:{contentRef:this.contentRef,showBtn:this.option.isGenerateMedicalRecord}})}),((e,t)=>{this.handleError({msg:e,isUserNotAllow:t})}))}start(e={}){return Object.assign(this.option,e),new Promise(((e,t)=>{if(this.messageHandlerQueue.length>0)return void t({result:"fail",msg:"当前已存在正在录音的任务"});if(this.hasEventListener||(document.addEventListener("keydown",this.handleKeydown),this.hasEventListener=!0),!this.webSocket)return this.webSocket=new WebSocket(this.option.origin||"/flow/ws/speech"),this.webSocket.onopen=()=>{this.isReady=!0,this.run({resolve:e,reject:t})},this.webSocket.onmessage=this.handleMessage.bind(this),void(this.webSocket.onerror=()=>console.log("WebSocket连接失败"));const i=this;!async function s(n=0){if(n>5)return t({result:"fail",msg:"WebSocket连接失败"});i.isReady?i.run({resolve:e,reject:t}):setTimeout((()=>{s(++n)}),100)}()}))}stop(){if(this.recordingModal.hide(),this.option.realTimeRecognition){const e=this.messageHandlerQueue.shift();if(!e)return;const{resolve:t,reject:i}=e;t({result:"success",data:this.contentRef.value}),this.reset()}else this.recorder.stop((async(e,t)=>{this.toSend(e)}),(e=>{this.handleError({msg:e})}),!0)}async toEdit(){var e;try{this.loading=!0,null==(e=this.recorder)||e.
|
1
|
+
import{ref as e,nextTick as t}from"vue";import i from"recorder-core";import"recorder-core/src/engine/mp3";import"recorder-core/src/engine/mp3-engine";import{RecordingModal as s}from"./utils/recordingModal.js";import n from"axios";import{isString as r}from"lodash-es";const o=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.loading=!1,this.isReady=!1,o.instance)return o.instance;o.instance=this}static create(){return new o}initRecorder(){this.recorder=i({type:"mp3",sampleRate:16e3,bitRate:16,...this.option.realTimeRecognition?{onProcess:this.onProcess.bind(this),takeoffEncodeChunk:this.takeoffEncodeChunk.bind(this)}:{}})}async onProcess(e,t,i,s,n){0===this.realTimeSendStartTime&&(this.realTimeSendStartTime=Date.now(),this.realTimeSendBytesChunks=[],this.realTimeSendClearPrevBufferIdx=0);for(let t=this.realTimeSendClearPrevBufferIdx;t<n;t++)e[t]=null;this.realTimeSendClearPrevBufferIdx=n}async takeoffEncodeChunk(e){e&&this.realTimeSendBytesChunks.push(e);const t=Date.now();if(t-this.realTimeSendStartTime<o.sendInterval)return;this.realTimeSendStartTime=t;let i=0;for(let e=0;e<this.realTimeSendBytesChunks.length;e++)i+=this.realTimeSendBytesChunks[e].length;const s=new Uint8Array(i);for(let e=0,t=0;e<this.realTimeSendBytesChunks.length;e++){const i=this.realTimeSendBytesChunks[e];s.set(i,t),t+=i.length}if(this.realTimeSendBytesChunks=[],s.length>0){const e=new Blob([s],{type:"audio/mp3"});this.toSend(e)}}toSend(e){if((null==e?void 0:e.size)>0){const t=new FileReader;t.onloadend=()=>{var e,i;const s=null==(e=t.result)?void 0:e.toString().split(",")[1];s&&(null==(i=this.webSocket)||i.send(JSON.stringify({data:s})))},t.readAsDataURL(e)}}run(e){this.recorder||this.initRecorder(),this.messageHandlerQueue.push(e),this.option.timed&&(this.timer=setTimeout((()=>{this.stop()}),1e3*this.option.timed)),this.recorder.open((()=>{this.recorder.start(),this.recordingModal.show({instance:this.option.instance,onClose:()=>this.stop(),toEdit:()=>this.toEdit(),props:{contentRef:this.contentRef,showBtn:this.option.isGenerateMedicalRecord}})}),((e,t)=>{this.handleError({msg:e,isUserNotAllow:t})}))}start(e={}){return Object.assign(this.option,e),new Promise(((e,t)=>{if(this.messageHandlerQueue.length>0)return void t({result:"fail",msg:"当前已存在正在录音的任务"});if(this.hasEventListener||(document.addEventListener("keydown",this.handleKeydown),this.hasEventListener=!0),!this.webSocket)return this.webSocket=new WebSocket(this.option.origin||"/flow/ws/speech"),this.webSocket.onopen=()=>{this.isReady=!0,this.run({resolve:e,reject:t})},this.webSocket.onmessage=this.handleMessage.bind(this),void(this.webSocket.onerror=()=>console.log("WebSocket连接失败"));const i=this;!async function s(n=0){if(n>5)return t({result:"fail",msg:"WebSocket连接失败"});i.isReady?i.run({resolve:e,reject:t}):setTimeout((()=>{s(++n)}),100)}()}))}stop(){if(this.recordingModal.hide(),this.option.realTimeRecognition){const e=this.messageHandlerQueue.shift();if(!e)return;const{resolve:t,reject:i}=e;t({result:"success",data:this.contentRef.value}),this.reset()}else this.recorder.stop((async(e,t)=>{this.toSend(e)}),(e=>{this.handleError({msg:e})}),!0)}async toEdit(){var e;try{this.timer&&(clearTimeout(this.timer),this.timer=null),this.loading=!0,null==(e=this.recorder)||e.close();const i=l(this.option.medicalTemplateInfo||[]),{data:s}=await n.post("/flow/openApi/consultationRecord",{taskId:1,audioText:this.contentRef.value,medicalTemplateInfo:i},{headers:{Authorization:`bearer ${this.option.token}`}});this.loading=!1,this.recordingModal.hide(),await t(),this.recordingModal.show({modalType:"form",instance:this.option.instance,onClose:()=>this.stop(),createMedicalRecord:e=>this.createMedicalRecord(e),props:{configs:i,data:(null==s?void 0:s.data)||{}}})}catch(e){this.handleError({msg:"请求错误"})}finally{this.loading=!1}}createMedicalRecord(e){var t;null==(t=this.recordingModal)||t.hide();const i=this.messageHandlerQueue.shift();if(!i)return;const{resolve:s,reject:n}=i;s({result:"success",data:this.contentRef.value,medicalTemplateInfo:h(e,this.option.medicalTemplateInfo||[])}),this.reset()}handleError(e){const t=this.messageHandlerQueue.shift();if(!t)return;const{resolve:i,reject:s}=t;s({result:"fail",...e}),this.reset()}handleMessage(e){const{data:t}=e||{};if(r(t))if(this.option.realTimeRecognition){const e=this.option.allowPunctuationMark?t:t.replace(/[??,。,.\s]/g,"");this.contentRef.value+=e}else{const e=this.messageHandlerQueue.shift();if(!e)return;const{resolve:i,reject:s}=e;i({result:"success",data:this.option.allowPunctuationMark?t:t.replace(/[??,。,.\s]/g,"")}),this.reset()}else this.handleError({msg:"接收到的数据不是一个有效字符串"})}handleKeydown(e){var t,i,s,n,r,a,l;if(" "===e.key||"Space"===e.code){if(console.log("空格 ==>",null==(t=o.instance)?void 0:t.loading),!(null==(s=null==(i=o.instance)?void 0:i.recordingModal)?void 0:s.rendered)||"recording"!==(null==(n=o.instance)?void 0:n.recordingModal.modalType)||(null==(r=o.instance)?void 0:r.loading)||0===(null==(a=o.instance)?void 0:a.messageHandlerQueue.length))return;e.preventDefault(),null==(l=o.instance)||l.stop()}}reset(){var e;null==(e=this.recorder)||e.close(),this.realTimeSendStartTime=0,this.contentRef.value="",this.timer&&(clearTimeout(this.timer),this.timer=null),Object.assign(this.option,{realTimeRecognition:!1,allowPunctuationMark:!0,timed:5,isGenerateMedicalRecord:!1}),this.messageHandlerQueue=[],this.loading=!1}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(){o.instance&&(o.instance.destroy(),o.instance=null)}};let a=o;function l(e){return e.reduce(((e,t)=>{var i;return(null==(i=t.children)?void 0:i.length)?Object.assign(e,l(t.children)):e[t.innerIdentifier||t.dataId]=t.elementName,e}),{})}function h(e,t=[]){const i=[];return t.forEach((t=>{var s;if(null==(s=t.children)?void 0:s.length){const s={...t,children:h(e,t.children)};i.push(s)}else i.push({...t,text:e[t.innerIdentifier||t.dataId]})})),i}a.sendInterval=2e3;export{a as default};
|
@@ -1 +1 @@
|
|
1
|
-
import{createElementVNode as e,defineComponent as o,ref as
|
1
|
+
import{createElementVNode as e,defineComponent as o,ref as s,openBlock as t,createBlock as n,unref as i,normalizeStyle as r,withCtx as l,createElementBlock as a,Fragment as c,toDisplayString as d,createVNode as p,createTextVNode as u,createCommentVNode as m}from"vue";import{NModal as f,NSpin as v,NIcon as h,NButton as k}from"naive-ui";import{Mic as y}from"@vicons/ionicons5";import{useTheme as g}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";var w;const C={class:"c-recording-wrapper"},_={class:"content"},j=e("p",null,(null==(w=window.getLanguageByCode)?void 0:w.call(window,"10010.1.141"))||"按下空格键停止录音",-1),B={key:0,class:"btns"};var b=o({__name:"recording",props:{content:{type:String,default:""},showBtn:{type:Boolean}},emits:["close","edit"],setup(o,{emit:w}){const b=g(),x=s(!1);function S(){w("close")}function L(){x.value=!0,w("edit")}return(s,g)=>(t(),n(i(f),{style:r(i(b)),"close-on-esc":!1,"mask-closable":!1},{default:l((()=>[e("div",C,[x.value?(t(),n(i(v),{key:0,description:"加载中..."})):(t(),a(c,{key:1},[e("p",_,d(o.content||"正在聆听..."),1),e("div",{class:"icon-box",onClick:S},[p(i(h),{size:"60",color:"#fff",component:i(y)},null,8,["component"])]),j,o.showBtn?(t(),a("div",B,[p(i(k),{type:"primary",onClick:L},{default:l((()=>[u("结束录音")])),_:1}),p(i(k),{onClick:S},{default:l((()=>[u("取消录音")])),_:1})])):m("v-if",!0)],64))])])),_:1},8,["style"]))}});export{b as default};
|
@@ -1 +1 @@
|
|
1
|
-
var e="@cnhis-design-vue/shared",i="3.3.1-beta.
|
1
|
+
var e="@cnhis-design-vue/shared",i="3.3.1-beta.7",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.3.1-beta.7",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.3.1-beta.
|
3
|
+
"version": "3.3.1-beta.7",
|
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": "dd6ae6f6673cbd2519923130c750845e7a5bd58f"
|
76
76
|
}
|