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

feat:chagpt

上级 d87bfb13
......@@ -42,25 +42,30 @@ Component({
},
aiConfig: {
avatarUrl: 'https://yongma16.xyz/staticFile/common/img/aiTop.jpg',
bgUrl: 'https://yongma16.xyz/staticFile/common/img/aiBg.jpg'
bgUrl: 'https://yongma16.xyz/staticFile/common/img/aiBg.jpg',
nickName: 'openai',
},
searchOpenAiText: '',
responseText: '',
reportText: '',
// questions,answer,index
chatObjConfig: {
option: [{
question: '',
answer: '',
isEdit: true
isEdit: true,
createTime: ''
}],
currentIndex: 0
},
layoutConfig:{
introduceText:'api介绍',
useText:'使用',
returnText:'返回介绍',
sendText:'发送',
searchText:'关键词查询'
layoutConfig: {
introduceText: 'api介绍',
useText: '使用',
returnText: '返回介绍',
sendText: '发送',
searchText: '关键词查询',
reportText: '复制数据',
copyText: '复制'
}
},
observers: {
......@@ -73,12 +78,12 @@ Component({
// 在当前同步流程结束后,下一个时间片执行
wx.nextTick(() => {
wx.hideLoading({
success: (res) => {},
success: (res) => { },
})
// 触发父组件事件
// 触发父组件事件
this.triggerEvent('updateBottomNavigation', newVal === 'introduce')
})
}
},
lifetimes: {
......@@ -91,7 +96,7 @@ Component({
{
chatObjConfig: openAiOptions,
mode: app.wxProgramConfig.apiPageConfig.mode,
layoutConfig:app.wxProgramConfig.apiPageConfig.layoutConfig,
layoutConfig: app.wxProgramConfig.apiPageConfig.layoutConfig,
}
)
}
......@@ -142,11 +147,24 @@ Component({
})
},
scrollToBottom() {
const index=this.data.chatObjConfig.option.length-1
const index = this.data.chatObjConfig.option.length - 1
this.setData({
toView:`chat-mode${index}`
toView: `chat-mode${index}`
})
},
getCurrentTime() {
const now = new Date()
const year = now.getFullYear()
const month = now.getMonth()
const date = now.getDate()
const hour = now.getHours()
const minutes = now.getMinutes()
const second = now.getSeconds()
const formatNum = (n) => {
return n > 9 ? n.toString() : '0' + n
}
return `${year}-${formatNum(month + 1)}-${formatNum(date)} ${formatNum(hour)}:${formatNum(minutes)}:${formatNum(second)}`
},
getRemoteArticle: function (id) {
this.setData({
isLoading: true
......@@ -193,27 +211,35 @@ Component({
})
},
bindKeyInput(e) {
const { columnIndex } = e.currentTarget.dataset
console.log('this.data.chatObjConfig', this.data.chatObjConfig)
const option = this.data.chatObjConfig.option
option.some((item, index) => {
if (columnIndex === index) {
item.question = e.detail.value
item.isEdit = true
return true
}
return false
})
this.setData({
searchOpenAiText: e.detail.value,
chatObjConfig: {
option: option,
currentIndex: columnIndex
}
searchOpenAiText: e.detail.value
})
},
reportAnswerData() {
const data=this.data.chatObjConfig.option
wx.setClipboardData({
data: JSON.stringify(data)
})
console.log(wx.getClipboardData({
success: (option) => {
console.log(option)
},
}))
},
copyBtn(e) {
console.log('data', e)
const response = e.target.dataset.response
wx.setClipboardData({
data: response
})
console.log(wx.getClipboardData({
success: (option) => {
console.log(option)
},
}))
},
search(e) {
console.log(this.data.searchOpenAiText)
this.scrollToBottom()
if (!this.data.searchOpenAiText) {
wx.showModal({
......@@ -228,7 +254,6 @@ Component({
this.setData({
isLoading: true
})
console.log(e)
const path = '/common-api/searchOpenAiText/'
const headers = { 'Content-Type': 'application/json;charset=UTF-8' }
const params = {
......@@ -252,26 +277,26 @@ Component({
option.some((item, index) => {
if (currentIndex === index) {
item.answer = answer
item.question = params.text
item.createTime = this.getCurrentTime()
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
})
// // 只保留30 条 缓存
// if(option.length&&option.length>30){
// option.shift()
// }
const chatObjConfig = {
option: option,
currentIndex: currentIndex + 1
}
option.push({
question: '',
answer: '',
isEdit: true
})
// option.push({
// question: '',
// answer: '',
// isEdit: true
// })
thisBack.setData(
{
isLoading: false,
......@@ -282,6 +307,14 @@ Component({
wx.hideLoading()
thisBack.scrollToBottom()
resolve(res)
setTimeout(() => {
thisBack.createOpenRecord({
wx_name: thisBack.data.currentUserInfo.nickName,
wx_img: thisBack.data.currentUserInfo.avatarUrl,
search_text: params.text,
search_response: answer
})
}, 10)
},
fail: error => {
thisBack.setData({
......
<!--pages/future/future.wxml-->
<view class="container-future" style="background: {{currentUserInfo.bgUrl}};">
<!-- <view class="header-container"> -->
<!-- <view >
<view class="flex-container">
<view class='title'>疫情</view>
<view class="header-btn" class="{{btnType==='map'? 'actived':'btn-default'}}" bindtap="clickHeadBtn" data-btn-type='map'>地图</view>
<view class="header-btn" class="{{btnType==='line'? 'actived':'btn-default'}}" bindtap="clickHeadBtn" data-btn-type='line'>折线图</view>
<view class="header-btn" class="{{btnType==='blockInfo'? 'actived':'btn-default'}}" bindtap="clickHeadBtn" data-btn-type='blockInfo'>分类信息</view>
</view> -->
<view class="container-future">
<view class="form-container-introduce" wx:if="{{mode==='introduce'}}">
<view class="header-box" style="display: flex;">
<view style="width: {{isShowOenAi? '50%':'100%'}}">
<button style="width: 100%;" type="primary" style="background: rgb(8, 183, 252);" loading="{{isLoading}}">{{layoutConfig.introduceText}}</button>
<button style="width: 100%;" type="primary" style="background: rgb(8, 183, 252);" loading="{{isLoading}}">{{layoutConfig.introduceText}}
</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'>{{layoutConfig.useText}}</button>
......@@ -27,45 +20,71 @@
</view>
</view>
<view class="form-container-api" wx:if="{{mode==='openAiUse'}}">
<view>
<button style="width: 100%;background-color: #0758c1;" type="primary" bindtap="changeMode" loading="{{isLoading}}" data-mode='introduce'>{{layoutConfig.returnText}}</button>
<view style="display: flex;justify-content: space-between;">
<button style="width: 50%;background-color: #0758c1;" type="primary" bindtap="changeMode" loading="{{isLoading}}" data-mode='introduce'>{{layoutConfig.returnText}}</button>
<button style="width: 50%;" type="primary" style="background: rgb(0, 114, 221);" bindtap="reportAnswerData" loading="{{isLoading}}" data-mode='openAiUse'>{{layoutConfig.reportText}}</button>
</view>
<view class="chat-container" id="chat-container-id" style="width: 100%;">
<view style="float: right;position: absolute;right:0;z-index: 10px">
</view>
<scroll-view scroll-y="true" class="scroll-answer" scroll-with-animation bindscrolltoupper="upper" bindscrolltolower="lower" bindscroll="scroll" scroll-into-view="{{toView}}" scroll-top="{{scrollTop}}">
<view wx:for="{{ chatObjConfig.option }}" wx:for-index="index" wx:for-item="item" wx:key="*this" id="chat-mode{{index}}">
<view wx:for="{{ chatObjConfig.option }}" wx:for-index="index" wx:for-item="item" wx:key="index" id="chat-mode{{index}}">
<view style="width: 100%;border-radius: 2px;text-align: center;color:rgb(255, 255, 255);background: rgb(0, 114, 221);width: fit-content;margin:5px auto">
{{item.createTime}}
</view>
<view class="form-request">
<view wx:if="{{item.isEdit}}">
<image class="user-image" src="{{currentUserInfo.avatarUrl}}"></image>
<view style="display: inline;">({{currentUserInfo.nickName}}):$ </view>
<input bindinput="bindKeyInput" style="display: inline;" placeholder="{{layoutConfig.searchText}}" data-column-index="{{index}}" disabled="{{isLoading}}" />
</view>
<view wx:else class='questioned'>
<view>
<image class="user-image" src="{{currentUserInfo.avatarUrl}}"></image> ({{currentUserInfo.nickName}}):$ {{item.question}}
<view wx:if="{{!item.isEdit}}" class='questioned'>
<view style="display: flex;text-align: right;flex-direction:row-reverse;">
<view class="questioned-box-container">
<view class='questioned-box' style="text-align: left;">
{{item.question}}
</view>
<view class='questioned-box-poly'>
</view>
<view style="text-align: right;line-height: 50px;display: flex;max-height: 50px;">
<view class='form-request-user'>
<!-- {{currentUserInfo.nickName}} -->
<image class="user-image" src="{{currentUserInfo.avatarUrl}}"></image>
</view>
</view>
</view>
</view>
</view>
</view>
<view class="form-response">
<view class='questioned'>
<image class="ai-image" src="{{aiConfig.avatarUrl}}"></image>
(openai):$ {{item.answer}}
</view>
</view>
<view class="form-response" wx:if="{{!item.isEdit}}">
<view style="display: flex;">
<view style="line-height: 50px;">
<view class='form-response-user'>
<image class="ai-image" src="{{aiConfig.avatarUrl}}"></image>
<!-- {{aiConfig.nickName}} -->
</view>
</view>
<view class="form-response-box-poly">
</view>
<view class='form-response-box'>
{{item.answer}}
</view>
</view>
<view style="display: flex;width: 100%;box-sizing: border-box;">
<view style="width: 70%;">
</view>
<view style="width: 30%;">
<button style="background-color: #0758c1;width:fit-content;border-radius: 10px;margin:5px 2px;" type="primary" bindtap="copyBtn" data-response=" {{item.answer}}">{{layoutConfig.copyText}}</button>
</view>
</view>
</view>
</view>
<view class="form-submit" wx:if="{{mode==='openAiUse'}}" style="width: 100%;">
</view>
</scroll-view>
<view>
<input class='send-btn' bindinput="bindKeyInput" placeholder="{{layoutConfig.searchText}}" bindconfirm="search" value="{{searchOpenAiText}}" disabled="{{isLoading}}" />
</view>
<button style="width: 100%;;background-color: #0758c1;" type="primary" bindtap="search" loading="{{isLoading}}">{{layoutConfig.sendText}}</button>
</view>
</view>
<view class="content-container" wx:if="{{!isLoading}}">
<!-- <geoMap wx:if="{{btnType==='map'}}" ></geoMap>
<lineChart wx:elif="{{btnType==='line'}}" bindtap="clickBottomBtn"></lineChart>
<blockInfo wx:else="{{btnType==='blockInfo'}}" bindtap="clickBottomBtn"></blockInfo> -->
</view>
</view>
\ No newline at end of file
......@@ -3,13 +3,12 @@
position: relative;
width: 100vw;
height: 100vh;
/* background: linear-gradient(to right, rgba(1, 41, 116, 0.1) 1px, transparent 1px), linear-gradient(to bottom, rgba(1, 41, 116, 0.1) 1px, transparent 1px);
background: linear-gradient(to right, rgba(1, 41, 116, 0.1) 1px, transparent 1px), linear-gradient(to bottom, rgba(1, 41, 116, 0.1) 1px, transparent 1px);
background-repeat: repeat;
background-size: 10px 10px;
border: 1px solid #01c4ff; */
background-image: url('https://yongma16.xyz/staticFile/common/img/aiBg.jpg');
background-repeat: no-repeat;
background-size: cover;
/* background-image: url('https://yongma16.xyz/media/editor/wallhaven-we1xx7_20230331165330942057.jpg'); */
/* background-repeat: no-repeat;
background-size: cover; */
overflow: hidden;
box-sizing: border-box;
}
......@@ -78,6 +77,8 @@ button {
font-weight: normal;
}
.btn-default {
color: #262626;
flex: 1;
......@@ -103,8 +104,8 @@ button {
.form-request {
display: block;
width: 100%;
color: #07c160;
background-color: rgba(37, 0, 97,.9);
color: #fff;
background-color: rgba(37, 0, 97,0);
line-height: 50px;
}
......@@ -114,12 +115,22 @@ button {
margin-top: 10px;
display: block;
margin-bottom: 10px;
color: #07c160;
background-color: rgba(0, 72, 94,.9);
color: #fff;
background-color: rgba(0, 72, 94,0);
box-sizing: border-box;
min-height: 60px;
}
.form-response-user{
background-color: rgba(0, 72, 94,0);
color:#fff;
}
.form-request-user{
background-color: rgba(37, 0, 97,0);
color:#fff;
}
.form-class-submit {
margin-top: 10px;
display: block;
......@@ -140,10 +151,9 @@ button {
overflow: auto;
}
.scroll-answer{
height: calc(100vh - 90px);
height: calc(100vh - 140px);
}
.chat-container {
margin-top: 10px;
width: 100%;
height: calc(100vh - 40px);
overflow-y: auto;
......@@ -172,6 +182,62 @@ button {
border-radius: 50%;
}
.questioned-box-container{
display: flex;
}
.questioned-box{
position: relative;
max-width: calc(100vw - 90px);
height: auto;
overflow-x: auto;
background-color:rgb(0, 114, 221);
border-radius: 10px;
right: -5px;
padding:0 10px;
z-index: 999;
}
.questioned-box-poly{
position: relative;
top:15px;
width: 0;
height: 0;
border-radius: 5px;
border-top: 10px solid transparent;
border-bottom: 10px solid transparent;
border-left: 12px solid rgb(0, 114, 221);
}
.send-btn{
height: 60px;background: rgba(255,255,255,.8);
color:rgb(0, 114, 221);
padding-left: 10px;
}
.form-response-box{
position: relative;
max-width: calc(100vw - 90px);
word-break:keep-all;
height: auto;
overflow-x: auto;
background-color: rgb(0, 114, 221);
border-radius: 10px;
left: -5px;
padding:0 10px;
box-sizing: content-box;
z-index: 999;
}
.form-response-box-poly{
position: relative;
top:15px;
width: 0;
height: 0;
border-radius: 5px;
border-top: 10px solid transparent;
border-bottom: 10px solid transparent;
border-right: 12px solid rgb(0, 114, 221);
}
/* .loader-child:nth-of-type(1) {
border-bottom: 3px solid #ffffff;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册