riku
2024-11-07 5a678cce1b157411f20fbddfaed49c7bc8d9fba7
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 });