|
@@ -1,21 +1,23 @@
|
|
|
import { CommonModule } from '@angular/common';
|
|
|
-import { Component, OnInit } from '@angular/core';
|
|
|
+import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
|
|
|
import { FormsModule } from '@angular/forms';
|
|
|
import { Router } from '@angular/router';
|
|
|
-import { NavController } from '@ionic/angular';
|
|
|
+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 { atOutline, bookmarkOutline, chevronBackSharp, closeOutline, happyOutline, imageOutline, } from 'ionicons/icons';
|
|
|
import { CloudObject, CloudUser } from 'src/lib/ncloud';
|
|
|
+import { IonModal, } from '@ionic/angular/standalone'; // 导入独立组件
|
|
|
+import { HwobsProvider } from './hwobs.service';
|
|
|
|
|
|
-addIcons({chevronBackSharp,imageOutline,atOutline,happyOutline,closeOutline });
|
|
|
+addIcons({chevronBackSharp,imageOutline,atOutline,happyOutline,closeOutline,bookmarkOutline });
|
|
|
@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,],
|
|
|
+ IonButton,IonIcon,IonButtons,IonInput,IonFooter,CommonModule,FormsModule,IonTextarea,IonModal],
|
|
|
})
|
|
|
export class SendPostComponent implements OnInit {
|
|
|
inputText: string = ''; // 用于绑定输入框的内容
|
|
@@ -24,7 +26,21 @@ export class SendPostComponent implements OnInit {
|
|
|
remainingChars: number = 20; // 剩余字符数
|
|
|
images: string[] = []; // 存储图片的数组
|
|
|
tags: string[] = []; // 存储标签的数组
|
|
|
- ngOnInit() {}
|
|
|
+ isPost: boolean = false; // 帖子发布状态
|
|
|
+ @Input() url:string = "";
|
|
|
+ @Output() onUrlChange:EventEmitter<string> = new EventEmitter<string>()
|
|
|
+
|
|
|
+ uploader:HwobsProvider|undefined
|
|
|
+
|
|
|
+ ngOnInit() {
|
|
|
+ this.uploader = new HwobsProvider({
|
|
|
+ bucketName:"nova-cloud",
|
|
|
+ prefix:"dev/jxnu/storage/",
|
|
|
+ host:"https://app.fmode.cn/",
|
|
|
+ access_key_id:"XSUWJSVMZNHLWFAINRZ1",
|
|
|
+ secret_access_key:"P4TyfwfDovVNqz08tI1IXoLWXyEOSTKJRVlsGcV6"
|
|
|
+ });
|
|
|
+ }
|
|
|
|
|
|
constructor(private router: Router,private navCtrl: NavController) {}
|
|
|
|
|
@@ -40,10 +56,10 @@ publishPost() {
|
|
|
console.warn('按钮处于默认样式,无法发布帖子');
|
|
|
return; // 如果按钮处于默认样式,直接返回,不执行后续逻辑
|
|
|
}
|
|
|
-
|
|
|
+this.isPost = true; // 发布成功后,将 isPost 设置为 true
|
|
|
// 创建一个 CloudObject 实例,表示要保存的帖子
|
|
|
const post = new CloudObject('post'); // 表名为 'post'
|
|
|
-
|
|
|
+
|
|
|
// 设置帖子内容
|
|
|
post.set({
|
|
|
user: new CloudUser().toPointer(), // 指向当前用户
|
|
@@ -66,6 +82,7 @@ publishPost() {
|
|
|
.catch((error:any) => {
|
|
|
console.error('发布帖子时出错:', error);
|
|
|
});
|
|
|
+ this.isPost = true; // 发布成功后,将 isPost 设置为 true
|
|
|
}
|
|
|
|
|
|
// 删除标签
|
|
@@ -78,28 +95,83 @@ publishPost() {
|
|
|
}
|
|
|
|
|
|
|
|
|
- // 处理文件选择
|
|
|
- uploadImage() {
|
|
|
- const fileInput = document.querySelector('input[type=file]') as HTMLInputElement; // 使用类型断言;
|
|
|
- if (fileInput) {
|
|
|
- fileInput.click(); // 点击文件输入框
|
|
|
+ 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) => {
|
|
|
- // 将图片数据存储到 images 数组中
|
|
|
- this.images.push(e.target.result); // 将 Base64 编码的图片数据添加到数组
|
|
|
- };
|
|
|
+ file:File|undefined
|
|
|
+ fileData:any = ""
|
|
|
+ fileList:File[] = []
|
|
|
+
|
|
|
+ async upload(){
|
|
|
+ let filename = this.file?.name;
|
|
|
+ let dateStr = `${new Date().getFullYear()}${new Date().getMonth()+1}${new Date().getDate()}`;
|
|
|
+ let hourStr = `${new Date().getHours()}${new Date().getMinutes()+1}${new Date().getSeconds()}`;
|
|
|
+ let key = `${dateStr}/${hourStr}-${filename}`;
|
|
|
+ // let key = `storage/${filename}`
|
|
|
+ if(this.file){
|
|
|
+ let attachment = await this.uploader?.uploadFile(this.file,key);
|
|
|
+ console.log(attachment);
|
|
|
+ this.url = attachment?.get("url");
|
|
|
+ console.log(this.url);
|
|
|
+ this.onUrlChange.emit(this.url);
|
|
|
+ console.log(this.url);
|
|
|
+ this.images.push(this.url);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 文件选择器 选择文件触发事件
|
|
|
+ * @param event
|
|
|
+ */
|
|
|
+ async onFileChange(event:any){
|
|
|
+ console.log(event)
|
|
|
+ // 将选择的文件列表,赋值给fileList
|
|
|
+ this.fileList = event?.target?.files;
|
|
|
+ // 默认将第一个文件,显示在展示区域
|
|
|
+ this.setFile(event?.target?.files?.[0]);
|
|
|
+ this.upload();
|
|
|
+ this.fileList =[];
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 设置展示区域文件
|
|
|
+ * @param file
|
|
|
+ */
|
|
|
+ async setFile(file:any){
|
|
|
+ // 将文件设置为展示区域文件
|
|
|
+ this.file = file
|
|
|
|
|
|
- reader.readAsDataURL(file); // 读取文件为 Data URL
|
|
|
}
|
|
|
- }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ isEmojiPickerOpen: boolean = false; // 控制表情选择器的打开状态
|
|
|
+ emojis: string[] = ['😀', '😃', '😄', '😁', '😆', '😅', '🤣', '😂', '🙂', '🙃', '🫠', '😉', '😊', '😇', '🥰', '😍', '🤩', '😘',
|
|
|
+ '😗', '☺️', '😚', '😙', '🥲', '😋', '😛', '😜', '🤪', '😝', '🤑', '🤗', '🤭', '🫢', '🫣', '🤫', '🤔', '🫡', '🤐', '🤨', '😐',
|
|
|
+ '😑', '😶', '🫥', '😶🌫️', '😏', '😒', '🙄', '😬', '😮💨', '🤥', '🫨', '🙂↔️', '🙂↕️', '😌', '😔', '😪', '🤤', '😴', '', '😷',
|
|
|
+ '🤒', '🤕', '🤢', '🤮', '🤧', '🥵', '🥶', '🥴', '😵', '😵💫', '🤯', '🤠', '🥳', '🥸', '😎', '🤓', '🧐', '😕', '🫤', '😟',
|
|
|
+ '🙁', '☹️', '😮', '😯', '😲', '😳', '🥺', '🥹', '😦', '😧', '😨', '😰', '😥', '😢', '😭', '😱', '😖', '😣', '😞', '😓',
|
|
|
+ '😩', '😫', '🥱', '😤', '😡', '😠', '🤬', '😈', '👿', '💀', '☠️', '💩', '🤡', '👹', '👺', '👻', '👽', '👾', '🤖', '😺',
|
|
|
+ '😸', '😹', '😻', '😼', '😽', '🙀', '😿', '😾', '🙈', '🙉', '🙊', '💌', '💘', '❤️', '🖤', '💋', '💯', '💢', '💥', '💫',
|
|
|
+ '💦', '💤']; // 表情数组
|
|
|
+// 打开表情选择器
|
|
|
+openEmojiPicker() {
|
|
|
+ this.isEmojiPickerOpen = true;
|
|
|
+}
|
|
|
+
|
|
|
+// 关闭表情选择器
|
|
|
+closeEmojiPicker() {
|
|
|
+ this.isEmojiPickerOpen = false; // 关闭模态框
|
|
|
+}
|
|
|
+
|
|
|
+// 添加表情到输入框
|
|
|
+addEmoji(emoji: string) {
|
|
|
+ this.inputText += emoji; // 将选中的表情添加到输入框
|
|
|
|
|
|
+}
|
|
|
+
|
|
|
}
|