123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500 |
- <template>
- <view @tap="ontap">
- <scroll-view class="chat-detail" :style="{'height':chatheight+'px'}" id="chat" scroll-y="true"
- :scroll-into-view="scrollToView" @scroll="chatscroll">
- <!-- <view class="chat-detail" id="chat" auto-height="true" > -->
- <!-- 加载历史数据waitingUI -->
- <view class="nodata" v-if="showmore && system.chattime<3650"> 仅能查看最近{{system.chattime}}日的聊天记录</view>
- <view class="loading" v-if="showLoading">
- <view class="spinner">
- <view class="rect1"></view>
- <view class="rect2"></view>
- <view class="rect3"></view>
- <view class="rect4"></view>
- <view class="rect5"></view>
- </view>
- </view>
- <view v-for="(m,index) in messagelist_old" :key="'itemold_'+m.msg_id" :id="'item_'+m.msg_id"
- v-if="m.isloading!=3">
- <messageitem :item="m" :loading_id="loading_id" :userid="userid" :playVoiceId="playVoiceId"
- @redpack_open="redpack_open" @atusuer='atusuer' @clickAvatar='clickAvatar' @msgAction='msgAction'
- @play_vedio='play_vedio' @playVoice="playVoice"></messageitem>
- </view>
- <view v-for="(m,index) in messagelist" :key="'itemnew_'+m.msg_id" :id="'item_'+m.msg_id"
- v-if="m.isloading!=3">
- <view class="nodata" v-if="unreadid==m.msg_id">以下是未读消息</view>
- <messageitem :item="m" :ref="'messageitem_'+index" :loading_id="loading_id" :unreadid="unreadid"
- :userid="userid" :playVoiceId="playVoiceId" @redpack_open="redpack_open" @atusuer='atusuer'
- @clickAvatar='clickAvatar' @msgAction='msgAction' @play_vedio='play_vedio' @playVoice="playVoice">
- </messageitem>
- </view>
- <view v-if="sending">
- <messageitem id="self_send" :item="sendingdata" :userid="userid" :loading_id="loading_id"
- @clickAvatar='clickAvatar' @redpack_open="redpack_open" @msgAction='msgAction'
- @play_vedio='play_vedio' @playVoice="playVoice"></messageitem>
- </view>
- <view id="self_bottom1" class="self_bottom">
- </view>
- <view id="self_bottom2" class="self_bottom">
- </view>
- </scroll-view>
- <view class="unread" @tap="scrollto_unread" v-if="unreadnum>0">有<view class="num">{{unreadnum}}</view>条未读消息
- </view>
- <view :class="touch_class" :style="touch_style" v-if="touch_menu">
- <block v-for="(m1,index1) in touch_menulist" :key="'menu_'+index1">
- <view @tap="tap_menu(m1.type)">{{m1.text}}</view>
- </block>
- </view>
- <view class="vedioplay" v-if="videoshow" :style="{'display':videoshow?'inline-block':'none'}">
- <video id="video_play" :src="videosrc" loop="false" autoplay="true" @play="playVedio()" @ended="endVedio()"
- @pause="pauseVedio()" :poster="poster"></video>
- <view class="bottom">
- <uni-icons type='closeempty' class="icon1" @tap="endVedio()"></uni-icons>
- </view>
- </view>
- <redpick v-if="is_redpack_open" :item="redpack_info" @closePick="is_redpack_open=false;"
- @fresmsg="freshmsg_fromredopen"></redpick>
- <logoutwords v-if="showlogout" :item="logoutinfo" @sub="logout_sub" @cancle="showlogout=false;"></logoutwords>
- </view>
- </template>
- <script>
- import {
- mapState,
- mapGetters
- } from 'vuex';
- import action from '../library/action.js'
- import messageitem from './messageitem.vue'
- import http from "../library/http.js"
- import chat from "../library/chat.js"
- import uniIcons from './uni-icons/uni-icons.vue'
- import redpick from './get-redpick.vue'
- import Vue from 'vue';
- import logoutwords from './logout_words.vue'
- const innerAudioContext = uni.createInnerAudioContext();
- let loadStatus = false;
- let lastMid = '';
- var windowHeight = uni.getSystemInfoSync().windowHeight;
- var windowWidth = uni.getSystemInfoSync().windowWidth;
- var statusBarHeight = uni.getSystemInfoSync().statusBarHeight;
- var chatheight = windowHeight - 60;
- var chattop = 0;
- // #ifndef APP-PLUS
- var chattop = statusBarHeight + 45;
- var windowWidth = uni.getSystemInfoSync().screenHeight;
- var chatheight = uni.getSystemInfoSync().windowHeight - chattop - 60;
- // #endif
- function timestampToTime(timestamp) {
- var date = new Date(timestamp * 1000); //时间戳为10位需*1000,时间戳为13位的话不需乘1000
- var Y = date.getFullYear();
- var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1);
- var D = date.getDate();
- var h = date.getHours();
- var m = date.getMinutes();
- var s = date.getSeconds();
- if (D < 10) D = '0' + D;
- if (h < 10) h = '0' + h;
- if (m < 10) m = '0' + m;
- if (s < 10) s = '0' + s;
- return Y + '-' + M + '-' + D + ' ' + h + ':' + m + ':' + s;
- }
- export default {
- components: {
- uniIcons,
- messageitem,
- redpick,
- logoutwords
- },
- props: {
- storeKey: {
- require: true
- },
- boardheight: {
- type: Number,
- default: 0
- },
- manager: {
- type: [Number, String, Object, Boolean],
- default: 0
- },
- thistype: {
- default: '',
- },
- sending: {
- type: Boolean,
- default: false
- },
- sendingdata: {
- default: {}
- },
- no_add: {
- type: Boolean,
- default: false
- },
- atme: {
- default: 0
- },
- at_msg_id: {
- default: 0
- }
- },
- data() {
- return {
- chatheight: chatheight,
- chattop: chattop,
- panelheight: chatheight,
- paddingtop: 0,
- scrollToView: 'self_bottom2',
- scrollAnimation: true,
- showLoading: false,
- playVoiceId: '',
- isizes: {},
- pageHeight: 0,
- contentViewHeight: 0,
- footViewHeight: 90,
- mitemHeight: 0,
- scrollTop: 0,
- letterDetails: [],
- senderheight: 0,
- hide_list: '',
- loading_id: 0,
- playVedioId: '',
- videoshow: false,
- videosrc: "",
- video_playing: false,
- video_end: false,
- poster: null,
- isbottom: false,
- pagemaxtop: 0,
- isscroll: false,
- pagetop: 0,
- storeId: 0,
- isgroup: 1,
- page: 0,
- pagenum: 0,
- userid: parseInt(uni.getStorageSync('access_token')),
- isfrist: 0,
- oldheight: 0,
- lastmessage: [],
- oldlength: 0,
- showmore: false,
- touch_menu: false,
- touch_style: "",
- touch_class: 'touch_menu',
- touch_menulist: [],
- touch_time: 0,
- touch_timer: null,
- message: [],
- touch_item: null,
- isfristload: true,
- maxheight: 0,
- msg_id1: 0,
- messagelist: uni.getStorageSync(uni.getStorageSync('access_token') + "_chat_" + this.storeKey),
- messagelist_old: [],
- isupdate: false,
- lastscroll: 0,
- scrollpos: 'down',
- unreadid: 0,
- unreadnum: 0,
- redpack_info: {},
- is_redpack_open: false,
- showlogout: false,
- logoutinfo: {},
- keyboardheight: 0,
- system: uni.getStorageSync('system')
- };
- },
- mounted() {
- uni.setStorageSync('storeykey', 'chat');
- if (this.atme == 1 && this.at_msg_id > 0) {
- this.scrolltoAtme();
- } else {
- this.isfristload = false;
- }
- this.scrollToBottom(0);
- this.storeId = this.storeKey.substr(1, this.storeKey.length - 1);
- if (this.storeKey.indexOf('G') > -1) {
- this.isgroup = 1;
- //群组消息
- this.group_read(this.storeId);
- } else {
- this.isgroup = 0;
- this.user_read(this.storeId);
- //私人消息
- }
- // console.log(this.messagelist.length)
- // if(this.messagelist.length>30){
- // for(var i=0;i<this.messagelist.length-30;i++){
- // this.messagelist.splice(i,1);
- // }
- // uni.setStorageSync(uni.getStorageSync('access_token')+"_chat_"+this.storeKey,this.messagelist);
- // }
- var that = this;
- that.messageslist(0);
- var that = this;
- this.$socket.on('chat', (res) => {
- this.sendmsg(res);
- console.log('zhe',res)
- })
- // #ifdef APP-PLUS
- var that = this;
- setTimeout(function() {
- var wh = uni.getSystemInfoSync().screenHeight;
- var ch = wh - statusBarHeight - 105;
- if (ch < that.chatheight) that.chatheight = ch;
- else {
- var wh = uni.getSystemInfoSync().windowHeight;
- var ch = wh - 60;
- that.chatheight = ch;
- }
- }, 1000)
- uni.onKeyboardHeightChange(res => {
- if (res.height > 0) {
- that.scrollToBottom();
- }
- this.chatheight = this.panelheight - res.height;
- this.$forceUpdate();
- this.keyboardheight = res.height;
- // console.log(this.chatheight);
- // console.log(this.panelheight,this.maxheight)
- // if(this.panelheight<=this.maxheight && this.messagelist.length<=6){
- // // that.paddingtop=res.height;
- // // that.$forceUpdate();
- // }
- })
- // #endif
- // console.log(message)
- },
- destroyed() {
- this.$socket.off('chat');
- uni.setStorageSync('storeykey', "index");
- if (this.isgroup == 1) {
- this.group_read(this.storeId);
- } else {
- this.user_read(this.storeId);
- }
- },
- computed: {},
- methods: {
- redpack_open(m) {
- this.redpack_info = m;
- this.is_redpack_open = true;
- },
- scrolltoAtme() {
- if (this.atme == 1 && this.at_msg_id > 0 && this.isfristload == true) {
- this.scrollToView = 'item_' + this.at_msg_id;
- this.isfristload = false;
- }
- },
- sendmsg(res) {
- var res = chat.push(res, 'chat');
- if (res != false) {
- // console.log(res.msglist.length)
- this.$store.commit('chat/update_msglist', res.msglist);
- }
- this.freshmsg()
- },
- freshmsg() {
- this.messagelist = uni.getStorageSync(this.userid + "_chat_" + this.storeKey);
- },
- freshmsg_fromredopen(e) {
- //this.messagelist='';
- this.freshmsg();
- // var index=this.messagelist.findIndex(v => v.msg_id == e.msg_id);
- // console.log(index)
- // this.$set(this.messagelist,index,e)
- },
- isindexhtml(str) {
- var arr = ['<br', ' ', "<div", "<span"];
- str = str.toString();
- for (var i = 0; i < arr.length; i++) {
- //console.log(str,arr[i])
- if (str.indexOf(arr[i]) > -1) return true;
- }
- return false;
- },
- getautoheight() {
- // console.log(this.oldheight);
- this.showLoading = false;
- var that = this;
- setTimeout(function() {
- if (this.pagenum > 0)
- that.scrollToView = 'item_'.that.msg_id1;
- }, 200)
- },
- message_format(data) {
- var messagedata = [];
- if (data.length > 0) {
- for (var i = 0; i < data.length; i++) {
- var item = data[i];
- try {
- if (item.type == 'time') {
- var temp = {
- type: 'tips',
- message: {
- content: item.content,
- type: 'tips'
- },
- 'msg_id': item.id,
- isloading: 0
- };
- temp['sender_id'] = item.userid;
- temp['sender'] = item.sender;
- temp['timestamp'] = item.addtime;
- messagedata.push(temp);
- } else if (item.addtime != undefined && item.addtime > 0) {
- var temp = {};
- temp['_mid'] = 'm' + Math.random().toString(36).substring(2);
- temp['cache_key'] = this.storeKey;
- temp['group_id'] = item.groupid;
- if (this.isgroup == 1) temp['id'] = item.groupid;
- else temp['id'] = item.userid;
- temp['isloading'] = 0;
- temp['msg_id'] = item.id;
- temp['self'] = item.self;
- temp['sender_id'] = item.userid;
- temp['sender'] = item.sender;
- temp['timestamp'] = item.addtime;
- temp['unread'] = 0;
- temp['type'] = item.type;
- temp['message'] = {
- 'type': item.type,
- 'content': item.content1
- };
- messagedata.push(temp);
- }
- } catch (e) {
- //TODO handle the exception
- /// console.log(e)
- }
- }
- }
- return messagedata;
- },
- //获取云端消息记录
- messageslist(totime) {
- var lists = [];
- var time1 = (new Date()).getTime() / 1000 - 7 * 24 * 3600;
- if (totime < 1) {
- var isfrist = true;
- totime = parseInt((new Date()).getTime() / 1000);
- } else {
- var isfrist = false;
- if (this.showLoading == true) return false;
- }
- var storekey = this.storeKey
- var postdata = {
- id: parseInt(this.storeId),
- userid: parseInt(this.userid),
- isgroup: this.isgroup,
- totime: totime
- };
- var that = this;
- http.setWait(false).get('group.php?act=messages2', postdata).then(res => {
- if (res.code == 200) {
- // console.log(res);
- var data = res.data;
- var messagedata = this.message_format(data);
- if (isfrist == true) {
- if (messagedata.length < 1) {
- this.messagelist = [];
- this.showmore = true;
- }
- uni.setStorageSync(this.userid + "_chat_" + this.storeKey, messagedata);
- this.freshmsg();
- var that = this;
- setTimeout(function() {
- if (that.atme == 1 && that.at_msg_id > 0) {
- that.scrolltoAtme();
- } else
- that.scrollToBottom();
- that.isupdate = true;
- }, 300)
- } else {
- this.showLoading = false;
- if (messagedata.length > 0) {
- if (this.messagelist_old.length > 0) {
- var scrollToView = 'item_' + this.messagelist_old[0].msg_id;
- this.messagelist_old.unshift(...messagedata)
- } else {
- var scrollToView = 'item_' + this.messagelist[0].msg_id;
- this.messagelist_old = messagedata;
- }
- this.showmore = false;
- var that = this;
- setTimeout(function() {
- that.scrollToView = scrollToView
- }, 200)
- } else {
- this.showmore = true;
- }
- }
- }
- })
- },
- update_message(data) {
- var isin = 0;
- for (var i = this.messagelist.length - 1; i >= 0; i--) {
- var item = this.messagelist[i];
- if (parseInt(item.msg_id) == parseInt(data.msg.msg_id)) {
- return false;
- }
- }
- var messageold = uni.getStorageSync(this.userid + "_chatold_" + this.storeKey);
- for (var i = messageold.length - 1; i >= 0; i--) {
- var item = messageold[i];
- if (parseInt(item.msg_id) == parseInt(data.msg.msg_id)) {
- return false;
- }
- }
- var message = messageold.concat(this.messagelist);
- },
- //设置群未读消息
- group_read(group_id) {
- this.$store.commit('chat/clearunread', this.storeKey);
- },
- user_read(userid) {
- this.$store.commit('chat/clearunread', this.storeKey);
- },
- scrollto_unread() {
- this.scrollToView = "item_" + this.unreadid;
- this.unreadid = 0;
- this.unreadnum = 0;
- },
- chatscroll(e) {
- // if(this.keyboardheight>0) uni.hideKeyboard();
- this.touch_menu = false;
- var top = e.detail.scrollTop;
- this.maxheight = e.detail.scrollHeight;
- if (top > this.maxheight) this.maxheight = top;
- if (top + this.panelheight >= this.maxheight - 100 && top > 0) {
- this.isbottom = true;
- this.unreadid = 0;
- this.unreadnum = 0;
- } else this.isbottom = false;
- if (top > this.lastscroll) this.scrollpos = 'down';
- else this.scrollpos = 'up';
- // console.log(this.scrollpos,this.isbottom);
- this.lastscroll = top;
- if (top < 50 && this.isfristload == false && this.isupdate == true) {
- if (this.messagelist_old.length > 0) {
- var msg = this.messagelist_old[0];
- } else {
- var msg = this.messagelist[0];
- }
- if (msg.timestamp == undefined) var totime = msg.msg_id;
- else var totime = msg.timestamp;
- if (totime > 0) totime = totime - 1;
- this.messageslist(parseInt(totime));
- this.showLoading = true;
- }
- },
- setAutoHeight(e) {
- //console.log(e);
- this.touch_menu = false;
- },
- vedio_show(m) {
- if (m.isloading == 1) {
- return m.message.content.src;
- } else
- return this.image_cache(m.message.content.src)
- },
- poster_show(m) {
- if (m.isloading == 1) {
- return false;
- } else {
- var src = m.message.content.src;
- try {
- var arr = src.split('/');
- var filename = arr[arr.length - 1];
- var arr1 = filename.split('.');
- var newname = arr1[0] + "_video.jpg";
- var poster = src.replace(filename, newname);
- return poster;
- } catch (e) {
- //TODO handle the exception
- return "/static/img/vediobanner.jpg";
- }
- }
- },
- scrollToBottom: function() {
- var that = this;
- setTimeout(function() {
- if (that.scrollToView == "self_bottom1")
- that.scrollToView = "self_bottom2";
- else {
- that.scrollToView = "self_bottom1";
- }
- that.pagenum = 0;
- that.isbottom = true;
- that.unreadnum = 0;
- that.unreadid = 0;
- }, 200)
- },
- play_vedio(m) {
- this.videoshow = true;
- this.videosrc = this.vedio_show(m);
- this.poster = this.poster_show(m);
- this.video_playing = false;
- var that = this;
- setTimeout(function() {
- var videoContext = uni.createVideoContext('video_play');
- if (that.video_playing == false) {
- // videoContext.requestFullScreen(0);
- // setTimeout(function(){videoContext.play()},100);
- that.playVedioId = m._mid;
- videoContext.play();
- }
- }, 500)
- },
- //结束播放
- endVedio() {
- this.video_end = true;
- var videoContext = uni.createVideoContext('video_play');
- // videoContext.exitFullScreen();
- videoContext.pause();
- this.playVedioId = "";
- this.videosrc = "";
- this.pauseVedio();
- var that = this;
- that.video_end = false;
- },
- playVedio() {
- this.video_playing = true;
- this.video_end = false;
- this.videoshow = true;
- },
- pauseVedio() {
- this.video_playing = false;
- this.videoshow = false;
- },
- screenchange() {
- if (this.video_playing == true) {
- var videoContext = uni.createVideoContext('video_play');
- videoContext.exitFullScreen();
- videoContext.pause();
- this.playVedioId = "";
- this.videosrc = "";
- this.pauseVedio();
- } else {
- if (this.video_end == false) {
- var videoContext = uni.createVideoContext('video_play');
- videoContext.play();
- }
- }
- },
- playVoice(message) {
- var that = this;
- var id = message._mid;
- if (this.playVoiceId == id) {
- innerAudioContext.stop();
- innerAudioContext.src = '';
- that.playVoiceId = "";
- that.loading_id = 0;
- return false;
- }
- if (this.playVoiceId !== '') {
- innerAudioContext.stop();
- innerAudioContext.src = '';
- that.playVoiceId = "";
- that.loading_id = 0;
- }
- // if (this.playVoiceId == '') {
- this.loading_id = id;
- innerAudioContext.src = this.image_cache(message.message.content.url);
- innerAudioContext.volume = 1;
- innerAudioContext.autoplay = true;
- innerAudioContext.onCanplay(function() {
- innerAudioContext.play();
- that.playVoiceId = id;
- that.loading_id = 0;
- })
- innerAudioContext.onEnded(() => {
- innerAudioContext.stop();
- innerAudioContext.src = '';
- that.playVoiceId = "";
- that.loading_id = 0;
- });
- },
- atusuer(msg) {
- if (msg.sender.id != this.userid) {
- let result = {
- id: msg.id,
- nickname: msg.sender.nickname
- }
- this.$emit('close', result);
- }
- // console.log(msg) ;
- },
- clickAvatar(msg) {
- if (msg.id > 0) {
- var params = {
- id: msg.sender.id,
- 'group_id': msg.group_id,
- thistype: this.thistype
- };
- // console.log(JSON.stringify(msg));
- return this.$jump('friend.detail', params)
- //this.$emit('click-avatar', this.messages[index]);
- } else {
- return false;
- }
- },
- toText(msg) {
- var text = msg.replace(/ /g, ' ');
- text = text.replace(/<br>/g, '\n');
- text = text.replace(/<\/?[^>]*>/g, '');
- return text;
- },
- copyText(msg) {
- var message = msg.message;
- if (message.content.type == 'remind')
- var content = message.content.content;
- else if (message.type == 'url')
- var content = message.content.content;
- else var content = message.content
- content = this.toText(content);
- uni.setClipboardData({
- data: content,
- success: function() {
- uni.showToast({
- title: '复制成功',
- icon: 'none'
- })
- }
- });
- },
- ontap() {
- if (new Date().getTime() - this.touch_time > 1500) this.touch_menu = false;;
- },
- delete_msg(msg) {
- var list = this.messagelist;
- var isin = 0;
- var list11 = [];
- list.forEach(item => {
- if (parseInt(item.msg_id) == parseInt(msg.msg_id)) {
- // item.isloading=3;
- isin = 1;
- } else {
- list11.push(item);
- }
- })
- var that = this;
- if (isin == 1) {
- that.messagelist = list11;
- uni.setStorageSync(this.userid + "_chat_" + this.storeKey, list11);
- } else {
- var list = this.messagelist_old;
- var list11 = [];
- list.forEach(item => {
- if (parseInt(item.msg_id) == parseInt(msg.msg_id)) {
- } else {
- list11.push(item);
- }
- })
- that.messagelist_old = list11;
- }
- var postdata = {
- id: msg.msg_id,
- userid: this.userid
- };
- http.setWait(false).get('group.php?act=clearchatlist', postdata).then(res => {
- })
- // this.freshmsg();
- },
- logout_sub(e) {
- uni.showToast({
- icon: 'none',
- title: '操作成功'
- })
- },
- tap_menu(type) {
- var msg = this.touch_item;
- uni.showToast({
- title: new Date().getTime() - this.touch_time
- })
- if (new Date().getTime() - this.touch_time > 1000) {
- this.touch_menu = false;
- var that = this;
- if(type == 'quote') {
- console.log('this.touch_item:',this.touch_item);
- this.$emit('chooseQuote',this.touch_item)
- }
- if (type == "delete") {
- // this.clearchatlist(msg);
- this.delete_msg(msg)
- }
- if (type == 'copy') {
- that.copyText(msg);
- }
- if (type == 'back') {
- let data = {
- userid: that.userid,
- msg_id: msg.msg_id,
- type: 'chat_back',
- store: that.storeKey
- }
- that.$socket.send(data);
- }
- if (type == 'at') {
- that.atusuer(msg);
- }
- if (type == 'view') {
- that.clickAvatar(msg);
- }
- if (type == 'manage0') {
- var data = {
- type: 'groupset1',
- mode: 'manage',
- settype: 0,
- group_id: msg.group_id,
- userid: msg.sender.id,
- from_uid: uni.getStorageSync('access_token')
- };
- that.$socket.send(data);
- }
- if (type == 'manage1') {
- var data = {
- type: 'groupset1',
- mode: 'manage',
- settype: 1,
- group_id: msg.group_id,
- userid: msg.sender.id,
- from_uid: uni.getStorageSync('access_token')
- };
- that.$socket.send(data);
- }
- if (type == 'deny0') {
- var data = {
- type: 'groupset1',
- mode: 'deny',
- settype: 0,
- group_id: msg.group_id,
- userid: msg.sender.id,
- from_uid: uni.getStorageSync('access_token')
- };
- that.$socket.send(data);
- }
- if (type == 'deny1') {
- var data = {
- type: 'groupset1',
- mode: 'deny',
- settype: 1,
- group_id: msg.group_id,
- userid: msg.sender.id,
- from_uid: uni.getStorageSync('access_token')
- };
- that.$socket.send(data);
- }
- if (type == 'deleteuser') {
- // var data={type:'deleteGroup',group_id:msg.group_id,userid:msg.id,fromid:uni.getStorageSync('access_token')};
- // that.$socket.send(data);
- this.showlogout = true;
- this.logoutinfo = {
- group_id: msg.group_id,
- userid: msg.sender.id,
- nickname: msg.sender.nickname
- };
- }
- if (type == 'manage0' || type == 'manage1' || type == 'deny0' || type == 'deny1' || type ==
- 'deleteuser') {
- uni.showToast({
- title: '操作成功',
- icon: 'none'
- })
- }
- }
- },
- msgAction(e, msg) {
- this.touch_item = msg;
- this.touch_time = new Date().getTime();
- var user_id = uni.getStorageSync('access_token');
- var that = this;
- var itemList = [{
- type: 'delete',
- text: '删除'
- }];
- if ((that.manager == 1 && msg.group_id > 0) || (user_id == msg.sender.id && new Date().getTime() /
- 1000 - (parseInt(msg.timestamp)) <= 120)) {
- itemList.push({
- type: 'back',
- text: '撤回消息'
- });
- }
- if (msg.message.type == 'text' || msg.message.type == 'url') {
- itemList = itemList.concat([{
- type: 'copy',
- text: '复制'
- }, {
- type: 'quote',
- text: '引用'
- }])
- // itemList.push({
- // type: 'copy',
- // text: '复制'
- // });
- }
- if(msg.message.type == 'emotion' || msg.message.type == 'image') {
- itemList.push({
- type: 'quote',
- text: '引用'
- });
- }
- if (that.manager == 1 && msg.group_id > 0 && user_id != msg.sender.id) {
- var users = uni.getStorageSync(msg.group_id + '_group_members');
- var thistype = 'user';
- var usertype = "user";
- var is_deny = 0;
- var isin = 0;
- for (var i = 0; i < users.length; i++) {
- if (users[i].id == user_id) thistype = users[i].type;
- if (users[i].id == msg.sender.id) {
- usertype = users[i].type;
- is_deny = users[i].is_deny;
- isin = 1;
- }
- }
- }
- if (thistype == 'owner') {
- if (usertype == 'manager') itemList.push({
- 'type': 'manage0',
- 'text': '取消管理'
- });
- else itemList.push({
- 'type': 'manage1',
- 'text': '设为管理'
- });
- if (is_deny == 1) itemList.push({
- 'type': 'deny0',
- 'text': '解除禁言'
- });
- else itemList.push({
- 'type': 'deny1',
- 'text': '禁言'
- });
- if (isin == 1) itemList.push({
- 'type': 'deleteuser',
- 'text': '踢人'
- });
- }
- if (thistype == 'manager' && usertype == 'user') {
- if (is_deny == 1) itemList.push({
- 'type': 'deny0',
- 'text': '解除禁言'
- });
- else itemList.push({
- 'type': 'deny1',
- 'text': '禁言'
- });
- if (isin == 1) itemList.push({
- 'type': 'deleteuser',
- 'text': '踢人'
- });
- }
- // itemList.push({type:'view',text:'查看名片'});
- this.touch_menulist = itemList;
- this.touch_menu = 0;
- var y = e.changedTouches[0].clientY + 50;
- var yy = "top";
- var xx = "left";
- var top = 0;
- var classname = "touch_menu";
- var len = itemList.length;
- if (y < 160) {
- yy = 'top'
- top = y - 10
- classname += ' top';
- } else {
- top = windowHeight - y + 85;
- yy = 'bottom';
- classname += ' bottom'
- }
- if (msg.sender.id == this.userid) {
- var xx = "right";
- //var x=windowWidth-x;
- classname += " right";
- } else classname += " left";
- this.touch_class = classname;
- this.touch_style = yy + ":" + top + "px";
- setTimeout(function() {
- that.touch_menu = true;
- }, 100)
- clearTimeout(this.touch_timer);
- this.touch_timer = setTimeout(function() {
- that.touch_menu = 0;
- }, 5000)
- },
- },
- watch: {
- messagelist(val) {
- console.log('消息改变',val)
- if (val.length > 0) {
- var last = val[val.length - 1];
- if (last.msg_id != this.lastmessage.msg_id) {
- //this.pagenum=0;
- // console.log(last);
- if (last.self == 1 && this.sendingdata._mid == last._mid || last.message.type == 'tips') {
- this.$emit('setSending', false);
- this.scrollToBottom();
- } else {
- if (this.isbottom == true) {
- this.scrollToBottom();
- } else {
- if (last.self != 1) {
- this.unreadnum++;
- if (this.unreadid == 0) this.unreadid = last.msg_id;
- }
- }
- }
- }
- this.lastmessage = last;
- } else {
- this.showmore = true;
- }
- var that = this;
- this.$store.commit('chat/clearunread', this.storeKey);
- // //创建后调用回到底部方法
- },
- sending(val) {
- if (val != false) {
- this.scrollToBottom();
- }
- }
- }
- }
- </script>
- <style lang="scss" scoped>
- $redpackBgColor: #EF9638;
- $reverseTextBgColor: #3388ff;
- $voiceBgColor: #fafafa;
- $voiceColor: #000;
- $reverseVoiceBgColor: #3388ff;
- $reverseVoiceColor: #fff;
- .chat-detail {
- width: 100%;
- padding: 0px 0px;
- position: fixed;
- z-index: 1;
- left: 0px;
- bottom: 60px;
- width: 100%;
- }
- .unread {
- position: fixed;
- z-index: 999s;
- right: 5px;
- bottom: 75px;
- height: 25px;
- line-height: 25px;
- padding: 0px 10px;
- border-radius: 10px;
- background-color: #eee;
- color: #333;
- font-size: 14px;
- clear: both;
- }
- .unread .num {
- color: #FF0000;
- padding: 0px 2px;
- display: inline-block;
- font-weight: 600;
- }
- .self_bottom {
- height: 10px;
- display: block;
- clear: both;
- margin-top: 10px;
- }
- .nodata {
- height: 30px;
- line-height: 30px;
- text-align: center;
- font-size: 12px;
- color: #ccc;
- }
- .vedioplay {
- position: fixed;
- z-index: 9999999999;
- background-color: #000;
- top: 0px;
- width: 100%;
- left: 0px;
- height: 100vh;
- line-height: calc(100vh - 45px);
- vertical-align: middle;
- display: table-cell;
- }
- .vedioplay video {
- vertical-align: middle;
- width: 100%;
- display: inline-block;
- height:90%;
- z-index: 99;
- }
- .vedioplay .bottom {
- position: absolute;
- z-index: 999;
- bottom: 10px;
- left: 0px;
- // background-color: red;
- width: 100%;
- height: 50px;
- line-height: 50px;
- color: #fff;
- text-align: center;
- }
- .vedioplay .bottom .icon1 {
- font-size: 36px !important;
- color: #eee !important;
- }
- .vedio {
- display: inline-block;
- float: left;
- width: calc(100% - 200upx);
- border-radius: 10upx;
- padding-top: 0upx;
- padding-bottom: 0upx;
- overflow: hidden;
- position: relative;
- z-index: 0;
- }
- .vedio .timeshow {
- position: absolute;
- right: 12upx;
- bottom: 16upx;
- font-size: 24upx;
- color: #FFFFFF;
- z-index: 999999999;
- }
- .vedio .play_btn {
- position: absolute;
- height: 80upx;
- width: 80upx;
- left: calc(50% - 40upx);
- top: calc(50% - 40upx);
- z-index: 999999999;
- }
- .vedio_src {
- max-width: 100%;
- border-radius: 10upx;
- max-height: 70vw;
- z-index: 0 !important;
- }
- .touch_menu {
- position: fixed;
- z-index: 9999;
- background-color: rgba(0, 0, 0, 0.8);
- border: 1px #000 solid;
- border-radius: 10px;
- padding: 0px 10px;
- line-height: 30px;
- max-width: 100%;
- font-size: 14px;
- min-height: 40px;
- }
- .touch_menu view {
- height: 45px;
- line-height: 45px;
- color: #fff;
- display: inline-block;
- padding: 0px 10px;
- text-align: center;
- border-right: 1px #999 solid;
- }
- .touch_menu view:last-child {
- border-width: 0px;
- ;
- }
- .touch_menu.right view {
- padding: 0px 15px;
- }
- .touch_menu::before {
- display: block;
- content: " ";
- position: absolute;
- width: 0;
- height: 0;
- border-style: solid;
- }
- .touch_menu.top::before {
- top: -12px;
- border-width: 0px 12px 12px 12px;
- border-color: #000 transparent;
- }
- .touch_menu.bottom::before {
- bottom: -24px;
- border-width: 12px;
- border-color: #000 transparent transparent transparent;
- }
- .touch_menu.left {
- text-align: left;
- left: 3px;
- }
- .touch_menu.right {
- text-align: right;
- right: 20px;
- }
- .touch_menu.left::before {
- left: 70px;
- }
- .touch_menu.right::before {
- right: 50px;
- }
- .first {
- width: 2px;
- height: 2px;
- background: #fff;
- top: 22px;
- left: 22px;
- }
- .second {
- width: 12px;
- height: 12px;
- top: 17px;
- left: 17px;
- }
- .third {
- width: 20px;
- height: 20px;
- top: 12px;
- left: 12px;
- }
- @keyframes fadeInOut {
- 0% {
- opacity: 0;
- }
- 100% {
- opacity: 1;
- }
- }
- /**/
- .loading {
- //loading动画
- display: flex;
- justify-content: center;
- @keyframes stretchdelay {
- 0%,
- 40%,
- 100% {
- transform: scaleY(0.6);
- }
- 20% {
- transform: scaleY(1.0);
- }
- }
- .spinner {
- margin: 20upx 0;
- width: 60upx;
- height: 25px;
- display: flex;
- align-items: center;
- justify-content: space-between;
- view {
- background-color: #ff9800;
- height: 25px;
- width: 3px;
- border-radius: 3px;
- animation: stretchdelay 1.2s infinite ease-in-out;
- }
- .rect2 {
- animation-delay: -1.1s;
- }
- .rect3 {
- animation-delay: -1.0s;
- }
- .rect4 {
- animation-delay: -0.9s;
- }
- .rect5 {
- animation-delay: -0.8s;
- }
- }
- }
- image {
- will-change: transform;
- }
- .loadingbox {
- height: 80upx;
- width: 70upx;
- justify-content: center;
- line-height: 80upx;
- display: inline-block;
- text-align: center;
- vertical-align: top;
- }
- .loadingbox image {
- height: 36upx;
- width: 36upx;
- vertical-align: middle;
- }
- </style>
|