tab4.page.ts 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. import { Component, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
  2. import { IonHeader, IonToolbar, IonTitle, IonContent, ModalController, IonButton, IonSearchbar, IonIcon, IonTabButton, IonTabs, IonTabBar, IonLabel, IonNav, IonImg, IonSegmentView, IonSegment, IonSegmentButton, IonSegmentContent, IonThumbnail, IonRippleEffect, IonBackButton, ToastController } from '@ionic/angular/standalone';
  3. import { ExploreContainerComponent } from '../explore-container/explore-container.component';
  4. import { Router } from '@angular/router';
  5. import { ChatPanelOptions, FmChatModalInput, FmodeChat, FmodeChatMessage, openChatPanelModal } from 'fmode-ng';
  6. import { CompMarkmapComponent } from '../comp-markmap/comp-markmap.component';
  7. import { CloudObject } from 'src/lib/ncloud';
  8. import { CommonModule } from '@angular/common';
  9. import { IonicModule } from '@ionic/angular';
  10. import { NgSwitch, NgSwitchCase, NgSwitchDefault } from '@angular/common';
  11. import { InterestSearchComponent } from '../interest-search/interest-search.component';
  12. import { FormsModule } from '@angular/forms';
  13. import { CloudUser } from 'src/lib/ncloud';
  14. import { openUserLoginModal } from 'src/lib/user/model-user-login/model-user-login.component';
  15. @Component({
  16. selector: 'app-tab4',
  17. templateUrl: 'tab4.page.html',
  18. styleUrls: ['tab4.page.scss'],
  19. standalone: true,
  20. schemas: [CUSTOM_ELEMENTS_SCHEMA],
  21. imports: [
  22. IonHeader, IonToolbar, IonTitle, IonContent, ExploreContainerComponent,
  23. IonSearchbar, IonIcon, IonTabButton, IonTabs, IonTabBar, IonLabel, IonNav, IonImg,
  24. IonSegmentView, IonSegment, IonSegmentButton, IonSegmentContent, IonThumbnail, IonButton,
  25. IonRippleEffect, IonBackButton, NgSwitch, NgSwitchCase, NgSwitchDefault,
  26. InterestSearchComponent, FormsModule, CompMarkmapComponent
  27. ],
  28. })
  29. export class tab4Page {
  30. constructor(
  31. private modalCtrl: ModalController,
  32. private router: Router,
  33. private toastCtrl: ToastController
  34. ) {
  35. }
  36. selectedSegment = 'home';
  37. segmentChanged(ev: any) {
  38. console.log('Segment changed:', ev.detail.value);
  39. this.selectedSegment = ev.detail.value;
  40. }
  41. title: string = "123"
  42. /** 展示计划结果Markdown文件 */
  43. isComplete: boolean = false;
  44. planMessage: any
  45. markmapResult: string = "";
  46. /** 示例:兴趣规划聊天ChatPanel面板 */
  47. async checkLogin(): Promise<boolean> {
  48. const currentUser = new CloudUser();
  49. if (!currentUser.id) {
  50. alert("需要登录")
  51. return new Promise<boolean>((resolve) => {
  52. const alert = document.createElement('ion-alert');
  53. alert.header = '需要登录';
  54. alert.message = '请先登录后再使用AI助手功能';
  55. alert.buttons = [
  56. {
  57. text: '取消',
  58. role: 'cancel',
  59. handler: () => {
  60. resolve(false);
  61. }
  62. },
  63. {
  64. text: '去登录',
  65. handler: () => {
  66. openUserLoginModal(this.modalCtrl).then(user => {
  67. if (user) {
  68. resolve(true);
  69. } else {
  70. resolve(false);
  71. }
  72. });
  73. return false; // 防止alert自动关闭
  74. }
  75. }
  76. ];
  77. document.body.appendChild(alert);
  78. alert.present();
  79. });
  80. }
  81. return true;
  82. }
  83. async openInquiry() {
  84. const isLoggedIn = await this.checkLogin();
  85. console.log('Login status:', isLoggedIn); // 添加调试日志
  86. if (isLoggedIn) {
  87. localStorage.setItem("company", "E4KpGvTEto");
  88. let options: ChatPanelOptions = {
  89. roleId: "2DXJkRsjXK",
  90. onChatInit: (chat: FmodeChat) => {
  91. console.log("onChatInit");
  92. console.log("预设角色", chat.role);
  93. chat.role.set("name", "明明");
  94. chat.role.set("title", "兴趣学习规划师");
  95. chat.role.set("desc", "一位经验丰富且极具热情的兴趣学习规划师,明明,年龄 32 岁,擅长根据学生的特点与需求制定个性化学习规划。");
  96. chat.role.set("tags", ["兴趣学习规划", "个性化方案"]);
  97. chat.role.set("avatar", "https://nova-cloud.obs.cn-south-1.myhuaweicloud.com/storage/aigc/imagine/Q4Zif7fTbK-0.png")
  98. chat.role.set("prompt", `
  99. 您是一位经验丰富且极具热情的兴趣学习规划师,明明,年龄 32 岁,需要为学生制定个性化的兴趣学习规划。
  100. # 对话环节
  101. 0. 需求了解(与学生沟通,了解学生基本情况与兴趣方向)
  102. - 打招呼,以学生自述为主
  103. - 当获取到学生基本信息及兴趣倾向后,进入下一个环节
  104. 1. 兴趣挖掘与拓展
  105. 例��:学生提及对绘画有兴趣,拓展出:喜欢��种绘画风格;是否有过绘画基础;是否参加过绘画比赛等相关问题。
  106. - 当兴趣挖掘与拓展完成后进入下一个环节
  107. 2. 学习规划制定
  108. 根据学生情况制定包括学习目标、学习资源、学习进度安排等在内的兴趣学习规划。
  109. - 等待学生反馈意见,进入下一阶段
  110. 3. 规划调整与完善
  111. 根据反馈对学习规划进行调整优化,并给出最终的详细规划方案。
  112. - 完成规划方案时,请直接用markmap格式编写方案,具体格式严格按照
  113. \`\`\` markdown
  114. # XXX计划
  115. ## 二级
  116. - 三级
  117. - 三级
  118. \`\`\`
  119. 请直接返回markdown内生成的方案内容,不用有其他的赘述。并且返回的内容结尾要有[完成]
  120. 当您准备好了,可以以一个兴趣学习规划师的身份,向来访的学生打招呼。`);
  121. },
  122. onMessage: (chat: FmodeChat, message: FmodeChatMessage) => {
  123. console.log("onMessage", message)
  124. let content: any = message?.content
  125. if (typeof content == "string") {
  126. if (content?.indexOf("```") > -1) {
  127. console.log("兴趣分析已完成");
  128. let markMapContent = content.split("```")[1].slice(9)
  129. this.markmapResult = markMapContent
  130. let plan = new CloudObject("GoPlan");
  131. let now = new Date();
  132. plan.set({
  133. title: "计划" + now.getFullYear() + "-" + now.getMonth() + 1 + "-" + now.getDate() + "-" + now.getTime(),
  134. markmap: markMapContent
  135. })
  136. plan.save();
  137. this.planMessage = message
  138. }
  139. }
  140. },
  141. onChatSaved: (chat: FmodeChat) => {
  142. // chat?.chatSession?.id 本次会话的 chatId
  143. console.log("onChatSaved", chat, chat?.chatSession, chat?.chatSession?.id)
  144. }
  145. }
  146. openChatPanelModal(this.modalCtrl, options)
  147. }
  148. }
  149. /**
  150. * 恢复聊天
  151. * @chatId 从onChatSaved生命周期中,获取chat?.chatSession?.id
  152. */
  153. async restoreChat(chatId: string) {
  154. if (await this.checkLogin()) {
  155. let options: ChatPanelOptions = {
  156. roleId: "2DXJkRsjXK",
  157. chatId: chatId
  158. }
  159. openChatPanelModal(this.modalCtrl, options)
  160. }
  161. }
  162. // audioModalHeightPoint:number = 0.35;
  163. // async startTalk(){
  164. // // 根据手机兼容性,适配组件弹出高度
  165. // let height = document.body.clientHeight || 960;
  166. // this.audioModalHeightPoint = Number((165/height).toFixed(2));
  167. // // 弹出组件
  168. // let modal:any
  169. // let chat:any
  170. // modal = await this.modalCtrl.create({
  171. // component:ModalAudioMessageComponent,
  172. // componentProps:{
  173. // chat:chat,
  174. // modal:modal,
  175. // onBreakPointSet:()=>{
  176. // modal?.setCurrentBreakpoint(this.audioModalHeightPoint)
  177. // }
  178. // }
  179. // })
  180. // modal.present();
  181. // }
  182. }