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ACtC,IAAI,CAAC,aAAa,GAAG,CAAC,CAAC;YACvB,IAAI,CAAC,MAAM,GAAG,CAAC,GAAG,CAAC,CAAC,cAAc;SACnC;aAAM;YACL,IAAI,CAAC,aAAa,GAAG,CAAC,CAAC;YACvB,IAAI,CAAC,MAAM,GAAG,CAAC,SAAS,GAAG,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,qBAAqB;SAChF;QACD,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;YAC7B,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC;QAC/C,CAAC,CAAC,CAAC;IACL,CAAC;IAED,KAAK;QACH,IAAI,CAAC,OAAO,CAAC,EAAE,SAAS,EAAE,IAAI,CAAC,gBAAgB,EAAE,aAAa,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO;QAC7E,IAAI,CAAC,sBAAsB,GAAG,UAAU,CAAC,GAAG,EAAE;YAC5C,cAAc;YACd,IAAI,CAAC,sBAAsB,GAAG,CAAC,CAAC;YAEhC,IAAI,IAAI,CAAC,4BAA4B,EAAE;gBACrC,YAAY,CAAC,IAAI,CAAC,4BAA4B,CAAC,CAAC;gBAChD,IAAI,CAAC,4BAA4B,GAAG,CAAC,CAAC;aACvC;YAED,IAAI,CAAC,OAAO,CAAC,EAAE,aAAa,EAAE,CAAC,EAAE,CAAC,CAAC;YACnC,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC,CAAC,SAAS;QACnC,CAAC,EAAE,IAAI,CAAkB,CAAC;IAC5B,CAAC;CACF,CAAA;AApNoB,eAAe;IADnC,WAAW,EAAE;GACO,eAAe,CAoNnC;eApNoB,eAAe","file":"pull-down-refresh.js","sourcesContent":["/* eslint-disable dot-notation */\n/* eslint-disable prefer-destructuring */\nimport { SuperComponent, wxComponent } from '../common/src/index';\nimport config from '../common/config';\nimport props from './props';\n\nconst { prefix } = config;\nconst name = `${prefix}-pull-down-refresh`;\n\n@wxComponent()\nexport default class PullDownRefresh extends SuperComponent {\n isScrollToTop = true;\n\n pixelRatio = 1; // 像素比(rpx与px在此设备上的比值)\n\n startPoint: { pageX: number; pageY: number } | null = null; // 下拉开始的起点,主要用于计算下拉高度\n\n isPulling = false; // 是否下拉中\n\n defaultBarHeight = 0; // 下拉效果的默认高度\n\n maxBarHeight = 276; // 最大下拉高度,单位 rpx\n\n // 触发刷新的下拉高度,单位rpx\n // 松开时下拉高度大于这个值即会触发刷新,触发刷新后松开,会恢复到这个高度并保持,直到刷新结束\n loadingBarHeight = 200;\n\n refreshTimeout = 3000; // 刷新超时时间,超过没有回调刷新成功,会自动结束刷新动画。单位 ms\n\n /** 开始刷新 - 刷新成功/失败 最小间隔时间setTimeout句柄 */\n minRefreshTimeFlag = 0;\n\n /** 刷新成功/失败 - 关闭刷新动画 最小间隔时间setTimeout句柄 */\n minRefreshStatusShowTimeFlag = 0;\n\n /** 开始刷新 - 刷新成功/失败 最大间隔时间setTimeout句柄 */\n maxRefreshAnimateTimeFlag = 0;\n\n /** 关闭动画耗时setTimeout句柄 */\n closingAnimateTimeFlag = 0;\n\n externalClasses = ['t--class', 't-class-loading', 't-class-tex', 't-class-indicator'];\n\n options = {\n multipleSlots: true,\n };\n\n properties = props;\n\n data = {\n classPrefix: name,\n barHeight: this.defaultBarHeight,\n refreshStatus: 0, // 0-未开始,1释放可刷新,2-刷新中,3-刷新成功,4-结束中\n refreshTypes: ['not-start', 'wait-start', 'refreshing', 'success', 'finishing'],\n rotate: 0, // 旋转角度,refreshStatus为0、1时根据下拉距离动态计算得出\n };\n\n attached() {\n const systemInfo = wx.getSystemInfoSync();\n // 计算像素比\n this.screenWidth = systemInfo.screenWidth;\n this.pixelRatio = 750 / systemInfo.screenWidth;\n // 判断是否ios\n this.ios = !!(systemInfo.system.toLowerCase().search('ios') + 1);\n\n // 自定义拉下宽度\n const maxBarHeight = this.properties.maxBarHeight as any as number;\n if (maxBarHeight) {\n this.maxBarHeight = maxBarHeight;\n }\n const loadingBarHeight = this.properties.loadingBarHeight as any as number;\n if (loadingBarHeight) {\n this.loadingBarHeight = loadingBarHeight;\n }\n const refreshTimeout = this.properties.refreshTimeout as any as number;\n if (refreshTimeout) {\n this.refreshTimeout = refreshTimeout;\n }\n }\n\n detached() {\n this.cleanTimeFlag();\n }\n\n onPageScroll(e: WechatMiniprogram.Component.TrivialInstance) {\n const { scrollTop } = e;\n this.isScrollToTop = scrollTop === 0;\n }\n\n /** 清理timeout */\n cleanTimeFlag() {\n clearTimeout(this.minRefreshTimeFlag);\n clearTimeout(this.minRefreshStatusShowTimeFlag);\n clearTimeout(this.maxRefreshAnimateTimeFlag);\n clearTimeout(this.closingAnimateTimeFlag);\n }\n\n onTouchStart(e: WechatMiniprogram.Component.TrivialInstance) {\n // 如果页面没滚动到顶部,不做处理\n // 如果下拉效果没有结束,不做处理\n if (!this.isScrollToTop || this.isPulling) return;\n const { touches } = e;\n if (touches.length !== 1) return;\n const { pageX, pageY } = touches[0];\n this.startPoint = { pageX, pageY }; // 设置起点\n this.isPulling = true; // 进入下拉状态\n }\n\n onTouchMove(e: WechatMiniprogram.Component.TrivialInstance) {\n // 如果页面没滚到顶部,不做处理\n // 如果没有起点,不做处理\n if (!this.isScrollToTop || !this.startPoint) return;\n const { touches } = e;\n if (touches.length !== 1) return;\n const { pageY } = touches[0];\n const offset = pageY - this.startPoint.pageY;\n const barHeight = this.toRpx(offset);\n if (barHeight > 0) {\n if (barHeight > this.maxBarHeight) {\n // 限高\n this.setRefreshBarHeight(this.maxBarHeight);\n this.startPoint.pageY = pageY - this.toPx(this.maxBarHeight); // 限高的同时修正起点,避免触摸点上移时无效果\n } else {\n this.setRefreshBarHeight(barHeight);\n }\n }\n }\n\n onTouchEnd(e: WechatMiniprogram.Component.TrivialInstance) {\n // 如果没有起点,不做处理\n if (!this.startPoint) return;\n const { changedTouches } = e;\n if (changedTouches.length !== 1) return;\n const { pageY } = changedTouches[0];\n const barHeight = this.toRpx(pageY - this.startPoint.pageY);\n this.startPoint = null; // 清掉起点,之后将忽略touchMove、touchEnd事件\n // 松开时高度超过阈值则触发刷新\n if (barHeight > this.loadingBarHeight) {\n this.setData({\n barHeight: this.loadingBarHeight,\n rotate: 0,\n refreshStatus: 2,\n }); // 正在刷新\n const startTime = Date.now();\n const callback = () => {\n // 正在刷新效果至少持续1秒钟\n const remainTime = 1000 - (Date.now() - startTime);\n this.minRefreshTimeFlag = setTimeout(\n () => {\n // 清理自身timeout\n this.minRefreshTimeFlag = 0;\n // 如果还没超时\n if (this.maxRefreshAnimateTimeFlag) {\n // 清理超时setup\n clearTimeout(this.maxRefreshAnimateTimeFlag);\n this.maxRefreshAnimateTimeFlag = 0;\n\n // 执行成功状态展示\n this.setData({ refreshStatus: 3 }); // 刷新成功\n this.minRefreshStatusShowTimeFlag = setTimeout(() => {\n this.minRefreshStatusShowTimeFlag = 0;\n\n this.close();\n }, 1000) as any as number; // 刷新成功展示持续一段时间后再结束\n }\n },\n remainTime > 0 ? remainTime : 0,\n ) as any as number;\n };\n this.triggerEvent('refresh', { callback });\n this.maxRefreshAnimateTimeFlag = setTimeout(() => {\n // 清理自身timeout\n this.maxRefreshAnimateTimeFlag = 0;\n\n if (this.data.refreshStatus === 2) {\n // 超时回调\n this.triggerEvent('timeout');\n this.close(); // 超时仍未被回调,则直接结束下拉\n }\n }, this.refreshTimeout) as any as number;\n } else {\n this.close();\n }\n }\n\n toRpx(v: number) {\n return v * this.pixelRatio;\n }\n\n toPx(v: number) {\n return v / this.pixelRatio;\n }\n\n setRefreshBarHeight(barHeight: number): Promise {\n const data: Record = { barHeight };\n if (barHeight >= this.loadingBarHeight) {\n data.refreshStatus = 1;\n data.rotate = -720; // 大于正常高度后不再旋转\n } else {\n data.refreshStatus = 0;\n data.rotate = (barHeight / this.loadingBarHeight) * -720; // 小于正常高度时随下拉高度旋转720度\n }\n return new Promise((resolve) => {\n this.setData(data, () => resolve(barHeight));\n });\n }\n\n close() {\n this.setData({ barHeight: this.defaultBarHeight, refreshStatus: 4 }); // 结束下拉\n this.closingAnimateTimeFlag = setTimeout(() => {\n // 清理自身timeout\n this.closingAnimateTimeFlag = 0;\n\n if (this.minRefreshStatusShowTimeFlag) {\n clearTimeout(this.minRefreshStatusShowTimeFlag);\n this.minRefreshStatusShowTimeFlag = 0;\n }\n\n this.setData({ refreshStatus: 0 });\n this.isPulling = false; // 退出下拉状态\n }, 1000) as any as number;\n }\n}\n"]}