From 8b18f5232ca5da3f18f63a6562c8a91b7eb85809 Mon Sep 17 00:00:00 2001 From: yma16 <17685043634@163.com> Date: Sat, 11 Feb 2023 23:38:22 +0800 Subject: [PATCH] add openAi remove dataView --- miniprogram/pages/future/future.js | 119 ++++++++++++++++++++++++++- miniprogram/pages/future/future.wxml | 57 ++++++++----- miniprogram/pages/future/future.wxss | 50 +++++++++-- 3 files changed, 198 insertions(+), 28 deletions(-) diff --git a/miniprogram/pages/future/future.js b/miniprogram/pages/future/future.js index 603944c..df1a23a 100644 --- a/miniprogram/pages/future/future.js +++ b/miniprogram/pages/future/future.js @@ -16,8 +16,19 @@ Component({ content: '子组件的content', btnType:'map', homeHeaderItem: '', - isLoading: true, - article: { 'key': 12 } + isLoading: false, + article: { 'key': 12 }, + searchOpenAiText:'', + responseText:'', + // questions,answer,index + chatObjConfig:{ + option:[{ + question:'', + answer:'', + isEdit:true + }], + currentIndex:0 + } }, observers: { @@ -25,10 +36,17 @@ Component({ lifetimes: { // 生命周期函数,可以为函数,或一个在 methods 段中定义的方法名 attached: function () { - this.initData() + if(wx.getStorageSync('openAiOptions')){ + this.setData( + { + chatObjConfig:wx.getStorageSync('openAiOptions') + } + ) + } }, moved: function () { }, detached: function () { + wx.setStorageSync('openAiOptions', this.data.chatObjConfig) }, }, @@ -46,6 +64,101 @@ Component({ }, methods: { + 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 + } + }) + }, + search(e){ + console.log(this.data.searchOpenAiText) + if(!this.data.searchOpenAiText){ + wx.showModal({ + cancelColor: 'cancelColor', + title:'请输入!' + }) + } + wx.showLoading({ + title: '加载中', + }) + this.setData({ + isLoading: true + }) + console.log(e) + const path = '/common-api/searchOpenAiText/' + const headers = { 'Content-Type': 'application/json;charset=UTF-8' } + const params={ + "text":this.data.searchOpenAiText + } + const thisBack=this + return new Promise((resolve, reject) => { + wx.request({ + url: baseUrl + path, + headers: headers, + data:params, + method: 'GET', + success: (res) => { + console.log(res,'res') + const data=res.data.data + const option=thisBack.data.chatObjConfig.option + const currentIndex=thisBack.data.chatObjConfig.currentIndex + const choices=data.choices + console.log('choices',choices) + option.some((item,index)=>{ + if(currentIndex===index){ + item.answer=choices?choices.map(choicesItem=>{return choicesItem.text}).join('\n'):'。。。未知' + item.isEdit=false + return true + } + return false + }) + const chatObjConfig={ + option:option, + currentIndex:currentIndex+1 + } + option.push({ + question:'', + answer:'', + isEdit:true + }) + thisBack.setData( + { + isLoading: false, + chatObjConfig:chatObjConfig + } + ) + setTimeout(function () { + wx.hideLoading() + }, 2000) + resolve(res) + }, + fail: error => { + thisBack.setData({ + isLoading: false + }) + setTimeout(function () { + wx.hideLoading() + }, 2000) + reject(error) + } + }); + }) + }, + clickHeadBtn(e){ console.log(e) const {btnType}=e.currentTarget.dataset diff --git a/miniprogram/pages/future/future.wxml b/miniprogram/pages/future/future.wxml index 3905e58..a5840cf 100644 --- a/miniprogram/pages/future/future.wxml +++ b/miniprogram/pages/future/future.wxml @@ -1,28 +1,45 @@ - - - - + + + + + + + + + + 问:$ + + + 问:$ {{item.question}} + + + + + + openai回答:$ {{item.answer}} + + + + + + - - - - - - - - + + + + + + + + + \ No newline at end of file diff --git a/miniprogram/pages/future/future.wxss b/miniprogram/pages/future/future.wxss index 3f40087..1652694 100644 --- a/miniprogram/pages/future/future.wxss +++ b/miniprogram/pages/future/future.wxss @@ -3,13 +3,12 @@ position: relative; width: 100vw; height:100vh; - background: linear-gradient(to right, #fff 1px, transparent 1px), linear-gradient(to bottom, #fff 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; overflow: hidden; box-sizing: border-box; - } .loading{ @@ -24,20 +23,20 @@ } .container-box{ position: relative; - width: 100vw; + width: 100%; height: 100vh; overflow: auto; } .header-container{ position: absolute; height:30px; - width: 100vw; + width: 100%; } .content-container{ margin-top:30px; position: absolute; height:100vh; - width: 100vw; + width: 100%; overflow: auto; } .flex-container{ @@ -79,4 +78,45 @@ button{ flex:1; text-align: center; background-color: rgb(8, 183, 252); +} + +.form-container-api{ + display: block; + height:auto; + width: 100%; +} + + +.form-request{ + display: block; + width: 100%; + color:#07c160; + background-color: rgb(37, 0, 97); +} +.form-response{ + position: relative; + width: 100%; + margin-top: 10px; + display: block; + margin-bottom: 10px; + color:#07c160; + background-color: rgb(0, 72, 94); +} +.form-class-submit{ + margin-top: 10px; + display: block; + width: 100%; + background-color: rgb(248, 70, 0); +} + +.form-submit-btn{ + width: 100%; + display: block; +} + +.chat-container{ + margin-top:20px; + width: 100%; + height: 336px; + overflow: auto; } \ No newline at end of file -- GitLab