新增对话上下文,限制上下文最多5000字

This commit is contained in:
weipengfei 2023-09-22 09:41:36 +08:00
parent f14b0b11be
commit fbdb8fe8c6
1 changed files with 55 additions and 29 deletions

View File

@ -49,7 +49,7 @@
return {
talkList: [],
ajax: {
rows: 100, //
rows: 15, //
page: 1, //
flag: false, //
loading: false, //
@ -76,8 +76,8 @@
uni.onKeyboardHeightChange(e => {
let h = this.keyboardHeight;
this.keyboardHeight = e.height;
this.$nextTick(()=>{
setTimeout(()=>{
this.$nextTick(() => {
setTimeout(() => {
uni.pageScrollTo({
scrollTop: 9999999, //
duration: 300 // 300ms300ms
@ -106,7 +106,7 @@
if (cl < nc.length) {
this.c_content += nc[cl];
cl++;
if (cl % 6 == 0) this.$nextTick(()=>{
if (cl % 6 == 0) this.$nextTick(() => {
uni.pageScrollTo({
scrollTop: 999999,
})
@ -136,7 +136,7 @@
},
//
getHistoryMsg() {
return ;
return;
if (this.ajax.flag) {
return; //
}
@ -222,7 +222,7 @@
}, 1500);
})
},
focus(){
focus() {
// this.$nextTick(()=>{
// setTimeout(()=>{
// uni.pageScrollTo({
@ -263,13 +263,13 @@
})
return;
}
try{
try {
clearInterval(this.timer);
this.talkList[this.talkList.length-1].content = this.c_content+'';
this.talkList[this.talkList.length - 1].content = this.c_content + '';
this.c_content = '';
this.n_content = '';
this.socketTask.close({
success:(res)=> {
success: (res) => {
console.log('关闭成功', res);
this.wsLiveFlag = false;
},
@ -277,7 +277,7 @@
console.log('关闭失败', err)
}
})
}catch(e){
} catch (e) {
//TODO handle the exception
}
//
@ -307,7 +307,7 @@
// });
})
this.sendToSpark();
},
async sendToSpark() {
// let myUrl = await this.getWebSocketUrl();
@ -350,7 +350,9 @@
// }
// }
// };
let params = this.TEXT
if (this.historyTextList.length > 8) this.historyTextList = this.historyTextList.splice(-8);
this.isSurpass();
let params = this.historyTextList;
realThis.socketTask.send({ // uni
data: JSON.stringify(params),
success() {
@ -404,6 +406,19 @@
}
})
},
//
isSurpass(){
let sum = this.historyTextList.reduce((accumulator, currentValue) => {
return accumulator + currentValue.content;
}, '');
if(sum.length>5000){
this.historyTextList.shift();
return this.isSurpass();
}else {
console.log(`本次发送${sum.length}`);
return sum;
}
},
//
getWebSocketUrl() {
return new Promise((resolve, reject) => {
@ -429,17 +444,17 @@
},
//
bindScroll() {
if (this.userId == 0) {
this.getHistory();
this.getproductInfo();
this.getOrderInfo();
this.getRefundDetail();
this.getStoreDetail();
} else {
this.getMerHistory();
}
if (this.userId == 0) {
this.getHistory();
this.getproductInfo();
this.getOrderInfo();
this.getRefundDetail();
this.getStoreDetail();
} else {
this.getMerHistory();
}
},
touchmove(e){
touchmove(e) {
uni.hideKeyboard()
}
}
@ -453,13 +468,21 @@
background-color: #f5f5f5;
font-size: 28rpx;
}
@keyframes blink {
0% { opacity: 1; }
50% { opacity: 0; }
100% { opacity: 1; }
0% {
opacity: 1;
}
50% {
opacity: 0;
}
100% {
opacity: 1;
}
}
.blinking-box {
background-color: #333;
color: #333;
@ -521,8 +544,10 @@
border-top: #e5e5e5 solid 1px;
box-sizing: content-box;
background-color: #f5f5f5;
transform: translateY(0); /* 初始化 transform 属性 */
transition: transform 0.3s ease; /* 添加过渡效果 */
transform: translateY(0);
/* 初始化 transform 属性 */
transition: transform 0.3s ease;
/* 添加过渡效果 */
/* 兼容iPhoneX */
padding-bottom: 0;
@ -640,6 +665,7 @@
margin: 0 !important;
padding: 0 !important;
}
.placeholder {
width: 100vw;
background-color: #1573fb;