|
@@ -0,0 +1,105 @@
|
|
|
+import { CommonModule } from '@angular/common';
|
|
|
+import { Component, OnInit } from '@angular/core';
|
|
|
+import { FormsModule } from '@angular/forms';
|
|
|
+import { Router } from '@angular/router';
|
|
|
+import { NavController } from '@ionic/angular';
|
|
|
+import { IonButton, IonButtons, IonContent, IonFooter, IonHeader, IonIcon, IonInput, IonItem, IonTextarea, IonTitle, IonToolbar, } from '@ionic/angular/standalone';
|
|
|
+import { addIcons } from 'ionicons';
|
|
|
+import { atOutline, chevronBackSharp, closeOutline, happyOutline, imageOutline } from 'ionicons/icons';
|
|
|
+import { CloudObject, CloudUser } from 'src/lib/ncloud';
|
|
|
+
|
|
|
+addIcons({chevronBackSharp,imageOutline,atOutline,happyOutline,closeOutline });
|
|
|
+@Component({
|
|
|
+ selector: 'app-send-post',
|
|
|
+ templateUrl: './send-post.component.html',
|
|
|
+ styleUrls: ['./send-post.component.scss'],
|
|
|
+ standalone: true,
|
|
|
+ imports: [IonHeader,IonToolbar,IonTitle,IonContent,IonItem,
|
|
|
+ IonButton,IonIcon,IonButtons,IonInput,IonFooter,CommonModule,FormsModule,IonTextarea,],
|
|
|
+})
|
|
|
+export class SendPostComponent implements OnInit {
|
|
|
+ inputText: string = '';
|
|
|
+ title: string = '';
|
|
|
+ showLocationTag: boolean = true;
|
|
|
+ remainingChars: number = 20;
|
|
|
+ images: string[] = [];
|
|
|
+ tags: string[] = [];
|
|
|
+ ngOnInit() {}
|
|
|
+
|
|
|
+ constructor(private router: Router,private navCtrl: NavController) {}
|
|
|
+
|
|
|
+ goBack() {
|
|
|
+
|
|
|
+ this.navCtrl.back();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+publishPost() {
|
|
|
+
|
|
|
+ if (this.inputText.length === 0 || this.remainingChars ===20) {
|
|
|
+ console.warn('按钮处于默认样式,无法发布帖子');
|
|
|
+ return;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+ const post = new CloudObject('post');
|
|
|
+
|
|
|
+
|
|
|
+ post.set({
|
|
|
+ user: new CloudUser().toPointer(),
|
|
|
+ content: this.inputText,
|
|
|
+ title: this.title,
|
|
|
+ image: this.images,
|
|
|
+ tag: this.tags,
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+ post.save()
|
|
|
+ .then(() => {
|
|
|
+ console.log('帖子已发布');
|
|
|
+
|
|
|
+ this.inputText = '';
|
|
|
+ this.title = '';
|
|
|
+ this.images = [];
|
|
|
+ this.tags = [];
|
|
|
+ })
|
|
|
+ .catch((error:any) => {
|
|
|
+ console.error('发布帖子时出错:', error);
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+ removeLocationTag() {
|
|
|
+ this.showLocationTag = false;
|
|
|
+ }
|
|
|
+
|
|
|
+ updateTitleLength() {
|
|
|
+ this.remainingChars = 20 - this.title.length;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ uploadImage() {
|
|
|
+ const fileInput = document.querySelector('input[type=file]') as HTMLInputElement;
|
|
|
+ if (fileInput) {
|
|
|
+ fileInput.click();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ onFileSelected(event: Event) {
|
|
|
+ const input = event.target as HTMLInputElement;
|
|
|
+ if (input.files && input.files.length > 0) {
|
|
|
+ const file = input.files[0];
|
|
|
+ const reader = new FileReader();
|
|
|
+
|
|
|
+ reader.onload = (e: any) => {
|
|
|
+
|
|
|
+ this.images.push(e.target.result);
|
|
|
+ };
|
|
|
+
|
|
|
+ reader.readAsDataURL(file);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|