提交 37fe5428 编写于 作者: yma16's avatar yma16

add spring cloud record

上级 994999f9
......@@ -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&&currentUserInfo.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 => {
......
......@@ -10,10 +10,13 @@
</view> -->
<view class="form-container-introduce" wx:if="{{mode==='introduce'}}">
<view class="header-box" style="display: flex;">
<view style="width: 50%;">
<view style="width: 50%;" wx:if="{{isShowOenAi}}">
<button style="width: 100%;" type="primary" style="background: rgb(8, 183, 252);" loading="{{isLoading}}">api介绍</button>
</view>
<view style="width:50%">
<view style="width: 100%;" wx:else>
<button style="width: 100%;" type="primary" style="background: rgb(8, 183, 252);" loading="{{isLoading}}">api介绍</button>
</view>
<view style="width:50%" wx:if="{{isShowOenAi}}">
<button style="width: 100%;" type="primary" style="background: rgb(0, 114, 221);" bindtap="changeMode" loading="{{isLoading}}" data-mode='openAiUse'>使用</button>
</view>
</view>
......@@ -25,8 +28,8 @@
<view>
<button style="width: 100%;" type="primary" bindtap="changeMode" loading="{{isLoading}}" data-mode='introduce'>返回介绍</button>
</view>
<view class="chat-container">
<view wx:for="{{ chatObjConfig.option }}" wx:for-index="index" wx:for-item="item" wx:key="index">
<view class="chat-container" id="chat-container-id">
<view wx:for="{{ chatObjConfig.option }}" wx:for-index="index" wx:for-item="item" wx:key="*this">
<view class="form-request">
<view wx:if="{{item.isEdit}}">
<image class="user-image" src="{{currentUserInfo.avatarUrl}}"></image>
......@@ -47,11 +50,11 @@
</view>
</view>
</view>
</view>
<view class="form-submit" wx:if="{{mode==='openAiUse'}}">
<view class="form-submit" wx:if="{{mode==='openAiUse'}}">
<button style="width: 100%;" type="primary" bindtap="search" loading="{{isLoading}}">发送</button>
</view>
</view>
</view>
<view class="loading" wx:if="{{isLoading}}">
<view class="loader-child" />
......
......@@ -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;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册