- 电子药箱: 药品库存管理 + 手动录入 + 今日用药打卡 - 药品百科: 搜索 + 分类筛选 + 20种药品静态数据 - 惠教中心: 4条药品使用指南课程 - 我的: 家庭成员信息管理 - 自定义TabBar + navigation-bar组件 - SVG药品分类插图
1 line
9.4 KiB
JavaScript
1 line
9.4 KiB
JavaScript
"use strict";var _notification=require("../../utils/notification"),_dynamicEmoji=require("../../utils/dynamic-emoji"),_utils=require("../../utils/utils"),_times=require("../../utils/times"),ENTRY_DURATION=2500,GIFT_DURATION=3500,ANNOUNCEMENT_DURATION=5e3,CUSTOM_DURATION=2e3,DYNAMIC_EMOJI_DURATION=2e3,ANNOUNCEMENT_EXIT_DELAY=300,ANNOUNCEMENT_NEXT_DELAY=900,sliceNickname=function(i){var e=String(i||"");return e.length>10?"".concat(e.slice(0,10),"..."):e},getGiftInfo=function(i){var e;return(null==i||null===(e=i.Extra)||void 0===e?void 0:e.GiftRewardInfo)||(null==i?void 0:i.GiftRewardInfo)||{}},getGiftUser=function(i){var e;return(null==i||null===(e=i.Extra)||void 0===e?void 0:e.User)||(null==i?void 0:i.User)||{}},getEntryView=function(i,e){return{nickname:sliceNickname((null==i?void 0:i.Nickname)||(null==i?void 0:i.UserName)),levelMeta:e}},isNotificationMessageInDisplayWindow=function(i){var e=Number((null==i?void 0:i.SendTime)||0);return!e||e>(0,_times.getCurrentServerTimeSecond)()-60},getGiftView=function(i){var e,t=getGiftInfo(i),n=getGiftUser(i);return{id:(null==i?void 0:i.__id)||(null==i||null===(e=i.Common)||void 0===e?void 0:e.MsgId)||"".concat(Date.now()),nickname:sliceNickname(n.Nickname||(null==i?void 0:i.Nickname)||(null==i?void 0:i.UserName)),giftName:(0,_utils.getBySplit)(t.GiftName)||"礼物",giftImage:t.GiftImage||"",giftCount:t.GiftCount||1,isHighlight:"highlight"===t.GiftShowMode}},getAnnouncementView=function(i){switch(null==i?void 0:i.__type){case _notification.NOTIFICATION_SEND_TYPE.LOTTERY:return{type:"lottery",id:null==i?void 0:i.ID,content:"直播间发起了一场抽奖",actionText:"参与",iconSrc:"./assets/lottery-icon.svg",isCustom:!1};case _notification.NOTIFICATION_SEND_TYPE.LUCKMONEY:return{type:"luckymoney",id:(null==i?void 0:i.RedPacketID)||(null==i?void 0:i.ID),content:"主办方正在发送红包",actionText:"参与",iconSrc:"./assets/redpacket-icon.svg",isCustom:!1};case _notification.NOTIFICATION_SEND_TYPE.CUSTOM:return null!=i&&i.Content?{type:"custom",content:(null==i?void 0:i.Content)||"",actionText:"",iconSrc:"./assets/custom-message-icon.svg",isCustom:!0}:null;default:return null}};Component({properties:{sdkInstance:{type:Object,value:null},isLandscape:{type:Boolean,value:!1}},data:{isNotificationOpen:!0,entryVisible:!1,entry:null,giftVisible:!1,gifts:[],announcementVisible:!1,announcementExiting:!1,announcement:null,dynamicEmojiVisible:!1,dynamicEmoji:null,shouldRenderNotification:!1,isViewerLevelEnable:!1,viewerLevelMetas:[]},observers:{sdkInstance:function(i){var e=this;i&&(this.sdkInstance=i,this.store=i.store,"function"==typeof this.unsub&&this.unsub(),this.unsub=null,this.unsub=this.store.get({"notification.isNotificationOpen":function(i){e.setData({isNotificationOpen:!1!==i},function(){e.syncRenderState()})},"notification.queueCommentArea":function(){e.showNextCommentMessage()},"notification.queueAnnouncementArea":function(){e.showNextAnnouncementMessage()},"notification.queueDynamicEmojiArea":function(){e.showNextDynamicEmoji()},liveInfo:function(i){var t,n=(null==i||null===(t=i.Basic)||void 0===t?void 0:t.ViewerLevelConfig)||{};e.setData({isViewerLevelEnable:1===(null==n?void 0:n.IsViewerLevelEnable),viewerLevelMetas:(null==n?void 0:n.ViewerLevelMetas)||[]})}}))}},lifetimes:{detached:function(){"function"==typeof this.unsub&&this.unsub(),this.unsub=null,this.clearCommentTimer(),this.clearGiftTimers(),this.clearAnnouncementTimer(),this.clearDynamicEmojiTimer(),this.commentActive=!1,this.announcementActive=!1,this.dynamicEmojiActive=!1}},methods:{clearCommentTimer:function(){this.commentTimer&&(clearTimeout(this.commentTimer),this.commentTimer=null)},clearGiftTimers:function(){var i=this;Object.keys(this.giftTimers||{}).forEach(function(e){clearTimeout(i.giftTimers[e])}),this.giftTimers={}},clearAnnouncementTimer:function(){this.announcementTimer&&(clearTimeout(this.announcementTimer),this.announcementTimer=null),this.announcementNextTimer&&(clearTimeout(this.announcementNextTimer),this.announcementNextTimer=null)},clearDynamicEmojiTimer:function(){this.dynamicEmojiTimer&&(clearTimeout(this.dynamicEmojiTimer),this.dynamicEmojiTimer=null)},showNextNotificationMessage:function(){this.showNextCommentMessage(),this.showNextAnnouncementMessage(),this.showNextDynamicEmoji()},getLevelMeta:function(i){if(!this.data.isViewerLevelEnable||!i)return null;var e=String(i);return this.data.viewerLevelMetas.find(function(i){return String(i.LevelId)===e})||null},appendShowedId:function(i,e){if(this.store&&e){var t=this.store.get(i)||[];t.some(function(i){return String(i)===String(e)})||this.store.set(i,t.concat(e))}},startEntryMessageTimer:function(i){var e=this;this.appendShowedId("notification.idShowedCommentArea",i.__id),this.commentTimer=setTimeout(function(){e.setData({entryVisible:!1,entry:null},function(){e.syncRenderState()}),e.commentTimer=null,e.commentActive=!1,e.showNextNotificationMessage()},ENTRY_DURATION)},showNextCommentMessage:function(){var i=this;if(this.store&&!this.commentActive&&!this.data.entryVisible){var e=(this.store.get("notification.queueCommentArea")||[]).filter(isNotificationMessageInDisplayWindow),t=e[0];if(!((null==t?void 0:t.__type)===_notification.NOTIFICATION_SEND_TYPE.ENTRY&&(this.data.gifts||[]).length>0))if(this.commentActive=!0,this.store.set("notification.queueCommentArea",e.slice(1)),t)if(t.__type===_notification.NOTIFICATION_SEND_TYPE.ENTRY){var n=this.getLevelMeta(t.LevelId);this.setData({entryVisible:!0,entry:getEntryView(t,n)},function(){i.syncRenderState(function(){i.startEntryMessageTimer(t)})})}else t.__type===_notification.NOTIFICATION_SEND_TYPE.GIFT?(this.appendShowedId("notification.idShowedCommentArea",t.__id),this.appendGift(t),this.commentActive=!1,this.showNextNotificationMessage()):this.commentActive=!1;else this.commentActive=!1}},appendGift:function(i){var e=this,t=getGiftView(i),n=this.data.gifts||[],o=this.giftTimers||{};o[t.id]&&clearTimeout(o[t.id]);var s=n.filter(function(i){return i.id!==t.id}).concat(t).slice(-2);Object.keys(o).forEach(function(i){s.some(function(e){return String(e.id)===String(i)})||(clearTimeout(o[i]),delete o[i])}),this.giftTimers=o,this.setData({gifts:s,giftVisible:s.length>0},function(){e.syncRenderState()}),o[t.id]=setTimeout(function(){var i=(e.data.gifts||[]).filter(function(i){return i.id!==t.id});delete o[t.id],e.setData({gifts:i,giftVisible:i.length>0},function(){e.syncRenderState()}),e.showNextNotificationMessage()},GIFT_DURATION)},syncRenderState:function(i){var e,t=this.data.isNotificationOpen&&(this.data.entryVisible||(this.data.gifts||[]).length>0),n=this.data.announcementVisible&&(!(null!==(e=this.data.announcement)&&void 0!==e&&e.isCustom)||this.data.isNotificationOpen),o=this.data.isNotificationOpen&&this.data.dynamicEmojiVisible,s=!!(t||n||o);(0,_utils.setDataIfChanged)(this,{shouldRenderNotification:s},i)||null==i||i()},showNextDynamicEmoji:function(){var i=this;if(this.store&&!this.dynamicEmojiActive&&!this.data.dynamicEmojiVisible){var e=this.store.get("notification.queueDynamicEmojiArea")||[],t=e[0];if(this.dynamicEmojiActive=!0,this.store.set("notification.queueDynamicEmojiArea",e.slice(1)),t){this.appendShowedId("notification.idShowedDynamicEmojiArea",t.__id);var n=(0,_dynamicEmoji.normalizeDynamicEmojiToken)(t.token),o=(0,_dynamicEmoji.getDynamicEmojiView)(n);this.setData({dynamicEmojiVisible:!0,dynamicEmoji:o},function(){i.syncRenderState()}),this.dynamicEmojiTimer=setTimeout(function(){i.setData({dynamicEmojiVisible:!1,dynamicEmoji:null},function(){i.syncRenderState()}),i.dynamicEmojiTimer=null,i.dynamicEmojiActive=!1,i.showNextNotificationMessage()},DYNAMIC_EMOJI_DURATION)}else this.dynamicEmojiActive=!1}},showNextAnnouncementMessage:function(){var i=this;if(this.store&&!this.announcementActive&&!this.data.announcementVisible){var e=this.store.get("notification.idShowedAnnouncementArea")||[],t=(this.store.get("notification.queueAnnouncementArea")||[]).filter(function(i){return!e.some(function(e){return String(e)===String(i.ID)})}),n=t[0];if(this.announcementActive=!0,this.store.set("notification.queueAnnouncementArea",t.slice(1)),n){var o=getAnnouncementView(n);if(o){this.setData({announcementVisible:!0,announcementExiting:!1,announcement:o},function(){i.syncRenderState()});var s=n.__type===_notification.NOTIFICATION_SEND_TYPE.CUSTOM?CUSTOM_DURATION:ANNOUNCEMENT_DURATION;this.announcementTimer=setTimeout(function(){i.setData({announcementExiting:!0}),setTimeout(function(){i.store.set("notification.idShowedAnnouncementArea",e.concat(n.ID)),i.setData({announcementVisible:!1,announcementExiting:!1,announcement:null},function(){i.syncRenderState()}),i.announcementTimer=null,i.showNextNotificationMessage()},ANNOUNCEMENT_EXIT_DELAY)},s+ANNOUNCEMENT_EXIT_DELAY),this.announcementNextTimer=setTimeout(function(){i.announcementActive=!1,i.showNextAnnouncementMessage()},s+ANNOUNCEMENT_NEXT_DELAY)}else this.announcementActive=!1}else this.announcementActive=!1}},handleAnnouncementTap:function(){var i=this.data.announcement;if(i&&!i.isCustom&&this.isLogin(!0))if("lottery"!==i.type){if("luckymoney"===i.type){var e,t;if(!i.id)return;null===(e=this.sdkInstance)||void 0===e||null===(t=e.openLuckymoneyModal)||void 0===t||t.call(e,i.id)}}else{var n;if(!i.id)return;null===(n=this.store)||void 0===n||n.set("AwardInfo",{visible:!0,currentId:i.id})}},isLogin:function(){var i,e,t=arguments.length>0&&void 0!==arguments[0]&&arguments[0];return 2===((null===(i=this.store)||void 0===i||null===(e=i.get)||void 0===e?void 0:e.call(i,"mainInfo"))||{}).mode||(t&&this.triggerEvent("commentCheck"),!1)}}}); |