const template=` `; import {rand} from '../../util.js' export default { name: "Message", data: function () { return { imgFolder:'', //消息总数 total:0, activeName:'0', list:'', } }, created:function (){ this.imgFolder='/assets/img/'; }, mounted:function (){ this.getMessage(); }, props:{ }, template:template, methods:{ changeTabs:function (){ this.readMessage(); }, readMessage:function (msg=''){ //点击的时候之间阅读普通消息 let ids=[]; if(!msg){ this.list[parseInt(this.activeName)].list.forEach(res=>{ if(!res.action){ res.is_read=true; ids.push(res.id); } }); }else{ msg.is_read=true; ids.push(msg.id); } if(ids.length===0){ return; } Yunqi.ajax.post('ajax/message',{ids:ids},false,false).then(res=>{ this.countMessage(); }); }, //每5分钟执行一次 getMessage:function (){ Yunqi.ajax.get('ajax/message').then(res=>{ this.list=res; this.countMessage(); setTimeout(()=>{ this.getMessage(); },60*1000*5) }); }, showMessage:function (msg){ if(msg.action=='link'){ window.open(msg.url,"_blank"); } if(msg.action=='tab'){ Yunqi.api.addtabs(msg.options); } if(msg.action=='layer'){ Yunqi.api.open(msg.options); } this.readMessage(msg); }, countMessage:function (){ let r=0; this.list.forEach(tab=>{ tab.list.forEach(msg=>{ if(msg.is_read==undefined){ r++; } }); }); this.total=r; }, formateStyle:function (style){ return `color:var(--el-color-${style})`; }, formateTime:function(timestamp) { timestamp=(new Date(timestamp+':00')).getTime(); const now = new Date().getTime(); const seconds = Math.floor((now - timestamp) / 1000); let interval = Math.floor(seconds / 31536000); if (interval >= 1) { return `${interval}年前`; } interval = Math.floor(seconds / 2592000); if (interval >= 1) { return `${interval}月前`; } interval = Math.floor(seconds / 86400); if (interval >= 1) { return `${interval}天前`; } interval = Math.floor(seconds / 3600); if (interval >= 1) { return `${interval}小时前`; } interval = Math.floor(seconds / 60); if (interval >= 1) { return `${interval}分钟前`; } return `${Math.floor(seconds)}秒前`; } } };