| | |
| | | import config from '../common/config'; |
| | | import props from './props'; |
| | | import { getRect } from '../common/utils'; |
| | | import { getObserver } from '../common/wechat'; |
| | | let ARRAY = []; |
| | | const { prefix } = config; |
| | | const name = `${prefix}-swipe-cell`; |
| | |
| | | closed: true, |
| | | classPrefix: name, |
| | | }; |
| | | } |
| | | attached() { |
| | | ARRAY.push(this); |
| | | } |
| | | ready() { |
| | | this.setSwipeWidth(); |
| | | this.observers = { |
| | | 'left, right'() { |
| | | this.setSwipeWidth(); |
| | | }, |
| | | }; |
| | | this.lifetimes = { |
| | | attached() { |
| | | ARRAY.push(this); |
| | | }, |
| | | ready() { |
| | | this.setSwipeWidth(); |
| | | }, |
| | | detached() { |
| | | ARRAY = ARRAY.filter((item) => item !== this); |
| | | }, |
| | | }; |
| | | } |
| | | setSwipeWidth() { |
| | | Promise.all([getRect(this, `${ContainerClass}__left`), getRect(this, `${ContainerClass}__right`)]).then(([leftRect, rightRect]) => { |
| | | if (leftRect.width === 0 && rightRect.width === 0 && !this._hasObserved) { |
| | | this._hasObserved = true; |
| | | getObserver(this, `.${name}`).then(() => { |
| | | this.setSwipeWidth(); |
| | | }); |
| | | } |
| | | this.setData({ |
| | | leftWidth: leftRect.width, |
| | | rightWidth: rightRect.width, |
| | | }); |
| | | }); |
| | | } |
| | | detached() { |
| | | ARRAY = ARRAY.filter((item) => item !== this); |
| | | } |
| | | open() { |
| | | this.setData({ opened: true }); |