|
@@ -0,0 +1,183 @@
|
|
|
|
+import { CommonModule } from '@angular/common';
|
|
|
|
+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 { IonButton, IonButtons, IonCardContent, IonContent, IonFooter, IonHeader, IonIcon, IonImg, IonInfiniteScrollContent, IonInput, IonItem, IonTextarea, IonTitle, IonToolbar, } from '@ionic/angular/standalone';
|
|
|
|
+import { addIcons } from 'ionicons';
|
|
|
|
+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';
|
|
|
|
+import { CustomHeaderComponent } from 'src/lib/component/custom-header/custom-header.component';
|
|
|
|
+
|
|
|
|
+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, IonModal, CustomHeaderComponent, IonImg, IonInfiniteScrollContent],
|
|
|
|
+})
|
|
|
|
+export class SendPostComponent implements OnInit {
|
|
|
|
+ inputText: string = ''; // 用于绑定输入框的内容
|
|
|
|
+ title: string = ''; // 帖子标题
|
|
|
|
+ showLocationTag: boolean = true; // 控制标签是否显示
|
|
|
|
+ remainingChars: number = 20; // 剩余字符数
|
|
|
|
+ images: string[] = []; // 存储图片的数组
|
|
|
|
+ tags: string[] = []; // 存储标签的数组
|
|
|
|
+ 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) { }
|
|
|
|
+ goBack() {
|
|
|
|
+ this.navCtrl.back(); // 返回上一页
|
|
|
|
+ }
|
|
|
|
+ /**
|
|
|
|
+ * @发帖操作函数
|
|
|
|
+ *
|
|
|
|
+ */
|
|
|
|
+ // 添加标签
|
|
|
|
+ addTags(tag: string) {
|
|
|
|
+ this.tags.push(tag); // 添加标签到 tags 数组中
|
|
|
|
+ console.log(this.tags)
|
|
|
|
+ }
|
|
|
|
+ // 删除标签
|
|
|
|
+ removeTags(tag: string) {
|
|
|
|
+ this.tags = this.tags.filter((item) => item !== tag); // 从 tags 数组中删除指定标签
|
|
|
|
+ console.log(this.tags)
|
|
|
|
+ }
|
|
|
|
+ // 添加图片
|
|
|
|
+ uploadImage() {
|
|
|
|
+ const fileInput = document.querySelector('input[type=file]') as HTMLInputElement;
|
|
|
|
+ if (fileInput) {
|
|
|
|
+ fileInput.click(); // 点击文件输入框
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ //删除上传的图片
|
|
|
|
+ removeImage(index: number) {//删除图片
|
|
|
|
+ this.images.splice(index, 1); // 从数组中删除指定索引的图片
|
|
|
|
+ }
|
|
|
|
+ // 发布帖子
|
|
|
|
+ publishPost() {
|
|
|
|
+ this.isPost = true;
|
|
|
|
+ const post = new CloudObject('post');
|
|
|
|
+ //设置帖子默认属性
|
|
|
|
+ post.set({
|
|
|
|
+ UserID: new CloudUser().toPointer(),
|
|
|
|
+ content: this.inputText,
|
|
|
|
+ title: this.title,
|
|
|
|
+ image: this.images,
|
|
|
|
+ tag: this.tags,
|
|
|
|
+ like: 0,
|
|
|
|
+ });
|
|
|
|
+ // 保存帖子到数据库
|
|
|
|
+ post.save()
|
|
|
|
+ .then(() => {
|
|
|
|
+ console.log('帖子已发布');
|
|
|
|
+ // 清空输入框和其他状态
|
|
|
|
+ this.inputText = '';
|
|
|
|
+ this.title = '';
|
|
|
|
+ this.images = [];
|
|
|
|
+ this.tags = [];
|
|
|
|
+ })
|
|
|
|
+ .catch((error: any) => {
|
|
|
|
+ console.error('发布帖子时出错:', error);
|
|
|
|
+ });
|
|
|
|
+ this.isPost = true; // 发布成功后,将 isPost 设置为 true
|
|
|
|
+ this.goBack();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * @内置操作函数
|
|
|
|
+ */
|
|
|
|
+ // 删除标签
|
|
|
|
+ removeLocationTag() {
|
|
|
|
+ this.showLocationTag = false; // 设置为 false 隐藏标签
|
|
|
|
+ }
|
|
|
|
+ // 更新标题长度
|
|
|
|
+ updateTitleLength() {
|
|
|
|
+ this.remainingChars = 20 - this.title.length; // 更新剩余字符数
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ 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
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ isEmojiPickerOpen: boolean = false; // 控制表情选择器的打开状态
|
|
|
|
+ emojis: string[] = ['😀', '😃', '😄', '😁', '😆', '😅', '🤣', '😂', '🙂', '🙃', '🫠', '😉', '😊', '😇', '🥰', '😍', '🤩', '😘',
|
|
|
|
+ '😗', '☺️', '😚', '😙', '🥲', '😋', '😛', '😜', '🤪', '😝', '🤑', '🤗', '🤭', '🫢', '🫣', '🤫', '🤔', '🫡', '🤐', '🤨', '😐',
|
|
|
|
+ '😑', '😶', '🫥', '😶🌫️', '😏', '😒', '🙄', '😬', '😮💨', '🤥', '🫨', '🙂↔️', '🙂↕️', '😌', '😔', '😪', '🤤', '😴', '', '😷',
|
|
|
|
+ '🤒', '🤕', '🤢', '🤮', '🤧', '🥵', '🥶', '🥴', '😵', '😵💫', '🤯', '🤠', '🥳', '🥸', '😎', '🤓', '🧐', '😕', '🫤', '😟',
|
|
|
|
+ '🙁', '☹️', '😮', '😯', '😲', '😳', '🥺', '🥹', '😦', '😧', '😨', '😰', '😥', '😢', '😭', '😱', '😖', '😣', '😞', '😓',
|
|
|
|
+ '😩', '😫', '🥱', '😤', '😡', '😠', '🤬', '😈', '👿', '💀', '☠️', '💩', '🤡', '👹', '👺', '👻', '👽', '👾', '🤖', '😺',
|
|
|
|
+ '😸', '😹', '😻', '😼', '😽', '🙀', '😿', '😾', '🙈', '🙉', '🙊', '💌', '💘', '❤️', '🖤', '💋', '💯', '💢', '💥', '💫',
|
|
|
|
+ '💦', '💤']; // 表情数组
|
|
|
|
+ // 打开表情选择器
|
|
|
|
+ openEmojiPicker() {
|
|
|
|
+ this.isEmojiPickerOpen = true;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 关闭表情选择器
|
|
|
|
+ closeEmojiPicker() {
|
|
|
|
+ this.isEmojiPickerOpen = false; // 关闭模态框
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 添加表情到输入框
|
|
|
|
+ addEmoji(emoji: string) {
|
|
|
|
+ this.inputText += emoji; // 将选中的表情添加到输入框
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+}
|