riku
2024-11-07 5036880fc037e5d112206b93a729f60be12bf8ab
miniprogram_npm/tdesign-miniprogram/checkbox/checkbox.js
@@ -26,13 +26,17 @@
                linked(parent) {
                    const { value, disabled, borderless } = parent.data;
                    const valueSet = new Set(value);
                    const checkedFromParent = valueSet.has(this.data.value);
                    const data = {
                        disabled: disabled || this.data.disabled,
                        _disabled: this.data.disabled == null ? disabled : this.data.disabled,
                    };
                    if (borderless) {
                        data.borderless = true;
                    }
                    data.checked = valueSet.has(this.data.value);
                    data.checked = this.data.checked || checkedFromParent;
                    if (this.data.checked) {
                        parent.updateValue(this.data);
                    }
                    if (this.data.checkAll) {
                        data.checked = valueSet.size > 0;
                    }
@@ -46,13 +50,16 @@
        this.properties = Object.assign(Object.assign({}, Props), { theme: {
                type: String,
                value: 'default',
            }, borderless: {
                type: Boolean,
                value: false,
            } });
        this.data = {
            prefix,
            classPrefix: name,
            _disabled: false,
        };
        this.observers = {
            disabled(v) {
                this.setData({ _disabled: v });
            },
        };
        this.controlledProps = [
            {
@@ -61,24 +68,26 @@
            },
        ];
        this.methods = {
            onChange(e) {
                const { disabled, readonly } = this.data;
                if (disabled || readonly)
                    return;
            handleTap(e) {
                const { _disabled, readonly, contentDisabled } = this.data;
                const { target } = e.currentTarget.dataset;
                const { contentDisabled } = this.data;
                if (target === 'text' && contentDisabled) {
                if (_disabled || readonly || (target === 'text' && contentDisabled))
                    return;
                }
                const { value, label } = this.data;
                const checked = !this.data.checked;
                const parent = this.$parent;
                if (parent) {
                    parent.updateValue(Object.assign(Object.assign({}, this.data), { checked }));
                }
                else {
                    this._trigger('change', { checked });
                    this._trigger('change', { context: { value, label }, checked });
                }
            },
            setDisabled(disabled) {
                this.setData({
                    _disabled: this.data.disabled || disabled,
                });
            },
        };
    }
};