|
|
@@ -1,71 +1,89 @@
|
|
|
-import { Component,OnInit } from '@angular/core';
|
|
|
+import { Component, OnInit } from '@angular/core';
|
|
|
import { ExploreContainerComponent } from '../explore-container/explore-container.component';
|
|
|
import { EditRatingStarComponent } from '../edit-rating-star/edit-rating-star.component';
|
|
|
import { IonicModule } from '@ionic/angular';
|
|
|
import { CommonModule } from '@angular/common';
|
|
|
import { FormsModule } from '@angular/forms'; // 导入 FormsModule
|
|
|
import { Router } from '@angular/router';
|
|
|
-import { CloudUser,CloudObject } from 'src/lib/ncloud';
|
|
|
+import { CloudUser, CloudObject, Cloudmy } from 'src/lib/ncloud';
|
|
|
+
|
|
|
@Component({
|
|
|
selector: 'app-review',
|
|
|
templateUrl: './review.component.html',
|
|
|
styleUrls: ['./review.component.scss'],
|
|
|
standalone: true,
|
|
|
- imports: [ExploreContainerComponent,EditRatingStarComponent,IonicModule,CommonModule,FormsModule]
|
|
|
+ imports: [ExploreContainerComponent, EditRatingStarComponent, IonicModule, CommonModule, FormsModule]
|
|
|
})
|
|
|
-export class ReviewComponent implements OnInit {
|
|
|
+export class ReviewComponent implements OnInit {
|
|
|
+ data: any;
|
|
|
userInput: string = '';
|
|
|
-submittedFeedback: string | null = null;
|
|
|
-currentScore: number = 0; // 初始分值
|
|
|
+ submittedFeedback: string | null = null;
|
|
|
+ currentScore: number = 0; // 初始分值
|
|
|
|
|
|
-handleScoreChange(newScore: number) {
|
|
|
- this.currentScore = newScore;
|
|
|
- console.log('新分值:', newScore); // 处理分值变化
|
|
|
-}
|
|
|
+ handleScoreChange(newScore: number) {
|
|
|
+ this.currentScore = newScore;
|
|
|
+ console.log('新分值:', newScore); // 处理分值变化
|
|
|
+ }
|
|
|
|
|
|
-submitFeedback() {
|
|
|
- this.submittedFeedback = this.userInput;
|
|
|
- console.log(this.userInput); // 打印输入框的数据
|
|
|
-
|
|
|
- let consult = new CloudObject("Review");
|
|
|
- // 设置聊天记录的基本信息
|
|
|
- let now = new Date();
|
|
|
- let currentUser = new CloudUser();
|
|
|
- let dateStr = `${now.getFullYear()}-${now.getMonth() + 1}-${now.getDate()}`;
|
|
|
-
|
|
|
- // 对象权限的精确制定
|
|
|
- let ACL: any = {
|
|
|
- "*": { read: true, write: true }
|
|
|
- };
|
|
|
+ async submitFeedback() { // 将此方法声明为 async
|
|
|
+ this.submittedFeedback = this.userInput;
|
|
|
+ console.log(this.userInput); // 打印输入框的数据
|
|
|
|
|
|
- consult.set({
|
|
|
- user: currentUser.toPointer(),
|
|
|
- feedbackContent: this.userInput,
|
|
|
- createdAt: dateStr, // 可以加上创建时间
|
|
|
- star: this.currentScore,
|
|
|
+ let currentUser = new CloudUser();
|
|
|
+ const userId = currentUser.toPointer();
|
|
|
|
|
|
+ // 查询 User 表
|
|
|
+ const quer = new Cloudmy('_User');
|
|
|
+ quer.equalTo('objectId', userId);
|
|
|
|
|
|
- // ACL: ACL
|
|
|
- });
|
|
|
+ try {
|
|
|
+ const latestuser = await quer.first(); // 等待 Promise 解析
|
|
|
|
|
|
- // 调用 save 方法来保存数据
|
|
|
- consult.save().then(() => {
|
|
|
- console.log('反馈保存成功');
|
|
|
- this.userInput = ''; // 清空输入框
|
|
|
- this.router.navigate(['/tabs/review-display']); // 跳转到显示页面
|
|
|
- }).catch((error) => {
|
|
|
- console.error('保存反馈时出错:', error);
|
|
|
- });
|
|
|
+ if (latestuser && latestuser.username) {
|
|
|
+ this.data = latestuser.username;
|
|
|
+ console.log('用户:', this.data);
|
|
|
+ } else {
|
|
|
+ console.log('没有找到 用户');
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ console.error('查询_User时出错:', error);
|
|
|
+ }
|
|
|
|
|
|
- this.userInput = ''; // 清空输入框
|
|
|
- this.router.navigate(['/tabs/review-display']);
|
|
|
-}
|
|
|
+ let consult = new CloudObject("Review");
|
|
|
+ // 设置聊天记录的基本信息
|
|
|
+ let now = new Date();
|
|
|
+ let dateStr = `${now.getFullYear()}-${now.getMonth() + 1}-${now.getDate()}`;
|
|
|
|
|
|
+ // 对象权限的精确制定
|
|
|
+ let ACL: any = {
|
|
|
+ "*": { read: true, write: true }
|
|
|
+ };
|
|
|
|
|
|
+ consult.set({
|
|
|
+ user: currentUser.toPointer(),
|
|
|
+ feedbackContent: this.userInput,
|
|
|
+ createdAt: dateStr, // 可以加上创建时间
|
|
|
+ star: this.currentScore,
|
|
|
+ username:this.data,
|
|
|
+ // ACL: ACL
|
|
|
+ });
|
|
|
|
|
|
- ngOnInit() {}
|
|
|
+ // 调用 save 方法来保存数据
|
|
|
+ consult.save().then(() => {
|
|
|
+ console.log('反馈保存成功');
|
|
|
+ this.userInput = ''; // 清空输入框
|
|
|
+ this.router.navigate(['/tabs/review-display']); // 跳转到显示页面
|
|
|
+ }).catch((error) => {
|
|
|
+ console.error('保存反馈时出错:', error);
|
|
|
+ });
|
|
|
|
|
|
- constructor(private router: Router) {}
|
|
|
+ this.userInput = ''; // 清空输入框
|
|
|
+ this.router.navigate(['/tabs/review-display']);
|
|
|
+ }
|
|
|
|
|
|
+ ngOnInit() {
|
|
|
+ // 初始化逻辑
|
|
|
+ }
|
|
|
|
|
|
-}
|
|
|
+ constructor(private router: Router) {}
|
|
|
+}
|