cainiao-hue 3 сар өмнө
parent
commit
5b0c72b422

+ 1 - 1
soul-app/angular.json

@@ -28,7 +28,7 @@
               {
                 "glob": "**/*",
                 "input": "src/assets",
-                "output": "assets"
+                "output": "assets",
               }
             ],
             "styles": ["src/global.scss", "src/theme/variables.scss"],

+ 1 - 1
soul-app/src/app/customer-service/customer-service.component.html

@@ -10,5 +10,5 @@
 <ion-content class="modal-content">
   <h2>欢迎来到客服帮助中心!</h2> 
   <p>客服热线:19870628587</p>
-  <p>早上8:00~晚上11:00</p>
+  <p>早上8:00~晚上23:00</p>
 </ion-content>

+ 0 - 20
soul-app/src/app/info-modal/info-modal.component.html

@@ -5,26 +5,6 @@
       用户名:{{currentUser?.get("username")}}
     </ion-card-title>
    </ion-card-header>
-
-   <!--
-   <ion-card-content>
-   <ion-item>
-     <ion-input [value]="userData['realname']" (ionChange)="userDataChange('realname',$event)" label="姓名" ></ion-input>
-   </ion-item>
-   <ion-item>
-    <ion-input [value]="userData['username']" (ionChange)="userDataChange('username',$event)" label="昵称" ></ion-input>
-  </ion-item>
-   <ion-item>
-     <ion-input type="number" [value]="userData['age']" (ionChange)="userDataChange('age',$event)" label="年龄" ></ion-input>
-    </ion-item>
-  <ion-item>
-     <ion-input [value]="userData['gender']" (ionChange)="userDataChange('gender',$event)" label="性别" ></ion-input>
-    </ion-item>
-    <ion-item>
-      <ion-input [value]="userData['avatar']" (ionChange)="userDataChange('avatar',$event)" label="头像" ></ion-input>
-     </ion-item>
-  </ion-card-content>
--->
 <ion-card-content>
   <ion-item>
     <ion-label>姓名: {{ userData['realname'] }}</ion-label>

+ 1 - 1
soul-app/src/app/tab1/tab1.page.ts

@@ -69,7 +69,7 @@ export class Tab1Page {
     {
       avatar: '/assets/img/6.png',
       content: '我喜欢这里的热门话题!',
-      rating: 4
+      rating: 5
     }
   ];
 

+ 1 - 0
soul-app/src/app/tab2/tab2.page.html

@@ -30,6 +30,7 @@
               <h2>{{ chatpartner.get('name') }}</h2>
               <p style="font-size: 15px;">专业领域:{{ chatpartner.get('expertise') }}</p>
             </ion-label>
+            <!--<ion-icon src="assets/outline/user.svg" slot="end"></ion-icon> -->
             <ion-button slot="end" (click)="clickToConsult(chatpartner)" style="margin-left: 10px;">开始陪聊</ion-button>
           </ion-item>
         </ion-list>

+ 4 - 0
soul-app/src/app/tab2/tab2.page.scss

@@ -54,4 +54,8 @@ ion-avatar {
 .custom-searchbar {
   --border-radius: 20px; /* 调整弯曲程度 */
   --background: #f0f0f0; /* 可以自定义背景颜色 */
+}
+ion-label p {
+  font-size: 1em; /* 调整字体大小,可以根据需要修改 */
+  line-height: 1.5; /* 调整行间距,使文本更易读 */
 }

+ 23 - 16
soul-app/src/app/tab2/tab2.page.ts

@@ -27,7 +27,6 @@ import { CustomerServiceComponent } from '../customer-service/customer-service.c
 })
 export class Tab2Page {
 
-  
   isModalOpen: boolean = false; // 定义 isModalOpen 属性
   placeholderText: string = '';
   placeholderIndex: number = 0;
@@ -47,8 +46,6 @@ export class Tab2Page {
     return await modal.present();
   }
 
-
-
   private modalCtrl: ModalController;
   constructor(private router: Router,modalCtrl: ModalController) {
     this.modalCtrl = modalCtrl;
@@ -56,6 +53,8 @@ export class Tab2Page {
     this.cyclePlaceholder();
   }
   async clickToConsult(chatpartner:CloudObject) {
+    let consult: CloudObject | null = null;
+    let messages: string[] = [];
     // 验证用户登录
     let currentUser = new CloudUser();
     let userPrompt = ``
@@ -63,8 +62,12 @@ export class Tab2Page {
       console.log("用户未登录,请登录后重试")
       let user = await openUserLoginModal(this.modalCtrl)
       if(!user?.id){
+        console.log("用户登录失败");
         return
-      }     
+      } 
+      else {
+        console.log("当前用户ID:", currentUser.id);
+      }    
     }
     if(currentUser?.get("username")){
       userPrompt += `当前来访的用户,姓名:${currentUser?.get("username")}`
@@ -78,8 +81,10 @@ export class Tab2Page {
 
     // 弹窗形式聊天:开始聊天
     localStorage.setItem("company","E4KpGvTEto")
-    let consult = new CloudObject("ChatRecord")
-    let messages: string[] = [];
+    // 创建聊天记录对象
+    consult = new CloudObject("ChatRecord")
+    messages = [];// 清空之前的消息记录
+    // 设置聊天记录的基本信息
     let now = new Date();
     let dateStr = `${now.getFullYear()}-${now.getMonth()+1}-${now.getDate()}`
     //对象权限的精确制定
@@ -89,12 +94,16 @@ export class Tab2Page {
     if(currentUser?.id){//当前用户 可读 可写
       ACL[currentUser?.id] = {read:true,write:true}
     }
+
     consult.set({
       title:`${chatpartner.get('expertise') || ""}领域聊天记录${dateStr}-${chatpartner.get('name')}`,
       chatpartner:chatpartner.toPointer(),
       user:currentUser.toPointer(),
-      ACL:ACL
+      ACL:ACL,
+      content: "", // 初始内容为空
+      createdAt: now, // 可以加上创建时间
     })
+    // 进入聊天面板
     let options:ChatPanelOptions = {
       roleId:"2DXJkRsjXK",
       onChatInit: (chat: FmodeChat) => {
@@ -104,7 +113,6 @@ export class Tab2Page {
         chat.role.set("bio",chatpartner.get("bio"));
         chat.role.set("expertise", chatpartner.get("expertise"));
         chat.role.set("avatar", chatpartner.get("avatar") || "/assets/img/2.png")//设置陪聊师头像
-
         chat.role.set("prompt", `
         # 角色设定
         您是${chatpartner.get("name")},一位${chatpartner.get("bio")},${chatpartner.get("expertise")},需要为用户提供陪伴和支持等积极情绪。
@@ -118,18 +126,18 @@ export class Tab2Page {
       onMessage:(chat:FmodeChat,message:FmodeChatMessage)=>{
         console.log("onMessage",message)
         let content:any = message?.content
-        if(typeof content == "string"){
+        if(typeof content === "string"){
           messages.push(content); // 将新消息添加到 messages 数组中
             consult.set({
               content: messages.join("\n"), // 将所有消息合并为一个字符串
             });
-            //consult.save();
-            consult.save().then(() => {
+          // 在此之前检查 consult 对象是否有效
+          console.log("准备保存聊天记录:", consult);
+          consult.save().then(() => {
               console.log("聊天记录已保存");
           }).catch((error) => {
               console.error("保存聊天记录时出错:", error);
           });
-          //}
         }
       },
         // chat?.chatSession?.id 本次会话的 chatId
@@ -138,6 +146,7 @@ export class Tab2Page {
       }
     }
     openChatPanelModal(this.modalCtrl,options)
+    
   }
   matchedCounselor: { name: string; specialty: string } | null = null;
 
@@ -190,7 +199,6 @@ export class Tab2Page {
         chat.role.set("bio",chatcompanion.get("bio"));
         chat.role.set("expertise", chatcompanion.get("expertise"));
         chat.role.set("avatar", chatcompanion.get("avatar") || "/assets/img/2.png")//设置聊天伙伴头像
-
         chat.role.set("prompt", `
         # 角色设定
         您是${chatcompanion.get("name")},一位${chatcompanion.get("bio")}的聊天伙伴,需要为用户提供陪伴和支持等积极情绪。
@@ -209,7 +217,6 @@ export class Tab2Page {
             consult.set({
               content: messages.join("\n"), // 将所有消息合并为一个字符串
             });
-            //consult.save();
             consult.save().then(() => {
               console.log("聊天记录已保存");
           }).catch((error) => {
@@ -224,9 +231,10 @@ export class Tab2Page {
       }
     }
     openChatPanelModal(this.modalCtrl,options)
-
+    
   }
 
+
   questions = [
     {
       title: '如何应对焦虑?',
@@ -245,7 +253,6 @@ export class Tab2Page {
     },
   ];
 
-  //matchCounselor() {
   ngOnInit() {
     this.loadChatPartnerList(),
     this.loadChatCompanionList()

+ 1 - 0
soul-app/src/app/tab3/tab3.page.html

@@ -42,6 +42,7 @@
     }
     </ion-card-content>
   </ion-card>
+  
   <!-- 功能列表 -->
   <ion-card>
   <ion-list>

+ 1 - 1
soul-app/src/app/tab3/tab3.page.ts

@@ -18,7 +18,7 @@ import { openInfoModal } from '../info-modal/info-modal.component';
     ExploreContainerComponent
   ],
   schemas: [CUSTOM_ELEMENTS_SCHEMA]
-})
+  })
 export class Tab3Page {
 
   currentUser:CloudUser|undefined

+ 5 - 2
soul-app/src/app/tabs/tabs.page.ts

@@ -3,7 +3,10 @@ import { IonTabs, IonTabBar, IonTabButton, IonTitle,IonIcon, IonLabel } from '@i
 import { addIcons } from 'ionicons';
 import { home, chatbubbles, person,chevronBack, headset, personOutline, chevronForwardOutline, heartOutline, notificationsOutline,
    settingsOutline,
-   informationCircleOutline, } from 'ionicons/icons';
+   informationCircleOutline,
+   chevronDown,
+   chevronUp,
+   star, } from 'ionicons/icons';
 
 
 @Component({
@@ -18,7 +21,7 @@ export class TabsPage {
 
   constructor() {
     addIcons({ home, chatbubbles, person ,chevronBack,headset,personOutline,chevronForwardOutline,heartOutline,notificationsOutline,
-      settingsOutline,informationCircleOutline});
+      settingsOutline,informationCircleOutline,chevronDown,chevronUp,star});
   }
 
 }

+ 3 - 0
soul-app/src/assets/outline/user.svg

@@ -0,0 +1,3 @@
+<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24">
+  <path d="M12 12c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm0 2c-3.31 0-10 1.67-10 5v2h20v-2c0-3.33-6.69-5-10-5z"/>
+</svg>

+ 46 - 33
soul-app/src/lib/ncloud.ts

@@ -256,9 +256,10 @@ export class CloudUser extends CloudObject {
             method: "POST"
         });
 
-        const result = await response?.json();
-        if (result?.error) {
-            console.error(result?.error);
+        const result = await response.json();
+        console.log("响应状态:", response.status, "响应数据:", result); // 打印响应状态和数据
+        if (result?.error||response.status !== 200) {//检查响应状态
+            console.error(result?.error|| '登录请求失败');
             return null;
         }
         
@@ -272,40 +273,11 @@ export class CloudUser extends CloudObject {
         return this;
     }
 
-    /** 登出 */
-    async logout() {
-        if (!this.sessionToken) {
-            console.error("用户未登录");
-            return;
-        }
-
-        const response = await fetch(`http://dev.fmode.cn:1337/parse/logout`, {
-            headers: {
-                "x-parse-application-id": "dev",
-                "x-parse-session-token": this.sessionToken
-            },
-            method: "POST"
-        });
-
-        const result = await response?.json();
-        if (result?.error) {
-            console.error(result?.error);
-            return false;
-        }
-
-        // 清除用户信息
-        localStorage.removeItem("NCloud/dev/User")
-        this.id = null;
-        this.sessionToken = null;
-        this.data = {};
-        return true;
-    }
-
     /** 注册 */
     async signUp(username: string, password: string, additionalData: Record<string, any> = {}) {
         const userData = {
             username,
-            password,
+            password,   
             ...additionalData // 合并额外的用户数据
         };
 
@@ -330,6 +302,47 @@ export class CloudUser extends CloudObject {
         this.data = result; // 保存用户数据
         return this;
     }
+    
+    /** 登出 */
+    async logout() {
+
+        if (!this.sessionToken) {
+            console.error("用户未登录或会话令牌无效,直接清除用户信息");
+            this.forceLogout(); // 直接强制登出
+            return;
+        }
+
+        const response = await fetch(`http://dev.fmode.cn:1337/parse/logout`, {
+            headers: {
+                "x-parse-application-id": "dev",
+                "x-parse-session-token": this.sessionToken
+            },
+            method: "POST"
+        });
+
+        const result = await response?.json();
+        if (result?.error) {
+            console.error(result?.error);
+            return false;
+        }
+
+        // 清除用户信息
+        localStorage.removeItem("NCloud/dev/User")
+        this.id = null;
+        this.sessionToken = null;
+        this.data = {};
+        return true;
+    }
+    /** 强制登出 */
+    async forceLogout() {
+    // 清除本地存储中的用户信息
+    localStorage.removeItem("NCloud/dev/User");
+    // 清空当前用户的状态
+    this.id = null;
+    this.sessionToken = null;
+    this.data = {};
+    console.log("用户已被强制登出");
+    }
 
     override async save() {
         let method = "POST";

+ 1 - 1
soul-app/src/lib/user/modal-user-edit/modal-user-edit.component.html

@@ -27,7 +27,7 @@
       <ion-input [value]="userData['email']" (ionChange)="userDataChange('avatar',$event)" label="邮箱" placeholder="请您输入邮箱号"></ion-input>
     </ion-item>
     <ion-item>
-      <ion-input [value]="userData['account']" (ionChange)="userDataChange('avatar',$event)" label="号" placeholder="请您输入手机号"></ion-input>
+      <ion-input [value]="userData['account']" (ionChange)="userDataChange('avatar',$event)" label="手机号" placeholder="请您输入手机号"></ion-input>
     </ion-item>
 
    <ion-button expand="block" color="danger" (click)="save()">保存</ion-button>

+ 1 - 1
soul-app/src/lib/user/modal-user-login/modal-user-login.component.html

@@ -18,7 +18,7 @@
       <ion-input [value]="username" (ionChange)="usernameChange($event)" label="昵称" placeholder="昵称"></ion-input>
     </ion-item>
     <ion-item>
-      <ion-input [value]="password" (ionChange)="passwordChange($event)" label="密码" type="password" value="password"></ion-input>
+      <ion-input [value]="password" (ionChange)="passwordChange($event)" label="密码" type="password" value="password"placeholder="密码"></ion-input>
     </ion-item>
 
     @if(type==="signup"){

+ 1 - 1
soul-app/src/lib/user/modal-user-login/modal-user-login.component.ts

@@ -49,7 +49,7 @@ export class ModalUserLoginComponent  implements OnInit {
     if(user?.id){
        this.modalCtrl.dismiss(user,"confirm")
     }else{
-      console.log("登录失败")
+      console.log("登录失败,请检查账号和密码")
     }
   }