Files
ruo-shan-cloud-pharmacy/miniprogram/package-live/volc-mini-sdk/components/attention-detection/attention-detection.js
T
陈誉午 994b267f5c feat: 电子药箱小程序 - 4Tab药品管理
- 电子药箱: 药品库存管理 + 手动录入 + 今日用药打卡
- 药品百科: 搜索 + 分类筛选 + 20种药品静态数据
- 惠教中心: 4条药品使用指南课程
- 我的: 家庭成员信息管理
- 自定义TabBar + navigation-bar组件
- SVG药品分类插图
2026-07-29 11:20:52 +08:00

1 line
11 KiB
JavaScript

"use strict";var _DEFAULT_COPY,_constant=require("../../utils/constant"),_theme=require("../../utils/theme"),_utils=require("../../utils/utils");function _typeof(e){return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},_typeof(e)}function _defineProperty(e,t,i){return(t=_toPropertyKey(t))in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,e}function _toPropertyKey(e){var t=_toPrimitive(e,"string");return"symbol"===_typeof(t)?t:String(t)}function _toPrimitive(e,t){if("object"!==_typeof(e)||null===e)return e;var i=e[Symbol.toPrimitive];if(void 0!==i){var n=i.call(e,t||"default");if("object"!==_typeof(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}var DetectionType={BeforeWatching:1,CutScreen:2,MutedChange:3,NotInteraction:4,NotInteractionKickOut:5},DEFAULT_COPY=(_defineProperty(_DEFAULT_COPY={},DetectionType.BeforeWatching,"请认真观看直播内容"),_defineProperty(_DEFAULT_COPY,DetectionType.CutScreen,"请保持在当前直播间观看"),_defineProperty(_DEFAULT_COPY,DetectionType.MutedChange,"当前播放已暂停,请继续观看"),_defineProperty(_DEFAULT_COPY,DetectionType.NotInteraction,"请继续参与直播互动"),_defineProperty(_DEFAULT_COPY,DetectionType.NotInteractionKickOut,"长时间未互动,请点击继续观看"),_DEFAULT_COPY),PLAYER_CREATED_VIDEO_TYPES=["live","vod"],isOpen=function(e){return e&&1===Number(e.IsOpen)},isPlayerCreatedVideoType=function(e){return PLAYER_CREATED_VIDEO_TYPES.includes(e)},getConfigType=function(e){return Number(null==e?void 0:e.AttentionDetectionType)},getConfigCopy=function(e,t){return(null==e?void 0:e.ReminderCopy)||DEFAULT_COPY[t]},getConfigSignature=function(e){return JSON.stringify(Object.keys(e).sort().map(function(t){var i,n,o,a=e[t]||{};return{type:t,isOpen:1===Number(a.IsOpen),copy:a.ReminderCopy||"",minTime:Number(null!==(i=null!==(n=null==a||null===(o=a.DetectionRule)||void 0===o?void 0:o.MinTime)&&void 0!==n?n:null==a?void 0:a.MinTime)&&void 0!==i?i:0)}}))},getMinTimeMs=function(e){var t,i,n,o=Number(null!==(t=null!==(i=null==e||null===(n=e.DetectionRule)||void 0===n?void 0:n.MinTime)&&void 0!==i?i:null==e?void 0:e.MinTime)&&void 0!==t?t:0);return!Number.isFinite(o)||o<=0?0:1e3*o};Component({properties:{sdkInstance:{type:Object,value:null}},data:{dialogVisible:!1,dialogTitle:"温馨提示",dialogContent:"",useDarkTheme:!1},observers:{sdkInstance:function(e){var t=this;e&&(this.sdkInstance=e,this.store=e.store,"function"==typeof this.unsub&&this.unsub(),this.unsub=null,this.unsub=this.store.get({liveInfo:function(e){var i,n,o=(e||{}).Basic,a=void 0===o?{}:o,r=a.ActivityId||(null===(i=t.store)||void 0===i||null===(n=i.get)||void 0===n?void 0:n.call(i,"mainInfo.activityId"))||"";r&&r!==t.activityId&&(t.activityId=r,t.configSignature="",t.beforeWatchingShown=!1,t.hasPlayStarted=!1,t.activeDialogType=null,t.beforeWatchingPending=!1,t.noInteractionKickOutActive=!1,t.clearAllTimers());var s=(0,_theme.isUseDarkTheme)(a);(0,_utils.setDataIfChanged)(t,{useDarkTheme:s}),t.syncConfigs(a.AttentionDetectionConfigArray||[])},"reportInfo.isPlay":function(e){t.handlePlayStateChange(!!e)},"reportInfo.videoType":function(e){t.handlePlayerVideoTypeChange(e)},"ui.commentInitialRendered":function(e){t.handleCommentInitialRendered(!!e)}}))}},lifetimes:{attached:function(){var e,t,i;this.configMap={},this.configSignature="",this.beforeWatchingShown=!1,this.hasPlayStarted=!1,this.activeDialogType=null,this.beforeWatchingPending=!1,this.noInteractionKickOutActive=!1,this.timers={},this.isAppHidden=!1,this.isKeyboardVisible=!1,this.isPlayerCreated=!1,this.playerVideoType="",this._boundHandleAppHide=this.handleAppHide.bind(this),this._boundHandleAppShow=this.handleAppShow.bind(this),this._boundHandleKeyboardHeightChange=this.handleKeyboardHeightChange.bind(this),"function"==typeof(null===(e=wx)||void 0===e?void 0:e.onAppHide)&&wx.onAppHide(this._boundHandleAppHide),"function"==typeof(null===(t=wx)||void 0===t?void 0:t.onAppShow)&&wx.onAppShow(this._boundHandleAppShow),"function"==typeof(null===(i=wx)||void 0===i?void 0:i.onKeyboardHeightChange)&&wx.onKeyboardHeightChange(this._boundHandleKeyboardHeightChange)},detached:function(){var e,t,i;"function"==typeof this.unsub&&this.unsub(),this.unsub=null,"function"==typeof(null===(e=wx)||void 0===e?void 0:e.offAppHide)&&this._boundHandleAppHide&&wx.offAppHide(this._boundHandleAppHide),"function"==typeof(null===(t=wx)||void 0===t?void 0:t.offAppShow)&&this._boundHandleAppShow&&wx.offAppShow(this._boundHandleAppShow),"function"==typeof(null===(i=wx)||void 0===i?void 0:i.offKeyboardHeightChange)&&this._boundHandleKeyboardHeightChange&&wx.offKeyboardHeightChange(this._boundHandleKeyboardHeightChange),this.clearAllTimers()}},methods:{syncConfigs:function(e){var t,i,n={};e.forEach(function(e){var t=getConfigType(e);t&&(n[t]=e)});var o=getConfigSignature(n);o!==this.configSignature&&(this.configSignature=o,this.configMap=n,isOpen(n[DetectionType.BeforeWatching])||(this.beforeWatchingShown=!1,this.beforeWatchingPending=!1),isOpen(n[DetectionType.BeforeWatching])&&!this.beforeWatchingShown&&(this.beforeWatchingShown=!0,this.scheduleBeforeWatchingDialog()),this.resetInteractionTimer(),this.handlePlayStateChange(!(null===(t=this.store)||void 0===t||null===(i=t.get)||void 0===i||!i.call(t,"reportInfo.isPlay"))),this.syncKickOutStateWithConfig())},recordInteraction:function(){this.isPlayerCreated&&!this.isAppHidden&&this.hasPlayStarted&&this.resetInteractionTimer()},resetDetectionForPlayerDestroy:function(){this.hasPlayStarted=!1,this.pauseCausedByAppHide=!1,this.clearAllTimers(),this.data.dialogVisible&&this.activeDialogType!==DetectionType.BeforeWatching&&((0,_utils.setDataIfChanged)(this,{dialogVisible:!1}),this.activeDialogType=null)},handlePlayerVideoTypeChange:function(e){var t,i,n=e||"",o=isPlayerCreatedVideoType(n),a=this.isPlayerCreated,r=n!==this.playerVideoType;(r||a!==o)&&(a&&r&&this.resetDetectionForPlayerDestroy(),this.playerVideoType=n,this.isPlayerCreated=o,o?this.handlePlayStateChange(!(null===(t=this.store)||void 0===t||null===(i=t.get)||void 0===i||!i.call(t,"reportInfo.isPlay"))):a||this.clearAllTimers())},handlePlayStateChange:function(e){var t,i,n=this;if(!this.isPlayerCreated)return this.clearTimer("mutedChange"),this.clearTimer("notInteraction"),void this.clearTimer("notInteractionKickOut");if(e)return this.clearTimer("mutedChange"),this.hasPlayStarted=!0,this.pauseCausedByAppHide=!1,void this.resetInteractionTimer();var o=null===(t=this.configMap)||void 0===t?void 0:t[DetectionType.MutedChange];if(this.isAppHidden||this.pauseCausedByAppHide||!this.hasPlayStarted||!isOpen(o))return this.clearTimer("mutedChange"),void(this.mutedChangeTimerKey="");var a=getMinTimeMs(o);if(a){var r="".concat(a,"_").concat(getConfigCopy(o,DetectionType.MutedChange));null!==(i=this.timers)&&void 0!==i&&i.mutedChange&&this.mutedChangeTimerKey===r||(this.clearTimer("mutedChange"),this.mutedChangeTimerKey=r,this.startTimer("mutedChange",a,function(){n.mutedChangeTimerKey="",n.showDetectionDialog(DetectionType.MutedChange)}))}else this.clearTimer("mutedChange")},resetInteractionTimer:function(){var e,t,i=this;if(this.clearTimer("notInteraction"),this.clearTimer("notInteractionKickOut"),!this.isAppHidden&&!this.isKeyboardVisible&&this.hasPlayStarted){var n=null===(e=this.configMap)||void 0===e?void 0:e[DetectionType.NotInteraction],o=null===(t=this.configMap)||void 0===t?void 0:t[DetectionType.NotInteractionKickOut];isOpen(o)?this.startTimer("notInteractionKickOut",getMinTimeMs(o),function(){i.kickOutForNoInteraction()}):isOpen(n)&&this.startTimer("notInteraction",getMinTimeMs(n),function(){i.showDetectionDialog(DetectionType.NotInteraction)})}},startTimer:function(e,t,i){t&&(this.timers[e]=setTimeout(i,t))},clearTimer:function(e){var t;null!==(t=this.timers)&&void 0!==t&&t[e]&&(clearTimeout(this.timers[e]),this.timers[e]=null),"mutedChange"===e&&(this.mutedChangeTimerKey="")},clearAllTimers:function(){var e=this;Object.keys(this.timers||{}).forEach(function(t){return e.clearTimer(t)})},scheduleBeforeWatchingDialog:function(){var e,t;null!==(e=this.store)&&void 0!==e&&null!==(t=e.get)&&void 0!==t&&t.call(e,"ui.commentInitialRendered")?(this.beforeWatchingPending=!1,this.data.dialogVisible||this.showDetectionDialog(DetectionType.BeforeWatching)):this.beforeWatchingPending=!0},handleCommentInitialRendered:function(e){e&&this.beforeWatchingPending&&this.scheduleBeforeWatchingDialog()},handleAppHide:function(){var e,t;this.isAppHidden||(this.isAppHidden=!0,this.pauseCausedByAppHide=!(null===(e=this.store)||void 0===e||null===(t=e.get)||void 0===t||!t.call(e,"reportInfo.isPlay")),this.clearTimer("mutedChange"),this.clearTimer("notInteraction"),this.clearTimer("notInteractionKickOut"))},handleKeyboardHeightChange:function(){var e=Number((arguments.length>0&&void 0!==arguments[0]?arguments[0]:{}).height||0)>0;if(this.isKeyboardVisible!==e){if(this.isKeyboardVisible=e,e)return this.clearTimer("notInteraction"),void this.clearTimer("notInteractionKickOut");this.resetInteractionTimer()}},handleAppShow:function(){var e,t;this.isAppHidden&&(this.isAppHidden=!1,this.isPlayerCreated&&this.hasPlayStarted&&this.showDetectionDialog(DetectionType.CutScreen),this.resetInteractionTimer(),this.handlePlayStateChange(!(null===(e=this.store)||void 0===e||null===(t=e.get)||void 0===t||!t.call(e,"reportInfo.isPlay"))))},syncKickOutStateWithConfig:function(){var e,t,i,n=null===(e=this.configMap)||void 0===e?void 0:e[DetectionType.NotInteractionKickOut];if(!isOpen(n)){var o,a,r=(null===(t=this.store)||void 0===t||null===(i=t.get)||void 0===i?void 0:i.call(t,"banStatus"))||{};this.noInteractionKickOutActive&&r.isSoftBan&&r.banType===_constant.BAN_TYPE.KICK_OUT&&"noInteraction"===r._attentionDetectionSource&&(this.noInteractionKickOutActive=!1,null===(o=this.store)||void 0===o||null===(a=o.set)||void 0===a||a.call(o,"banStatus",{isBanned:!1,isSoftBan:!1,banType:_constant.BAN_TYPE.NONE,banTips:""}))}},showDetectionDialog:function(e){var t;if(e===DetectionType.BeforeWatching||this.isPlayerCreated){var i=null===(t=this.configMap)||void 0===t?void 0:t[e];isOpen(i)&&(this.activeDialogType=e,this.setData({dialogVisible:!0,dialogContent:getConfigCopy(i,e)}))}},onDialogButtonTap:function(){var e,t,i=this.activeDialogType;this.setData({dialogVisible:!1}),this.activeDialogType=null,this.resetInteractionTimer(),i===DetectionType.MutedChange&&this.handlePlayStateChange(!(null===(e=this.store)||void 0===e||null===(t=e.get)||void 0===t||!t.call(e,"reportInfo.isPlay")))},kickOutForNoInteraction:function(){var e,t,i,n=null===(e=this.configMap)||void 0===e?void 0:e[DetectionType.NotInteractionKickOut];isOpen(n)&&(this.noInteractionKickOutActive=!0,null===(t=this.store)||void 0===t||null===(i=t.set)||void 0===i||i.call(t,"banStatus",{isBanned:!0,isSoftBan:!0,banType:_constant.BAN_TYPE.KICK_OUT,banTips:n.ReminderCopy||DEFAULT_COPY[DetectionType.NotInteractionKickOut],_attentionDetectionSource:"noInteraction"}))}}});