From f2a0ea849099f49a3d2a9c7e5c44d033df22468f Mon Sep 17 00:00:00 2001 From: riku <risaku@163.com> Date: 星期三, 14 八月 2024 14:55:38 +0800 Subject: [PATCH] 设备管理模块 --- miniprogram_npm/tdesign-miniprogram/swipe-cell/swipe-cell.js | 32 +++++++++++++++++++++++--------- 1 files changed, 23 insertions(+), 9 deletions(-) diff --git a/miniprogram_npm/tdesign-miniprogram/swipe-cell/swipe-cell.js b/miniprogram_npm/tdesign-miniprogram/swipe-cell/swipe-cell.js index f785d95..b7f12e5 100644 --- a/miniprogram_npm/tdesign-miniprogram/swipe-cell/swipe-cell.js +++ b/miniprogram_npm/tdesign-miniprogram/swipe-cell/swipe-cell.js @@ -8,6 +8,7 @@ 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`; @@ -26,23 +27,36 @@ 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 }); -- Gitblit v1.9.3