From 37fe54289c7349ad61d1e6e32a8e4a45942820cb Mon Sep 17 00:00:00 2001 From: yma16 <17685043634@163.com> Date: Mon, 13 Feb 2023 00:04:06 +0800 Subject: [PATCH] add spring cloud record --- miniprogram/pages/future/future.js | 47 ++++++++++++++++++++++++---- miniprogram/pages/future/future.wxml | 17 +++++----- miniprogram/pages/future/future.wxss | 5 +-- 3 files changed, 54 insertions(+), 15 deletions(-) diff --git a/miniprogram/pages/future/future.js b/miniprogram/pages/future/future.js index da12ccd..052d438 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 1ff2ac9..c8d183d 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 a85d065..3231319 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; } -- GitLab