0225172 4 mesi fa
parent
commit
d34ebb2dc3

+ 2 - 2
src/app/contact/contact.page.html

@@ -21,9 +21,9 @@
         <ion-card class="out-card" *ngFor="let area of LvYouAreaList">
           <ion-icon name="add-circle" class="add-icon"></ion-icon>
           <!-- <h2>{{ card.title }}</h2> -->
-           <h2>{{area?.get('name')}}</h2>
+           <h2>{{area.get('name')}}</h2>
           <ion-card class="inner-card">
-            {{ area?.get('message') }}
+            {{ area.get('message') }}
           </ion-card>
         </ion-card>
       </ion-list>

+ 12 - 4
src/app/tab3/tab3.page.html

@@ -85,10 +85,18 @@
       </div>
     </ion-card>
   
-    <ion-card  *ngIf="currentTab === 'published'">
-      <img src="https://gd-hbimg.huaban.com/068da346d1fbca8edd952fb7e77b0eb0468ac03512a0f-Rm3mAD_fw658webp" class="img-center" style="width: 300px; height: 300px;">
-      <ion-card class="center-text">暂无内容</ion-card>
-    </ion-card>
+    <ion-item  *ngIf="currentTab === 'published'" >
+      <ion-card *ngFor="let CreatContent of InputContentsList" class="custom-card">
+        <img *ngIf="!hasData"  src="https://gd-hbimg.huaban.com/068da346d1fbca8edd952fb7e77b0eb0468ac03512a0f-Rm3mAD_fw658webp" class="img-center" style="width: 300px; height: 300px;">
+        <div class="center-text" *ngIf="!hasData">暂无内容</div>
+        <ion-card-header class="custom-header">
+         {{CreatContent.get("title")}}
+        </ion-card-header>
+        <ion-card-content class="custom-content">
+          {{CreatContent.get("contents")}}
+        </ion-card-content>
+      </ion-card>    
+    </ion-item>
   
     <div *ngIf="currentTab === 'liked'">
       <div class="center-text">

+ 16 - 1
src/app/tab3/tab3.page.scss

@@ -85,5 +85,20 @@
   padding: 10px 0; /* 设置底部容器内边距 */
 }
 
- 
+.custom-card {
+  width: 800px;
+  height: 200px;
+  border-radius: 8px;
+  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
+}
+
+.custom-header {
+  width: 100px;
+  font-size: 18px;
+  font-weight: bold;
+}
+
+.custom-content {
+  font-size: 14px;
+}
 

+ 42 - 24
src/app/tab3/tab3.page.ts

@@ -10,20 +10,39 @@ Parse.serverURL = "http://web2023.fmode.cn:9999/parse"; // 设置serverURL
   styleUrls: ['tab3.page.scss']
 })
 export class Tab3Page implements OnInit{
+  //数据定义
+  hasData: boolean = false;
+  currentTab: string = 'unpublished';
+  userImage: string = 'https://via.placeholder.com/150'; // 默认图片地址
+    // 由于Parse.User.current()是随着localStorage变化的属性
+  // 为了避免首次复制后用户状态变化,页面不同步,通过get方法实现实时获取
+  user:Parse.User|undefined
+
+  async ngOnInit() {
+      this.user = await Parse.User.current()
+      setInterval(async ()=>{
+      this.user = await Parse.User.current()
+    },1000)
+    this.loadCreatContentsDate()
+  }
+  logout(){
+    Parse.User.logOut();
+  }
 
+
+  constructor(private router: Router) {  this.checkData();}
+
+  
   cards = [
     { title: '我的订单', content: '查看全部', icon: 'document-text-outline' },
     { title: '积分中心', content: '答题赢积分', icon: 'trophy-outline' },
     { title: '我的勋章', content: '2枚勋章', icon: 'medal-outline' }
   ];
 
- 
-  currentTab: string = 'unpublished';
-  userImage: string = 'https://via.placeholder.com/150'; // 默认图片地址
-
+  
   onFileSelected(event: Event) {
     const inputElement = event.target as HTMLInputElement;
-   if (inputElement.files && inputElement.files.length > 0) {
+    if (inputElement.files && inputElement.files.length > 0) {
     const file = inputElement.files[0];
     const reader = new FileReader();
     reader.onload = () => {
@@ -32,39 +51,38 @@ export class Tab3Page implements OnInit{
       }
     };
     reader.readAsDataURL(file);
+    }
   }
 
-  }
 
-  // 由于Parse.User.current()是随着localStorage变化的属性
-  // 为了避免首次复制后用户状态变化,页面不同步,通过get方法实现实时获取
-  user:Parse.User|undefined
-  async ngOnInit() {
-      this.user = await Parse.User.current()
-      setInterval(async ()=>{
-      this.user = await Parse.User.current()
-    },1000)
-    this.loadPets()
-  }
-  logout(){
-    Parse.User.logOut();
-  }
-  constructor(private router: Router) {}
+  //跳转到新页面
   GoToLoginPage(){
     this.router.navigate(['/user/login'])
   }
- //跳转到新页面
  navigateToCreatePage() {
   this.router.navigate(['/tab3/tab3-create']);
   }
 
    
-    
-      
+    //数据库CreatContents中数据调入前端页面
     InputContentsList:Array<Parse.Object> = []
-    async loadPets(){
+    async loadCreatContentsDate(){
     let query = new Parse.Query("CreatContents");
     let list = await query.find();
     this.InputContentsList = list
     }
+
+
+    //查询数据库中是否有CreatContents的数据
+    async checkData() {
+      const CreatContents = Parse.Object.extend("CreatContents");
+      const query = new Parse.Query(CreatContents);
+      const results = await query.find();
+  
+      if (results.length > 0) {
+        this.hasData = true;
+      } else {
+        this.hasData = false;
+      }
+    }
 }

+ 11 - 32
src/modules/page/tab3-create/tab3-create.page.ts

@@ -2,8 +2,7 @@ import { Component, OnInit } from '@angular/core';
 import { Router } from '@angular/router';
 import { ToastController } from '@ionic/angular';
 import Parse from "parse";
-Parse.initialize("dev"); // 设置applicationId
-Parse.serverURL = "http://web2023.fmode.cn:9999/parse"; // 设置
+
 @Component({
   selector: 'app-tab3-create',
   templateUrl: './tab3-create.page.html',
@@ -20,9 +19,7 @@ export class Tab3CreatePage implements OnInit {
     this.presentToast('草稿已保存');
   }
 
-  publish() {
-    this.presentToast('内容已发布');
-  }
+
 
   async presentToast(message: string) {
     const toast = await this.toastController.create({
@@ -36,33 +33,15 @@ export class Tab3CreatePage implements OnInit {
   ngOnInit(){
 
   }
-  title: string="";
-  contents: string="";
-  async register(){
-    let user = new Parse.User()
-    user.set("title",this.title)
-    user.set("contents",this.contents)
-    try {
-      let result = await user.signUp();
+  title: string = "";
+  contents: string = "";
+  async publish(){
+    this.presentToast('内容已发布');
+    let InputContentsList =  new Parse.Object("CreatContents");
+    InputContentsList.set("title",this.title)
+    InputContentsList.set("contents",this.contents)
+    
+      let result = await InputContentsList.save();
       console.log(result)
-      // if(result?.id){
-      //   this.navCtrl.back()
-      // }
-      // Hooray! Let them use the app now.
-  } catch (error:any) {
-      // 新增提示词详情,根据Parse.User.signUp方法返回的不同英文提示词,增加对应的中文内容转换
-      // let message:string = ""
-      // if(error?.message.indexOf("already exists")>-1){
-      //   message = "该账号已存在请修改后重试"
-      // }
-      // if(error?.message.indexOf("empty")>-1){
-      //   message = "账号不能为空请输入后重试"
-      // }
-      // this.presentAlert({
-      //   header:"注册失败",
-      //   subHeader:"状态码:"+error.code,
-      //   message:message || error.message
-      // })
-    }
   }
 }