|
|
@@ -2,7 +2,7 @@ import { Component } from '@angular/core';
|
|
|
import { IonHeader, IonToolbar, IonTitle, IonContent,
|
|
|
IonCard, IonCardHeader, IonCardTitle, IonCardContent,
|
|
|
IonItem, IonAvatar, IonLabel, IonList, IonThumbnail,
|
|
|
- IonIcon, IonButton, ModalController,
|
|
|
+ IonIcon, IonButton, ModalController, IonSpinner
|
|
|
} from '@ionic/angular/standalone';
|
|
|
import { ExploreContainerComponent } from '../explore-container/explore-container.component';
|
|
|
import { CommonModule } from '@angular/common';
|
|
|
@@ -25,7 +25,7 @@ interface DialogueItem {
|
|
|
IonHeader, IonToolbar, IonTitle, IonContent, ExploreContainerComponent,
|
|
|
IonIcon, IonButton,
|
|
|
IonCard, IonCardHeader, IonCardTitle, IonCardContent,
|
|
|
- IonItem, IonAvatar, IonLabel, IonList, IonThumbnail,
|
|
|
+ IonItem, IonAvatar, IonLabel, IonList, IonThumbnail, IonSpinner
|
|
|
]
|
|
|
})
|
|
|
export class Tab2Page {
|
|
|
@@ -86,8 +86,13 @@ export class Tab2Page {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ isLoading: boolean = false; // 定义加载状态属性
|
|
|
+
|
|
|
sendMessage() {
|
|
|
console.log("create");
|
|
|
+
|
|
|
+ this.isLoading = true; // 开始加载
|
|
|
+ this.isComplete = false; // 重置完成状态
|
|
|
|
|
|
let dialogues = this.chatList.map(chat => {
|
|
|
const dialogueArray = chat.get('dialogue');
|
|
|
@@ -95,9 +100,9 @@ export class Tab2Page {
|
|
|
}).join('\n');
|
|
|
|
|
|
let PromptTemplate = `
|
|
|
- 请根据以下的用户聊天记录生成该用户的影视剧推荐列表。
|
|
|
-
|
|
|
- ${dialogues}
|
|
|
+ 请根据以下的用户聊天记录和用户画像生成该用户的影视剧推荐列表。
|
|
|
+ 聊天记录:${dialogues},
|
|
|
+ 用户画像:${this.currentUser.get("imagery")}。
|
|
|
|
|
|
请生成推荐列表,包括剧名、题材、评分和描述。
|
|
|
严格按照下面的格式生成:
|
|
|
@@ -118,6 +123,7 @@ export class Tab2Page {
|
|
|
|
|
|
if (message?.complete) {
|
|
|
this.isComplete = true;
|
|
|
+ this.isLoading = false; // 完成加载
|
|
|
|
|
|
// 假设 message.content 是自然语言文本而不是 JSON
|
|
|
try {
|
|
|
@@ -129,7 +135,18 @@ export class Tab2Page {
|
|
|
|
|
|
// 遍历推荐列表并保存到 FilmRecommendation 表
|
|
|
for (const rec of recommendations) {
|
|
|
+ // 检查是否已存在相同剧名的推荐
|
|
|
+ let query = new CloudQuery("FilmRecommendation");
|
|
|
+ query.equalTo("user", currentUser.toPointer()); // 只查询当前用户的记录
|
|
|
+ query.equalTo("title", rec.title); // 检查剧名是否相同
|
|
|
+
|
|
|
+ const existingRecommendations = await query.find();
|
|
|
+
|
|
|
+ if (existingRecommendations.length === 0) {
|
|
|
+ // 如果没有相同剧名的记录,保存新的推荐
|
|
|
+
|
|
|
const recommendation = new CloudObject("FilmRecommendation");
|
|
|
+
|
|
|
recommendation.set({
|
|
|
user: currentUser.toPointer(), // 设置用户指针
|
|
|
title: rec.title,
|
|
|
@@ -144,6 +161,9 @@ export class Tab2Page {
|
|
|
} catch (error) {
|
|
|
console.error('保存推荐失败:', error);
|
|
|
}
|
|
|
+ } else {
|
|
|
+ console.log(`推荐已存在,剧名: ${rec.title}`);
|
|
|
+ }
|
|
|
}
|
|
|
} catch (error) {
|
|
|
console.error('解析推荐内容失败:', error);
|