From 5a678cce1b157411f20fbddfaed49c7bc8d9fba7 Mon Sep 17 00:00:00 2001
From: riku <risaku@163.com>
Date: 星期四, 07 十一月 2024 17:03:13 +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