提交 d47ae269 编写于 作者: DCloud_JSON's avatar DCloud_JSON

1.0.16

上级 a3103637
## 1.0.16(2023-05-26)
- 更新 默认不启用(注释掉)广告组件`uni-ad-rewarded-video`
## 1.0.15(2023-05-26)
- 修复 由1.0.12优化引起的 web-pc端 样式不正确的问题
## 1.0.14(2023-05-25)
- 修复 报` config is not defined`的问题
## 1.0.13(2023-05-24)
......
......@@ -21,7 +21,11 @@
<view v-if="msgIndex == msgIndexList.length-1 && adpid && msg.insufficientScore">
<uni-ad-rewarded-video :adpid="adpid" @onAdClose="onAdClose"></uni-ad-rewarded-video>
<view style="flex-direction: column;color: red;">
<view>默认不启用广告组件(被注释),如需使用,请"去掉注释"</view>
<view>位置:/components/uni-ai-msg/uni-ai-msg.vue 第28行,或全局搜索 uni-ad-rewarded-video</view>
</view>
<!-- <uni-ad-rewarded-video :adpid="adpid" @onAdClose="onAdClose"></uni-ad-rewarded-video> -->
</view>
</view>
<uni-icons v-if="msgIndex == msgIndexList.length-1 && !msg.isAi && msg.state != 100 && msgStateIcon(msg)"
......@@ -278,7 +282,11 @@
.reverse-align {
align-items: flex-end;
}
.create_time-box {
margin-top: 15px;
justify-content: center;
}
/* #ifndef VUE3 && APP-PLUS */
......
......@@ -61,7 +61,7 @@
},
"quickapp" : {},
"mp-weixin" : {
"appid" : "wxdcbd74f0961c068d",
"appid" : "wx07597007230e3702",
"setting" : {
"urlCheck" : false,
"es6" : false
......
{
"id": "uni-ai-chat",
"name": "uni-ai-chat",
"version": "1.0.14",
"version": "1.0.16",
"description": "基于uni-ai的聊天示例项目,支持流式、支持前文总结,云端一体",
"main": "main.js",
"scripts": {
......
......@@ -4,13 +4,13 @@
<view v-if="isWidescreen" class="header">uni-ai-chat</view>
<text class="noData" v-if="msgLength === 0">没有对话记录</text>
<scroll-view :scroll-into-view="scrollIntoView" scroll-y="true" class="msg-list" :enable-flex="true">
<uni-ai-msg ref="msg" v-for="(msgIndex,index) in msgLength" :key="index" :msgIndex="index"
:show-cursor="index == msgLength - 1 && msgLength%2 === 0 && sseIndex"
></uni-ai-msg>
<uni-ai-msg ref="msg" v-for="(msgIndex,index) in msgLength" :key="index" :msgIndex="index"
:show-cursor="index == msgLength - 1 && msgLength%2 === 0 && sseIndex"></uni-ai-msg>
<view class="tip-ai-ing" v-if="msgLength && msgLength%2 !== 0">
<text>uni-ai正在思考中...</text>
<view v-if="NODE_ENV == 'development' && !enableStream">
如需提速,请开通<uni-link class="uni-link" href="https://uniapp.dcloud.net.cn/uniCloud/uni-ai-chat.html" text="[流式响应]"></uni-link>
如需提速,请开通<uni-link class="uni-link" href="https://uniapp.dcloud.net.cn/uniCloud/uni-ai-chat.html"
text="[流式响应]"></uni-link>
</view>
</view>
<view id="last-msg-item"></view>
......@@ -48,8 +48,10 @@
<script>
// 引入配置文件
import config from '@/config.js';
import {msgList} from '@/pages/chat/msgList.js';
import {
msgList
} from '@/pages/chat/msgList.js';
// 获取广告id
const {
......@@ -63,13 +65,13 @@
// 键盘的shift键是否被按下
let shiftKeyPressed = false
export default {
export default {
data() {
return {
// 使聊天窗口滚动到指定元素id的值
scrollIntoView: "",
// 消息长度(个数)
msgLength:0,
msgLength: 0,
// 消息列表数据
msgList: [],
// 输入框的消息内容
......@@ -84,7 +86,7 @@
adpid,
focus: false
}
},
},
computed: {
// 输入框是否禁用
inputBoxDisabled() {
......@@ -122,30 +124,30 @@
// console.log('this.focus', this.focus);
})
},
// #endif
// #endif
msgList: {
handler(msgList) {
let msgLength = msgList.length
if(msgLength != this.msgLength){
this.msgLength = msgLength
this.$nextTick(()=>{
this.updateLastMsg(msgList[msgLength - 1])
})
}
handler(msgList) {
let msgLength = msgList.length
if (msgLength != this.msgLength) {
this.msgLength = msgLength
this.$nextTick(() => {
this.updateLastMsg(msgList[msgLength - 1])
})
}
// 将msgList存储到本地缓存中
uni.setStorage({
"key":"uni-ai-msg",
"data":msgList
})
uni.setStorage({
"key": "uni-ai-msg",
"data": msgList
})
},
// 深度监听msgList变化
deep: true
}
},
async mounted() {
async mounted() {
// 如果存在广告位id且用户token未过期
if (this.adpid && uniCloud.getCurrentUserInfo().tokenExpired > Date.now()) {
// 查询当前用户的积分
......@@ -172,14 +174,14 @@
// content: "1-" + i
// })
// }
let _msgList = uni.getStorageSync('uni-ai-msg') || [];
if(_msgList.length){
msgList.push(..._msgList)
}
this.msgList = msgList
let _msgList = uni.getStorageSync('uni-ai-msg') || [];
if (_msgList.length) {
msgList.push(..._msgList)
}
this.msgList = msgList
// 如果上一次对话中 最后一条消息ai未回复。则一启动就自动重发。
let length = this.msgList.length
......@@ -292,7 +294,7 @@
lastMsg = Object.assign(lastMsg, data)
}
}
this.msgList.splice(length - 1, 1, lastMsg)
this.msgList.splice(length - 1, 1, lastMsg)
},
// 广告关闭事件
onAdClose(e) {
......@@ -424,8 +426,8 @@
state: 0,
// 消息创建时间
create_time: Date.now()
})
})
// 展示最后一条消息
this.showLastMsg()
// dom加载完成后 清空文本内容
......@@ -552,9 +554,9 @@
})
.then(res => {
// console.log(111,res);
if (!sseChannel) {
if(!res.data){
return
if (!sseChannel) {
if (!res.data) {
return
}
// 更新最后一条消息的状态为100(发送成功)
this.updateLastMsg({
......@@ -597,10 +599,10 @@
} else {
console.log('用户点击了清空按钮,跳过前一次请求的回调。内容:', res.data.reply);
}
}else{
// 处理 sseChannel没结束 云函数提前结束的情况
sseChannel.close()
this.sseIndex = 0
} else {
// 处理 sseChannel没结束 云函数提前结束的情况
sseChannel.close()
this.sseIndex = 0
}
})
.catch(e => {
......@@ -611,7 +613,7 @@
// 如果最后一条消息的来源是人工智能机器人 就将流式响应计数值设置为0
if (l && sseChannel && this.msgList[l - 1].isAi) {
sseChannel.close()
sseChannel.close()
this.sseIndex = 0
}
......@@ -678,7 +680,7 @@
// 将流式响应计数值归零
this.sseIndex = 0
// 将消息列表清空
this.msgList.splice(0,this.msgLength);
this.msgList.splice(0, this.msgLength);
}
}
});
......@@ -700,6 +702,7 @@
display: flex;
box-sizing: border-box;
}
/* #endif */
......@@ -803,6 +806,7 @@
.send::after {
display: none;
}
/* #endif */
......@@ -811,6 +815,7 @@
height: 1px;
width: 750rpx;
}
.noData {
margin-top: 15px;
text-align: center;
......@@ -819,6 +824,7 @@
font-size: 12px;
justify-content: center;
}
.tip-ai-ing {
align-items: center;
flex-direction: column;
......@@ -847,112 +853,106 @@
max-width: 950px;
}
.container,
.container
{
box-shadow: 0 0 5px #e0e1e7;
margin-top: 44px;
border-radius: 10px;
overflow: hidden;
}
.container .header {
height: 44px;
line-height: 44px;
border-bottom: 1px solid #F0F0F0;
width: 100vw;
justify-content: center;
font-weight: 500;
}
box-shadow: 0 0 5px #e0e1e7;
margin-top: 44px;
border-radius: 10px;
overflow: hidden;
}
.content {
background-color: #f9f9f9;
position: relative;
max-width: 90%;
}
.container .header {
height: 44px;
line-height: 44px;
border-bottom: 1px solid #F0F0F0;
width: 100vw;
justify-content: center;
font-weight: 500;
}
// .copy {
// color: #888888;
// position: absolute;
// right: 8px;
// top: 8px;
// font-size: 12px;
// cursor:pointer;
// }
// .copy :hover{
// color: #4b9e5f;
// }
.foot-box,
.foot-box-content,
.msg-list,
.msg-item,
// .create_time,
.noData,
.textarea-box,
.textarea,
textarea-box {
width: 100% !important;
}
.content {
background-color: #f9f9f9;
position: relative;
max-width: 90%;
}
.create_time-box {
margin-top: 15px;
justify-content: center;
}
// .copy {
// color: #888888;
// position: absolute;
// right: 8px;
// top: 8px;
// font-size: 12px;
// cursor:pointer;
// }
// .copy :hover{
// color: #4b9e5f;
// }
.foot-box,
.foot-box-content,
.msg-list,
.msg-item,
// .create_time,
.noData,
.textarea-box,
.textarea,
textarea-box {
width: 100% !important;
}
.textarea-box,
.textarea,
textarea,
textarea-box {
height: 120px;
}
.textarea-box,
.textarea,
textarea,
textarea-box {
height: 120px;
}
.container,
.foot-box,
.textarea-box {
background-color: #FFF;
}
.foot-box,
.textarea-box {
background-color: #FFF;
}
.foot-box-content {
flex-direction: column;
justify-content: center;
align-items: flex-end;
padding-bottom: 0;
}
.foot-box-content {
flex-direction: column;
justify-content: center;
align-items: flex-end;
padding-bottom: 0;
}
.menu {
padding: 0 10px;
}
.menu {
padding: 0 10px;
}
.menu-item {
height: 20px;
justify-content: center;
align-items: center;
align-content: center;
display: flex;
margin-right: 10px;
cursor: pointer;
}
.menu-item {
height: 20px;
justify-content: center;
align-items: center;
align-content: center;
display: flex;
margin-right: 10px;
cursor: pointer;
}
.trash {
opacity: 0.8;
}
.trash {
opacity: 0.8;
}
.trash image {
height: 15px;
}
.trash image {
height: 15px;
}
.textarea-box,
.textarea-box * {
// border: 1px solid #000;
}
.textarea-box,
.textarea-box * {
// border: 1px solid #000;
}
.send-btn-box .send-btn-tip {
color: #919396;
margin-right: 8px;
font-size: 12px;
line-height: 28px;
}
.send-btn-box .send-btn-tip {
color: #919396;
margin-right: 8px;
font-size: 12px;
line-height: 28px;
}
}
/* #endif */
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册