flat: 优化语音
This commit is contained in:
@@ -13,7 +13,9 @@ class BaseStore {
|
||||
}
|
||||
checkAndInitDB() {
|
||||
// 获取本地数据库版本
|
||||
// this.initDB()
|
||||
if (config.OnlyUseCachedDB) {
|
||||
return this.initDB()
|
||||
}
|
||||
const localVersion = uni.getStorageSync('indexedDBVersion') || 1
|
||||
console.log('DBVersion: ', localVersion, config.DBversion)
|
||||
if (localVersion === config.DBversion) {
|
||||
|
@@ -47,7 +47,8 @@ const useChatGroupDBStore = defineStore("messageGroup", () => {
|
||||
chatSessionID.value = tabelRow.sessionId
|
||||
initMessage(tabelRow.sessionId)
|
||||
} else {
|
||||
console.warn('本地数据库存在数据')
|
||||
if (config.OnlyUseCachedDB) return;
|
||||
console.warn('本地数据库不存在数据')
|
||||
getHistory('refresh')
|
||||
}
|
||||
}, 1000)
|
||||
@@ -132,7 +133,7 @@ const useChatGroupDBStore = defineStore("messageGroup", () => {
|
||||
displayText: '', // 用于流式渲染展示
|
||||
dataId: customDataID
|
||||
};
|
||||
|
||||
console.log(messages.value)
|
||||
const index = messages.value.length;
|
||||
messages.value.push(newMsg);
|
||||
|
||||
@@ -143,7 +144,12 @@ const useChatGroupDBStore = defineStore("messageGroup", () => {
|
||||
|
||||
function handleUnload() {
|
||||
newMsg.parentGroupId = chatSessionID.value;
|
||||
baseDB.db.add(massageName.value, newMsg);
|
||||
baseDB.db.add(massageName.value, newMsg).then((id) => {
|
||||
messages.value[index] = {
|
||||
...newMsg,
|
||||
id
|
||||
};
|
||||
});
|
||||
}
|
||||
window.addEventListener("unload", handleUnload);
|
||||
|
||||
@@ -192,15 +198,32 @@ const useChatGroupDBStore = defineStore("messageGroup", () => {
|
||||
}
|
||||
|
||||
// 云端数据
|
||||
function badFeedback(dataId, sessionId = chatSessionID.value, content = '') {
|
||||
let parmas = {
|
||||
dataId: dataId,
|
||||
sessionId: sessionId,
|
||||
userBadFeedback: '这是反馈',
|
||||
}
|
||||
// $api.chatRequest('/stepped', parmas, 'POST').then((res) => {
|
||||
// console.log('反馈成功')
|
||||
// })
|
||||
function badFeedback(msgs, content = '') {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (!msgs.dataId) {
|
||||
return msg('旧数据,没有dataId')
|
||||
}
|
||||
let parmas = {
|
||||
dataId: msgs.dataId,
|
||||
sessionId: msgs.parentGroupId,
|
||||
userBadFeedback: content,
|
||||
}
|
||||
|
||||
const dbData = {
|
||||
...toRaw(msgs),
|
||||
userBadFeedback: content,
|
||||
}
|
||||
|
||||
$api.chatRequest('/stepped', parmas, 'POST').then((res) => {
|
||||
baseDB.db.update(massageName.value, dbData) // 更新本地数据库
|
||||
messages.value.forEach((item) => {
|
||||
if (item.id === dbData.id) {
|
||||
item.userBadFeedback = content
|
||||
resolve()
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// 云端数据
|
||||
@@ -226,11 +249,11 @@ const useChatGroupDBStore = defineStore("messageGroup", () => {
|
||||
sessionId: chatSessionID.value
|
||||
}
|
||||
$api.chatRequest('/detail', params, 'GET', loading).then((res) => {
|
||||
console.log('detail:', res.data)
|
||||
let list = parseHistoryDetail(res.data.list, chatSessionID.value)
|
||||
if (list.length) {
|
||||
messages.value = list
|
||||
baseDB.db.add(massageName.value, list);
|
||||
baseDB.db.add(massageName.value, list).then((ids) => {
|
||||
messages.value = listAddId(list, ids)
|
||||
});
|
||||
}
|
||||
console.log('解析后:', list)
|
||||
}).catch(() => {
|
||||
@@ -271,7 +294,7 @@ const useChatGroupDBStore = defineStore("messageGroup", () => {
|
||||
displayText: text,
|
||||
self: self,
|
||||
text: text,
|
||||
userBadFeedback: element.userBadFeedback,
|
||||
userBadFeedback: element.userBadFeedback || '',
|
||||
dataId: element.dataId,
|
||||
files,
|
||||
})
|
||||
@@ -279,12 +302,19 @@ const useChatGroupDBStore = defineStore("messageGroup", () => {
|
||||
return arr
|
||||
}
|
||||
|
||||
|
||||
function listAddId(list, ids) {
|
||||
return list.map((item, index) => ({
|
||||
...item,
|
||||
id: ids[index] || ids
|
||||
}))
|
||||
}
|
||||
|
||||
return {
|
||||
messages,
|
||||
isTyping,
|
||||
textInput,
|
||||
chatSessionID,
|
||||
addMessage,
|
||||
tabeList,
|
||||
init,
|
||||
toggleTyping,
|
||||
|
Reference in New Issue
Block a user