新增对话上下文,限制上下文最多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 { return {
talkList: [], talkList: [],
ajax: { ajax: {
rows: 100, // rows: 15, //
page: 1, // page: 1, //
flag: false, // flag: false, //
loading: false, // loading: false, //
@ -76,8 +76,8 @@
uni.onKeyboardHeightChange(e => { uni.onKeyboardHeightChange(e => {
let h = this.keyboardHeight; let h = this.keyboardHeight;
this.keyboardHeight = e.height; this.keyboardHeight = e.height;
this.$nextTick(()=>{ this.$nextTick(() => {
setTimeout(()=>{ setTimeout(() => {
uni.pageScrollTo({ uni.pageScrollTo({
scrollTop: 9999999, // scrollTop: 9999999, //
duration: 300 // 300ms300ms duration: 300 // 300ms300ms
@ -106,7 +106,7 @@
if (cl < nc.length) { if (cl < nc.length) {
this.c_content += nc[cl]; this.c_content += nc[cl];
cl++; cl++;
if (cl % 6 == 0) this.$nextTick(()=>{ if (cl % 6 == 0) this.$nextTick(() => {
uni.pageScrollTo({ uni.pageScrollTo({
scrollTop: 999999, scrollTop: 999999,
}) })
@ -136,7 +136,7 @@
}, },
// //
getHistoryMsg() { getHistoryMsg() {
return ; return;
if (this.ajax.flag) { if (this.ajax.flag) {
return; // return; //
} }
@ -222,7 +222,7 @@
}, 1500); }, 1500);
}) })
}, },
focus(){ focus() {
// this.$nextTick(()=>{ // this.$nextTick(()=>{
// setTimeout(()=>{ // setTimeout(()=>{
// uni.pageScrollTo({ // uni.pageScrollTo({
@ -263,13 +263,13 @@
}) })
return; return;
} }
try{ try {
clearInterval(this.timer); 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.c_content = '';
this.n_content = ''; this.n_content = '';
this.socketTask.close({ this.socketTask.close({
success:(res)=> { success: (res) => {
console.log('关闭成功', res); console.log('关闭成功', res);
this.wsLiveFlag = false; this.wsLiveFlag = false;
}, },
@ -277,7 +277,7 @@
console.log('关闭失败', err) console.log('关闭失败', err)
} }
}) })
}catch(e){ } catch (e) {
//TODO handle the exception //TODO handle the exception
} }
// //
@ -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 realThis.socketTask.send({ // uni
data: JSON.stringify(params), data: JSON.stringify(params),
success() { 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() { getWebSocketUrl() {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
@ -429,17 +444,17 @@
}, },
// //
bindScroll() { bindScroll() {
if (this.userId == 0) { if (this.userId == 0) {
this.getHistory(); this.getHistory();
this.getproductInfo(); this.getproductInfo();
this.getOrderInfo(); this.getOrderInfo();
this.getRefundDetail(); this.getRefundDetail();
this.getStoreDetail(); this.getStoreDetail();
} else { } else {
this.getMerHistory(); this.getMerHistory();
} }
}, },
touchmove(e){ touchmove(e) {
uni.hideKeyboard() uni.hideKeyboard()
} }
} }
@ -455,9 +470,17 @@
} }
@keyframes blink { @keyframes blink {
0% { opacity: 1; } 0% {
50% { opacity: 0; } opacity: 1;
100% { opacity: 1; } }
50% {
opacity: 0;
}
100% {
opacity: 1;
}
} }
.blinking-box { .blinking-box {
@ -521,8 +544,10 @@
border-top: #e5e5e5 solid 1px; border-top: #e5e5e5 solid 1px;
box-sizing: content-box; box-sizing: content-box;
background-color: #f5f5f5; background-color: #f5f5f5;
transform: translateY(0); /* 初始化 transform 属性 */ transform: translateY(0);
transition: transform 0.3s ease; /* 添加过渡效果 */ /* 初始化 transform 属性 */
transition: transform 0.3s ease;
/* 添加过渡效果 */
/* 兼容iPhoneX */ /* 兼容iPhoneX */
padding-bottom: 0; padding-bottom: 0;
@ -640,6 +665,7 @@
margin: 0 !important; margin: 0 !important;
padding: 0 !important; padding: 0 !important;
} }
.placeholder { .placeholder {
width: 100vw; width: 100vw;
background-color: #1573fb; background-color: #1573fb;