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

1 line
5.2 KiB
JavaScript

"use strict";var _thumbService=_interopRequireDefault(require("../../../services/thumb-service")),_likeAnimation=require("./like-animation");function _interopRequireDefault(t){return t&&t.__esModule?t:{default:t}}Component({properties:{enable:{type:Boolean,value:!0}},data:{isThumbUpEnable:!1,thumbUpEffectUrls:[],canvasVisible:!1},lifetimes:{attached:function(){this._onConfigChange=this.onConfigChange.bind(this),_thumbService.default.on("onConfigChange",this._onConfigChange),this.updateConfig(_thumbService.default.config),this.lastTapTime=0,this.lastTapPoint=null,this.comboLikeUntil=0,this.lastClickTime=0,this.animations=[],this.animating=!1,this.pendingAnimationPoints=[],this.touchStartPoint=null,this.touchMoved=!1,this.wrapperRect=null,this.config={duration:500,stopTime:100},this.tapMoveThreshold=12,this.doubleTapDistanceThreshold=32,this.comboLikeDuration=220},ready:function(){this.measureWrapperRect()},detached:function(){_thumbService.default.off("onConfigChange",this._onConfigChange)}},methods:{measureWrapperRect:function(){var t=this;this.createSelectorQuery().select("#doubleTapLikeWrapper").boundingClientRect(function(i){t.wrapperRect=i||null}).exec()},onConfigChange:function(t){this.updateConfig(t)},updateConfig:function(t){var i=this;if(t){var n={};void 0!==t.isThumbUpEnable&&(n.isThumbUpEnable=!!t.isThumbUpEnable),t.thumbUpEffectUrls&&(n.thumbUpEffectUrls=t.thumbUpEffectUrls),this.setData(n,function(){i.data.isThumbUpEnable||i.clearCanvasState()})}},clearCanvasState:function(){this.canvas=null,this.ctx=null,this.width=0,this.height=0,this.pendingAnimationPoints=[],this.setData({canvasVisible:!1})},initCanvas:function(){var t=this,i=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;this.createSelectorQuery().select("#likeCanvas").fields({node:!0,size:!0}).exec(function(n){if(n[0]){var e=n[0].node,a=n[0].width,s=n[0].height,h=wx.getSystemInfoSync().pixelRatio;e.width=a*h,e.height=s*h,t.ctx=e.getContext("2d"),t.ctx.scale(h,h),t.canvas=e,t.width=a,t.height=s,t.flushPendingAnimations(),console.log("Double-tap like canvas initialized:",{width:a,height:s,dpr:h})}else i<5?setTimeout(function(){t.initCanvas(i+1)},500):console.warn("Failed to initialize double-tap like canvas after 5 retries")})},ensureCanvasReady:function(t){var i=this;t&&this.pendingAnimationPoints.push(t),this.canvas?this.flushPendingAnimations():this.data.canvasVisible||this.setData({canvasVisible:!0},function(){i.measureWrapperRect(),i.initCanvas()})},flushPendingAnimations:function(){var t=this;this.canvas&&this.pendingAnimationPoints.length&&this.pendingAnimationPoints.splice(0,this.pendingAnimationPoints.length).forEach(function(i){return t._addAnimation(i.x,i.y)})},handleTouchStart:function(t){var i,n=null===(i=t.touches)||void 0===i?void 0:i[0];if(!n)return this.touchStartPoint=null,void(this.touchMoved=!1);this.touchStartPoint={pageX:n.pageX,pageY:n.pageY},this.touchMoved=!1},handleTouchMove:function(t){var i;if(this.touchStartPoint){var n=null===(i=t.touches)||void 0===i?void 0:i[0];if(n){var e=Math.abs(n.pageX-this.touchStartPoint.pageX),a=Math.abs(n.pageY-this.touchStartPoint.pageY);(e>this.tapMoveThreshold||a>this.tapMoveThreshold)&&(this.touchMoved=!0)}}},handleTouchEnd:function(t){var i;if(!this.data.isThumbUpEnable||!this.properties.enable)return this.touchStartPoint=null,void(this.touchMoved=!1);if(this.touchMoved)return this.touchStartPoint=null,void(this.touchMoved=!1);var n=null===(i=t.changedTouches)||void 0===i?void 0:i[0];if(!n)return this.touchStartPoint=null,void(this.touchMoved=!1);var e=Date.now(),a=e-this.lastTapTime,s=this.getRelativePoint(n),h=this.isSameTapArea(s,this.lastTapPoint);e<=this.comboLikeUntil&&h?(this.triggerLike(s),this.comboLikeUntil=e+this.comboLikeDuration):a<300&&h?(this.triggerLike(s),this.comboLikeUntil=e+this.comboLikeDuration,this.lastTapTime=e,this.lastTapPoint=s):(this.comboLikeUntil=0,this.lastTapTime=e,this.lastTapPoint=s),this.touchStartPoint=null,this.touchMoved=!1},handleTouchCancel:function(){this.touchStartPoint=null,this.touchMoved=!1},getRelativePoint:function(t){var i=this.wrapperRect;return i?{x:t.pageX-i.left,y:t.pageY-i.top}:{x:t.pageX,y:t.pageY}},isSameTapArea:function(t,i){return!(!t||!i)&&Math.abs(t.x-i.x)<=this.doubleTapDistanceThreshold&&Math.abs(t.y-i.y)<=this.doubleTapDistanceThreshold},triggerLike:function(t){var i=Date.now();this.lastClickTime>0&&i-this.lastClickTime<this.config.stopTime||(this.lastClickTime=i,_thumbService.default.addLike()&&(this.addAnimation(t.x,t.y),wx.vibrateShort({type:"light"}).catch(function(){})))},addAnimation:function(t,i){this.canvas?this._addAnimation(t,i):this.ensureCanvasReady({x:t,y:i})},_addAnimation:function(t,i){if(this.canvas){var n=new _likeAnimation.LikeAnimation(t,i,this.canvas,this.data.thumbUpEffectUrls);this.animations.push(n),this.animating||(this.animating=!0,this.animate())}},animate:function(){var t=this;if(0===this.animations.length)return this.animating=!1,this.ctx&&this.ctx.clearRect(0,0,this.width,this.height),void this.clearCanvasState();this.ctx&&(this.ctx.clearRect(0,0,this.width,this.height),this.animations=this.animations.filter(function(t){return t.update()}),this.animations.forEach(function(i){return i.draw(t.ctx)})),this.canvas.requestAnimationFrame(function(){return t.animate()})}}});