Browse Source

Merge branch 'master' of http://git.fmode.cn:3000/19808003398/20222670105

s202226701043 3 tháng trước cách đây
mục cha
commit
dd8bcb0ba4

+ 18 - 12
novel-app/src/app/agent-create/agent-create.page.html

@@ -22,27 +22,33 @@
           <!-- <ion-input label="输入你想了解的科普信息" placeholder="Enter text"></ion-input> -->
           <ion-input  [value]="name" placeholder="输入名称" (ionInput)="nameInput($event)"></ion-input>
         </ion-item>
-        <ion-item>
+        <!-- <ion-item>
           <p style="width: 60px; font-weight: bolder;">年龄:</p>
           <ion-input  [value]="age" placeholder="输入年龄" (ionInput)="ageInput($event)"></ion-input>
         </ion-item>
         <ion-item>
           <p style="width: 60px;  font-weight: bolder;">性别:</p>
-          <ion-select
-            aria-label="性别"
-            placeholder="选择性别"
-            (ionChange)="genderChange($event)"
-            (ionCancel)="genderCancel()"
-            (ionDismiss)="genderDismiss()"
-          >
-            <ion-select-option value="男">男</ion-select-option>
-            <ion-select-option value="女">女</ion-select-option>
-          </ion-select>
-        </ion-item>
+          <ion-input  [value]="gender" placeholder="输入种族" (ionInput)="genderChange($event)"></ion-input>
+        
+            
+          
+        </ion-item> -->
         <ion-item style="height: auto;">
             <p style="width:120px;font-weight: bolder;">设定描述:</p>
             <ion-textarea [value]="desc" placeholder="示例:" (ionInput)="descInput($event)" autoGrow="true"></ion-textarea> 
         </ion-item>
+        <ion-item>
+          <ion-label position="stacked">上传角色图片</ion-label>
+          <div class="image-upload" (click)="fileInput.click()">
+            <input type="file" #fileInput (change)="onFileSelected($event)" accept="image/*" style="display: none;" />
+            <div class="image-preview" *ngIf="selectedImage">
+              <img style="height:200px;" [src]="selectedImage" alt="角色图片" />
+            </div>
+            <div class="upload-text" *ngIf="!selectedImage">
+              点击上传图片
+            </div>
+          </div>
+        </ion-item>
       </ion-list>
     </ion-card>
   </div>

+ 15 - 2
novel-app/src/app/agent-create/agent-create.page.ts

@@ -40,18 +40,29 @@ export class AgentCreatePage implements OnInit {
   nameInput(e:any) {
     this.name = e.detail.value;
   }
-  age: number = 25
+  age: string = ''
   ageInput(e:any) {
     this.age = e.detail.value;
   }
-  gender: string = 'male'
+  gender: string = '人族'
   genderChange(e:any) {
     this.gender = e.detail.value;}
   genderCancel(){}
+  selectedImage: string | ArrayBuffer | null = null;
   genderDismiss(){}
   desc: string = ''
   descInput(e:any) {
     this.desc = e.detail.value;}
+    onFileSelected(event: Event) {
+      const file = (event.target as HTMLInputElement).files?.[0];
+      if (file) {
+        const reader = new FileReader();
+        reader.onload = () => {
+          this.selectedImage = reader.result; // 将图片数据存储到 selectedImage
+        };
+        reader.readAsDataURL(file);
+      }
+    }
   PictureDescResult:string = `` // 画面描述结果
   async createAgent() {
     localStorage.setItem("company","E4KpGvTEto")
@@ -75,6 +86,8 @@ export class AgentCreatePage implements OnInit {
                     age:`${this.age}`,
                     gender:`${this.gender}`,
                     desc:`${this.desc}`,
+                    username: this.currentUser.data["username"],
+                    avatar: this.selectedImage,
                     user:this.currentUser.toPointer(), 
                   })
                   consult.save();

+ 2 - 2
novel-app/src/app/component/article-card/article-card.component.html

@@ -2,8 +2,8 @@
   <!-- <img [src]="card.get('image')[0]" alt="Image"> -->
   <div class="content">
     <h3>{{ card.get('title') }}</h3>
-    <p>焚枯食淡荆防颗粒收到了发</p>
-    <!-- <p>{{ card.get('topic') }} &nbsp; {{ card.get('date') }}</p> -->
+    
+    <p>作者:{{ card.get('username') }}</p> <p>{{ card.get('date') }}</p>
     <!-- <p>
       阅读量: {{ card.get('views') }} &nbsp; 赞: {{ card.get('likes') }}
     </p> -->

+ 1 - 1
novel-app/src/app/component/article-card/article-card.component.scss

@@ -15,7 +15,7 @@
   .card .content {
     display: flex;
     flex-direction: column;
-    justify-content: space-between;
+    
   }
   
   .card h3 {

+ 12 - 5
novel-app/src/app/short-generator/short-generator.page.ts

@@ -44,11 +44,13 @@ import { AvatarModule, ChatPanelOptions, DalleOptions, FmodeChat, FmodeChatMessa
     IonSelectOption,
     // IonButtons,
     IonProgressBar,
-    IonText
+    IonText,MarkdownPreviewModule
   ],
 })
 export class ShortGeneratorPage implements OnInit {
-  constructor(private router: Router) { }
+  constructor(private router: Router) { 
+    this.currentUser = new CloudUser();
+  }
 
   ngOnInit() { }
 
@@ -68,7 +70,7 @@ export class ShortGeneratorPage implements OnInit {
     this.style = ev.detail.value;
   }
 
-
+  currentUser: CloudUser;
   // 人物词条
   entryList: Array<any> = []
   list: any = [];
@@ -101,9 +103,10 @@ export class ShortGeneratorPage implements OnInit {
     console.log("create");
     console.log(JSON.stringify(this.entryList));
     console.log(this.titlel);
+    this.entry = JSON.stringify(this.entryList); // 将 entryList 转换为字符串并存储在 entry 中
     console.log(this.entry)
     let PromptTemplate = `
-    您作为一名专业的${this.style}作者,请您根据用户提供的标题${this.titlel},根据这个词条${this.entry}的内容,添加文章信息,并给出短篇小说大纲。
+    您作为一名专业的${this.style}作者,请您根据用户提供的标题${this.titlel},根据这个词条${JSON.stringify(this.entryList)}的内容,添加文章信息,并给出短篇小说大纲。
     
     `;
     console.log(PromptTemplate);
@@ -171,11 +174,15 @@ export class ShortGeneratorPage implements OnInit {
             // age: `${this.age}`,
             // gender: `${this.gender}`,
             // desc: `${this.desc}`,
-            // user: this.currentUser.toPointer(),
+            user: this.currentUser.toPointer(),
+            username: this.currentUser.data["username"],
             title: `${this.titlel}`,
             topic: `${this.style}`,
             content2: `${this.generatedContent}`,
+            entry: `${this.entry}`,
+             outline: `${this.generatedOutline}`,
             date: dateStr,
+            
             category: `短篇小说` 
           });
                   consult.save();

+ 27 - 0
novel-app/src/app/tab1/tab1.page.html

@@ -4,6 +4,33 @@
     <ion-refresher-content></ion-refresher-content>
   </ion-refresher>
 <div>
+  @if(user.id == admin){
+    <div>
+      <h1>我是管理员</h1>
+      <ion-card>
+        <ion-card-header>
+          <ion-card-title>所有人的智能体</ion-card-title>
+          <ion-card-subtitle>智能体简介</ion-card-subtitle>
+        </ion-card-header>
+        <ion-card-content>
+          <ion-list>
+            <ion-item   *ngFor="let doctor of doctorList1" lines="none">
+              <ion-thumbnail slot="start" (click)="openInquiry(doctor)">
+                <img [src]="doctor.get('avatar')" [alt]="doctor.get('name')" />
+              </ion-thumbnail>
+              <div class="doctor-info" (click)="openInquiry(doctor)">
+                <p>{{doctor.get("username")}}</p>
+                <h3>{{ doctor.get('name') }}({{ doctor.get('age') }}岁)</h3>
+                <p>{{ doctor.get('desc') }}</p>
+                
+              </div>
+              <ion-button ios="logo-apple" size="small" color="danger" (click)="deleteAgent(doctor)" slot="end">删除</ion-button>
+            </ion-item>
+          </ion-list>
+        </ion-card-content>
+      </ion-card>
+    </div>
+  }
   <ion-card>
     <ion-card-header>
       <ion-card-title>智能体</ion-card-title>

+ 13 - 2
novel-app/src/app/tab1/tab1.page.ts

@@ -39,6 +39,15 @@ export class Tab1Page {
       event.target.complete();
     }, 2000);
   }
+  admin:string = 'nRDdxdEn2k'
+  user : CloudUser 
+  doctorList1: Array<CloudObject> = []
+  async loadAllagent(){
+    let query = new CloudQuery("NovelCharacter")
+    query.include("user")
+    this.doctorList1=await query.find()
+    console.log("doctor.get('user').username",this.doctorList1[0].get("username"))
+  }
   constructor(
     private router: Router,
      private modalCtrl: ModalController,
@@ -46,7 +55,8 @@ export class Tab1Page {
     private http: HttpClient// 注入 HttpClient,
 
   ) {
-
+    this.user = new CloudUser();
+    this.loadAllagent();
     addIcons({ add });
   }
   navigateToPage() {
@@ -77,9 +87,10 @@ export class Tab1Page {
   
    /** 示例:问诊根据doctor拼接提示词 */
    openInquiry(doctor:CloudObject){
+    console.log("doctor",doctor)
     localStorage.setItem("company","E4KpGvTEto")
 
-    let consult = new CloudObject("Consultation")
+    let consult = new CloudObject("NovelCharacter")
     let now = new Date();
     let dateStr = `${now.getFullYear()}-${now.getMonth()+1}-${now.getDate()}`
     consult.set({

+ 3 - 2
novel-app/src/app/tab2/tab2.page.html

@@ -87,8 +87,9 @@
       <ion-content class="ion-padding">
         <div class="modal-content" *ngIf="currentProduct">
           <h1 class="product-name">{{currentProduct.get('title')}}</h1>
-          <p><strong>作者:</strong>{{currentProduct.get('author')}}</p>
-          <p>{{currentProduct.get('content')[0]}}</p>
+          <p><strong>作者:</strong>{{currentProduct.get('username')}}</p>
+          <fm-markdown-preview  [content]="currentProduct.get('content2')"></fm-markdown-preview>
+          
           <!-- <div class="image-container">
             <img style="width: 100%; height: auto;" [src]="currentProduct.get('image')[0]" alt="图片" class="medicine-image">
           </div> -->

+ 2 - 0
novel-app/src/app/tab2/tab2.page.scss

@@ -1,3 +1,5 @@
+// @import '@fortawesome/fontawesome-free/css/all.min.css'; // 字体图标
+// @import 'highlight.js/scss/monokai.scss'; // 代码高亮 - monokai主题
 .custom-toolbar {
   --background: rgba(255, 255, 255, 0.8); /* 使工具栏背景透明 */
   display: flex; /* 使用 Flexbox 布局 */

+ 6 - 2
novel-app/src/app/tab2/tab2.page.ts

@@ -1,3 +1,4 @@
+import { MarkdownPreviewModule } from 'fmode-ng';
 import { Component } from '@angular/core';
 import { ModalController, IonModal, IonHeader, IonToolbar, IonTitle, IonContent, IonList, IonItem, IonLabel, IonAvatar, IonButton, IonSegment, IonSegmentButton, IonSegmentContent, IonSegmentView, IonCardContent, IonCardTitle, IonCardHeader, IonCard, IonIcon, IonButtons, IonSearchbar, IonFab, IonFabButton, IonFabList } from '@ionic/angular/standalone';
 import { ExploreContainerComponent } from '../explore-container/explore-container.component';
@@ -27,7 +28,7 @@ addIcons({ chevronDownCircle, chevronForwardCircle, chevronUpCircle, colorPalett
     IonLabel,IonItem,IonList,IonAvatar,ArticleCardComponent,CommonModule,IonButton,
     IonSegment, IonSegmentButton,
     IonSegmentContent,IonSegmentView,IonCardContent, IonCardTitle, IonCardHeader,IonCard,
-    IonModal,IonIcon, IonButtons, IonSearchbar, IonFab, IonFabButton,IonFabList,
+    IonModal,IonIcon, IonButtons, IonSearchbar, IonFab, IonFabButton,IonFabList,MarkdownPreviewModule
   ]
 })
 
@@ -91,11 +92,12 @@ setSlidePosition() {
 
 
   type:"hotdot"|"export" = "hotdot"
-
+content = ''
   constructor(
     private modalCtrl:ModalController,
     private router:Router,
   ) { 
+    
     this.loadCards(); // 初始化时加载所有科普信息
   }
 
@@ -108,10 +110,12 @@ setSlidePosition() {
 
   async loadCards() {
     const query = new CloudQuery('NovelAriticle');
+    // this.content = '',
     this.allCards = await query.find(); 
     console.log(this.allCards);
     this.cards = this.allCards.filter((card) => card.get('category').toLowerCase().includes(this.type));
     console.log(this.cards);
+   
   }
 
 

+ 6 - 3
novel-app/src/app/tab7/tab7.page.html

@@ -18,9 +18,12 @@
   <!-- 按钮:执行消息生成函数 -->
   <ion-button (click)="sendMessage()" expand="block">生成大纲</ion-button>
 
-  <ion-textarea [(ngModel)]="generatedOutline" placeholder="生成的小说大纲" autoGrow="true"
-    class="generated-outline"></ion-textarea>
-  
+  <!-- <ion-textarea [(ngModel)]="generatedOutline" placeholder="生成的小说大纲" autoGrow="true"
+    class="generated-outline"></ion-textarea> -->
+    @if(isComplete){
+      <fm-markdown-preview  [content]="responseMsg"></fm-markdown-preview>
+    }
+   
 
   <!-- 保存按钮 -->
   <ion-button (click)="saveNovel()" expand="block" color="success">保存小说</ion-button>

+ 12 - 64
novel-app/src/app/tab7/tab7.page.ts

@@ -48,13 +48,12 @@ import { AvatarModule, ChatPanelOptions, DalleOptions, FmodeChat, FmodeChatMessa
   ],
 })
 export class Tab7Page implements OnInit {
-  constructor(private router: Router) { }
+  constructor(private router: Router) {
+    this.currentUser = new CloudUser();
+   }
 
   ngOnInit() { }
-
-  navigateToContentGenerator() {
-    this.router.navigate(['/content-generator'], { queryParams: { outline: this.generatedOutline } });
-  }
+  currentUser: CloudUser;
 
   // 用户输入提示词
   titlel: string = "";
@@ -67,29 +66,10 @@ export class Tab7Page implements OnInit {
   styleInput(ev: any) {
     this.style = ev.detail.value;
   }
-
-
-  // 人物词条
-  entryList: Array<any> = []
-  list: any = [];
-  entry: string = ''; 
-  onEntryListChange(ev: any) {
-    this.entryList = ev;
-    let list =JSON.stringify(this.entryList) ;
-    console.log(list);
-
-  }
   
-  showEntryList() {
-    console.log(JSON.stringify(this.entryList))
-    
-  }
   // 生成的小说大纲
   generatedOutline: string = "";
 
-  // 生成的小说内容
-  generatedContent: string = "";
-
   // 属性:组件内用于展示消息内容的变量
   responseMsg: any = "";
 
@@ -98,13 +78,8 @@ export class Tab7Page implements OnInit {
 
   sendMessage() {
     console.log("create");
-    console.log(JSON.stringify(this.entryList));
-    console.log(this.titlel);
-    this.entry = JSON.stringify(this.entryList); // 将 entryList 转换为字符串并存储在 entry 中
-    console.log(this.entry); // 输出 entry 的值
     let PromptTemplate = `
-    您作为一名专业的${this.style}作者,请您根据用户提供的标题${this.titlel},根据这个词条${this.entry}的内容,添加文章信息,并给出短篇小说大纲。
-    
+    您作为一名专业的${this.style}作者,请您根据用户提供的标题${this.titlel},添加文章信息,并给出短篇小说大纲。
     `;
     console.log(PromptTemplate);
     let completion = new FmodeChatCompletion([
@@ -124,32 +99,6 @@ export class Tab7Page implements OnInit {
       }
     });
   }
-
-  sendOutline() {
-    console.log("create");
-
-    let PromptTemplate = `
-    根据短篇小说大纲${this.generatedOutline},生成一个短篇小说。
-    `;
-
-    let completion = new FmodeChatCompletion([
-      { role: "system", content: "" },
-      { role: "user", content: PromptTemplate }
-    ]);
-
-    completion.sendCompletion().subscribe((message: any) => {
-      // 打印消息体
-      console.log(message.content);
-      // 赋值消息内容给组件内属性
-      this.responseMsg = message.content;
-      if (message?.complete) { // 判断message为完成状态,则设置isComplete为完成
-        this.isComplete = true;
-        // 将生成的小说内容放入文本框中
-        this.generatedContent = this.responseMsg;
-      }
-    });
-  }
-
   saveNovel() {
     let consult = new CloudObject("NovelAriticle")
     let now = new Date();
@@ -157,8 +106,7 @@ export class Tab7Page implements OnInit {
     // 对象权限的精确指定
       let completion = new FmodeChatCompletion([
         {role:"system",content:""},
-      ])
-      
+      ])     
       completion.sendCompletion().subscribe((message:any)=>{
         // 打印消息体
         console.log(message.content)
@@ -167,15 +115,15 @@ export class Tab7Page implements OnInit {
          
           
           consult.set({
-            // name: `${this.name}`,
-            // age: `${this.age}`,
-            // gender: `${this.gender}`,
-            // desc: `${this.desc}`,
-            // user: this.currentUser.toPointer(),
+            user: this.currentUser.toPointer(),
+            username: this.currentUser.data["username"],
             title: `${this.titlel}`,
             topic: `${this.style}`,
-            content2: `${this.generatedContent}`,
+            
+           
+             outline: `${this.generatedOutline}`,
             date: dateStr,
+            
             category: `工具箱内容` 
           });
                   consult.save();

+ 1 - 1
novel-app/src/app/tabs/tabs.page.html

@@ -5,7 +5,7 @@
       <ion-label>首页</ion-label>
     </ion-tab-button>
 
-    <ion-tab-button tab="character" (click)="goPage('/tabs/character')">
+    <ion-tab-button tab="character" (click)="goPage('/tab1')">
       <ion-icon aria-hidden="true" name="chatbox"></ion-icon>
       <ion-label>角色</ion-label>
     </ion-tab-button>