flat: 暂存
This commit is contained in:
@@ -13,6 +13,7 @@ class BaseStore {
|
||||
}
|
||||
checkAndInitDB() {
|
||||
// 获取本地数据库版本
|
||||
// this.initDB()
|
||||
const localVersion = uni.getStorageSync('indexedDBVersion') || 1
|
||||
console.log('DBVersion: ', localVersion, config.DBversion)
|
||||
if (localVersion === config.DBversion) {
|
||||
|
@@ -3,7 +3,8 @@ import {
|
||||
} from 'pinia';
|
||||
import {
|
||||
reactive,
|
||||
ref
|
||||
ref,
|
||||
toRaw
|
||||
} from 'vue'
|
||||
import IndexedDBHelper from '@/common/IndexedDBHelper.js'
|
||||
import baseDB from './BaseDBStore';
|
||||
@@ -31,13 +32,6 @@ const useChatGroupDBStore = defineStore("messageGroup", () => {
|
||||
const chatSessionID = ref('')
|
||||
const lastDateRef = ref('')
|
||||
|
||||
// const groupPages = reactive({
|
||||
// page: 0,
|
||||
// total: 0,
|
||||
// maxPage: 2,
|
||||
// pageSize: 50,
|
||||
// })
|
||||
|
||||
async function init() {
|
||||
// 获取所有数据
|
||||
setTimeout(async () => {
|
||||
@@ -54,7 +48,7 @@ const useChatGroupDBStore = defineStore("messageGroup", () => {
|
||||
initMessage(tabelRow.sessionId)
|
||||
} else {
|
||||
console.warn('本地数据库存在数据')
|
||||
// getHistory('refresh')
|
||||
getHistory('refresh')
|
||||
}
|
||||
}, 1000)
|
||||
}
|
||||
@@ -106,28 +100,37 @@ const useChatGroupDBStore = defineStore("messageGroup", () => {
|
||||
}
|
||||
|
||||
async function addMessageIndexdb(payload) {
|
||||
console.log(payload)
|
||||
return await baseDB.db.add(massageName.value, payload);
|
||||
}
|
||||
|
||||
async function getStearm(text, fileUrls = [], progress) {
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
try {
|
||||
toggleTyping(true);
|
||||
|
||||
const customDataID = 'message_' + UUID.generate()
|
||||
const params = {
|
||||
data: text,
|
||||
sessionId: chatSessionID.value,
|
||||
dataId: customDataID
|
||||
};
|
||||
|
||||
if (fileUrls && fileUrls.length) {
|
||||
params['fileUrl'] = fileUrls.map((item) => item.url);
|
||||
}
|
||||
|
||||
// ------>
|
||||
const MsgData = {
|
||||
text: text,
|
||||
self: true,
|
||||
displayText: text,
|
||||
files: fileUrls
|
||||
};
|
||||
addMessage(MsgData); // 添加message数据
|
||||
// <------
|
||||
const newMsg = {
|
||||
text: [], // 存储原始结构化内容
|
||||
text: '', // 存储原始结构化内容
|
||||
self: false,
|
||||
displayText: '' // 用于流式渲染展示
|
||||
displayText: '', // 用于流式渲染展示
|
||||
dataId: customDataID
|
||||
};
|
||||
|
||||
const index = messages.value.length;
|
||||
@@ -144,36 +147,10 @@ const useChatGroupDBStore = defineStore("messageGroup", () => {
|
||||
}
|
||||
window.addEventListener("unload", handleUnload);
|
||||
|
||||
function renderPart(part) {
|
||||
if (typeof part === 'string') {
|
||||
newMsg.displayText += part;
|
||||
} else if (typeof part === 'object' && part.type === 'highlight') {
|
||||
consol.log('自定义样式')
|
||||
newMsg.displayText += `<span class="highlight">${part.content}</span>`;
|
||||
} else {
|
||||
newMsg.displayText += String(part); // 兜底
|
||||
}
|
||||
}
|
||||
|
||||
function onDataReceived(data) {
|
||||
let parsed;
|
||||
try {
|
||||
parsed = JSON.parse(data);
|
||||
} catch {
|
||||
parsed = data;
|
||||
}
|
||||
|
||||
// 支持追加多个部分
|
||||
if (Array.isArray(parsed)) {
|
||||
parsed.forEach((part) => {
|
||||
newMsg.text.push(part); // 存结构
|
||||
renderPart(part); // 渲染显示
|
||||
});
|
||||
} else {
|
||||
newMsg.text.push(parsed);
|
||||
renderPart(parsed);
|
||||
}
|
||||
|
||||
newMsg.text += data;
|
||||
newMsg.displayText += data;
|
||||
messages.value[index] = {
|
||||
...newMsg
|
||||
};
|
||||
@@ -214,6 +191,18 @@ const useChatGroupDBStore = defineStore("messageGroup", () => {
|
||||
initMessage(item.sessionId)
|
||||
}
|
||||
|
||||
// 云端数据
|
||||
function badFeedback(dataId, sessionId = chatSessionID.value, content = '') {
|
||||
let parmas = {
|
||||
dataId: dataId,
|
||||
sessionId: sessionId,
|
||||
userBadFeedback: '这是反馈',
|
||||
}
|
||||
// $api.chatRequest('/stepped', parmas, 'POST').then((res) => {
|
||||
// console.log('反馈成功')
|
||||
// })
|
||||
}
|
||||
|
||||
// 云端数据
|
||||
function getHistory() {
|
||||
$api.chatRequest('/getHistory').then((res) => {
|
||||
@@ -282,6 +271,7 @@ const useChatGroupDBStore = defineStore("messageGroup", () => {
|
||||
displayText: text,
|
||||
self: self,
|
||||
text: text,
|
||||
userBadFeedback: element.userBadFeedback,
|
||||
dataId: element.dataId,
|
||||
files,
|
||||
})
|
||||
@@ -303,6 +293,7 @@ const useChatGroupDBStore = defineStore("messageGroup", () => {
|
||||
changeDialogue,
|
||||
getStearm,
|
||||
getHistory,
|
||||
badFeedback
|
||||
};
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user