Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
yma16
yma16_miniprogram
提交
c0d8491d
Y
yma16_miniprogram
项目概览
yma16
/
yma16_miniprogram
通知
11
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Y
yma16_miniprogram
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
c0d8491d
编写于
4月 01, 2023
作者:
yma16
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat:chagpt
上级
d87bfb13
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
207 addition
and
89 deletion
+207
-89
miniprogram/pages/future/future.js
miniprogram/pages/future/future.js
+76
-43
miniprogram/pages/future/future.wxml
miniprogram/pages/future/future.wxml
+54
-35
miniprogram/pages/future/future.wxss
miniprogram/pages/future/future.wxss
+77
-11
未找到文件。
miniprogram/pages/future/future.js
浏览文件 @
c0d8491d
...
...
@@ -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
({
...
...
miniprogram/pages/future/future.wxml
浏览文件 @
c0d8491d
<!--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
miniprogram/pages/future/future.wxss
浏览文件 @
c0d8491d
...
...
@@ -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 -
9
0px);
height: calc(100vh -
14
0px);
}
.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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录