|
|
@@ -92,8 +92,8 @@ import DefaultMessage from "@/components/DefaultMessage/index.vue";
|
|
|
const props = defineProps({
|
|
|
//根据需求传输
|
|
|
isCourse: { type: Boolean, default: false},
|
|
|
- cacheDataKey: { type: String, default: localStorage.getItem('token') + "_ai_textToText" },
|
|
|
- cacheDataHistoryKey: { type: String, default: localStorage.getItem('token') + "_ai_textToText_history" },
|
|
|
+ cacheDataKey: { type: String, default: null },
|
|
|
+ cacheDataHistoryKey: { type: String, default: null },
|
|
|
preDialogueList: { type: Array, default: () => []},
|
|
|
replySupplement: { type: String, default: ''},
|
|
|
|
|
|
@@ -103,6 +103,33 @@ const props = defineProps({
|
|
|
personIntroduce: { type: String},
|
|
|
})
|
|
|
|
|
|
+// 计算带personId的缓存键
|
|
|
+const computedCacheDataKey = computed(() => {
|
|
|
+ let cacheKey = props.cacheDataKey;
|
|
|
+ if (!cacheKey) {
|
|
|
+ cacheKey = localStorage.getItem('token') + "_ai_textToText";
|
|
|
+ }
|
|
|
+ if (props.personId) {
|
|
|
+ cacheKey += `_${props.personId}`;
|
|
|
+ }
|
|
|
+ return cacheKey;
|
|
|
+});
|
|
|
+
|
|
|
+// 计算带personId的历史记录缓存键
|
|
|
+const computedCacheDataHistoryKey = computed(() => {
|
|
|
+ let historyKey = props.cacheDataHistoryKey;
|
|
|
+ if (!historyKey) {
|
|
|
+ historyKey = localStorage.getItem('token') + "_ai_textToText";
|
|
|
+ }
|
|
|
+ if (props.personId) {
|
|
|
+ historyKey += `_${props.personId}`;
|
|
|
+ }
|
|
|
+ if (!props.cacheDataHistoryKey){
|
|
|
+ historyKey += "_history";
|
|
|
+ }
|
|
|
+ return historyKey;
|
|
|
+});
|
|
|
+
|
|
|
// 定义emits
|
|
|
const emits = defineEmits(['saveProgress'])
|
|
|
|
|
|
@@ -195,8 +222,7 @@ const getConversation = async (id) => {
|
|
|
// )
|
|
|
|
|
|
// 取缓存历史记录
|
|
|
- let cacheDataHistoryStr = localStorage.getItem(props.cacheDataHistoryKey);
|
|
|
- console.log("cacheDataHistoryStr", cacheDataHistoryStr);
|
|
|
+ let cacheDataHistoryStr = localStorage.getItem(computedCacheDataHistoryKey.value);
|
|
|
if (cacheDataHistoryStr) {
|
|
|
cacheDataHistoryList.value = JSON.parse(cacheDataHistoryStr) || [];
|
|
|
activeMessageList.value.push(...cacheDataHistoryList.value);
|
|
|
@@ -204,7 +230,7 @@ const getConversation = async (id) => {
|
|
|
// 加入预置对话
|
|
|
activeMessageList.value.push(...props.preDialogueList);
|
|
|
cacheDataHistoryList.value.push(...props.preDialogueList);
|
|
|
- localStorage.setItem(props.cacheDataHistoryKey, JSON.stringify(cacheDataHistoryList.value));
|
|
|
+ localStorage.setItem(computedCacheDataHistoryKey.value, JSON.stringify(cacheDataHistoryList.value));
|
|
|
}
|
|
|
};
|
|
|
|
|
|
@@ -305,7 +331,7 @@ const doSendMessage = async (content) => {
|
|
|
content: content,
|
|
|
createTime: new Date(),
|
|
|
});
|
|
|
- localStorage.setItem(props.cacheDataHistoryKey, JSON.stringify(cacheDataHistoryList.value));
|
|
|
+ localStorage.setItem(computedCacheDataHistoryKey.value, JSON.stringify(cacheDataHistoryList.value));
|
|
|
|
|
|
|
|
|
// 执行发送
|
|
|
@@ -548,7 +574,7 @@ const textRoll = async () => {
|
|
|
content: receiveMessageFullText.value,
|
|
|
createTime: new Date(),
|
|
|
});
|
|
|
- localStorage.setItem(props.cacheDataHistoryKey, JSON.stringify(cacheDataHistoryList.value));
|
|
|
+ localStorage.setItem(computedCacheDataHistoryKey.value, JSON.stringify(cacheDataHistoryList.value));
|
|
|
}
|
|
|
|
|
|
// 不是对话中可以结束
|
|
|
@@ -602,17 +628,17 @@ onMounted(async () => {
|
|
|
selectedImage.value = personImage.value;
|
|
|
|
|
|
//创建对话
|
|
|
- let cacheDataKeyData = localStorage.getItem(props.cacheDataKey);
|
|
|
+ let cacheDataKeyData = localStorage.getItem(computedCacheDataKey.value);
|
|
|
if (cacheDataKeyData) {
|
|
|
activeConversationId.value = cacheDataKeyData;
|
|
|
}else{
|
|
|
// 智能问答
|
|
|
CreateDialogue({ roleId: personId.value })
|
|
|
.then((res) => {
|
|
|
- console.log("创建会话:", res);
|
|
|
+ console.log("创建会话:", res.data);
|
|
|
activeConversationId.value = res.data;
|
|
|
//将会话存入会话缓存
|
|
|
- localStorage.setItem(props.cacheDataKey, activeConversationId.value)
|
|
|
+ localStorage.setItem(computedCacheDataKey.value, activeConversationId.value)
|
|
|
})
|
|
|
.catch((error) => {
|
|
|
console.error("请求出错:", error);
|
|
|
@@ -905,4 +931,4 @@ defineExpose({
|
|
|
cursor: pointer;
|
|
|
box-shadow: 0 0px 2px rgba(0, 0, 0, 0.3);
|
|
|
}
|
|
|
-</style>
|
|
|
+</style>
|