Skip to content

Commit

Permalink
fix: delayQuerySelector 改版
Browse files Browse the repository at this point in the history
  • Loading branch information
jimczj committed Dec 27, 2018
1 parent 08afad3 commit 4436f17
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
8 changes: 5 additions & 3 deletions src/common/utils.ts
Original file line number Diff line number Diff line change
@@ -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<null> {
return new Promise(resolve => {
if (Taro.getEnv() === Taro.ENV_TYPE.WEB) {
if (ENV === Taro.ENV_TYPE.WEB) {
setTimeout(() => {
resolve()
}, REM_LAYOUT_DELAY)
Expand All @@ -16,9 +17,10 @@ function delay (): Promise<null> {
}

function delayQuerySelector (
$scope,
self,
selectorStr: string
): Promise<Array<execObject>> {
const $scope = ENV === Taro.ENV_TYPE.WEB ? self : self.$scope
const selector: SelectorQuery = Taro.createSelectorQuery().in($scope)

return new Promise(resolve => {
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/components/calendar/body/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/swipe-action/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion src/components/swipe-action/options/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down

0 comments on commit 4436f17

Please sign in to comment.