Эх сурвалжийг харах

完成生成结果界面,增加跳转分享功能

s202226701053 5 сар өмнө
parent
commit
845aee4ea3

+ 13 - 14
E-Cover-app/src/app/generate-result/generate-result.component.html

@@ -3,7 +3,7 @@
 <ion-content>
     <img id="background" [src]="history?.get('image')" />
     <img id="shade" />
-    <img id="share" src="https://s1.imagehub.cc/images/2025/01/11/e19a2422768dc1412e6dbf26a8aaf060.png">
+    <img (click)="goSendPost(history?.get('image'),jsonData['方案名'])" id="share" src="https://s1.imagehub.cc/images/2025/01/11/e19a2422768dc1412e6dbf26a8aaf060.png">
     <ion-card>
         <img class="scan" [src]="history?.get('image')">
         <div>
@@ -23,8 +23,8 @@
                     <p>衣靠评分</p>
                 </div>
                 <div id="score-content">
-                    <p>8.2</p>
-                    <img src="https://s1.imagehub.cc/images/2025/01/11/e8eb352cc826f7e4cfc858cd9a239ab6.png" />
+                    <p>{{animatedScore}}</p>
+                    <img [src]="getIcon(ECScore[0])" />
                 </div>
             </div>
             <div id="right">
@@ -34,18 +34,18 @@
                 <div id="shape-content">
                     <div class="shape-list">
                         <p class="label">功能</p>
-                        <ion-progress-bar [value]="0.72"></ion-progress-bar>
-                        <p class="value">7.2</p>
+                        <ion-progress-bar [value]="ECScore[1]"></ion-progress-bar>
+                        <p class="value">{{ECScore[1] * 10 | number: '1.1-1'}}</p>
                     </div>
                     <div class="shape-list">
                         <p class="label">区域</p>
-                        <ion-progress-bar [value]="0.8"></ion-progress-bar>
-                        <p class="value">8.0</p>
+                        <ion-progress-bar [value]="ECScore[2]"></ion-progress-bar>
+                        <p class="value">{{ECScore[2] * 10 | number: '1.1-1'}}</p>
                     </div>
                     <div class="shape-list">
                         <p class="label">设计</p>
-                        <ion-progress-bar [value]="0.91"></ion-progress-bar>
-                        <p class="value">9.1</p>
+                        <ion-progress-bar [value]="ECScore[3]"></ion-progress-bar>
+                        <p class="value">{{ECScore[3] * 10 | number: '1.1-1'}}</p>
                     </div>
                 </div>
             </div>
@@ -58,10 +58,9 @@
 
 
     <ion-card id="show">
-        <ion-label>{{jsonData['方案名']}}</ion-label>
-        <ion-card *ngFor="let key of keys">
-            <ion-label class="name">{{jsonData['schemeList'][key]['name']}}</ion-label>
-            <ion-label class="desc">{{jsonData['schemeList'][key]['desc']}}</ion-label>
-        </ion-card>
+        <div *ngFor="let key of keys" (click)="toggleDetails(key)" [class.expanded]="isDetailShown(key)">
+            <h1>{{ jsonData['schemeList'][key]['name'] }}</h1>
+            <p *ngIf="isDetailShown(key)">{{ jsonData['schemeList'][key]['desc'] }}</p>
+        </div>
     </ion-card>
 </ion-content>

+ 38 - 34
E-Cover-app/src/app/generate-result/generate-result.component.scss

@@ -1,3 +1,13 @@
+@font-face {
+    font-family: 'HandWritten';
+    src: url(/assets/fonts/handWritten.woff);
+}
+
+@font-face {
+    font-family: 'mainButton';
+    src: url(/assets/fonts/mainButton.TTC);
+}
+
 ion-content {
     --background: #f8f8f8;
     position: relative;
@@ -25,7 +35,7 @@ ion-content {
         background-color: rgba(0, 0, 0, 0.4); // 设置半透明黑色遮罩效果
     }
 
-    #share{
+    #share {
         position: fixed;
         bottom: 5vh;
         right: 5vw;
@@ -33,7 +43,7 @@ ion-content {
         width: 80px;
         object-fit: cover;
         z-index: 9;
-        box-shadow :1px 1px 10px rgba(0, 0, 0, 0.5);
+        box-shadow: 1px 1px 10px rgba(0, 0, 0, 0.5);
         border-radius: 50%;
     }
 
@@ -58,12 +68,6 @@ ion-content {
 
             h1 {
                 margin: 10px 0;
-
-                @font-face {
-                    font-family: 'HandWritten';
-                    src: url(/assets/fonts/handWritten.woff);
-                }
-
                 font-size: 25px;
                 font-family: 'HandWritten';
                 font-weight: bolder;
@@ -72,12 +76,6 @@ ion-content {
             h2 {
                 margin: 5px 0;
                 font-size: 15px;
-
-                @font-face {
-                    font-family: 'mainButton';
-                    src: url(/assets/fonts/mainButton.TTC);
-                }
-
                 font-family: 'mainButton';
             }
         }
@@ -119,6 +117,8 @@ ion-content {
                         text-align: center;
                         margin: 5px;
                         font-size: 35px;
+                        color: orange;
+                        font-weight: bold;
                     }
 
                     img {
@@ -190,36 +190,40 @@ ion-content {
     }
 
     #show {
-        background: none;
+        background: rgba(0, 0, 0, 0.3);
         border-radius: 20px;
-        margin-top: 20px;
         box-shadow: none;
+        width: 96%;
         height: auto;
+        margin: 2%;
 
-        ion-label {
-            font-size: 20px;
-            text-align: center;
+        div {
             display: block;
-            color: black;
-        }
+            width: 100%;
+            border-bottom: #6c6c6c 1px solid;
+            overflow: hidden;
+            max-height: 50px;
+            transition: max-height 1s ease-in-out;
 
-        ion-card {
-            --background: #fef8ef;
-            margin: 0;
-            border-radius: 20px;
-            box-shadow: none;
-            width: 95%;
-            height: auto;
-            margin: 2%;
+            h1 {
+                font-family: 'mainButton';
+                color: white;
+                margin: 10px;
+                font-size: 20px;
+            }
 
-            .name {
-                margin: 15px;
+            p {
+                padding: 0 10px;
+                font-family: 'HandWritten';
+                color: white;
+                font-size: 20px;
+                margin-top: 10px;
             }
 
-            .desc {
-                text-align: start;
-                text-indent: 40px;
+            &.expanded {
+                max-height: 1000px;
             }
         }
+
     }
 }

+ 220 - 10
E-Cover-app/src/app/generate-result/generate-result.component.ts

@@ -1,7 +1,7 @@
 import { CommonModule } from '@angular/common';
 import { Component, Input, OnInit } from '@angular/core';
 import { ActivatedRoute, ParamMap } from '@angular/router';
-import { IonAvatar, IonButton, IonCard, IonContent, IonLabel, IonProgressBar, NavController } from '@ionic/angular/standalone';
+import { IonAvatar, IonButton, IonCard, IonContent, IonItem, IonItemOption, IonItemOptions, IonItemSliding, IonLabel, IonList, IonListHeader, IonProgressBar, NavController } from '@ionic/angular/standalone';
 import { addIcons } from 'ionicons';
 import { arrowBackOutline } from 'ionicons/icons';
 import { map, switchMap } from 'rxjs';
@@ -13,18 +13,19 @@ addIcons({ arrowBackOutline });
   templateUrl: './generate-result.component.html',
   styleUrls: ['./generate-result.component.scss'],
   standalone: true,
-  imports: [IonContent, CustomHeaderComponent, IonCard, IonLabel, CommonModule,IonButton,IonAvatar,
-    IonProgressBar
+  imports: [IonContent, CustomHeaderComponent, IonCard, IonLabel, CommonModule, IonButton, IonAvatar,
+    IonProgressBar, IonItem, IonList
   ],
 })
 
 export class GenerateResultComponent implements OnInit {
   @Input() objectId: string | null = '';
-  history: CloudObject | undefined;
-  jsonData: Record<string, any> = {};
-  keys: Array<string> = [];
-  constructor(private navCtrl: NavController, private route: ActivatedRoute) { }
-  ngOnInit() {
+  constructor(private navCtrl: NavController, private route: ActivatedRoute) {
+    this.keys.forEach(key => {
+      this.detailsShown[key] = false;
+    });
+  }
+  async ngOnInit() {
     this.route.paramMap.pipe(
       switchMap((params: ParamMap) => this.route.queryParamMap.pipe(
         map(() => params.get('resultId'))
@@ -35,10 +36,25 @@ export class GenerateResultComponent implements OnInit {
     });
     console.log("正在加载历史记录:" + this.objectId)
     this.getGenerateResult();
+    this.ECScore[0] = await this.getAllData();
+    this.startAnimation();
+    this.ECScore[1] = this.getFunctionScore();
+    this.ECScore[2] = await this.getRegionScore();
+    this.ECScore[3] = await this.getDesignScore();
   }
-  goBack() {
-    this.navCtrl.back();
+  /**
+   * @页面跳转函数
+   */
+  goSendPost(image: string, name: string) {
+    //传递参数
+    this.navCtrl.navigateForward(['/sendPost'], {
+      state: { image, name }
+    });
   }
+  /*获取相应生成记录*/
+  history: CloudObject | undefined;
+  jsonData: Record<string, any> = {};
+  keys: Array<string> = [];
   async getGenerateResult() {
     let query = new CloudQuery('GenerateResult');
     query.equalTo('objectId', this.objectId);
@@ -50,4 +66,198 @@ export class GenerateResultComponent implements OnInit {
     this.keys = Object.keys(this.jsonData['schemeList']);
     console.log(this.keys);
   }
+  /**
+   * @项目展开函数
+   */
+  /*点击切换展示状态*/
+  detailsShown: Record<string, boolean> = {};
+  toggleDetails(key: string) {
+    this.detailsShown[key] = !this.detailsShown[key];
+  }
+  /*判断是否展示*/
+  isDetailShown(key: string): boolean {
+    return this.detailsShown[key];
+  }
+  /**
+   * @生成记录评分函数
+   */
+  allData: Record<string, number> = {
+    //搭配方案词典,记录出现次数
+  }
+  ECScore: any[] = [];
+  async getAllData() {
+    //获取所有生成记录,建立词典,记录出现次数
+    let query = new CloudQuery('GenerateResult');
+    let result = await query.find();
+    for (let i = 0; i < result.length; i++) {
+      let jsonData = JSON.parse(result[i]?.get('content'));
+      let code = '';
+      for (let key of ['季节', '功能', '区域风格', '设计理念', '艺术风格']) {
+        code += jsonData[key];
+      }
+      if (this.allData[code]) {
+        this.allData[code]++;
+      }
+      else {
+        this.allData[code] = 1;
+      }
+    }
+    this.allData['total'] = result.length;
+    console.log(this.allData);
+    //获得当前生成记录的代码数量
+    let query_code = '';
+    for (let key of ['季节', '功能', '区域风格', '设计理念', '艺术风格']) {
+      query_code += this.jsonData[key];
+    }
+    const number = this.allData[query_code];
+    //获得比当前生成记录代码数量更小的所有生成记录的数量
+    let count = 0;
+    for (let key in this.allData) {
+      if (this.allData[key] < number) {
+        count += this.allData[key];
+      }
+    }
+    console.log(count)
+    let score = count / this.allData['total'] * 10;
+    return score.toFixed(1);
+  }
+  /*更改评分图标*/
+  getIcon(score: string) {
+    //将score转换为数字
+    let num = Number(score);
+    if (num == 0) {
+      return 'https://s1.imagehub.cc/images/2025/01/11/fc2041e35a146350a7654ed1559f294c.png';
+    }
+    else if (num > 0 && num < 3) {
+      return 'https://s1.imagehub.cc/images/2025/01/11/716566121c19ee91e3acbdda2ba1ca6e.png';
+    }
+    else if (num >= 3 && num < 6) {
+      return 'https://s1.imagehub.cc/images/2025/01/11/0e5e74f3f76cee6364274ac339c15e43.png';
+    }
+    else if (num >= 6 && num < 7.5) {
+      return 'https://s1.imagehub.cc/images/2025/01/11/e8eb352cc826f7e4cfc858cd9a239ab6.png';
+    }
+    else {
+      return 'https://s1.imagehub.cc/images/2025/01/11/773c4fe23c418bc596aa76d993780d70.png';
+    }
+  }
+  /*读取功能评分*/
+  getFunctionScore() {
+    let functionData: Record<string, number> = {}
+    //读取this.allData中的每个key中的第三和第四个字符,组成functionData的key
+    for (let key in this.allData) {
+      let functionKey = key.charAt(2) + key.charAt(3);
+      if (functionData[functionKey]) {
+        functionData[functionKey] += this.allData[key];
+      }
+      else {
+        functionData[functionKey] = this.allData[key];
+      }
+    }
+    //获得比当前生成记录代码数量更小的所有生成记录的数量
+    let count = 0;
+    const funcString = this.jsonData['功能'].charAt(0) + this.jsonData['功能'].charAt(1);
+    const number = functionData[funcString];
+    for (let key in functionData) {
+      if (functionData[key] < number) {
+        count += functionData[key];
+      }
+    }
+    console.log(count)
+    let score = count / functionData['ta'];
+    return score;
+  }
+  /*读取区域风格评分*/
+  async getRegionScore() {
+    let regionData: Record<string, number> = {}
+    let query = new CloudQuery('GenerateResult');
+    let result = await query.find();
+    for (let i = 0; i < result.length; i++) {
+      let jsonData = JSON.parse(result[i]?.get('content'));
+      let regionKey = jsonData['区域风格'];
+      if (regionData[regionKey]) {
+        regionData[regionKey]++;
+      }
+      else {
+        regionData[regionKey] = 1;
+      }
+    }
+    regionData['total'] = result.length;
+    //获得比当前生成记录代码数量更小的所有生成记录的数量
+    let count = 0;
+    const regionString = this.jsonData['区域风格'];
+    const number = regionData[regionString];
+    for (let key in regionData) {
+      if (regionData[key] < number) {
+        count += regionData[key];
+      }
+    }
+    console.log(count)
+    let score = count / regionData['total'];
+    return score;
+  }
+  /*读取设计理念评分*/
+  async getDesignScore() {
+    let designData: Record<string, number> = {}
+    let query = new CloudQuery('GenerateResult');
+    let result = await query.find();
+    for (let i = 0; i < result.length; i++) {
+      let jsonData = JSON.parse(result[i]?.get('content'));
+      let designKey = jsonData['设计理念'];
+      if (designData[designKey]) {
+        designData[designKey]++;
+      }
+      else {
+        designData[designKey] = 1;
+      }
+    }
+    designData['total'] = result.length;
+    //获得比当前生成记录代码数量更小的所有生成记录的数量
+    let count = 0;
+    const designString = this.jsonData['设计理念'];
+    const number = designData[designString];
+    for (let key in designData) {
+      if (designData[key] < number) {
+        count += designData[key];
+      }
+    }
+    console.log(count)
+    let score = count / designData['total'];
+    return score;
+  }
+  /**
+   * @评分动画函数
+   */
+  animatedScore = '0.0'; // 初始评分
+  animationFrame: any; // 动画帧ID
+  startTime: any; // 动画开始时间
+  duration: number = 3000; // 动画总时长,单位为毫秒
+  easeFunction: (t: number) => number = this.easeInOutQuad; // 缓动函数
+
+  startAnimation() {
+    this.startTime = Date.now(); // 记录当前时间
+    this.animationFrame = requestAnimationFrame(() => this.animate());
+  }
+
+  animate() {
+    const currentTime = Date.now() - this.startTime; // 计算当前时间相对于动画开始时间的偏移量
+    const ease = this.easeFunction(currentTime / this.duration); // 计算缓动值
+    const targetScore = parseFloat(this.ECScore[0]); // 将目标评分转换为浮点数
+    const step = (targetScore - parseFloat(this.animatedScore)) / 5; // 计算每帧评分的增量
+    this.animatedScore = (parseFloat(this.animatedScore) + step * ease).toFixed(1); // 更新评分,并保留一位小数
+
+    if (currentTime < this.duration) {
+      // 如果动画未结束,则请求下一帧
+      this.animationFrame = requestAnimationFrame(() => this.animate());
+    } else {
+      // 如果动画结束,则清除动画帧ID
+      cancelAnimationFrame(this.animationFrame);
+      this.animatedScore = this.ECScore[0]; // 确保最终评分与目标评分一致
+    }
+  }
+
+  // 缓动函数示例:easeInOutQuad(先加速后减速)
+  easeInOutQuad(t: number) {
+    return t < 0.5 ? 2 * t * t : -1 + (4 - 2 * t) * t;
+  }
 }

+ 13 - 2
E-Cover-app/src/app/send-post/send-post.component.ts

@@ -1,7 +1,7 @@
 import { CommonModule } from '@angular/common';
 import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
 import { FormsModule } from '@angular/forms';
-import { Router } from '@angular/router';
+import { ActivatedRoute, Router } from '@angular/router';
 import { NavController } from '@ionic/angular';
 import { IonButton, IonButtons, IonCardContent, IonContent, IonFooter, IonHeader, IonIcon, IonImg, IonInfiniteScrollContent, IonInput, IonItem, IonTextarea, IonTitle, IonToolbar, } from '@ionic/angular/standalone';
 import { addIcons } from 'ionicons';
@@ -29,10 +29,12 @@ export class SendPostComponent implements OnInit {
   images: string[] = []; // 存储图片的数组
   tags: any = []; // 存储选中的标签
   isPost: boolean = false; // 帖子发布状态
+  preReceived: any = []; // 预接收的图片和标题数组
   @Input() url: string = "";
   @Output() onUrlChange: EventEmitter<string> = new EventEmitter<string>()
   uploader: HwobsProvider | undefined
   async ngOnInit() {
+    // 初始化上传器对象
     this.uploader = new HwobsProvider({
       bucketName: "nova-cloud",
       prefix: "dev/jxnu/storage/",
@@ -40,10 +42,19 @@ export class SendPostComponent implements OnInit {
       access_key_id: "XSUWJSVMZNHLWFAINRZ1",
       secret_access_key: "P4TyfwfDovVNqz08tI1IXoLWXyEOSTKJRVlsGcV6"
     });
+    //接受来自穿搭分享的路由参数
+    const navigation = this.router.getCurrentNavigation();
+    if (navigation?.extras.state) {
+      this.preReceived[0] = navigation.extras.state['image'];
+      this.preReceived[1] = navigation.extras.state['name'];
+      console.log('接收到的参数:', this.preReceived[0], this.preReceived[1]);
+      this.images.push(this.preReceived[0]);
+      this.title = this.preReceived[1];
+    }
     await this.getTags(); // 获取所有标签
     this.getSixTags(); // 获取六个标签
   }
-  constructor(private router: Router, private navCtrl: NavController) { }
+  constructor(private navCtrl: NavController,private router:Router) {}
   goBack() {
     this.navCtrl.back(); // 返回上一页
   }