|
@@ -2,7 +2,16 @@ import { DatePipe } from '@angular/common';
|
|
|
import { HttpClient } from '@angular/common/http';
|
|
|
import { Component, OnInit } from '@angular/core';
|
|
|
import { FormsModule } from '@angular/forms';
|
|
|
-import { IonicModule, ScrollDetail } from '@ionic/angular';
|
|
|
+import {
|
|
|
+ IonicModule,
|
|
|
+ LoadingController,
|
|
|
+ ModalController,
|
|
|
+ ScrollDetail,
|
|
|
+ ToastController,
|
|
|
+} from '@ionic/angular';
|
|
|
+// import * as JIMServ from '../../services/common/jim';
|
|
|
+// var JIM = JIMServ.JIM;
|
|
|
+// var Events = JIMServ.Events;
|
|
|
import * as Parse from 'parse';
|
|
|
|
|
|
@Component({
|
|
@@ -15,10 +24,10 @@ import * as Parse from 'parse';
|
|
|
})
|
|
|
export class ChatComponent implements OnInit {
|
|
|
targetUser: any = {
|
|
|
- name: '小兰花',
|
|
|
+ name: '紫霞仙子',
|
|
|
avatar: '',
|
|
|
};
|
|
|
- msg: string = '';
|
|
|
+ text: string = '';
|
|
|
list: any = {
|
|
|
data: [
|
|
|
{
|
|
@@ -74,116 +83,133 @@ export class ChatComponent implements OnInit {
|
|
|
height: number = 0;
|
|
|
showEmoji: boolean = false;
|
|
|
showMore: boolean = false;
|
|
|
- emojis: Array<any> = []
|
|
|
+ emojis: Array<any> = [];
|
|
|
+ isOpen: boolean = false;
|
|
|
+ currentScroll: number = 0; //滚动条位置
|
|
|
+ constructor(
|
|
|
+ private http: HttpClient,
|
|
|
+ public datePipe: DatePipe,
|
|
|
+ private modalController: ModalController,
|
|
|
+ public toastController: ToastController,
|
|
|
+ private loadingCtrl: LoadingController
|
|
|
+ ) {}
|
|
|
|
|
|
- constructor(private http: HttpClient, public datePipe: DatePipe) {}
|
|
|
-
|
|
|
- ngOnInit() {}
|
|
|
+ ngOnInit() {
|
|
|
+ this.initEmoji();
|
|
|
+ }
|
|
|
initEmoji() {
|
|
|
let emojiChar =
|
|
|
- "☺-😋-😌-😍-😏-😜-😝-😞-😔-😪-😁-😂-😃-😅-😆-👿-😒-😓-😔-😏-😖-😘-😚-😒-😡-😢-😣-😤-😢-😨-😳-😵-😷-😸-😻-😼-😽-😾-😿-🙊-🙋-🙏-✈-🚇-🚃-🚌-🍄-🍅-🍆-🍇-🍈-🍉-🍑-🍒-🍓-🐔-🐶-🐷-👦-👧-👱-👩-👰-👨-👲-👳-💃-💄-💅-💆-💇-🌹-💑-💓-💘-🚲";
|
|
|
+ '☺-😋-😌-😍-😏-😜-😝-😞-😔-😪-😁-😂-😃-😅-😆-👿-😒-😓-😔-😏-😖-😘-😚-😒-😡-😢-😣-😤-😢-😨-😳-😵-😷-😸-😻-😼-😽-😾-😿-🙊-🙋-🙏-✈-🚇-🚃-🚌-🍄-🍅-🍆-🍇-🍈-🍉-🍑-🍒-🍓-🐔-🐶-🐷-👦-👧-👱-👩-👰-👨-👲-👳-💃-💄-💅-💆-💇-🌹-💑-💓-💘-🚲';
|
|
|
|
|
|
let emojiKey = [
|
|
|
- "60a",
|
|
|
- "60b",
|
|
|
- "60c",
|
|
|
- "60d",
|
|
|
- "60f",
|
|
|
- "61b",
|
|
|
- "61d",
|
|
|
- "61e",
|
|
|
- "61f",
|
|
|
- "62a",
|
|
|
- "62c",
|
|
|
- "602",
|
|
|
- "603",
|
|
|
- "605",
|
|
|
- "606",
|
|
|
- "608",
|
|
|
- "612",
|
|
|
- "613",
|
|
|
- "614",
|
|
|
- "615",
|
|
|
- "616",
|
|
|
- "618",
|
|
|
- "619",
|
|
|
- "620",
|
|
|
- "621",
|
|
|
- "623",
|
|
|
- "624",
|
|
|
- "625",
|
|
|
- "627",
|
|
|
- "629",
|
|
|
- "633",
|
|
|
- "635",
|
|
|
- "637",
|
|
|
- "63a",
|
|
|
- "63b",
|
|
|
- "63c",
|
|
|
- "63d",
|
|
|
- "63e",
|
|
|
- "63f",
|
|
|
- "64a",
|
|
|
- "64b",
|
|
|
- "64f",
|
|
|
- "681",
|
|
|
- "68a",
|
|
|
- "68b",
|
|
|
- "68c",
|
|
|
- "344",
|
|
|
- "345",
|
|
|
- "346",
|
|
|
- "347",
|
|
|
- "348",
|
|
|
- "349",
|
|
|
- "351",
|
|
|
- "352",
|
|
|
- "353",
|
|
|
- "414",
|
|
|
- "415",
|
|
|
- "416",
|
|
|
- "466",
|
|
|
- "467",
|
|
|
- "468",
|
|
|
- "469",
|
|
|
- "470",
|
|
|
- "471",
|
|
|
- "472",
|
|
|
- "473",
|
|
|
- "483",
|
|
|
- "484",
|
|
|
- "485",
|
|
|
- "486",
|
|
|
- "487",
|
|
|
- "490",
|
|
|
- "491",
|
|
|
- "493",
|
|
|
- "498",
|
|
|
- "6b4",
|
|
|
+ '60a',
|
|
|
+ '60b',
|
|
|
+ '60c',
|
|
|
+ '60d',
|
|
|
+ '60f',
|
|
|
+ '61b',
|
|
|
+ '61d',
|
|
|
+ '61e',
|
|
|
+ '61f',
|
|
|
+ '62a',
|
|
|
+ '62c',
|
|
|
+ '602',
|
|
|
+ '603',
|
|
|
+ '605',
|
|
|
+ '606',
|
|
|
+ '608',
|
|
|
+ '612',
|
|
|
+ '613',
|
|
|
+ '614',
|
|
|
+ '615',
|
|
|
+ '616',
|
|
|
+ '618',
|
|
|
+ '619',
|
|
|
+ '620',
|
|
|
+ '621',
|
|
|
+ '623',
|
|
|
+ '624',
|
|
|
+ '625',
|
|
|
+ '627',
|
|
|
+ '629',
|
|
|
+ '633',
|
|
|
+ '635',
|
|
|
+ '637',
|
|
|
+ '63a',
|
|
|
+ '63b',
|
|
|
+ '63c',
|
|
|
+ '63d',
|
|
|
+ '63e',
|
|
|
+ '63f',
|
|
|
+ '64a',
|
|
|
+ '64b',
|
|
|
+ '64f',
|
|
|
+ '681',
|
|
|
+ '68a',
|
|
|
+ '68b',
|
|
|
+ '68c',
|
|
|
+ '344',
|
|
|
+ '345',
|
|
|
+ '346',
|
|
|
+ '347',
|
|
|
+ '348',
|
|
|
+ '349',
|
|
|
+ '351',
|
|
|
+ '352',
|
|
|
+ '353',
|
|
|
+ '414',
|
|
|
+ '415',
|
|
|
+ '416',
|
|
|
+ '466',
|
|
|
+ '467',
|
|
|
+ '468',
|
|
|
+ '469',
|
|
|
+ '470',
|
|
|
+ '471',
|
|
|
+ '472',
|
|
|
+ '473',
|
|
|
+ '483',
|
|
|
+ '484',
|
|
|
+ '485',
|
|
|
+ '486',
|
|
|
+ '487',
|
|
|
+ '490',
|
|
|
+ '491',
|
|
|
+ '493',
|
|
|
+ '498',
|
|
|
+ '6b4',
|
|
|
];
|
|
|
- let emojis = []
|
|
|
- let emojiCharArr = emojiChar.split("-");
|
|
|
+ let emojis = [];
|
|
|
+ let emojiCharArr = emojiChar.split('-');
|
|
|
for (let i in emojiKey) {
|
|
|
let em = {
|
|
|
char: emojiCharArr[i],
|
|
|
- emoji: "0x1f" + emojiKey[i],
|
|
|
+ emoji: '0x1f' + emojiKey[i],
|
|
|
};
|
|
|
emojis.push(em);
|
|
|
}
|
|
|
- this.emojis = emojis
|
|
|
+ this.emojis = emojis;
|
|
|
}
|
|
|
handleScrollStart() {
|
|
|
- console.log('scroll start');
|
|
|
+ // console.log('scroll start');
|
|
|
}
|
|
|
-
|
|
|
handleScroll(ev: CustomEvent<ScrollDetail>) {
|
|
|
- console.log('scroll', ev.detail);
|
|
|
- let srcollop = ev.detail.startY;
|
|
|
- console.log(srcollop);
|
|
|
+ // console.log('scroll', ev.detail);
|
|
|
+ let srcollop = ev.detail.scrollTop;
|
|
|
+ // console.log(srcollop);
|
|
|
+ this.currentScroll = srcollop;
|
|
|
}
|
|
|
|
|
|
- handleScrollEnd() {
|
|
|
- console.log('scroll end');
|
|
|
+ async handleScrollEnd() {
|
|
|
+ // console.log('scroll end');
|
|
|
+ console.log(this.currentScroll);
|
|
|
+ if (this.currentScroll === 0){
|
|
|
+ const loading = await this.loadingCtrl.create({
|
|
|
+ message: '消息加载中',
|
|
|
+ duration: 1500,
|
|
|
+ });
|
|
|
+ loading.present();
|
|
|
+ }
|
|
|
}
|
|
|
//调起表情
|
|
|
changeShowEmoji() {
|
|
@@ -193,11 +219,45 @@ export class ChatComponent implements OnInit {
|
|
|
}
|
|
|
//添加表情
|
|
|
emojiChoose(value: any) {
|
|
|
- this.msg = this.msg + value.char;
|
|
|
+ console.log(value);
|
|
|
+ this.text = this.text + value;
|
|
|
}
|
|
|
//删除表情
|
|
|
delEmoji() {
|
|
|
- this.msg = this.msg.substring(0, this.msg.length - 2);
|
|
|
+ this.text = this.text.substring(0, this.text.length - 2);
|
|
|
+ }
|
|
|
+ //发送文字
|
|
|
+ comfirmText(e?: any) {
|
|
|
+ if (e && e.keyCode != 13) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (this.text == '' && this.text.trim() == '') {
|
|
|
+ this.presentToast('聊天内容不能为空');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ this.send({
|
|
|
+ msg_type: 'text',
|
|
|
+ content: this.text,
|
|
|
+ });
|
|
|
+ this.text = ''
|
|
|
+ }
|
|
|
+ async send(param: { msg_type: string; content: string }) {
|
|
|
+ let that = this;
|
|
|
+ // 2.开始发送消息
|
|
|
+ // let isLogin = JIMServ.checkLogin();
|
|
|
+ this.list.data.push({
|
|
|
+ is_self: true,
|
|
|
+ avatar:
|
|
|
+ 'https://file-cloud.fmode.cn/Qje9D4bqol/20241109/2t1lp0032258601.png',
|
|
|
+ msg_type: param.msg_type,
|
|
|
+ content: param.content,
|
|
|
+ create_time: new Date(),
|
|
|
+ istoday: true,
|
|
|
+ timeStamp: new Date(),
|
|
|
+ })
|
|
|
+ }
|
|
|
+ dismiss(evt: any) {
|
|
|
+ this.isOpen = false;
|
|
|
}
|
|
|
predivimg<T>(value: string) {
|
|
|
this.showPreView = true;
|
|
@@ -206,4 +266,12 @@ export class ChatComponent implements OnInit {
|
|
|
onBack() {
|
|
|
history.back();
|
|
|
}
|
|
|
+ async presentToast(title: string, time?: number, color?: string) {
|
|
|
+ const toast = await this.toastController.create({
|
|
|
+ message: title,
|
|
|
+ duration: time || 1500,
|
|
|
+ color: color || 'danger',
|
|
|
+ });
|
|
|
+ toast.present();
|
|
|
+ }
|
|
|
}
|