Преглед на файлове

refactor(novel-app): 重构角色创建功能

18460000105 преди 3 месеца
родител
ревизия
d28cdfccf6
променени са 2 файла, в които са добавени 34 реда и са изтрити 102 реда
  1. 5 43
      novel-app/src/app/agent-create/agent-create.page.ts
  2. 29 59
      novel-app/src/app/atest/atest.page.ts

+ 5 - 43
novel-app/src/app/agent-create/agent-create.page.ts

@@ -27,12 +27,9 @@ export class AgentCreatePage implements OnInit {
   ) {
    this.currentUser = new CloudUser();
   // 示例任务,自己生成图片后请存储新的ID 
-  
-
   }
  images:Array<string> = []
   back:string = "<";
-
   backhome() {
     this.router.navigate(['/tab1']);
   }
@@ -42,61 +39,33 @@ export class AgentCreatePage implements OnInit {
   name: string = ''
   nameInput(e:any) {
     this.name = e.detail.value;
-    console.log(this.name);
   }
   age: number = 25
   ageInput(e:any) {
     this.age = e.detail.value;
-    console.log(this.age);
   }
   gender: string = 'male'
   genderChange(e:any) {
-    console.log('ionChange fired with value: ' + e.detail.value);
-    this.gender = e.detail.value;
-  }
-  genderCancel(){
-
-  }
-  genderDismiss(){
-
-  }
-  // 描述
+    this.gender = e.detail.value;}
+  genderCancel(){}
+  genderDismiss(){}
   desc: string = ''
   descInput(e:any) {
-    this.desc = e.detail.value;
-    console.log(this.desc);
-  }
-  
+    this.desc = e.detail.value;}
   PictureDescResult:string = `` // 画面描述结果
-
-  // 创建医生
   async createAgent() {
-  
-   
     localStorage.setItem("company","E4KpGvTEto")
-
     let consult = new CloudObject("NovelCharacter")
     let now = new Date();
     let dateStr = `${now.getFullYear()}-${now.getMonth()+1}-${now.getDate()}`
     // 对象权限的精确指定
-    let ACL:any = {
-      "*":{read:true,write:true}
-    }
-    if(this.currentUser?.id){
-      ACL[this.currentUser?.id] = {read:true,write:true}
-    }
-
-    
       let completion = new FmodeChatCompletion([
         {role:"system",content:""},
-       
       ])
- 
       completion.sendCompletion().subscribe((message:any)=>{
         // 打印消息体
         console.log(message.content)
         // 赋值消息内容给组件内属性
-        this.PictureDescResult = message.content
         if(message?.complete){ // 判断message为完成状态,则设置isComplete为完成
               // 图片生成
             let PicturePrompt = ``
@@ -106,20 +75,13 @@ export class AgentCreatePage implements OnInit {
                     age:`${this.age}`,
                     gender:`${this.gender}`,
                     desc:`${this.desc}`,
-                    user:this.currentUser.toPointer(),
-                    ACL:ACL,
+                    user:this.currentUser.toPointer(), 
                   })
                   consult.save();
                   console.log(consult);
         }
       })
  
-  
   }
-  
-
-
-
-
 
 }

+ 29 - 59
novel-app/src/app/atest/atest.page.ts

@@ -27,18 +27,9 @@ export class AtestPage implements OnInit {
   ) {
    this.currentUser = new CloudUser();
   // 示例任务,自己生成图片后请存储新的ID 
-  this.imagineWork = new ImagineWork("");
-  this.imagineWork.fetchTask().then(work=>{
-    if(work){
-      this.imagineWork.id = work.id
-    }
-    this.images = this.imagineWork?.images || '../../assets/image/头像示例.png';
-  })
-  this.loadAgentData()
   }
  images:Array<string> = []
   back:string = "<";
-
   backhome() {
     this.router.navigate(['/tab1']);
   }
@@ -48,72 +39,51 @@ export class AtestPage implements OnInit {
   name: string = ''
   nameInput(e:any) {
     this.name = e.detail.value;
-    console.log(this.name);
   }
   age: number = 25
   ageInput(e:any) {
     this.age = e.detail.value;
-    console.log(this.age);
   }
   gender: string = 'male'
   genderChange(e:any) {
-    console.log('ionChange fired with value: ' + e.detail.value);
-    this.gender = e.detail.value;
-  }
-  genderCancel(){
-
-  }
-  genderDismiss(){
-
-  }
-  // 描述
+    this.gender = e.detail.value;}
+  genderCancel(){}
+  genderDismiss(){}
   desc: string = ''
   descInput(e:any) {
-    this.desc = e.detail.value;
-    console.log(this.desc);
-  }
-  imagineWork:ImagineWork
+    this.desc = e.detail.value;}
   PictureDescResult:string = `` // 画面描述结果
-
-  // 创建医生
+  isConsultSet: boolean = false;
   async createAgent() {
-    const alert = await this.alertController.create({
-      header: '温馨提示',
-      subHeader: 'Tips',
-      message: '把信息填写完整哦~',
-      buttons: ['好的'],
-    });
-    if (this.name == '' || this.age == 0 || this.gender == '' || this.desc == '') {
-      //await alert.present();
-      return;
-    } 
-    localStorage.setItem("company","E4KpGvTEto")
-
-    let consult = new CloudObject("NovelCharacter")
+   // localStorage.setItem("company","E4KpGvTEto")
+    let consult = new CloudObject("test")
     let now = new Date();
     let dateStr = `${now.getFullYear()}-${now.getMonth()+1}-${now.getDate()}`
     // 对象权限的精确指定
-    let ACL:any = {
-      "*":{read:true,write:true}
-    }
-    if(this.currentUser?.id){
-      ACL[this.currentUser?.id] = {read:true,write:true}
-    }
-
- 
+      let completion = new FmodeChatCompletion([
+        {role:"system",content:""},
+      ])
       
+      completion.sendCompletion().subscribe((message:any)=>{
+        // 打印消息体
+        console.log(message.content)
+        // 赋值消息内容给组件内属性
+        if (message?.complete && !this.isConsultSet) {
+          this.isConsultSet = true; // 标记为已设置
+          
+          consult.set({
+            name: `${this.name}`,
+            age: `${this.age}`,
+            gender: `${this.gender}`,
+            desc: `${this.desc}`,
+            user: this.currentUser.toPointer(),
+          });
+                  consult.save();
+                  console.log(consult);
+        }
+      })
  
- 
-  
+     
   }
-  
-  agentList: Array<CloudObject> = [];
-  async loadAgentData() {
-    let query = new CloudQuery("test")
-    this.agentList = await query.find()
-    console.log(this.agentList);
-  }
-
-
 
 }