diff --git a/src/common/utils.ts b/src/common/utils.ts index 975d11a4d..31c8c8e09 100644 --- a/src/common/utils.ts +++ b/src/common/utils.ts @@ -1,11 +1,12 @@ import Taro from '@tarojs/taro' import { execObject, SelectorQuery } from '@tarojs/taro/types/index' +const ENV = Taro.getEnv() const REM_LAYOUT_DELAY: number = 500 function delay (): Promise { return new Promise(resolve => { - if (Taro.getEnv() === Taro.ENV_TYPE.WEB) { + if (ENV === Taro.ENV_TYPE.WEB) { setTimeout(() => { resolve() }, REM_LAYOUT_DELAY) @@ -16,9 +17,10 @@ function delay (): Promise { } function delayQuerySelector ( - $scope, + self, selectorStr: string ): Promise> { + const $scope = ENV === Taro.ENV_TYPE.WEB ? self : self.$scope const selector: SelectorQuery = Taro.createSelectorQuery().in($scope) return new Promise(resolve => { @@ -38,7 +40,7 @@ function uuid ( radix = 16 ): string { - var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split('') + var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split('') var uuid: string[] = [] var i = 0 radix = radix || chars.length diff --git a/src/components/calendar/body/index.tsx b/src/components/calendar/body/index.tsx index 4f26d3099..65382d3c1 100644 --- a/src/components/calendar/body/index.tsx +++ b/src/components/calendar/body/index.tsx @@ -139,7 +139,7 @@ export default class AtCalendarBody extends Taro.Component< } componentDidMount () { - delayQuerySelector(this.$scope, '.at-calendar-slider__main').then(res => { + delayQuerySelector(this, '.at-calendar-slider__main').then(res => { this.maxWidth = res[0].width }) } diff --git a/src/components/swipe-action/index.js b/src/components/swipe-action/index.js index e9ad25f3b..601ae438e 100644 --- a/src/components/swipe-action/index.js +++ b/src/components/swipe-action/index.js @@ -35,7 +35,7 @@ export default class AtSwipeAction extends AtComponent { componentDidMount () { delayQuerySelector( - Taro.getEnv() === Taro.ENV_TYPE.WEB ? this : this.$scope, + this, `#swipeAction-${this.state.componentId}` ).then(res => { this.domInfo = res[0] diff --git a/src/components/swipe-action/options/index.js b/src/components/swipe-action/options/index.js index 278f9e32e..ef730a12a 100644 --- a/src/components/swipe-action/options/index.js +++ b/src/components/swipe-action/options/index.js @@ -7,7 +7,7 @@ import { delayQuerySelector } from '../../../common/utils' export default class AtSwiperActionOptions extends AtComponent { componentDidMount () { delayQuerySelector( - Taro.getEnv() === Taro.ENV_TYPE.WEB ? this : this.$scope, + this, `#swipeActionOptions-${this.props.componentId}` ).then(res => { this.props.onQueryedDom(res[0])