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