tab4.page.ts 6.1 KB

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