Browse Source

add:edit

yi 1 year ago
parent
commit
4ac85cc7f1

+ 86 - 31
FilmDraw-app/src/app/tab4/tab4.page.html

@@ -6,36 +6,91 @@
   
 <ion-content [fullscreen]="true">
 
-<!-- 用户信息区 -->
-<section>
-  <!-- 用户登录状态 -->
-  <ion-card>
+
     <!-- 未登录 -->
-     @if(!currentUser?.id){
-       <ion-card-header>
-         <ion-card-title>请登录</ion-card-title>
-         <ion-card-subtitle>暂无信息</ion-card-subtitle>
-        </ion-card-header>
-      }
-        <!-- 已登录 -->
-     @if(currentUser?.id){
-      <ion-card-header>
-        <ion-card-title>{{currentUser?.get("username")}} {{currentUser?.get("realname")}}</ion-card-title>
-        <ion-card-subtitle>性别:{{currentUser?.get("gender")||"-"}} 年龄:{{currentUser?.get("age")||"-"}}</ion-card-subtitle>
-      </ion-card-header>
-      }
-      <ion-card-content>
-      @if(!currentUser?.id){
-        <ion-button expand="block" (click)="signup()">注册</ion-button>
-        <ion-button expand="block" (click)="login()">登录</ion-button>
-      }
-     @if(currentUser?.id){
-      <ion-button expand="block" (click)="editUser()">编辑资料</ion-button>
-      <ion-button expand="block" (click)="logout()" color="light">登出</ion-button>
+    @if(!currentUser?.id){
+      <div class="profile-container1">
+        <div class="avatar-container">
+          <ion-avatar class="avatar">
+            <img [src]="avatarUrl" alt="avatar">
+          </ion-avatar>
+          <div class="user-info">
+              <ion-label class="username"><a (click)="login()">登录</a><a>/</a><a (click)="signup()">注册</a></ion-label>
+          </div>
+        
+        </div>
+        <ion-label class="bio">个人简介: '请登录后查看' </ion-label>
+        
+      </div>
     }
-    </ion-card-content>
-  </ion-card>
-</section>
-  
-</ion-content>
-  
+
+<!-- 已登录 -->
+@if(currentUser?.id){
+    <div class="profile-container">
+      <div class="avatar-container">
+        <ion-avatar class="avatar">
+          <img [src]="currentUser?.get('avatar')" alt="avatar">
+        </ion-avatar>
+        <div class="user-info">
+          <ion-label class="username">{{ currentUser?.get("username") }}</ion-label>
+          </div>
+
+      </div>
+                <ion-label class="bio">性别:{{ currentUser?.get("gender") || '-' }}  年龄:{{ currentUser?.get("age") || '-' }}</ion-label>
+                <ion-label class="bio">个人简介:{{ currentUser?.get("bio") || '暂无简介' }}</ion-label>
+                <ion-label class="edit" (click)="editUser()" >点击这里编辑资料</ion-label>
+          <ion-button class="button" (click)="logout()">退出登录</ion-button>
+
+    </div>
+  } 
+    <div class="settings-container">
+      <ion-row>
+        <ion-col>
+          <ion-item>
+            <ion-label>历史记录</ion-label>
+            <ion-icon name="footsteps-outline" slot="end"></ion-icon>
+          </ion-item>
+        </ion-col>
+      </ion-row>
+      <ion-row>
+        <ion-col>
+          <ion-item>
+            <ion-icon name="bookmark-outline" slot="end"></ion-icon>
+          <ion-label>收藏</ion-label>
+        </ion-item>
+        </ion-col>
+      </ion-row>
+      <ion-row>
+        <ion-col>
+          <ion-item>
+            <ion-label>隐私与安全设置</ion-label>
+            <ion-icon name="lock-closed-outline" slot="end"></ion-icon>
+          </ion-item>
+        </ion-col>
+      </ion-row>
+      <ion-row>
+        <ion-col>
+          <ion-item>
+            <ion-label>个性化偏好设置</ion-label>
+            <ion-icon name="settings" slot="end"></ion-icon>
+          </ion-item>
+        </ion-col>
+      </ion-row>
+      <ion-row>
+        <ion-col>
+          <ion-item>
+            <ion-label>通知与消息管理</ion-label>
+            <ion-icon slot="end" name="notifications-outline"></ion-icon>
+          </ion-item>
+        </ion-col>
+      </ion-row>
+      <ion-row>
+        <ion-col>
+          <ion-item>
+            <ion-label>设置与帮助</ion-label>
+            <ion-icon name="help-circle" slot="end"></ion-icon>
+          </ion-item>
+        </ion-col>
+      </ion-row>
+    </div>
+  </ion-content>

+ 145 - 133
FilmDraw-app/src/app/tab4/tab4.page.scss

@@ -1,136 +1,148 @@
-ion-title {
-    flex: 1; // 使标题占据可用空间
-    text-align: left; // 确保文字左对齐
-    margin-left: 16px; // 左侧边距,可以根据需要调整
-    margin-top: 5px;
+  /* 全局样式 */
+  body {
+    font-family: Arial, sans-serif;
+    margin: 0;
+    padding: 0;
+    background-color: #f4f4f4;
   }
+ 
+  ion-content {
+    padding: 20px;
+  }
+ 
+  /* 个人中心模块样式 */
+  .profile-container1 {
+    background: rgba(232, 223, 223, 0.8);
+    backdrop-filter: blur(10px);/* 模糊背景 */
+    border-radius: 10px;
+    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
+    width: 100%;
+    max-width: 400px;
+    margin: 0 auto;
+    margin-bottom: 20px;
+    overflow: hidden;
+    position: relative;
+    height: calc(1/5 * 100vh); /* 大致占据页面长的1/5 */
+    display: flex;
+    flex-direction: column;
+    justify-content: space-between;
+  }
+
+
+
+  .profile-container {
+    background:rgb(248, 204, 204, 0.8);
+    backdrop-filter: blur(10px);/* 模糊背景 */
+    border-radius: 10px;
+    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
+    width: 100%;
+    max-width: 400px;
+    margin: 0 auto;
+    margin-bottom: 20px;
+    overflow: hidden;
+    position: relative;
+    height: calc(1/3 * 100vh); /* 大致占据页面长的1/3 */
+    display: flex;
+    flex-direction: column;
+    justify-content: space-between;
+  }
+ 
+
+  .avatar-container {
+    display: flex;
+    align-items: center;
+    padding: 15px;
+  }
+ 
+  .avatar {
+    width: 80px;
+    height: 80px;
+    border-radius: 50%;
+    overflow: hidden;
+    margin-right: 15px;
+  }
+ 
+  .avatar img {
+    width: 100%;
+    height: 100%;
+    object-fit: cover;
+  }
+ 
+  .user-info {
+    flex-grow: 1;
+  }
+ 
+  .username {
+    font-size: 20px;
+    font-weight: bold;
+    text-decoration: none;
+    color: #000000;
+  }
+ 
+  .bio {
+    padding-left: 15px;
+    padding-top: 10px;
+    font-size: 16px;
+    color: #4c4a4a;
+  }
+ 
+  .button {
+    background:#036a99!important;
+    text-transform: uppercase;
+    font-size: 15px;
+    font-weight: bold;
+    margin-left: 30%;
+    margin-right: 30%;
+    margin-bottom: 5px;
+    align-items: center;
+  }
+
+ .edit{
+  padding-left: 15px;
+  padding-top: 10px;
+  font-size: 16px;
+  color: #555050;
+  align-items: center;
+}
 
-  ion-header {
-    background-color: #007aff; // 设置头部背景色为鲜艳的蓝色
-    color: white; // 设置头部文字颜色
-  }
-  
-  ion-card {
-    margin: 10px; // 设置卡片之间的间距
-    border-radius: 15px; // 设置卡片圆角
-    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2); // 添加更明显的阴影效果
-    transition: transform 0.2s; // 添加过渡效果
-  }
-  
-  ion-card:hover {
-    transform: scale(1.02); // 鼠标悬停时放大卡片
-  }
-  
-  ion-card-header {
-    background-color: #e3f2fd; // 设置卡片头部背景色为浅蓝色
-  }
-  
-  ion-card-title {
-    font-size: 1.5em; // 设置卡片标题字体大小
-    font-weight: bold; // 设置卡片标题字体加粗
-    color: #0d47a1; // 设置标题颜色为深蓝色
-  }
-  
+ 
+ 
+  /* 设置与帮助等模块样式 */
+  .settings-container {
+    display: flex;
+    flex-direction: column;
+    gap: 10px;
+  }
+ 
+  ion-row {
+    display: flex;
+    justify-content: center;
+    padding: 5px 0;
+  }
+ 
+  ion-col {
+    flex: 1;
+    max-width: 400px;
+  }
+ 
   ion-item {
-    --ion-item-background: transparent; // 设置列表项背景透明
-  }
-  
-  ion-avatar {
-    border-radius: 50%; // 设置头像圆形
-    width: 60px; // 设置头像宽度
-    height: 60px; // 设置头像高度
-    border: 2px solid #007aff; // 添加边框
-  }
-  
-  h2 {
-    font-size: 1.2em; // 设置二级标题字体大小
-    margin: 0; // 去掉默认外边距
-    color: #1976d2; // 设置标题颜色为蓝色
-  }
-  
-  p {
-    font-size: 0.9em; // 设置段落字体大小
-    color: #555; // 设置段落文字颜色
-  }
-  
-  ion-thumbnail {
-    width: 100px; // 设置封面图宽度
-    height: 150px; // 设置封面图高度
-    border-radius: 10px; // 设置封面图圆角
-  }
-  
-  ion-button {
-    --background: #007aff; // 设置按钮背景色为鲜艳的蓝色
-    --color: white; // 设置按钮文字颜色
-    border-radius: 20px; // 设置按钮圆角
-    margin-left: 10px; // 设置按钮左边距
-    font-weight: bold; // 设置按钮文字加粗
-  }
-  
-  ion-list {
-    padding: 0; // 去掉列表内边距
-  }
-  ion-avatar {
-    width: 50px; /* 或者你需要的任何尺寸 */
-     height: 50px; /* 保持宽高一致,避免变形 */
-    }
-    
-    ion-avatar img {
-     width: 100%; /* 让图片填满avatar */
-    height: auto; /* 保持图片比例 */
-    }
-    
-    ion-header {
-      background: #f8f9fa; // 设置头部背景色
-     
-    }
-    
-      ion-item{
-        border-radius: 8px; // 设置列表项圆角
-        margin: 5px 0; // 添加列表项的上下外边距
-      }
-  
-    ion-content{
-       background: #f8f9fa; // 设置背景色
-    }
-        
-    ion-col {
-      text-align: center;   /* 确保列内的内容居中(但这里可能由 .ion-text-center 类已经处理) */
-      .avatar-container {
-        display: flex;
-        flex-direction: column; /* 垂直排列子元素 */
-        align-items: center;    /* 垂直居中容器内的内容(对于图像来说可能不是必需的,但对于整体布局有帮助) */
-        margin-top: 20px;       /* 可选:为容器添加一些顶部间距 */
-  
-        ion-avatar {
-          width: 100px;         /* 设置头像的宽度 */
-          height: 100px;        /* 设置头像的高度,与宽度相同以实现圆形 */
-          border-radius: 50%;   /* 将头像设置为圆形 */
-          overflow: hidden;     /* 确保图像不会溢出圆形框架 */
-  
-          img {
-            width: 100%;        /* 让图像填满头像容器 */
-            height: auto; /* 保持图片比例 */
-            object-fit: cover;  /* 确保图像内容适应圆形框架,而不失真 */
-          }
-       }  
-  
-    .username {
-      font-size: 40px;
-      font-weight: bold;
-      margin-top: 10px;
-    }
-       
-      }
-  }
-      ion-col {
-        ion-item {
-          background-color: #ffffff;
-          margin: 2px 0;
-          padding: 2px;
-          box-shadow: 0 1px 5px rgba(0, 0, 0, 0.1);
-          text-align: left;
-          font-size: 15px;
-          width: 100%;
-        }
-      }
+    background: rgba(255, 255, 255, 0.8);
+    backdrop-filter: blur(5px);
+    border-radius: 5px;
+    padding: 5px;
+    display: flex;
+    align-items: center;
+    justify-content: space-between;
+    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
+  }
+ 
+  ion-label {
+    flex-grow: 1;
+    font-size: 18px;
+    color: #333;
+  }
+ 
+  ion-icon {
+    font-size: 24px;
+    color: #37608a;
+  }

+ 25 - 4
FilmDraw-app/src/app/tab4/tab4.page.ts

@@ -1,21 +1,41 @@
 import { Component } from '@angular/core';
-import { IonHeader, IonToolbar, IonTitle, IonContent, IonCard, IonCardContent, IonButton, IonCardHeader, IonCardTitle, IonCardSubtitle, ModalController } from '@ionic/angular/standalone';
+import { 
+  IonAvatar,IonHeader ,IonButton,IonCol,IonContent,
+  IonItem,IonLabel,IonRow,IonTitle,IonToolbar,ModalController,
+  IonIcon
+   , } from '@ionic/angular/standalone';
 import { CloudUser } from 'src/lib/ncloud';
 import { openUserLoginModal } from 'src/lib/user/modal-user-login/modal-user-login.component';
 
+import { addIcons } from 'ionicons';
+import { bookmarkOutline, footstepsOutline, helpCircle, lockClosedOutline, notificationsOutline, settings } from 'ionicons/icons';
+import { openUserEditModal } from 'src/lib/user/modal-user-edit/modal-user-edit.component';
+
+
+
+
 @Component({
   selector: 'app-tab4',
   templateUrl: 'tab4.page.html',
   styleUrls: ['tab4.page.scss'],
   standalone: true,
-  imports: [IonHeader, IonToolbar, IonTitle, IonContent, 
-    IonCard,IonCardContent,IonButton,IonCardHeader,IonCardTitle,IonCardSubtitle
+  imports: [  
+      IonHeader,IonToolbar,IonTitle,IonContent,IonAvatar,IonLabel,IonButton,IonRow,IonCol,
+      IonItem,IonIcon,
   ],
 })
 export class Tab4Page {
+  userInfo: any = {
+    username: 'yi',
+    // 其他用户信息字段...
+  };
+  avatarUrl: string = 'assets/img/tx.jpg'; // 默认头像路径
+ 
   currentUser:CloudUser|undefined
   constructor(private modalCtrl:ModalController) {
     this.currentUser = new CloudUser();
+    addIcons({helpCircle,notificationsOutline,settings,lockClosedOutline,bookmarkOutline,footstepsOutline});
+  
   }
   async login(){
     // 弹出登录窗口
@@ -36,7 +56,8 @@ export class Tab4Page {
   }
 
   editUser(){
-
+    //弹出编辑窗口
+  openUserEditModal(this.modalCtrl);
   }
 
 }

+ 62 - 16
FilmDraw-app/src/lib/ncloud.ts

@@ -220,23 +220,25 @@ export class CloudUser extends CloudObject {
             console.error("用户未登录");
             return null; // 如果未登录,返回 null
         }
+        return this;
         
-        // 发送 GET 请求以获取当前用户信息
-        const response = await fetch(`http://dev.fmode.cn:1337/parse/users/me`, {
-            headers: {
-                "x-parse-application-id": "dev",
-                "x-parse-session-token": this.sessionToken // 使用 sessionToken 进行身份验证
-            },
-            method: "GET"
-        });
-
-        const result = await response?.json(); // 解析响应
-        if (result?.error) {
-            console.error(result?.error); // 处理错误
-            return null;
-        }
-        return result; // 返回用户信息
-    }
+    //     // 发送 GET 请求以获取当前用户信息
+    //     const response = await fetch(`http://dev.fmode.cn:1337/parse/users/me`, {
+    //         headers: {
+    //             "x-parse-application-id": "dev",
+    //             "x-parse-session-token": this.sessionToken // 使用 sessionToken 进行身份验证
+    //         },
+    //         method: "GET"
+    //     });
+
+    //     const result = await response?.json(); // 解析响应
+    //     if (result?.error) {
+    //         console.error(result?.error); // 处理错误
+    //         return null;
+    //     }
+    //     return result; // 返回用户信息
+    
+     }
 
     /** 登录 */
     async login(username: string, password: string): Promise<CloudUser | null> {
@@ -329,4 +331,48 @@ export class CloudUser extends CloudObject {
         this.data = result; // 保存用户数据
         return this; // 返回当前用户实例
     }
+
+    //覆盖save方法
+    override async save() {
+        let method = "POST";
+        let url = `http://dev.fmode.cn:1337/parse/users`;
+    
+        // 更新用户信息
+        if (this.id) {
+            url += `/${this.id}`;
+            method = "PUT";
+        }
+    
+        let data:any = JSON.parse(JSON.stringify(this.data))
+        delete data.createdAt
+        delete data.updatedAt
+        delete data.ACL
+        delete data.objectId
+        const body = JSON.stringify(data);
+        let headersOptions:any = {
+            "content-type": "application/json;charset=UTF-8",
+            "x-parse-application-id": "dev",
+            "x-parse-session-token": this.sessionToken, // 添加sessionToken以进行身份验证
+        }
+        const response = await fetch(url, {
+            headers: headersOptions,
+            body: body,
+            method: method,
+            mode: "cors",
+            credentials: "omit"
+        });
+    
+        const result = await response?.json();
+        if (result?.error) {
+            console.error(result?.error);
+        }
+        if (result?.objectId) {
+            this.id = result?.objectId;
+        }
+        localStorage.setItem("NCloud/dev/User",JSON.stringify(this.data))
+        return this;
+    }
+
+
+
 }

+ 32 - 0
FilmDraw-app/src/lib/user/modal-user-edit/modal-user-edit.component.html

@@ -0,0 +1,32 @@
+<!-- 用户登录状态 -->
+<ion-card>
+  <ion-card-header>
+    <ion-card-title>
+      账号:{{currentUser?.get("username")}}
+    </ion-card-title>
+    <ion-card-subtitle>请输入您的详细资料</ion-card-subtitle>
+   </ion-card-header>
+ <ion-card-content>
+
+   <ion-item>
+     <ion-input [value]="userData['realname']" (ionChange)="userDataChange('realname',$event)" label="姓名" placeholder="请您输入真实姓名"></ion-input>
+   </ion-item>
+   <ion-item>
+     <ion-input type="number" [value]="userData['age']" (ionChange)="userDataChange('age',$event)" label="年龄" placeholder="请您输入年龄"></ion-input>
+    </ion-item>
+  <ion-item>
+     <ion-input [value]="userData['gender']" (ionChange)="userDataChange('gender',$event)" label="性别" placeholder="请您输入男/女"></ion-input>
+    </ion-item>
+    <ion-item>
+      <ion-input [value]="userData['email']" (ionChange)="userDataChange('email',$event)" label="邮箱" placeholder="请输入邮箱"></ion-input>
+     </ion-item>
+     <ion-item>
+      <ion-input [value]="userData['bio']" (ionChange)="userDataChange('dio',$event)" label="个人简介" placeholder="个人简介"></ion-input>
+     </ion-item>
+
+   <ion-button expand="block" (click)="save()">保存</ion-button>
+   <ion-button expand="block" (click)="cancel()">取消</ion-button>
+ 
+
+</ion-card-content>
+</ion-card>

+ 0 - 0
FilmDraw-app/src/lib/user/modal-user-edit/modal-user-edit.component.scss


+ 22 - 0
FilmDraw-app/src/lib/user/modal-user-edit/modal-user-edit.component.spec.ts

@@ -0,0 +1,22 @@
+import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
+
+import { ModalUserEditComponent } from './modal-user-edit.component';
+
+describe('ModalUserEditComponent', () => {
+  let component: ModalUserEditComponent;
+  let fixture: ComponentFixture<ModalUserEditComponent>;
+
+  beforeEach(waitForAsync(() => {
+    TestBed.configureTestingModule({
+      imports: [ModalUserEditComponent],
+    }).compileComponents();
+
+    fixture = TestBed.createComponent(ModalUserEditComponent);
+    component = fixture.componentInstance;
+    fixture.detectChanges();
+  }));
+
+  it('should create', () => {
+    expect(component).toBeTruthy();
+  });
+});

+ 65 - 0
FilmDraw-app/src/lib/user/modal-user-edit/modal-user-edit.component.ts

@@ -0,0 +1,65 @@
+import {  OnInit } from '@angular/core';
+import { Component } from '@angular/core';
+import { IonHeader, IonToolbar, IonTitle, IonContent, IonCard, IonCardContent, IonButton, IonCardHeader, IonCardTitle, IonCardSubtitle, ModalController, IonInput, IonItem, IonSegment, IonSegmentButton, IonLabel } from '@ionic/angular/standalone';
+import { CloudUser } from 'src/lib/ncloud';
+
+@Component({
+  selector: 'app-modal-user-edit',
+  templateUrl: './modal-user-edit.component.html',
+  styleUrls: ['./modal-user-edit.component.scss'],
+  standalone: true,
+  imports: [IonHeader, IonToolbar, IonTitle, IonContent, 
+    IonCard,IonCardContent,IonButton,IonCardHeader,IonCardTitle,IonCardSubtitle,
+    IonInput,IonItem,
+    IonSegment,IonSegmentButton,IonLabel
+  ],
+})
+export class ModalUserEditComponent  implements OnInit {
+
+  currentUser:CloudUser|undefined
+  userData:any = {}
+  userDataChange(key:string,ev:any){
+    let value = ev?.detail?.value
+    if(value){
+      this.userData[key] = value
+    }
+  }
+  constructor(private modalCtrl:ModalController) { 
+    this.currentUser = new CloudUser();
+    this.userData = this.currentUser.data;
+  }
+
+  ngOnInit() {}
+
+  async save(){
+    Object.keys(this.userData).forEach(key=>{
+      if(key=="age"){
+        this.userData[key] = Number(this.userData[key])
+      }
+    })
+
+    this.currentUser?.set(this.userData)
+    await this.currentUser?.save()
+    this.modalCtrl.dismiss(this.currentUser,"confirm")
+  }
+  cancel(){
+    this.modalCtrl.dismiss(null,"cancel")
+
+  }
+}
+
+export async function openUserEditModal(modalCtrl:ModalController):Promise<CloudUser|null>{
+  const modal = await modalCtrl.create({
+    component: ModalUserEditComponent,
+    breakpoints:[0.7,1.0],
+    initialBreakpoint:0.7
+  });
+  modal.present();
+
+  const { data, role } = await modal.onWillDismiss();
+
+  if (role === 'confirm') {
+    return data;
+  }
+  return null
+}