diff --git a/miniprogram/pages/future/future.js b/miniprogram/pages/future/future.js index da12ccd26fa85b2bead9acf7c2b3cb82bc7120ae..052d438adfe6383e822c88ffce1b1c32f037472a 100644 --- a/miniprogram/pages/future/future.js +++ b/miniprogram/pages/future/future.js @@ -33,7 +33,10 @@ Component({ mode:'introduce', article:{}, articleId:44, + isShowOenAi:false, baseUrl:'https://yongma16.xyz/api/', + baseCloudUrl:'https://yongma16.xyz/cloudApi/', + baseCloudPath:'openAiRecord/add', path:'article/blog/', currentUserInfo:{ nickName:'', @@ -59,21 +62,26 @@ Component({ // 生命周期函数,可以为函数,或一个在 methods 段中定义的方法名 attached: function () { this.getRemoteArticle(this.data.articleId) - if(wx.getStorageSync('openAiOptions')){ + const openAiOptions=wx.getStorageSync('openAiOptions') + if(openAiOptions){ this.setData( { - chatObjConfig:wx.getStorageSync('openAiOptions') + chatObjConfig:openAiOptions } ) } - if(wx.getStorageSync('currentUserInfo')){ - console.log('currentUserInfo',wx.getStorageSync('currentUserInfo')) + const currentUserInfo=wx.getStorageSync('currentUserInfo') + if(currentUserInfo&¤tUserInfo.nickName){ + console.log('currentUserInfo',currentUserInfo) this.setData( { - currentUserInfo:wx.getStorageSync('currentUserInfo') + currentUserInfo:currentUserInfo } ) + this.setData({ + isShowOenAi:true + }) } }, @@ -84,6 +92,25 @@ Component({ }, methods: { + createOpenRecord(params){ + const headers = {'Content-Type':'application/json;charset=UTF-8'} + wx.request({ + url: this.data.baseCloudUrl + this.data.baseCloudPath, + headers: headers, + data:params, + method: 'POST', + success:(res=>{ + console.log('cloud res',res) + }), + fail:r=>{ + console.log('cloud r',r) + } + }) + }, + scrollToBottom(){ + const viewComponent = this.getEle('#chat-container-id') + console.log('viewComponent',viewComponent) + }, getRemoteArticle:function(id){ this.setData({ isLoading:true @@ -184,14 +211,21 @@ Component({ const currentIndex=thisBack.data.chatObjConfig.currentIndex const choices=data.choices console.log('choices',choices) + const answer=choices?choices.map(choicesItem=>{return choicesItem.text}).join('\n'):'。。。未知' option.some((item,index)=>{ if(currentIndex===index){ - item.answer=choices?choices.map(choicesItem=>{return choicesItem.text}).join('\n'):'。。。未知' + item.answer=answer item.isEdit=false return true } return false }) + thisBack.createOpenRecord({ + wx_name:thisBack.data.currentUserInfo.nickName, + wx_img:thisBack.data.currentUserInfo.avatarUrl, + search_text:params.text, + search_response:answer + }) const chatObjConfig={ option:option, currentIndex:currentIndex+1 @@ -209,6 +243,7 @@ Component({ } ) wx.hideLoading() + thisBack.scrollToBottom() resolve(res) }, fail: error => { diff --git a/miniprogram/pages/future/future.wxml b/miniprogram/pages/future/future.wxml index 1ff2ac95bdac3769ad4fad412e0c14411603c7d4..c8d183dfcf194d097fd00e62a09e829953853047 100644 --- a/miniprogram/pages/future/future.wxml +++ b/miniprogram/pages/future/future.wxml @@ -10,10 +10,13 @@ --> - + - + + + + @@ -25,8 +28,8 @@ - - + + @@ -47,11 +50,11 @@ - - - + + + diff --git a/miniprogram/pages/future/future.wxss b/miniprogram/pages/future/future.wxss index a85d065e0bbecf51ab36192e2e868d372ed87b00..3231319330d05026d1fddb3654af1e0dba07e80d 100644 --- a/miniprogram/pages/future/future.wxss +++ b/miniprogram/pages/future/future.wxss @@ -139,8 +139,9 @@ button { .chat-container { margin-top: 10px; width: 100%; - height: calc(100vh - 100px); - overflow: auto; + height: calc(100vh - 120px); + overflow-y: auto; + overflow-x: hidden; position: relative; }