|
@@ -1,16 +1,88 @@
|
|
|
import { Component } from '@angular/core';
|
|
|
-import { IonHeader, IonToolbar, IonTitle, IonContent } from '@ionic/angular/standalone';
|
|
|
-import { ExploreContainerComponent } from '../explore-container/explore-container.component';
|
|
|
+import { CommonModule } from '@angular/common';
|
|
|
+import { IonicModule } from '@ionic/angular';
|
|
|
+import { FormsModule } from '@angular/forms';
|
|
|
+import { addIcons } from 'ionicons';
|
|
|
+import { add,close,location,lockOpen} from 'ionicons/icons';
|
|
|
+
|
|
|
|
|
|
@Component({
|
|
|
selector: 'app-tab3',
|
|
|
- templateUrl: 'tab3.page.html',
|
|
|
- styleUrls: ['tab3.page.scss'],
|
|
|
+ templateUrl: './tab3.page.html',
|
|
|
+ styleUrls: ['./tab3.page.scss'],
|
|
|
standalone: true,
|
|
|
- imports: [IonHeader, IonToolbar, IonTitle, IonContent, ExploreContainerComponent]
|
|
|
+ imports: [
|
|
|
+ CommonModule,
|
|
|
+ IonicModule,
|
|
|
+ FormsModule,
|
|
|
+ ]
|
|
|
})
|
|
|
export class Tab3Page {
|
|
|
+ postTitle: string = '';
|
|
|
+ postContent: string = '';
|
|
|
+ selectedFiles: { src: string | ArrayBuffer | null, isImage: boolean }[] = []; // 用于存储多个文件信息
|
|
|
+ location: string = ''; // 新增属性,用于存储地点
|
|
|
+ isPublic: boolean = true; // 新增属性,用于存储公开可见状态
|
|
|
+ saveToAlbum: boolean = false; // 新增属性,用于存储是否保存到相册
|
|
|
+ visibility: string = 'none'; // 初始化可见性变量,默认值可以根据需求设定
|
|
|
+
|
|
|
+ cities: string[] = [
|
|
|
+ '北京', '上海', '广州', '深圳', '杭州', '成都', '武汉',
|
|
|
+ '南京', '西安', '重庆', '天津', '青岛', '沈阳', '郑州',
|
|
|
+ '合肥', '厦门', '福州', '哈尔滨', '长春', '济南', '南昌',
|
|
|
+ // ... 继续添加更多城市
|
|
|
+ ];
|
|
|
+
|
|
|
+ constructor() {
|
|
|
+ addIcons({ add,close,location,lockOpen});
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ onFilesSelected(event: Event) {
|
|
|
+ // 清空已选文件数组
|
|
|
+ this.selectedFiles = [];
|
|
|
+
|
|
|
+ const files = (event.target as HTMLInputElement).files;
|
|
|
+ if (files) {
|
|
|
+ for (let i = 0; i < files.length; i++) {
|
|
|
+ const file = files[i];
|
|
|
+ const reader = new FileReader();
|
|
|
+ reader.onload = () => {
|
|
|
+ this.selectedFiles.push({ src: reader.result, isImage: file.type.startsWith('image/') }); // 将文件信息添加到数组中
|
|
|
+ };
|
|
|
+ reader.readAsDataURL(file);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ removeFile(fileToRemove: { src: string | ArrayBuffer | null, isImage: boolean }) {
|
|
|
+ this.selectedFiles = this.selectedFiles.filter(file => file !== fileToRemove); // 从数组中移除指定文件
|
|
|
+ }
|
|
|
|
|
|
- constructor() {}
|
|
|
+ sendMessage() {}
|
|
|
|
|
|
-}
|
|
|
+ publishPost() {
|
|
|
+ if (this.postTitle && this.postContent) {
|
|
|
+ // 这里可以将帖子数据发送到服务器
|
|
|
+ console.log('发布帖子:', {
|
|
|
+ title: this.postTitle,
|
|
|
+ content: this.postContent,
|
|
|
+ files: this.selectedFiles,
|
|
|
+ location: this.location, // 新增属性
|
|
|
+ isPublic: this.isPublic, // 新增属性
|
|
|
+ saveToAlbum: this.saveToAlbum, // 新增属性
|
|
|
+ visibility: this.visibility, // 将可见性信息包含在发布的数据中
|
|
|
+ });
|
|
|
+ // 清空表单
|
|
|
+ this.postTitle = '';
|
|
|
+ this.postContent = '';
|
|
|
+ this.selectedFiles = [];
|
|
|
+ this.location = ''; // 清空地点
|
|
|
+ this.isPublic = true; // 重置公开可见状态
|
|
|
+ this.saveToAlbum = false; // 重置保存到相册状态
|
|
|
+ this.visibility = 'none'; // 重置可见性
|
|
|
+ } else {
|
|
|
+ console.log('标题和正文不能为空');
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|