5 Commits 23c14eb768 ... 832b7618ca

Author SHA1 Message Date
  0210348 832b7618ca 0210348-代码优化 4 months ago
  0210348 c03d22987b 0210348-界面刷新逻辑优化 4 months ago
  0210348 79eff1fd61 0210348-ai聊天界面优化 4 months ago
  0210331 bf705c010d 0210331-弹窗修改 4 months ago
  0210348 d62fe615ea 0210348-AI聊天界面完善 4 months ago
56 changed files with 883 additions and 410 deletions
  1. 1 6
      src/app/app-routing.module.ts
  2. 17 0
      src/app/chatpage/chatpage-routing.module.ts
  3. 20 0
      src/app/chatpage/chatpage.module.ts
  4. 34 0
      src/app/chatpage/chatpage.page.html
  5. 81 0
      src/app/chatpage/chatpage.page.scss
  6. 17 0
      src/app/chatpage/chatpage.page.spec.ts
  7. 138 0
      src/app/chatpage/chatpage.page.ts
  8. 0 0
      src/app/child-page/bounty-store/bounty-store-routing.module.ts
  9. 0 0
      src/app/child-page/bounty-store/bounty-store.module.ts
  10. 0 0
      src/app/child-page/bounty-store/bounty-store.page.html
  11. 0 0
      src/app/child-page/bounty-store/bounty-store.page.scss
  12. 0 0
      src/app/child-page/bounty-store/bounty-store.page.spec.ts
  13. 0 0
      src/app/child-page/bounty-store/bounty-store.page.ts
  14. 17 0
      src/app/child-page/chat/chat-routing.module.ts
  15. 20 0
      src/app/child-page/chat/chat.module.ts
  16. 29 0
      src/app/child-page/chat/chat.page.html
  17. 90 0
      src/app/child-page/chat/chat.page.scss
  18. 17 0
      src/app/child-page/chat/chat.page.spec.ts
  19. 137 0
      src/app/child-page/chat/chat.page.ts
  20. 30 20
      src/app/child-page/chat/class-chat-completion.ts
  21. 17 0
      src/app/home/home-routing.module.ts
  22. 20 0
      src/app/home/home.module.ts
  23. 21 28
      src/app/home/home.page.html
  24. 0 0
      src/app/home/home.page.scss
  25. 17 0
      src/app/home/home.page.spec.ts
  26. 38 42
      src/app/home/home.page.ts
  27. 17 0
      src/app/mine/mine-routing.module.ts
  28. 20 0
      src/app/mine/mine.module.ts
  29. 0 0
      src/app/mine/mine.page.html
  30. 20 0
      src/app/mine/mine.page.scss
  31. 17 0
      src/app/mine/mine.page.spec.ts
  32. 5 5
      src/app/mine/mine.page.ts
  33. 0 16
      src/app/tab1/tab1-routing.module.ts
  34. 0 20
      src/app/tab1/tab1.module.ts
  35. 0 27
      src/app/tab1/tab1.page.spec.ts
  36. 0 17
      src/app/tab2/tab2-routing.module.ts
  37. 0 27
      src/app/tab2/tab2.module.ts
  38. 0 22
      src/app/tab2/tab2.page.html
  39. 0 9
      src/app/tab2/tab2.page.scss
  40. 0 26
      src/app/tab2/tab2.page.spec.ts
  41. 0 29
      src/app/tab2/tab2.page.ts
  42. 0 16
      src/app/tab3/tab3-routing.module.ts
  43. 0 20
      src/app/tab3/tab3.module.ts
  44. 0 21
      src/app/tab3/tab3.page.scss
  45. 0 26
      src/app/tab3/tab3.page.spec.ts
  46. 25 21
      src/app/tabs/tabs-routing.module.ts
  47. 2 3
      src/app/tabs/tabs.page.html
  48. 2 2
      src/app/tabs/tabs.page.ts
  49. 0 0
      src/modules/tab/tree/explore-container/explore-container.component.html
  50. 0 0
      src/modules/tab/tree/explore-container/explore-container.component.scss
  51. 0 0
      src/modules/tab/tree/explore-container/explore-container.component.spec.ts
  52. 0 0
      src/modules/tab/tree/explore-container/explore-container.component.ts
  53. 0 0
      src/modules/tab/tree/explore-container/explore-container.module.ts
  54. 1 1
      src/modules/tab/tree/tree.page.spec.ts
  55. 11 4
      src/modules/tab/tree/tree.page.ts
  56. 2 2
      src/modules/user/login/login.page.ts

+ 1 - 6
src/app/app-routing.module.ts

@@ -11,14 +11,9 @@ const routes: Routes = [
     loadChildren: () => import('../modules/user/user.module').then(m => m.UserModule)
   },
   {
-    path: "tree",
+    path: "timer",
     loadChildren: () => import('../modules/tab/tree/tree.module').then(m => m.TreePageModule)
   },
-  {
-    path: 'bounty-store',
-    loadChildren: () => import('../app/bounty-store/bounty-store.module').then(mod => mod.BountyStorePageModule)
-  },
-
 ];
 @NgModule({
   imports: [

+ 17 - 0
src/app/chatpage/chatpage-routing.module.ts

@@ -0,0 +1,17 @@
+import { NgModule } from '@angular/core';
+import { Routes, RouterModule } from '@angular/router';
+
+import { ChatpagePage } from './chatpage.page';
+
+const routes: Routes = [
+  {
+    path: '',
+    component: ChatpagePage
+  }
+];
+
+@NgModule({
+  imports: [RouterModule.forChild(routes)],
+  exports: [RouterModule],
+})
+export class ChatpagePageRoutingModule {}

+ 20 - 0
src/app/chatpage/chatpage.module.ts

@@ -0,0 +1,20 @@
+import { NgModule } from '@angular/core';
+import { CommonModule } from '@angular/common';
+import { FormsModule } from '@angular/forms';
+
+import { IonicModule } from '@ionic/angular';
+
+import { ChatpagePageRoutingModule } from './chatpage-routing.module';
+
+import { ChatpagePage } from './chatpage.page';
+
+@NgModule({
+  imports: [
+    CommonModule,
+    FormsModule,
+    IonicModule,
+    ChatpagePageRoutingModule
+  ],
+  declarations: [ChatpagePage]
+})
+export class ChatpagePageModule {}

+ 34 - 0
src/app/chatpage/chatpage.page.html

@@ -0,0 +1,34 @@
+<ion-header>
+  <ion-toolbar class="title">
+    <ion-title class="ion-text-center">历史聊天</ion-title>
+  </ion-toolbar>
+</ion-header>
+
+<ion-content [fullscreen]="true" class="history">
+  <!-- Displaying chat history -->
+  <div *ngIf="chatHistory.length > 0; else noChats">
+    <ion-list>
+      <ion-item *ngFor="let chat of chatHistory" (click)="goToChat(chat.chatId)" class="chat-item">
+        <div class="avatar">{{ chat.username[0].toUpperCase() }}</div>
+        <ion-label>
+          <h2>{{ chat.userChat.slice(0, 18) }}</h2>
+          <p>{{ chat.aiChat.slice(0, 18) }}</p>
+        </ion-label>
+      </ion-item>
+    </ion-list>
+  </div>
+  <ng-template #noChats>
+    <ion-text color="medium" class="no-chats">
+      <p>暂无</p>
+    </ion-text>
+  </ng-template>
+</ion-content>
+
+<!-- Button to start new chat -->
+<ion-footer>
+  <ion-toolbar>
+    <ion-buttons slot="end" class="new-chat-button">
+      <ion-button expand="block" (click)="startNewChat()">开启新聊天</ion-button>
+    </ion-buttons>
+  </ion-toolbar>
+</ion-footer>

+ 81 - 0
src/app/chatpage/chatpage.page.scss

@@ -0,0 +1,81 @@
+.title{
+  font-size: 32px;
+  text-align: center;
+  font-weight: bold;
+  padding-top: 4px;
+  height:50px;
+}
+
+.history{
+  margin-top: 1px;
+}
+
+
+
+.chat-item {
+  display: flex;
+  align-items: center;
+  padding: 10px;
+  margin-top: 10px;
+  margin-bottom: 10px;
+  border-radius: 10px;
+  background-color: #ffffff; /* 更改为白色背景 */
+  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); /* 添加阴影效果 */
+  border: 1.5px solid #d2cccc; /* 添加边框 */;
+
+  .avatar {
+    display: flex;
+    justify-content: center;
+    align-items: center;
+    width: 40px;
+    height: 40px;
+    border-radius: 50%;
+    background-color: #007bff; /* 蓝色头像背景 */
+    color: white;
+    font-size: 1.5rem;
+    margin-right: 14px;
+    text-transform: uppercase;
+  }
+
+  ion-label {
+    h2 {
+      font-size: 1.2rem;
+      margin: 0;
+    }
+    p {
+      font-size: 1rem;
+      margin: 0;
+    }
+  }
+}
+
+ion-content {
+  ion-list {
+    padding: 0 10px;
+  }
+}
+
+.no-chats {
+  text-align: center;
+  margin-top: 20px;
+  font-size: 1.2rem;
+  color: #888;
+}
+
+ion-footer {
+  ion-toolbar {
+    .new-chat-button {
+      width: 100%;
+      ion-button {
+        font-size: 1.2rem;
+        --background: #007bff;
+        --background-hover: #0056b3;
+        --border-radius: 0;
+        --color: white;
+        padding: 15px 0;
+        width: 100%;
+        justify-content: center;
+      }
+    }
+  }
+}

+ 17 - 0
src/app/chatpage/chatpage.page.spec.ts

@@ -0,0 +1,17 @@
+import { ComponentFixture, TestBed } from '@angular/core/testing';
+import { ChatpagePage } from './chatpage.page';
+
+describe('ChatpagePage', () => {
+  let component: ChatpagePage;
+  let fixture: ComponentFixture<ChatpagePage>;
+
+  beforeEach(() => {
+    fixture = TestBed.createComponent(ChatpagePage);
+    component = fixture.componentInstance;
+    fixture.detectChanges();
+  });
+
+  it('should create', () => {
+    expect(component).toBeTruthy();
+  });
+});

+ 138 - 0
src/app/chatpage/chatpage.page.ts

@@ -0,0 +1,138 @@
+import { Component, OnInit } from '@angular/core';
+import { AlertController, NavController } from '@ionic/angular';
+import * as Parse from 'parse';
+
+interface ChatHistoryItem {
+  chatId: number;
+  username: string;
+  userChatOrder: number;
+  userChat: string;
+  aiChat: string;
+}
+
+@Component({
+  selector: 'app-chatpage',
+  templateUrl: './chatpage.page.html',
+  styleUrls: ['./chatpage.page.scss'],
+})
+export class ChatpagePage implements OnInit {
+  chatHistory: ChatHistoryItem[] = [];
+  username: string = ''; // 用户名
+  load: boolean | undefined;
+
+  constructor(private navCtrl: NavController, private alertController: AlertController) {}
+
+  ngOnInit() {}
+
+  ionViewDidEnter() {
+    this.loadUserData();
+    this.loadChatHistory();
+  }
+
+  async loadUserData() {
+    const currentUser = Parse.User.current();
+    if (currentUser) {
+      this.username = currentUser.getUsername()!;
+    } else {
+      this.username = '未登录';
+    }
+    console.log("tab-history:" + this.username);
+    this.CheckUser();
+  }
+
+  async CheckUser() {
+    if (this.username == '未登录') {
+      this.load = false;
+      this.presentLoginAlert();
+      return;
+    } else {
+      this.load = true;
+    }
+  }
+
+  async presentLoginAlert() {
+    const alert = await this.alertController.create({
+      header: '未登录',
+      message: '请先登录以继续操作',
+      buttons: [
+        {
+          text: '取消',
+          role: 'cancel'
+        },
+        {
+          text: '去登录',
+          handler: () => {
+            this.navCtrl.navigateForward('/user/login');
+          }
+        }
+      ]
+    });
+    await alert.present();
+  }
+
+  async loadChatHistory() {
+    try {
+      const Chat = Parse.Object.extend('ai_chat');
+      const query = new Parse.Query(Chat);
+      query.equalTo('username', this.username); // 只获取当前用户名的聊天记录
+      query.select('chatId', 'username', 'userChatOrder', 'userChat', 'aiChat');
+      query.descending('createdAt');
+      const results = await query.find();
+
+      const groupedChats: { [key: number]: ChatHistoryItem } = results.reduce(
+        (acc: { [key: number]: ChatHistoryItem }, chat: any) => {
+          const chatId = chat.get('chatId');
+          if (!acc[chatId]) {
+            acc[chatId] = {
+              chatId,
+              username: chat.get('username'),
+              userChatOrder: chat.get('userChatOrder'),
+              userChat: chat.get('userChat'),
+              aiChat: chat.get('aiChat'),
+            };
+          }
+          return acc;
+        },
+        {}
+      );
+
+      this.chatHistory = Object.values(groupedChats).map(chat => {
+        const firstMessage = results.find(
+          item => item.get('chatId') === chat.chatId && item.get('userChatOrder') === 1
+        );
+        return {
+          chatId: chat.chatId,
+          username: firstMessage?.get('username') || chat.username,
+          userChatOrder: firstMessage?.get('userChatOrder') || chat.userChatOrder,
+          userChat: firstMessage?.get('userChat') || chat.userChat,
+          aiChat: firstMessage?.get('aiChat') || chat.aiChat,
+        };
+      });
+
+    } catch (error) {
+      console.error('Error loading chat history:', error);
+    }
+  }
+
+  goToChat(chatId: number) {
+    this.navCtrl.navigateForward(`/tabs/chat`, {
+      queryParams: { chatId: chatId.toString() },
+    });
+  }
+
+  async startNewChat() {
+    this.loadUserData();
+    if (this.load) {
+      const Chat = Parse.Object.extend('ai_chat');
+      const query = new Parse.Query(Chat);
+      query.descending('chatId');
+      query.equalTo('username', this.username); // 确保chatId生成基于当前用户的历史记录
+      const latestChat = await query.first();
+      const newChatId = latestChat ? latestChat.get('chatId') + 1 : 1;
+
+      this.navCtrl.navigateForward(`/tabs/chat`, {
+        queryParams: { chatId: newChatId.toString() },
+      });
+    }
+  }
+}

+ 0 - 0
src/app/bounty-store/bounty-store-routing.module.ts → src/app/child-page/bounty-store/bounty-store-routing.module.ts


+ 0 - 0
src/app/bounty-store/bounty-store.module.ts → src/app/child-page/bounty-store/bounty-store.module.ts


+ 0 - 0
src/app/bounty-store/bounty-store.page.html → src/app/child-page/bounty-store/bounty-store.page.html


+ 0 - 0
src/app/bounty-store/bounty-store.page.scss → src/app/child-page/bounty-store/bounty-store.page.scss


+ 0 - 0
src/app/bounty-store/bounty-store.page.spec.ts → src/app/child-page/bounty-store/bounty-store.page.spec.ts


+ 0 - 0
src/app/bounty-store/bounty-store.page.ts → src/app/child-page/bounty-store/bounty-store.page.ts


+ 17 - 0
src/app/child-page/chat/chat-routing.module.ts

@@ -0,0 +1,17 @@
+import { NgModule } from '@angular/core';
+import { Routes, RouterModule } from '@angular/router';
+
+import { ChatPage } from './chat.page';
+
+const routes: Routes = [
+  {
+    path: '',
+    component: ChatPage
+  }
+];
+
+@NgModule({
+  imports: [RouterModule.forChild(routes)],
+  exports: [RouterModule],
+})
+export class ChatPageRoutingModule {}

+ 20 - 0
src/app/child-page/chat/chat.module.ts

@@ -0,0 +1,20 @@
+import { NgModule } from '@angular/core';
+import { CommonModule } from '@angular/common';
+import { FormsModule } from '@angular/forms';
+
+import { IonicModule } from '@ionic/angular';
+
+import { ChatPageRoutingModule } from './chat-routing.module';
+
+import { ChatPage } from './chat.page';
+
+@NgModule({
+  imports: [
+    CommonModule,
+    FormsModule,
+    IonicModule,
+    ChatPageRoutingModule
+  ],
+  declarations: [ChatPage]
+})
+export class ChatPageModule {}

+ 29 - 0
src/app/child-page/chat/chat.page.html

@@ -0,0 +1,29 @@
+<ion-header>
+  <ion-toolbar class="title">
+    <ion-title >聊天</ion-title>
+  </ion-toolbar>
+</ion-header>
+
+<ion-content>
+  <div class="chat-container">
+    <div *ngFor="let message of messageList" [ngClass]="{'user-message': message.role === 'user', 'ai-message': message.role === 'assistant'}">
+      <div *ngIf="message.role === 'user'" class="avatar-container">
+        <div class="message-content">{{ message.content }}</div>
+        <div class="avatar1">{{ username.charAt(0).toUpperCase() }}</div>
+      </div>
+      <div *ngIf="message.role === 'assistant'" class="avatar-container">
+        <div class="avatar2">AI</div>
+        <div class="message-content">{{ message.content }}</div>
+      </div>
+    </div>
+  </div>
+</ion-content>
+
+<ion-footer>
+  <ion-toolbar>
+    <ion-item>
+      <ion-input [(ngModel)]="userInput" placeholder="输入消息..."></ion-input>
+      <ion-button (click)="sendMessage()" class="sendButton">发送</ion-button>
+    </ion-item>
+  </ion-toolbar>
+</ion-footer>

+ 90 - 0
src/app/child-page/chat/chat.page.scss

@@ -0,0 +1,90 @@
+.title{
+  font-size: 32px;
+  text-align: center;
+  font-weight: bold;
+  padding-top: 4px;
+  height:50px;
+}
+
+.chat-container {
+  display: flex;
+  flex-direction: column;
+  padding: 10px;
+}
+
+.avatar-container {
+  display: flex;
+  align-items: flex-start;
+  margin: 5px 0;
+  padding: 0px;
+}
+
+.user-message {
+  display: flex;
+  justify-content: flex-end;
+  align-items: center;
+  margin: 5px 0;
+}
+
+.ai-message {
+  display: flex;
+  justify-content: flex-start;
+  align-items: center;
+  margin: 5px 0;
+}
+
+.message-content {
+  padding: 10px;
+  border-radius: 5px;
+  word-break: break-word; /* 处理消息内容换行问题 */
+  max-width: 310px; /* 设置消息内容的最大宽度,超过这个宽度会自动换行 */
+}
+
+
+.user-message .message-content {
+  background-color: #ffecb3; /* 更合适的用户消息背景颜色 */
+}
+
+.ai-message .message-content {
+  background-color: #e0f7fa; /* 更合适的AI消息背景颜色 */
+}
+
+.avatar1 {
+  width: 40px;
+  height: 40px;
+  border-radius: 50%;
+  font-size: 20px;
+  font-weight: bold;
+  display: flex;
+  justify-content: center;
+  align-items: center;
+  margin-left: 10px;
+  border: 2px solid #ccc; /* 添加边框 */
+}
+
+.avatar2 {
+  width: 40px;
+  height: 40px;
+  border-radius: 50%;
+  font-size: 20px;
+  font-weight: bold;
+  display: flex;
+  justify-content: center;
+  align-items: center;
+  margin-right: 10px;
+  border: 2px solid #ccc; /* 添加边框 */
+}
+
+.user-message .avatar1 {
+  background-color: #007bff;
+  color: rgb(255, 255, 255);
+}
+
+.ai-message .avatar2 {
+  background-color: #007bff;
+  color: rgb(255, 255, 255);
+}
+
+.sendButton{
+  width:60px;
+}

+ 17 - 0
src/app/child-page/chat/chat.page.spec.ts

@@ -0,0 +1,17 @@
+import { ComponentFixture, TestBed } from '@angular/core/testing';
+import { ChatPage } from './chat.page';
+
+describe('ChatPage', () => {
+  let component: ChatPage;
+  let fixture: ComponentFixture<ChatPage>;
+
+  beforeEach(() => {
+    fixture = TestBed.createComponent(ChatPage);
+    component = fixture.componentInstance;
+    fixture.detectChanges();
+  });
+
+  it('should create', () => {
+    expect(component).toBeTruthy();
+  });
+});

+ 137 - 0
src/app/child-page/chat/chat.page.ts

@@ -0,0 +1,137 @@
+import { Component, OnInit } from '@angular/core';
+import { ActivatedRoute, Router } from '@angular/router';
+import * as Parse from 'parse';
+import { TestChatCompletion, TestChatMessage } from './class-chat-completion';
+import { ChangeDetectorRef } from '@angular/core';
+
+@Component({
+  selector: 'app-chat',
+  templateUrl: './chat.page.html',
+  styleUrls: ['./chat.page.scss'],
+})
+export class ChatPage implements OnInit {
+  chatId: number | null = null;
+  messageList: Array<TestChatMessage> = [];
+  userInput: string = '';
+  username: string = ''; // 用户名
+  completion: TestChatCompletion;
+
+  constructor(
+    private route: ActivatedRoute,
+    private router: Router,
+    private cd: ChangeDetectorRef // 注入ChangeDetectorRef
+  ) {
+    this.completion = new TestChatCompletion(this.messageList);
+  }
+
+  ngOnInit() {
+    this.route.queryParams.subscribe(params => {
+      if (params['chatId']) {
+        this.chatId = +params['chatId'];
+        this.loadChatHistory(this.chatId);
+      } else {
+        this.chatId = null;
+        this.messageList = [];
+      }
+    });
+  }
+
+  ionViewDidEnter() {
+    //检测登录状况
+    this.loadUserData();
+  }
+
+  async loadUserData() {
+    const currentUser = Parse.User.current();
+    if (currentUser) {
+      this.username = currentUser.getUsername()!;
+    } else {
+      this.username = '未登录';
+    }
+    console.log("tab-ai:"+this.username);
+  }
+
+  async loadChatHistory(chatId: number | null) {
+    if (!chatId) return;
+
+    const Chat = Parse.Object.extend('ai_chat');
+    const query = new Parse.Query(Chat);
+    query.equalTo('chatId', chatId);
+    query.ascending('userChatOrder');
+
+    try {
+      const results = await query.find();
+      this.messageList = results.flatMap(chat => [
+        { role: 'user', content: chat.get('userChat') },
+        { role: 'assistant', content: chat.get('aiChat') }
+      ]).filter(message => message.content); // 过滤掉内容为空的消息
+      this.cd.detectChanges(); // 触发变更检测
+    } catch (error) {
+      console.error('Error loading chat history:', error);
+    }
+  }
+
+  async sendMessage() {
+    const userMessage: TestChatMessage = {
+      role: 'user',
+      content: this.userInput
+    };
+    this.messageList.push(userMessage);
+    this.userInput = '';
+
+    this.cd.detectChanges(); // 触发变更检测
+
+    // 调用AI接口处理消息
+    const aiMessage = await this.completion.createCompletionByStream(userMessage);
+
+    if (this.chatId !== null) {
+      await this.saveMessagesToDatabase(userMessage, aiMessage);
+    }
+
+    this.messageList.push(aiMessage);
+    this.cd.detectChanges(); // 触发变更检测
+  }
+
+  async saveMessagesToDatabase(userMessage: TestChatMessage, aiMessage: TestChatMessage) {
+    if (this.chatId === null) return;
+
+    const Chat = Parse.Object.extend('ai_chat');
+    const chat = new Chat();
+
+    chat.set('username', this.username); // 设置用户名
+    chat.set('chatId', this.chatId); // 设置chatId
+
+    // 查询最后一个userChatOrder以确定此消息的新顺序
+    const lastMessage = await this.getLastMessageInChat(this.chatId);
+    let userChatOrder = 1; // 如果是对话的第一条消息,则默认为1
+    if (lastMessage) {
+      userChatOrder = lastMessage.get('userChatOrder') + 1;
+    }
+    chat.set('userChatOrder', userChatOrder); // 设置userChatOrder
+
+    chat.set('userChat', userMessage.content); // 设置userChat
+    chat.set('aiChat', aiMessage.content); // 设置aiChat
+
+    try {
+      await chat.save();
+    } catch (error) {
+      console.error('Error saving message:', error);
+    }
+  }
+
+  async getLastMessageInChat(chatId: number): Promise<Parse.Object | undefined> {
+    const Chat = Parse.Object.extend('ai_chat');
+    const query = new Parse.Query(Chat);
+    query.equalTo('chatId', chatId);
+    query.descending('userChatOrder');
+    query.limit(1); // 限制为1条结果以获取最后一条消息
+
+    try {
+      const result = await query.first();
+      return result; // 返回最后一条消息对象,如果找不到则返回undefined
+    } catch (error) {
+      console.error('Error getting last message:', error);
+      return undefined;
+    }
+  }
+}

+ 30 - 20
src/app/tab2/class-chat-completion.ts → src/app/child-page/chat/class-chat-completion.ts

@@ -1,13 +1,17 @@
 export interface TestChatMessage {
-  role: string
-  content: string
+  role: string;
+  content: string;
 }
+
 export class TestChatCompletion {
-  messageList: Array<TestChatMessage>
+  messageList: Array<TestChatMessage>;
+
   constructor(messageList: Array<TestChatMessage>) {
-    this.messageList = messageList
+    this.messageList = messageList;
   }
-  async createCompletionByStream() {
+
+  async createCompletionByStream(userMessage: TestChatMessage): Promise<TestChatMessage> {
+    this.messageList.push(userMessage); // 添加用户消息到消息列表
 
     let token = localStorage.getItem("token");
     let bodyJson = {
@@ -36,8 +40,8 @@ export class TestChatCompletion {
       "credentials": "omit"
     });
 
-    let messageAiReply = ""
-    let messageIndex = this.messageList.length
+    let messageAiReply = "";
+    let messageIndex = this.messageList.length;
     let reader = response.body?.getReader();
     if (!reader) {
       throw new Error("Failed to get the response reader.");
@@ -61,32 +65,38 @@ export class TestChatCompletion {
       for (let i = 0; i < messages.length - 1; i++) {
         let message = messages[i];
 
-
-        let dataText = message.replace("data:\ ", "")
+        // Process the message as needed
+        /**
+         * data: {"id":"chatcmpl-y2PLKqPDnwAFJIj2L5aqdH5TWK9Yv","object":"chat.completion.chunk","created":1696770162,"model":"gpt-3.5-turbo-0613","choices":[{"index":0,"delta":{"role":"assistant","content":""},"finish_reason":null}]}
+         * data: {"id":"chatcmpl-y2PLKqPDnwAFJIj2L5aqdH5TWK9Yv","object":"chat.completion.chunk","created":1696770162,"model":"gpt-3.5-turbo-0613","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}
+         * data: [DONE]
+         */
+        let dataText = message.replace("data: ", "");
         if (dataText.startsWith("{")) {
           try {
-            let dataJson = JSON.parse(dataText)
-            console.log(dataJson)
-            messageAiReply += dataJson?.choices?.[0]?.delta?.content || ""
+            let dataJson = JSON.parse(dataText);
+            console.log(dataJson);
+            messageAiReply += dataJson?.choices?.[0]?.delta?.content || "";
             this.messageList[messageIndex] = {
               role: "assistant",
               content: messageAiReply
-            }
-          } catch (err) { }
+            };
+          } catch (err) {}
         }
         if (dataText.startsWith("[")) {
-          console.log(message)
-          console.log("完成")
+          console.log(message);
+          console.log("完成");
           this.messageList[messageIndex] = {
             role: "assistant",
             content: messageAiReply
-          }
-          messageAiReply = ""
+          };
+          messageAiReply = "";
         }
-
         // Clear the processed message from the buffer
         buffer = buffer.slice(message.length + 1);
       }
     }
+
+    return { role: "assistant", content: this.messageList[messageIndex].content };
   }
-}
+}

+ 17 - 0
src/app/home/home-routing.module.ts

@@ -0,0 +1,17 @@
+import { NgModule } from '@angular/core';
+import { Routes, RouterModule } from '@angular/router';
+
+import { HomePage } from './home.page';
+
+const routes: Routes = [
+  {
+    path: '',
+    component: HomePage
+  }
+];
+
+@NgModule({
+  imports: [RouterModule.forChild(routes)],
+  exports: [RouterModule],
+})
+export class HomePageRoutingModule {}

+ 20 - 0
src/app/home/home.module.ts

@@ -0,0 +1,20 @@
+import { NgModule } from '@angular/core';
+import { CommonModule } from '@angular/common';
+import { FormsModule } from '@angular/forms';
+
+import { IonicModule } from '@ionic/angular';
+
+import { HomePageRoutingModule } from './home-routing.module';
+
+import { HomePage } from './home.page';
+
+@NgModule({
+  imports: [
+    CommonModule,
+    FormsModule,
+    IonicModule,
+    HomePageRoutingModule
+  ],
+  declarations: [HomePage]
+})
+export class HomePageModule {}

+ 21 - 28
src/app/tab1/tab1.page.html → src/app/home/home.page.html

@@ -8,64 +8,57 @@
     </ion-toolbar>
   </ion-header>
     
-   <!-- 方框 -->
-   <ion-card (click)="openEditModal()">
+  <!-- 方框 -->
+  <ion-card (click)="openEditModal()">
     <ion-card-content>
       <ion-grid>
         <ion-row>
           <ion-col size="3">
             <div class="info-box">初始</div>
-            <div class="info-value">{{ initial }}</div>
+            <div class="info-value">{{ initial }}KG</div>
           </ion-col>
           <ion-col size="3">
             <div class="info-box">当前</div>
-            <div class="info-value">{{ current }}</div>
+            <div class="info-value">{{ current }}KG</div>
           </ion-col>
           <ion-col size="3">
             <div class="info-box">目标</div>
-            <div class="info-value">{{ target }}</div>
+            <div class="info-value">{{ target }}KG</div>
           </ion-col>
           <ion-col size="3">
             <div class="info-box">赏金</div>
-            <div class="info-value">{{ reward }}</div>
+            <div class="info-value">{{ reward }}</div>
           </ion-col>
         </ion-row>
       </ion-grid>
     </ion-card-content>
   </ion-card>
   
-<!-- 3D效果的圆 -->
-<div class="wave-container" (click)="navigateToTreePage()">
-  <div class="wave-circle">
-    <div class="wave">
-      <div class="wave-inner">
-        <span class="start-self-discipline">开始自律</span>
+  <!-- 3D效果的圆 -->
+  <div class="wave-container" (click)="navigateToTreePage()">
+    <div class="wave-circle">
+      <div class="wave">
+        <div class="wave-inner">
+          <span class="start-self-discipline">开始自律</span>
+        </div>
       </div>
     </div>
   </div>
-</div>
-
-
-
 
   <!-- 每日小习惯 -->
-<div class="daily-habit">
-  <div class="daily-habit-line"></div>
-  <div class="daily-habit-text">每日小习惯</div>
-</div>
+  <div class="daily-habit">
+    <div class="daily-habit-line"></div>
+    <div class="daily-habit-text">每日小习惯</div>
+  </div>
 
-  
-   <!-- 每日小习惯按钮 -->
-   <div class="button-container">
+  <!-- 每日小习惯按钮 -->
+  <div class="button-container">
     <ion-button *ngFor="let button of buttons; let i = index" (click)="onButtonClick(i)" [color]="button.color" class="custom-button">
       <ion-icon [name]="button.icon"></ion-icon>
       <p>{{ button.text }}</p>
     </ion-button>
   </div>
   <div class="habit-text-div">
-      <p class="habit-text centered" [ngClass]="{'success-text': allButtonsSuccess, 'failure-text': anyButtonFailure}">{{ habitText }}</p>
+    <p class="habit-text centered" [ngClass]="{'success-text': allButtonsSuccess, 'failure-text': anyButtonFailure}">{{ habitText }}</p>
   </div>
-
-</ion-content>
-  
-
+</ion-content>

+ 0 - 0
src/app/tab1/tab1.page.scss → src/app/home/home.page.scss


+ 17 - 0
src/app/home/home.page.spec.ts

@@ -0,0 +1,17 @@
+import { ComponentFixture, TestBed } from '@angular/core/testing';
+import { HomePage } from './home.page';
+
+describe('HomePage', () => {
+  let component: HomePage;
+  let fixture: ComponentFixture<HomePage>;
+
+  beforeEach(() => {
+    fixture = TestBed.createComponent(HomePage);
+    component = fixture.componentInstance;
+    fixture.detectChanges();
+  });
+
+  it('should create', () => {
+    expect(component).toBeTruthy();
+  });
+});

+ 38 - 42
src/app/tab1/tab1.page.ts → src/app/home/home.page.ts

@@ -1,44 +1,34 @@
-import { Component, OnInit,OnDestroy } from '@angular/core';
+import { Component, OnInit, OnDestroy } from '@angular/core';
 import { AlertController, NavController } from '@ionic/angular';
 import { Router } from '@angular/router';
 import * as Parse from 'parse';
-import { interval, Subscription } from 'rxjs';
 
 @Component({
-  selector: 'app-tab1',
-  templateUrl: 'tab1.page.html',
-  styleUrls: ['tab1.page.scss']
+  selector: 'app-home',
+  templateUrl: './home.page.html',
+  styleUrls: ['./home.page.scss'],
 })
-export class Tab1Page implements OnInit,OnDestroy {
-  initial: string = '0KG';
-  current: string = '0KG';
-  target: string = '0KG';
-  reward: string = '0元';
+export class HomePage implements OnInit {
+  initial: number = 0;
+  current: number = 0;
+  target: number = 0;
+  reward: number = 0;
   username: string = ''; // 当前用户的用户名
   blueColor: boolean = false;
-  private loadUserDataSubscription: Subscription | undefined;
   
   constructor(
     private alertController: AlertController,
     private router: Router,
     private navCtrl: NavController,
-    
   ) {}
 
-  ngOnInit() {
+  ngOnInit() {}
+
+  ionViewDidEnter() {
     this.loadUserData();
-    //每隔一秒检测登录状况
-    this.loadUserDataSubscription = interval(1000).subscribe(() => {
-      this.loadUserData();
-      console.log(this.username);
-    });
   }
 
-  ngOnDestroy() {
-    if (this.loadUserDataSubscription) {
-      this.loadUserDataSubscription.unsubscribe();
-    }
-  }
+  ngOnDestroy() {}
 
   async loadUserData() {
     const currentUser = Parse.User.current();
@@ -49,6 +39,7 @@ export class Tab1Page implements OnInit,OnDestroy {
       this.username = '未登录';
       this.loadData();
     }
+    console.log("tab1:" + this.username);
   }
 
   async loadData() {
@@ -57,16 +48,20 @@ export class Tab1Page implements OnInit,OnDestroy {
       query.equalTo('username', this.username); // 查找当前用户的数据
       const weightStatus = await query.first();
       if (weightStatus) {
-        this.initial = weightStatus.get('initial') + 'KG' || '--KG';
-        this.current = weightStatus.get('current') + 'KG' || '--KG';
-        this.target = weightStatus.get('target') + 'KG' || '--KG';
-        this.reward = weightStatus.get('reward') + '元' || '--元';
+        this.initial = weightStatus.get('initial') || 0;
+        this.current = weightStatus.get('current') || 0;
+        this.target = weightStatus.get('target') || 0;
+        this.reward = this.calculateReward(this.initial, this.target);
       }
     } catch (error) {
       console.error('Error loading data', error);
     }
   }
 
+  calculateReward(initial: number, target: number): number {
+    return (initial - target) * 10;
+  }
+
   async openEditModal() {
     if (this.username == '未登录') {
       // 如果用户未登录,则显示登录提示
@@ -76,30 +71,32 @@ export class Tab1Page implements OnInit,OnDestroy {
 
     const alert = await this.alertController.create({
       header: '编辑体重信息',
+      subHeader: '请根据您的需求编辑以下信息',
       inputs: [
         {
           name: 'initial',
-          type: 'text',
+          type: 'number',
           placeholder: '初始',
-          value: this.initial.replace('KG', '')
+          value: this.initial.toString()
         },
         {
           name: 'current',
-          type: 'text',
+          type: 'number',
           placeholder: '当前',
-          value: this.current.replace('KG', '')
+          value: this.current.toString()
         },
         {
           name: 'target',
-          type: 'text',
+          type: 'number',
           placeholder: '目标',
-          value: this.target.replace('KG', '')
+          value: this.target.toString()
         },
         {
           name: 'reward',
-          type: 'text',
+          type: 'number',
           placeholder: '赏金',
-          value: this.reward.replace('元', '')
+          value: this.reward.toString(),
+          disabled: true // 禁用输入框,显示但不能编辑
         }
       ],
       buttons: [
@@ -117,11 +114,12 @@ export class Tab1Page implements OnInit,OnDestroy {
               if (!weightStatus) {
                 weightStatus = new Parse.Object('weight_status');
               }
+              const rewardValue = this.calculateReward(Number(data.initial), Number(data.target));
               weightStatus.set('username', this.username);
-              weightStatus.set('initial', data.initial);
-              weightStatus.set('current', data.current);
-              weightStatus.set('target', data.target);
-              weightStatus.set('reward', data.reward);
+              weightStatus.set('initial', Number(data.initial));
+              weightStatus.set('current', Number(data.current));
+              weightStatus.set('target', Number(data.target));
+              weightStatus.set('reward', rewardValue);
               await weightStatus.save();
               this.loadData(); // 更新本地数据
             } catch (error) {
@@ -160,7 +158,6 @@ export class Tab1Page implements OnInit,OnDestroy {
     this.blueColor = !this.blueColor;
   }
 
-
   //每日习惯按钮颜色变化
   buttons = [
     { text: '足量饮水', color: 'light', icon: 'water' },
@@ -208,8 +205,7 @@ export class Tab1Page implements OnInit,OnDestroy {
     return this.buttons.some(btn => btn.color === 'danger');
   }
 
-
   navigateToTreePage() {
-    this.router.navigate(['/tabs/tree']);
+    this.router.navigate(['/tabs/timer']);
   }
 }

+ 17 - 0
src/app/mine/mine-routing.module.ts

@@ -0,0 +1,17 @@
+import { NgModule } from '@angular/core';
+import { Routes, RouterModule } from '@angular/router';
+
+import { MinePage } from './mine.page';
+
+const routes: Routes = [
+  {
+    path: '',
+    component: MinePage
+  }
+];
+
+@NgModule({
+  imports: [RouterModule.forChild(routes)],
+  exports: [RouterModule],
+})
+export class MinePageRoutingModule {}

+ 20 - 0
src/app/mine/mine.module.ts

@@ -0,0 +1,20 @@
+import { NgModule } from '@angular/core';
+import { CommonModule } from '@angular/common';
+import { FormsModule } from '@angular/forms';
+
+import { IonicModule } from '@ionic/angular';
+
+import { MinePageRoutingModule } from './mine-routing.module';
+
+import { MinePage } from './mine.page';
+
+@NgModule({
+  imports: [
+    CommonModule,
+    FormsModule,
+    IonicModule,
+    MinePageRoutingModule
+  ],
+  declarations: [MinePage]
+})
+export class MinePageModule {}

+ 0 - 0
src/app/tab3/tab3.page.html → src/app/mine/mine.page.html


+ 20 - 0
src/app/mine/mine.page.scss

@@ -0,0 +1,20 @@
+.avatar-img {
+  width: 100%;
+  height: 100%;
+  border-radius: 50%;
+  object-fit: cover;
+}
+
+ion-item.button {
+  --background-hover: rgba(0, 0, 0, 0.1);
+  --background-activated: rgba(0, 0, 0, 0.2);
+  transition: background-color 0.2s;
+
+  &:hover {
+    background-color: var(--background-hover);
+  }
+
+  &:active {
+    background-color: var(--background-activated);
+  }
+}

+ 17 - 0
src/app/mine/mine.page.spec.ts

@@ -0,0 +1,17 @@
+import { ComponentFixture, TestBed } from '@angular/core/testing';
+import { MinePage } from './mine.page';
+
+describe('MinePage', () => {
+  let component: MinePage;
+  let fixture: ComponentFixture<MinePage>;
+
+  beforeEach(() => {
+    fixture = TestBed.createComponent(MinePage);
+    component = fixture.componentInstance;
+    fixture.detectChanges();
+  });
+
+  it('should create', () => {
+    expect(component).toBeTruthy();
+  });
+});

+ 5 - 5
src/app/tab3/tab3.page.ts → src/app/mine/mine.page.ts

@@ -3,11 +3,11 @@ import { NavController, ToastController } from '@ionic/angular';
 import * as Parse from "parse";
 
 @Component({
-  selector: 'app-tab3',
-  templateUrl: './tab3.page.html',
-  styleUrls: ['./tab3.page.scss']
+  selector: 'app-mine',
+  templateUrl: './mine.page.html',
+  styleUrls: ['./mine.page.scss'],
 })
-export class Tab3Page {
+export class MinePage {
 
   constructor(private navCtrl: NavController, private toastController: ToastController) {}
 
@@ -24,7 +24,7 @@ export class Tab3Page {
   async logout() {
     try {
       await Parse.User.logOut();
-      this.navCtrl.navigateRoot('/tabs/calendar'); // 登出后跳转到登录界面
+      this.navCtrl.navigateRoot('/tabs/go-load'); // 登出后跳转到登录界面
     } catch (error: any) {
       console.error("Logout failed:", error);
       const toast = await this.toastController.create({

+ 0 - 16
src/app/tab1/tab1-routing.module.ts

@@ -1,16 +0,0 @@
-import { NgModule } from '@angular/core';
-import { RouterModule, Routes } from '@angular/router';
-import { Tab1Page } from './tab1.page';
-
-const routes: Routes = [
-  {
-    path: '',
-    component: Tab1Page,
-  }
-];
-
-@NgModule({
-  imports: [RouterModule.forChild(routes)],
-  exports: [RouterModule]
-})
-export class Tab1PageRoutingModule {}

+ 0 - 20
src/app/tab1/tab1.module.ts

@@ -1,20 +0,0 @@
-import { IonicModule } from '@ionic/angular';
-import { NgModule } from '@angular/core';
-import { CommonModule } from '@angular/common';
-import { FormsModule } from '@angular/forms';
-import { Tab1Page } from './tab1.page';
-import { ExploreContainerComponentModule } from '../explore-container/explore-container.module';
-
-import { Tab1PageRoutingModule } from './tab1-routing.module';
-
-@NgModule({
-  imports: [
-    IonicModule,
-    CommonModule,
-    FormsModule,
-    ExploreContainerComponentModule,
-    Tab1PageRoutingModule
-  ],
-  declarations: [Tab1Page]
-})
-export class Tab1PageModule {}

+ 0 - 27
src/app/tab1/tab1.page.spec.ts

@@ -1,27 +0,0 @@
-import { ComponentFixture, TestBed } from '@angular/core/testing';
-import { IonicModule } from '@ionic/angular';
-import { ExploreContainerComponentModule } from '../explore-container/explore-container.module';
-import { Tab1Page } from './tab1.page';
-import{Component}from'@angular/core';
-
-
-
-describe('Tab1Page', () => {
-  let component: Tab1Page;
-  let fixture: ComponentFixture<Tab1Page>;
-
-  beforeEach(async () => {
-    await TestBed.configureTestingModule({
-      declarations: [Tab1Page],
-      imports: [IonicModule.forRoot(), ExploreContainerComponentModule]
-    }).compileComponents();
-
-    fixture = TestBed.createComponent(Tab1Page);
-    component = fixture.componentInstance;
-    fixture.detectChanges();
-  });
-
-  it('should create', () => {
-    expect(component).toBeTruthy();
-  });
-});

+ 0 - 17
src/app/tab2/tab2-routing.module.ts

@@ -1,17 +0,0 @@
-import { NgModule } from '@angular/core';
-import { RouterModule, Routes } from '@angular/router';
-import { Tab2Page } from './tab2.page';
-
-
-const routes: Routes = [
-  {
-    path: '',
-    component: Tab2Page,
-  }
-];
-
-@NgModule({
-  imports: [RouterModule.forChild(routes)],
-  exports: [RouterModule]
-})
-export class Tab2PageRoutingModule {}

+ 0 - 27
src/app/tab2/tab2.module.ts

@@ -1,27 +0,0 @@
-import { IonicModule } from '@ionic/angular';
-import { NgModule } from '@angular/core';
-import { CommonModule } from '@angular/common';
-import { FormsModule } from '@angular/forms';
-import { Tab2Page } from './tab2.page';
-import { ExploreContainerComponentModule } from '../explore-container/explore-container.module';
-
-import { Tab2PageRoutingModule } from './tab2-routing.module';
-
-import { CalendarModule, DateAdapter } from 'angular-calendar';
-import { adapterFactory } from 'angular-calendar/date-adapters/date-fns';
-
-@NgModule({
-  imports: [
-    IonicModule,
-    CommonModule,
-    FormsModule,
-    ExploreContainerComponentModule,
-    Tab2PageRoutingModule,
-    CalendarModule.forRoot({
-      provide: DateAdapter,
-      useFactory: adapterFactory,
-    }),
-  ],
-  declarations: [Tab2Page]
-})
-export class Tab2PageModule {}

+ 0 - 22
src/app/tab2/tab2.page.html

@@ -1,22 +0,0 @@
-<ion-header>
-  <ion-toolbar>
-    <ion-title>每日记录</ion-title>
-  </ion-toolbar>
-</ion-header>
-
-<ion-content>
-  <ion-content>
-    <ion-item>
-      <ion-input placeholder="输入消息" [(ngModel)]="userInput"></ion-input>
-    </ion-item>
-    <ion-button expand="block" (click)="sendMessage()">发送</ion-button>
-    <ion-card *ngFor="let message of messageList">
-      <ion-card-header>
-        {{message?.role}}
-      </ion-card-header>
-      <ion-card-content>
-        {{ message?.content }}
-      </ion-card-content>
-    </ion-card>
-  </ion-content>
-</ion-content>

+ 0 - 9
src/app/tab2/tab2.page.scss

@@ -1,9 +0,0 @@
-ion-label.ai {
-  color: blue;
-  text-align: left;
-}
-
-ion-label.user {
-  color: green;
-  text-align: right;
-}

+ 0 - 26
src/app/tab2/tab2.page.spec.ts

@@ -1,26 +0,0 @@
-import { ComponentFixture, TestBed } from '@angular/core/testing';
-import { IonicModule } from '@ionic/angular';
-
-import { ExploreContainerComponentModule } from '../explore-container/explore-container.module';
-
-import { Tab2Page } from './tab2.page';
-
-describe('Tab2Page', () => {
-  let component: Tab2Page;
-  let fixture: ComponentFixture<Tab2Page>;
-
-  beforeEach(async () => {
-    await TestBed.configureTestingModule({
-      declarations: [Tab2Page],
-      imports: [IonicModule.forRoot(), ExploreContainerComponentModule]
-    }).compileComponents();
-
-    fixture = TestBed.createComponent(Tab2Page);
-    component = fixture.componentInstance;
-    fixture.detectChanges();
-  });
-
-  it('should create', () => {
-    expect(component).toBeTruthy();
-  });
-});

+ 0 - 29
src/app/tab2/tab2.page.ts

@@ -1,29 +0,0 @@
-import { Component,OnInit } from '@angular/core';
-import { AlertController } from '@ionic/angular';
-// 引用FmodeChatCompletion类
-import { TestChatCompletion, TestChatMessage } from './class-chat-completion';
-@Component({
-  selector: 'app-tab2',
-  templateUrl: './tab2.page.html',
-  styleUrls: ['./tab2.page.scss'],
-})
-export class Tab2Page implements OnInit {
-  messages: { sender: string, text: string }[] = [];
-  newMessage: string = '';
-  messageList:Array<TestChatMessage> = []
-  userInput:string = ""
-  completion:TestChatCompletion
-  constructor(private alertController: AlertController) {this.completion = new TestChatCompletion(this.messageList)}
-  ngOnInit() {}
-  //ai对话
-  sendMessage(){
-    this.messageList.push({
-      role:"user",
-      content: this.userInput
-    })
-    this.userInput = ""
-    this.completion.createCompletionByStream()
-
-  }
-
-}

+ 0 - 16
src/app/tab3/tab3-routing.module.ts

@@ -1,16 +0,0 @@
-import { NgModule } from '@angular/core';
-import { RouterModule, Routes } from '@angular/router';
-import { Tab3Page } from './tab3.page';
-
-const routes: Routes = [
-  {
-    path: '',
-    component: Tab3Page,
-  }
-];
-
-@NgModule({
-  imports: [RouterModule.forChild(routes)],
-  exports: [RouterModule]
-})
-export class Tab3PageRoutingModule {}

+ 0 - 20
src/app/tab3/tab3.module.ts

@@ -1,20 +0,0 @@
-import { IonicModule } from '@ionic/angular';
-import { NgModule } from '@angular/core';
-import { CommonModule } from '@angular/common';
-import { FormsModule } from '@angular/forms';
-import { Tab3Page } from './tab3.page';
-import { ExploreContainerComponentModule } from '../explore-container/explore-container.module';
-
-import { Tab3PageRoutingModule } from './tab3-routing.module';
-
-@NgModule({
-  imports: [
-    IonicModule,
-    CommonModule,
-    FormsModule,
-    ExploreContainerComponentModule,
-    Tab3PageRoutingModule
-  ],
-  declarations: [Tab3Page]
-})
-export class Tab3PageModule {}

+ 0 - 21
src/app/tab3/tab3.page.scss

@@ -1,21 +0,0 @@
-.avatar-img {
-      width: 100%;
-      height: 100%;
-      border-radius: 50%;
-      object-fit: cover;
-    }
-    
-    ion-item.button {
-      --background-hover: rgba(0, 0, 0, 0.1);
-      --background-activated: rgba(0, 0, 0, 0.2);
-      transition: background-color 0.2s;
-    
-      &:hover {
-        background-color: var(--background-hover);
-      }
-    
-      &:active {
-        background-color: var(--background-activated);
-      }
-    }
-    

+ 0 - 26
src/app/tab3/tab3.page.spec.ts

@@ -1,26 +0,0 @@
-import { ComponentFixture, TestBed } from '@angular/core/testing';
-import { IonicModule } from '@ionic/angular';
-
-import { ExploreContainerComponentModule } from '../explore-container/explore-container.module';
-
-import { Tab3Page } from './tab3.page';
-
-describe('Tab3Page', () => {
-  let component: Tab3Page;
-  let fixture: ComponentFixture<Tab3Page>;
-
-  beforeEach(async () => {
-    await TestBed.configureTestingModule({
-      declarations: [Tab3Page],
-      imports: [IonicModule.forRoot(), ExploreContainerComponentModule]
-    }).compileComponents();
-
-    fixture = TestBed.createComponent(Tab3Page);
-    component = fixture.componentInstance;
-    fixture.detectChanges();
-  });
-
-  it('should create', () => {
-    expect(component).toBeTruthy();
-  });
-});

+ 25 - 21
src/app/tabs/tabs-routing.module.ts

@@ -8,43 +8,47 @@ const routes: Routes = [
     component: TabsPage,
     children: [
       {
-        path: 'tab1',
-        loadChildren: () => import('../tab1/tab1.module').then(m => m.Tab1PageModule)
+        path: 'home',
+        loadChildren: () => import('../home/home.module').then(m => m.HomePageModule)
       },
+        {
+          path: "timer",
+          loadChildren: () => import('../../modules/tab/tree/tree.module').then(mod => mod.TreePageModule)
+        },
       {
         path: 'memo',
         loadChildren: () => import('../memo/memo.module').then(m => m.MemoPageModule)
       },
       {
-        path: 'tab2',
-        loadChildren: () => import('../tab2/tab2.module').then(m => m.Tab2PageModule)
-      },
-      {
-        path: 'tab3',
-        loadChildren: () => import('../tab3/tab3.module').then(m => m.Tab3PageModule)
-      },
-      {
-        path: 'calendar',
-        loadChildren: () => import('../../modules/user/mine/mine.module').then(mod => mod.MinePageModule)
-      },
-      {
-        path: "tree",
-        loadChildren: () => import('../../modules/tab/tree/tree.module').then(mod => mod.TreePageModule)
-      },
+        path: 'chatpage',
+        loadChildren: () => import('../chatpage/chatpage.module').then( m => m.ChatpagePageModule)
+      }, 
+        {
+          path: 'chat',
+          loadChildren: () => import('../child-page/chat/chat.module').then(m => m.ChatPageModule)
+        },
       {
-        path: 'bounty-store',
-        loadChildren: () => import('../bounty-store/bounty-store.module').then(mod => mod.BountyStorePageModule)
+        path: 'mine',
+        loadChildren: () => import('../mine/mine.module').then(m => m.MinePageModule)
       },
+        {
+          path: 'go-load',
+          loadChildren: () => import('../../modules/user/mine/mine.module').then(mod => mod.MinePageModule)
+        },
+        {
+          path: 'bounty-store',
+          loadChildren: () => import('../child-page/bounty-store/bounty-store.module').then(mod => mod.BountyStorePageModule)
+        },
       {
         path: '',
-        redirectTo: '/tabs/tab1',
+        redirectTo: '/tabs/home',
         pathMatch: 'full'
       }
     ]
   },
   {
     path: '',
-    redirectTo: '/tabs/tab1',
+    redirectTo: '/tabs/home',
     pathMatch: 'full'
   }
 ];

+ 2 - 3
src/app/tabs/tabs.page.html

@@ -1,6 +1,6 @@
 <ion-tabs>
   <ion-tab-bar slot="bottom">
-    <ion-tab-button tab="tab1" href="/tabs/tab1">
+    <ion-tab-button tab="home" href="/tabs/home">
       <ion-icon aria-hidden="true" name="scale-outline"></ion-icon>
       <ion-label>首页</ion-label>
     </ion-tab-button>
@@ -12,13 +12,12 @@
     </ion-tab-button>
 
     
-    <ion-tab-button tab="tab2" href="/tabs/tab2">
+    <ion-tab-button tab="chatpage" href="/tabs/chatpage">
       <ion-icon aria-hidden="true" name="chatbox-ellipses-outline"></ion-icon>
       <ion-label>ai对话</ion-label>
     </ion-tab-button>
 
 
-
     <ion-tab-button (click)="checkLogin()">
       <ion-icon aria-hidden="true" name="person"></ion-icon>
       <ion-label>我的</ion-label>

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

@@ -15,10 +15,10 @@ export class TabsPage {
     const currentUser = Parse.User.current();
     if (currentUser) {
       // 如果已登录,跳转到“我的”界面
-      this.navCtrl.navigateForward('/tabs/tab3');
+      this.navCtrl.navigateForward('/tabs/mine');
     } else {
       // 如果未登录,跳转到“登录”界面
-      this.navCtrl.navigateForward('/tabs/calendar');
+      this.navCtrl.navigateForward('/tabs/go-load');
     }
   }
 }

+ 0 - 0
src/app/explore-container/explore-container.component.html → src/modules/tab/tree/explore-container/explore-container.component.html


+ 0 - 0
src/app/explore-container/explore-container.component.scss → src/modules/tab/tree/explore-container/explore-container.component.scss


+ 0 - 0
src/app/explore-container/explore-container.component.spec.ts → src/modules/tab/tree/explore-container/explore-container.component.spec.ts


+ 0 - 0
src/app/explore-container/explore-container.component.ts → src/modules/tab/tree/explore-container/explore-container.component.ts


+ 0 - 0
src/app/explore-container/explore-container.module.ts → src/modules/tab/tree/explore-container/explore-container.module.ts


+ 1 - 1
src/modules/tab/tree/tree.page.spec.ts

@@ -2,7 +2,7 @@ import { ComponentFixture, TestBed } from '@angular/core/testing';
 import { IonicModule } from '@ionic/angular';
 import { TreePage } from './tree.page';
 
-import { ExploreContainerComponentModule } from 'src/app/explore-container/explore-container.module';
+import { ExploreContainerComponentModule } from 'src/modules/tab/tree/explore-container/explore-container.module';
 
 describe('TreePage', () => {
   let component: TreePage;

+ 11 - 4
src/modules/tab/tree/tree.page.ts

@@ -22,6 +22,13 @@ export class TreePage implements OnInit, OnDestroy {
     // No need to start the timer here; it starts when user interacts with it
   }
 
+  ionViewDidEnter() {
+    this.stopTimer();
+    this.minutes = 0;
+    this.seconds = 0;
+    console.log("tab-timer")
+  }
+
   startTimer() {
     this.stopTimer();
     console.log('Timer started');
@@ -89,11 +96,11 @@ export class TreePage implements OnInit, OnDestroy {
     this.isPaused = true; // Ensure the pause icon is dark when exiting
     this.exitClicked = true; // Set exit button clicked to true
     const alert = await this.alertController.create({
-      header: 'Confirm Exit',
-      message: 'Are you sure you want to exit and reset the timer?',
+      header: '确认退出',
+      message: '你确定想要退出并停止计时吗?',
       buttons: [
         {
-          text: 'Cancel',
+          text: '取消',
           role: 'cancel',
           handler: () => {
             console.log('Exit cancelled');
@@ -101,7 +108,7 @@ export class TreePage implements OnInit, OnDestroy {
           }
         },
         {
-          text: 'Confirm',
+          text: '确认',
           handler: () => {
             this.resetTimer();
             this.navCtrl.back();

+ 2 - 2
src/modules/user/login/login.page.ts

@@ -41,7 +41,7 @@ export class LoginPage implements OnInit {
     }
     console.log(user);
     if (user?.id) {
-      this.navCtrl.navigateForward('/tabs/tab3'); // 导航到主页或其他页面
+      this.navCtrl.navigateForward('/tabs/mine'); // 导航到主页或其他页面
     }
   }
 
@@ -55,7 +55,7 @@ export class LoginPage implements OnInit {
       if (result?.id) {
         // 注册成功后立即加载用户数据
         this.loadUserData();
-        this.navCtrl.navigateForward('/tabs/tab3'); // 导航到主页或其他页面
+        this.navCtrl.navigateForward('/tabs/mine'); // 导航到主页或其他页面
       }
     } catch (error: any) {
       let message: string = "";