7 2 napja
szülő
commit
465138123e

+ 37 - 10
myapp/src/app/tab2/create-request.page.ts

@@ -22,6 +22,7 @@ export class CreateRequestPage {
   };
   
   showTopics = false; // 控制下拉框显示
+    hasDraft= false;
 
   toggleTopics() {
     this.showTopics = !this.showTopics;
@@ -43,7 +44,30 @@ export class CreateRequestPage {
     }
   }
 
-  constructor(private router: Router) {}
+  constructor(private router: Router) {
+    this.loadDraft();
+  }
+
+  async loadDraft() {
+    try {
+      const query = new CloudQuery("Drafts");
+      const drafts = await query.find();
+      if (drafts.length > 0) {
+        const latestDraft = drafts[0];
+        this.request = {
+          title: latestDraft.get('title') || '',
+          description: latestDraft.get('description') || '',
+          type: latestDraft.get('type') || 'normal',
+          points: latestDraft.get('points') || 10,
+          images: latestDraft.get('images') || [],
+          topic: latestDraft.get('topic') || ''
+        };
+        this.hasDraft = true;
+      }
+    } catch (error) {
+      console.error('加载草稿失败:', error);
+    }
+  }
 
   async submitRequest() {
     try {
@@ -75,6 +99,10 @@ export class CreateRequestPage {
 
   async saveDraft() {
     try {
+      // 先清空所有草稿
+      await this.clearAllDrafts();
+      
+      // 保存当前数据为新草稿
       const obj = new CloudObject("Drafts");
       obj.set({
         title: this.request.title,
@@ -102,29 +130,28 @@ export class CreateRequestPage {
         status: 'pending',
         topic: this.request.topic,
         images: this.request.images,
-        time: new Date()  // 添加发布时间字段
+        time: new Date()
       });
       await obj.save();
       
-      // 发布成功后删除草稿
-      await this.deleteDraft();
-      this.router.navigate(['/tabs/tab2']); // 修改为正确的路由路径
+      // 发布成功后删除所有草稿
+      await this.clearAllDrafts();
+      this.router.navigate(['/tabs/tab2']);
     } catch (error) {
       console.error('发布到待领取失败:', error);
     }
   }
 
-  deleteDraft = async () => {
+  async clearAllDrafts() {
     try {
       const query = new CloudQuery("Drafts");
-      query.equalTo("status", "pending"); // 可以根据需要添加查询条件
       const drafts = await query.find();
       
-      if (drafts.length > 0) {
-        await drafts[0].destroy();
+      for (const draft of drafts) {
+        await draft.destroy();
       }
     } catch (error) {
-      console.error('删除草稿失败:', error);
+      console.error('清空草稿失败:', error);
     }
   }
 }

+ 1 - 2
myapp/src/app/tab5/tab5-routing.module.ts

@@ -18,8 +18,7 @@ const routes: Routes = [
   },
   {
     path: 'upload-qualification',
-    loadChildren: () => import('./upload-qualification.page').then(m => m.UploadQualificationPage),
-    canActivate: [AuthGuard]
+    loadComponent: () => import('./upload-qualification.page').then(m => m.UploadQualificationPage)
   }
 ];
 

+ 3 - 1
myapp/src/app/tab5/tab5.module.ts

@@ -7,13 +7,15 @@ import { IonicModule } from '@ionic/angular';
 import { Tab5PageRoutingModule } from './tab5-routing.module';
 
 import { Tab5Page } from './tab5.page';
+import { UploadQualificationPage } from './upload-qualification.page';
 
 @NgModule({
   imports: [
     CommonModule,
     FormsModule,
     IonicModule,
-    Tab5PageRoutingModule
+    Tab5PageRoutingModule,
+    UploadQualificationPage
   ],
   declarations: [Tab5Page]
 })

+ 8 - 0
myapp/src/app/tab5/tab5.page.ts

@@ -44,6 +44,8 @@ export class Tab5Page {
     if (result) {
       this.isLoggedIn = true;
       this.currentUser = result;
+      // 保存sessionToken到本地存储
+      localStorage.setItem('sessionToken', this.user.sessionToken as string);
       this.router.navigate(['/tabs/tab5/user-dashboard']);
     } else {
       alert('登录失败,请检查用户名和密码');
@@ -55,6 +57,8 @@ export class Tab5Page {
     if (success) {
       this.isLoggedIn = false;
       this.currentUser = null;
+      // 清除本地存储的sessionToken
+      localStorage.removeItem('sessionToken');
       alert('登出成功');
     } else {
       alert('登出失败');
@@ -95,4 +99,8 @@ export class Tab5Page {
   cancelEdit() {
     this.editMode = false;
   }
+
+  goToLogout() {
+    this.router.navigate(['/tabs/tab5/logout']);
+  }
 }

+ 1 - 1
myapp/src/app/tab5/user-dashboard.page.html

@@ -11,7 +11,7 @@
         <ion-icon name="chatbubble-ellipses" slot="icon-only"></ion-icon>
       </ion-button>
       <ion-button fill="clear" (click)="logout()">
-        <ion-icon name="settings" slot="icon-only"></ion-icon>
+        <ion-icon name="Exit" slot="icon-only"></ion-icon>
       </ion-button>
     </div>
     <div class="profile-content">

+ 1 - 0
myapp/src/app/tab5/user-dashboard.page.ts

@@ -6,6 +6,7 @@ import { CommonModule } from '@angular/common';
 import { ModalController } from '@ionic/angular'; // 导入 ModalController
 import { EditProfileComponent } from './edit-profile.component'; // 假设编辑资料组件名为 EditProfileComponent
 import { AlertController } from '@ionic/angular';
+import { UploadQualificationPage } from './upload-qualification.page';
 
 @Component({
   selector: 'app-user-dashboard',

+ 3 - 0
myapp/src/lib/ncloud.ts

@@ -101,6 +101,9 @@ export class CloudObject {
 
 // CloudQuery.ts
 export class CloudQuery {
+    descending(arg0: string) {
+        throw new Error('Method not implemented.');
+    }
     static query(arg0: string) {
         throw new Error('Method not implemented.');
     }