@tencentcloud/ai-desk-customer-wechat
Version:
AI Desk customer UIKit for wechat mini program
3 lines (2 loc) • 4.74 kB
JavaScript
;const e=require("../../../../common/vendor.js"),G=require("../../../adapter-vue.js"),o=require("../../../@aidesk/uikit-engine/index.js"),i=require("../../../../common/assets.js"),M=require("../../common/Toast/index-uniapp.js"),j=require("../../../utils/utils.js"),n=require("../../../utils/env.js"),y=require("../../common/Toast/type.js");Math||H();const H=()=>"../../common/Icon.js",J=e.defineComponent({__name:"message-input-audio-uniapp",props:{isInAudioMode:{type:Boolean,default:!1}},emits:["changeDisplayType"],setup(b,{emit:B}){var D;const{ref:s,onMounted:w,onUnmounted:E}=G.vue,z=B,d=b;let h=0,l=!1,m,C=-1,_=!1,k=!1;const r=(D=e.i)==null?void 0:D.getRecorderManager(),c=s(!1),f=s(o.jt.t("TUIChat.按住说话")),p=s(o.jt.t("TUIChat.正在录音")),q=s(!1),I=s(""),a=s(!1),O={duration:6e4,sampleRate:44100,numberOfChannels:1,encodeBitRate:192e3,format:n.isTikTok?"aac":"mp3"};function g(){z("changeDisplayType",d.isInAudioMode?"editor":"audio")}w(()=>{r.onStart(N),r.onStop(F),r.onError(L),o.Kt.watch(o.a.CONV,{currentConversationID:S})}),E(()=>{o.Kt.unwatch(o.a.CONV,{currentConversationID:S})});function S(t){I.value=t}function v(){x(),U()}function U(){c.value=!1,f.value=o.jt.t("TUIChat.按住说话"),p.value=o.jt.t("TUIChat.正在录音")}function x(t){clearInterval(m),m=void 0,h=0,C=-1,l=!1,a.value=!1,t!=null&&t.hasError||r.stop()}function P(){_&&(k=!0,e.index.authorize({scope:"scope.record",fail:t=>{e.index.__f__("error","at ai-desk-customer-uniapp/components/CustomerServiceChat/message-input/message-input-audio-uniapp.vue:233","authorize fail",t),R()},success:()=>{e.index.__f__("log","at ai-desk-customer-uniapp/components/CustomerServiceChat/message-input/message-input-audio-uniapp.vue:237","scope.record authorized")}}))}function V(){e.index.getSetting({success(t){t.authSetting["scope.record"]===!0?(_=!0,r.start(O)):R()},fail(t){e.index.__f__("error","at ai-desk-customer-uniapp/components/CustomerServiceChat/message-input/message-input-audio-uniapp.vue:257","getSetting fail",t)}})}function R(){M.Toast({message:o.jt.t("TUIChat.请检查麦克风访问权限"),type:y.TOAST_TYPE.NORMAL,duration:1500})}const A=j.throttle(function(t){if(c.value){const T=t.changedTouches[t.changedTouches.length-1].pageY;C<0&&(C=T);const u=C-T;u>110?(f.value=o.jt.t("TUIChat.松手取消"),p.value=o.jt.t("TUIChat.松手取消"),l=!0,a.value=!0):u>50?(f.value=o.jt.t("TUIChat.松开发送"),p.value=o.jt.t("TUIChat.松开发送"),l=!1,a.value=!1):(f.value=o.jt.t("TUIChat.松开发送"),p.value=o.jt.t("TUIChat.正在录音"),l=!1,a.value=!1)}},100);function Y(){_=!1,r.stop()}function N(){if(!_){k=!0,r.stop();return}m=setInterval(()=>{h+=1},1e3),f.value=o.jt.t("TUIChat.松开发送"),c.value=!0}function F(t){if(k){k=!1,v();return}if(l||!c.value){v();return}clearInterval(m);const T=t.tempFilePath,u=t.duration?t.duration:h*1e3,$=t.fileSize?t.fileSize:48*h/8*1024;if(u<1e3)M.Toast({message:o.jt.t("TUIChat.按压时间过短,请按压超过1秒"),type:y.TOAST_TYPE.NORMAL,duration:1500});else{const K={to:I.value.replace(o.Vt.TYPES.CONV_C2C,""),conversationType:o.Vt.TYPES.CONV_C2C,payload:{file:{duration:u,tempFilePath:T,fileSize:$}},needReadReceipt:j.isEnabledMessageReadReceiptGlobal()};o.Yt.sendAudioMessage(K)}v()}function L(){x({hasError:!0}),U()}return(t,T)=>e.e$1({a:e.unref(n.isTikTok)},e.unref(n.isTikTok)?{b:d.isInAudioMode?e.unref(i.keyboardIcon):e.unref(i.audioIcon),c:e.o(g)}:{d:e.o(g),e:e.p({file:d.isInAudioMode?e.unref(i.keyboardIcon):e.unref(i.audioIcon),size:"23px",hotAreaSize:"3px"})},{f:d.isInAudioMode},d.isInAudioMode?e.e$1({g:e.t(e.unref(f)),h:e.unref(c)},e.unref(c)?e.e$1({i:e.unref(n.isTikTok)},e.unref(n.isTikTok)?{j:e.unref(a)?e.unref(i.audioBubbleRed):e.unref(i.audioBubbleBlue)}:{k:e.p({file:e.unref(a)?e.unref(i.audioBubbleRed):e.unref(i.audioBubbleBlue),width:"160px",height:"74px"})},{l:!e.unref(n.isTikTok)},e.unref(n.isTikTok)?{}:{},{m:e.t(e.unref(p)),n:e.unref(n.isTikTok)},e.unref(n.isTikTok)?{o:e.unref(a)?e.unref(i.audioDeleteIcon):e.unref(i.audioBeforeDeleteIcon)}:{},{p:!e.unref(n.isTikTok)},e.unref(n.isTikTok)?{}:{q:e.p({file:e.unref(a)?e.unref(i.audioDeleteIcon):e.unref(i.audioBeforeDeleteIcon),width:"54px",height:"54px"})},{r:e.unref(n.isTikTok)},e.unref(n.isTikTok)?{s:e.unref(i.audioRecordIcon)}:{},{t:!e.unref(n.isTikTok)},e.unref(n.isTikTok)?{}:{v:e.p({width:"16px",height:"20px",file:e.unref(i.audioRecordIcon)})}):{},{w:e.o(P),x:e.o(V),y:e.o((...u)=>e.unref(A)&&e.unref(A)(...u)),z:e.o(Y)}):{},{A:e.unref(q)?1:""})}}),Q=e._export_sfc(J,[["__scopeId","data-v-d9e7034f"]]);wx.createComponent(Q);
//# sourceMappingURL=../../../../../.sourcemap/mp-weixin/ai-desk-customer-uniapp/components/CustomerServiceChat/message-input/message-input-audio-uniapp.js.map