(global["webpackJsonp"]=global["webpackJsonp"]||[]).push([["pages/index/index"],{"1c68":function(e,t,o){"use strict";o.r(t);var n=o("be94"),a=o.n(n);for(var s in n)"default"!==s&&function(e){o.d(t,e,(function(){return n[e]}))}(s);t["default"]=a.a},2348:function(e,t,o){"use strict";var n=o("cddc"),a=o.n(n);a.a},2494:function(e,t,o){"use strict";o.r(t);var n=o("a05a"),a=o("1c68");for(var s in a)"default"!==s&&function(e){o.d(t,e,(function(){return a[e]}))}(s);o("2348");var i,c=o("f0c5"),r=Object(c["a"])(a["default"],n["b"],n["c"],!1,null,"34783f25",null,!1,n["a"],i);t["default"]=r.exports},3918:function(e,t,o){"use strict";(function(e){o("8492");n(o("66fd"));var t=n(o("2494"));function n(e){return e&&e.__esModule?e:{default:e}}wx.__webpack_require_UNI_MP_PLUGIN__=o,e(t.default)}).call(this,o("543d")["createPage"])},a05a:function(e,t,o){"use strict";var n;o.d(t,"b",(function(){return a})),o.d(t,"c",(function(){return s})),o.d(t,"a",(function(){return n}));var a=function(){var e=this,t=e.$createElement,o=(e._self._c,e.historyRecord.length>0?e.__map(e.historyRecord,(function(t,o){var n=e.__get_orig(t),a=Object.keys(t.WObj);return{$orig:n,g0:a}})):null);e.$mp.data=Object.assign({},{$root:{l0:o}})},s=[]},be94:function(e,t,o){"use strict";(function(e){function o(e,t,o){return t in e?Object.defineProperty(e,t,{value:o,enumerable:!0,configurable:!0,writable:!0}):e[t]=o,e}Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var n=e.getRecorderManager(),a=e.createInnerAudioContext();a.autoplay=!0;var s={data:function(){return{loading2:!0,userInputName:"",showDialog:!0,userName:"",isHover:!1,base64Img:"",showResult:!1,showSend:"",activeState:"",focus:"",show:!1,monney:0,boxClass:"chat-window-message",items:[],historyRecord:[],socketTask:null,recive:null,codeUrl:"",dpPhoto:"",userPhoto:"",inputVal:"",loading:!1,finalVal:"",EPlayer:null,innerAudioContext:null,board:!1,storyContent:["头部内容","主体内容"],text:"uni-app",voicePath:"",timer:null}},beforeDestroy:function(){this.socketTask&&(this.socketTask.close(),this.socketTask=null),clearInterval(this.timer),this.EPlayer&&(this.EPlayer.cb&&(this.EPlayer.cb=null),this.EPlayer.stop(),this.EPlayer.destroy(),this.EPlayer=null)},mounted:function(){var t=this;this.$globalData.showEnding&&(this.board=!0,this.showResult=!0,this.storyContent=this.$globalData.EndingContent,this.base64Img=this.$globalData.base64ImageStr),n.onStop((function(e){console.log(222,e),t.convertAudioToStream(e.tempFilePath)}));var o=getApp().globalData.shareObject;console.log("首页传来的数据",o),e.request({url:"https://admin.mindepoch.com:8089/heartbeat",header:{Cookie:"".concat(e.getStorageSync("session_token"))}}).then((function(e){})).catch((function(e){console.log(e)})),this.getPhoto()},onLoad:function(){},methods:{submitUserName:function(){""==this.userInputName&&""==this.userInputName.trim()?e.showToast({title:"昵称不可为空!",icon:"none"}):(this.showDialog=!1,this.loading2=!1,this.socketConnect(),console.log("???"))},socketConnect:function(){var t=this;console.log(this.userInputName),this.socketTask=e.connectSocket({url:"wss://admin.mindepoch.com:8089/WorldChats/ws?id=".concat(this.$globalData.wxUid,'&world_name=情圣日记&BgInfo=我是罗翔爱徒&userInfo={"name":"').concat(this.userInputName,'","bk":"罗翔爱徒"}'),success:function(){return console.log("WebSocket 连接成功")},fail:function(){return console.log("WebSocket 连接失败")}}),this.socketTask.onOpen((function(){console.log("WebSocket 连接已打开"),t.getHistory()})),this.socketTask.onMessage((function(o){console.log("--------",JSON.parse(o.data)),clearInterval(t.timer),e.setNavigationBarTitle({title:"Ai聊天"}),t.loading=!1,e.hideLoading();var n=JSON.parse(o.data);if(0===n.code)t.badRequest(n.backValue);else if(3===n.code)t.badRequest(n.backValue);else if(4===n.code)t.badRequest(n.backValue);else if(-1===n.code)t.badRequest(n.backValue);else if(1===n.code){var a=n.ISLIU?n.ISLIU:"";if(console.log(a),""!==a&&(a=a.replaceAll("“",'"').replaceAll("”",'"'),t.finalVal=t.extractQuotedTexts(a).join(","),console.log("处理后的文字",t.finalVal),t.GoSound(t.finalVal,"huaHuo",(function(e,t){t&&console.log("讲话完毕!")}))),n.WObj&&n.WObj["物品"]&&Object.keys(n.WObj["物品"]).length>0){t.items=Object.values(t.monney=n.WObj["物品"]).filter((function(e){return!e.includes("存款:")}));var s=Object.values(t.monney=n.WObj["物品"]).filter((function(e){return e.includes("存款:")}));s[0]?t.monney=s[0].match(/\d+/):t.monney=0,t.storyContent=n.WObj.EndStr.split("@"),t.$globalData.EndingContent=n.WObj.EndStr.split("@"),n.WObj.EndStr?""!==n.WObj.EndStr&&e.request({url:"https://admin.mindepoch.com:8089/worlds/".concat(t.storyContent[0],".png"),method:"get",responseType:"arraybuffer",header:{Cookie:"".concat(e.getStorageSync("session_token"))}}).then((function(o){console.log("图片资源",o),t.board=!0,t.base64Img="data:image/png;base64,"+e.arrayBufferToBase64(o[1].data),t.showResult=!0,t.$globalData.showEnding=!0,t.$globalData.base64ImageStr=t.base64Img})).catch((function(e){console.log(e)})):(t.board=!1,t.showResult=!1,t.$globalData.showEnding=!1)}n.content||(0===t.historyRecord.length?t.historyRecord.push({Message:n.ISLIU,WObj:n.WObj}):t.historyRecord.push({Message:t.inputVal,WObj:{}},{Message:n.ISLIU,WObj:n.WObj}),t.inputVal="",t.loading=!1,e.hideLoading())}})),this.socketTask.onError((function(e){console.error("WebSocket 错误:",e)})),this.socketTask.onClose((function(){console.log("WebSocket 连接已关闭")}))},getHistory:function(){var t=this;e.request({url:"https://admin.mindepoch.com:8089/worldChat-history",method:"post",data:{id:1},header:{Cookie:"".concat(e.getStorageSync("session_token")),"Content-Type":"application/x-www-form-urlencoded"}}).then((function(o){console.log("从服务器获取历史聊天记录",o[1].data),1===o[1].data.code?o[1].data.chatRecordInfo&&(t.historyRecord=o[1].data.chatRecordInfo.Records):e.showToast({title:o[1].data.message,icon:"none"})})).catch((function(e){console.log(e)}))},getPhoto:function(){var t,n,a=this;e.request({url:"https://admin.mindepoch.com:8089/static/poster".concat(96,".png"),method:"GET",data:{id:1},responseType:"arraybuffer",header:{Cookie:"".concat(e.getStorageSync("session_token")),"Cache-Control":"no-cache"}}).then((function(t){var o=t[1].data;a.codeUrl="data:image/png;base64,"+e.arrayBufferToBase64(o)})).catch((function(e){return console.log(e)})),e.request((t={url:"https://admin.mindepoch.com:8089/static/avatar".concat(96,".png"),method:"GET",responseType:"arraybuffer",data:{id:96}},o(t,"responseType","arraybuffer"),o(t,"header",{Cookie:"".concat(e.getStorageSync("session_token")),"Cache-Control":"no-cache"}),t)).then((function(t){var o=t[1].data;a.dpPhoto="data:image/png;base64,"+e.arrayBufferToBase64(o)})).catch((function(e){console.log(e)})),e.request((n={url:"https://admin.mindepoch.com:8089/userFile/avatar".concat(1,".png"),method:"GET",responseType:"arraybuffer",data:{id:1}},o(n,"responseType","arraybuffer"),o(n,"header",{Cookie:"".concat(e.getStorageSync("session_token")),"Cache-Control":"no-cache"}),n)).then((function(t){var o=t[1].data;a.userPhoto="data:image/png;base64,"+e.arrayBufferToBase64(o)})).catch((function(e){return console.log(e)}))},badRequest:function(t){e.showToast({title:t,icon:"none"})},handleTouchStart:function(){this.isHover=!0},handleTouchEnd:function(){this.isHover=!1},handleText:function(e){var t=/[\u201c\u201d][^\u201c\u201d]*[\u201c\u201d]/g,o=e.replace(t,(function(e){return e.replace(/[\u201c\u201d](.*?)[\u201c\u201d]/g,(function(e){return"<span style='font-weight: bold;'>"+e.slice(1,-1)+"</span>"}))}));return o},handleHiddenShadow:function(){this.board=!1},getResults:function(){this.board=!0},open:function(){this.$refs.popup.open()},close:function(){this.$refs.popup.close()},confirm:function(e){console.log(e),this.$refs.popup.close()},backHome:function(){e.navigateTo({url:"/pages/homeCards/index"})},handleClearHistoryRecord:function(){var t=this;this.historyRecord=[],this.showResult=!1,this.board=!1,e.showLoading({title:"请稍等...",mask:!0}),this.loading=!0,e.request({url:"https://admin.mindepoch.com:8089/SoulNeuralFileWorldReset",method:"post",data:{worldName:"情圣日记",BgInfo:"我是罗翔爱徒",userInfo:'{"name":" '.concat(this.userInputName,' ","bk":"罗翔爱徒"}')},header:{Cookie:"".concat(e.getStorageSync("session_token")),"Cache-Control":"no-cache","Content-Type":"application/x-www-form-urlencoded"}}).then((function(o){console.log("用户的聊天历史记录",o[1]),t.loading=!1,e.hideLoading(),200===o[1].statusCode&&(t.$globalData.EndingContent=[],t.$globalData.base64ImageStr="",t.$globalData.showEnding=!1)})).catch((function(o){t.loading=!1,e.hideLoading()}))},convertAudioToStream:function(t){var o=this,n=e.getFileSystemManager();n.readFile({filePath:t,success:function(n){console.log("音频",n.data),e.uploadFile({url:"https://admin.mindepoch.com:8089/speechConvertor",filePath:t,name:"file",header:{"Content-Type":"multipart/form-data",Cookie:"".concat(e.getStorageSync("session_token"))},success:function(t){var n=JSON.parse(t.data);if(console.log("uploadFile success, res is:",t),1===n.code){if(0==n.message.transcription.length)return void e.showToast({title:"说话时长过短,请重新录制!",icon:"none"});o.inputVal=n.message.transcription[0].text,o.socketTask.send({data:JSON.stringify({type:0,content:o.inputVal}),success:function(){console.log("消息发送成功"),o.loading=!0,e.showLoading({title:n.message,mask:!0});var t="对方正在输入...",a=6;o.timer=setInterval((function(){a<10?a+=1:a=6,e.setNavigationBarTitle({title:t.substr(0,a)})}),400)}})}else o.loading=!1,e.showToast({title:n.message,icon:"none"})},fail:function(e){console.error("uploadFile error, err is:",e)}})},fail:function(e){console.log(e)}})},startRecord:function(){console.log("开始录音"),n.start(),this.activeState="activeMicrophone",e.setNavigationBarTitle({title:"语音输入中..."})},endRecord:function(){console.log("录音结束"),n.stop(),this.activeState="",e.setNavigationBarTitle({title:"AI聊天"})},handleShow:function(){this.show=!1},handleMore:function(){this.show=!0},handleFocus:function(){this.focus="activeFocus",this.showSend="showSend",this.boxClass="chat-window-message2",console.log("聚焦")},hadnleBlur:function(){this.focus="",console.log("失焦"),this.showSend="",this.boxClass="chat-window-message",e.setNavigationBarTitle({title:"AI聊天"})},handleSendMessage:function(){var t=this;if(""===this.inputVal.trim())return e.showToast({title:"输入框值不可为空",icon:"none"}),void(this.inputVal="");this.socketTask.send({data:JSON.stringify({type:0,content:this.inputVal}),success:function(){console.log("消息发送成功"),t.loading=!0,e.showLoading({title:"思考中...",mask:!0});var o="对方正在输入...",n=6;t.timer=setInterval((function(){n<10?n+=1:n=6,e.setNavigationBarTitle({title:o.substr(0,n)})}),400)}})},computeLen:function(e){console.log(e);var t="",o=e.content;while(1){var n=o.match(/,|,|。|\!|!|?|\?|\n/);if(!(t.length<20&&n)){(t.length+o.length<20||t.length<15)&&(t+=o);break}t+=o.substring(0,n.index+1),o=o.substring(n.index+1)}var a={};return a.Sr=t,a.content=e.content.replace(t,""),a},FetchAbuffer:function(t,o,n,a){var s=this,i=this.computeLen(t),c=i.Sr;e.request({url:"https://admin.mindepoch.com:8089/VoiceMode/GetVoiceEcho",method:"post",responseType:"arraybuffer",header:{"Content-Type":"application/x-www-form-urlencoded",Cookie:"".concat(e.getStorageSync("session_token"))},data:{name:o,voice_text:i.Sr,text_language:"zh"}}).then((function(e){if(200===e[1].statusCode)return e[1].data})).then((function(e){n.push({A:e,S:c}),t.content=i.content,t.Sr=i.Sr,""!=i.content&&setTimeout((function(){s.FetchAbuffer(i,o,n)}),1e3)}))},GoSound:function(t,o,n){var a=this,s=[],i=this.computeLen({content:t});e.request({url:"https://admin.mindepoch.com:8089/VoiceMode/GetVoiceEcho",method:"post",responseType:"arraybuffer",header:{"Content-Type":"application/x-www-form-urlencoded",Cookie:"".concat(e.getStorageSync("session_token"))},data:{name:o,voice_text:i.Sr,text_language:"zh"}}).then((function(e){if(200===e[1].statusCode)return e[1].data;console.log(e)})).then((function(t){console.log(t);var c=e.getFileSystemManager(),r=wx.env.USER_DATA_PATH+"/tempAudio_".concat((new Date).getTime(),".mp3");console.log("tempFilePath:",r),c.writeFile({filePath:r,data:t,encoding:"binary",success:function(){a.EPlayer&&(a.EPlayer.onEnded(),a.EPlayer.stop(),a.EPlayer.cb&&a.EPlayer.cb(i.Sr,!0,!0)),n&&n(i.Sr),a.EPlayer=e.createInnerAudioContext(),a.EPlayer.src=r,a.EPlayer.play(),a.EPlayer.cb=n;var t=function t(){if(0==s.length)return""!=i.content?void setTimeout((function(){a.EPlayer.onended()}),1e3):void(n&&n(i.Sr,!0));var o=s.shift();console.log(o),e.removeSavedFile({filePath:r,success:function(e){console.log("删除缓存文件成功")},fail:function(e){console.log("删除缓存文件失败",e)}}),r=wx.env.USER_DATA_PATH+"/tempAudio_".concat((new Date).getTime(),".mp3"),c.writeFile({filePath:r,data:o.A,encoding:"binary",success:function(){console.log(r),n&&n(i.Sr),a.EPlayer=e.createInnerAudioContext(),a.EPlayer.src=r,a.EPlayer.play(),a.EPlayer.onEnded(t),a.EPlayer.onended=t},fail:console.error})};a.EPlayer.onEnded(t),a.EPlayer.onended=t,""!=i.content&&setTimeout((function(){a.FetchAbuffer(i,o,s,n)}),5e3)},fail:console.error})})).catch((function(e){console.log(e)})).finally((function(){}))},extractQuotedTexts:function(e){var t,o=/(["'])(?:(?=(\\?))\2.)*?\1/g,n=[];while(null!==(t=o.exec(e))){var a=t[0].slice(1,-1).replace(/\\(["'])/g,"$1");n.push(a)}return 0==n.length?[e]:n}}};t.default=s}).call(this,o("543d")["default"])},cddc:function(e,t,o){}},[["3918","common/runtime","common/vendor"]]]);