riku
2025-04-27 f46786f11c5c08ead7501a82e5a71430ad69b782
miniprogram_npm/tdesign-miniprogram/checkbox-group/checkbox-group.js
@@ -23,16 +23,23 @@
            classPrefix: name,
            checkboxOptions: [],
        };
        this.properties = Object.assign(Object.assign({}, props), { borderless: {
                type: Boolean,
                value: false,
            } });
        this.properties = props;
        this.observers = {
            value() {
                this.updateChildren();
            },
            options() {
                this.initWithOptions();
            },
            disabled(v) {
                var _a;
                if ((_a = this.data.options) === null || _a === void 0 ? void 0 : _a.length) {
                    this.initWithOptions();
                    return;
                }
                this.getChildren().forEach((item) => {
                    item.setDisabled(v);
                });
            },
        };
        this.lifetimes = {
@@ -48,7 +55,7 @@
        ];
        this.$checkAll = null;
        this.methods = {
            getChilds() {
            getChildren() {
                let items = this.$children;
                if (!items.length) {
                    items = this.selectAllComponents(`.${prefix}-checkbox-option`);
@@ -56,7 +63,7 @@
                return items || [];
            },
            updateChildren() {
                const items = this.getChilds();
                const items = this.getChildren();
                const { value } = this.data;
                if (items.length > 0) {
                    items.forEach((item) => {
@@ -70,15 +77,15 @@
                    }
                }
            },
            updateValue({ value, checked, checkAll, indeterminate }) {
            updateValue({ value, checked, checkAll, item, indeterminate }) {
                let { value: newValue } = this.data;
                const { max } = this.data;
                const keySet = new Set(this.getChilds().map((item) => item.data.value));
                const keySet = new Set(this.getChildren().map((item) => item.data.value));
                newValue = newValue.filter((value) => keySet.has(value));
                if (max && checked && newValue.length === max)
                    return;
                if (checkAll) {
                    const items = this.getChilds();
                    const items = this.getChildren();
                    newValue =
                        !checked && indeterminate
                            ? items
@@ -100,7 +107,7 @@
                    const index = newValue.findIndex((v) => v === value);
                    newValue.splice(index, 1);
                }
                this._trigger('change', { value: newValue });
                this._trigger('change', { value: newValue, context: item });
            },
            initWithOptions() {
                const { options, value } = this.data;
@@ -128,17 +135,17 @@
                if (item.checkAll) {
                    rect.indeterminate = (_a = this.$checkAll) === null || _a === void 0 ? void 0 : _a.data.indeterminate;
                }
                this.updateValue(Object.assign(Object.assign(Object.assign({}, item), { checked }), rect));
                this.updateValue(Object.assign(Object.assign(Object.assign({}, item), { checked, item }), rect));
            },
            setCheckall() {
                const items = this.getChilds();
                const items = this.getChildren();
                if (!this.$checkAll) {
                    this.$checkAll = items.find((item) => item.data.checkAll);
                }
                if (!this.$checkAll)
                    return;
                const { value } = this.data;
                const valueSet = new Set(value.filter((val) => val !== this.$checkAll.data.value));
                const valueSet = new Set(value === null || value === void 0 ? void 0 : value.filter((val) => val !== this.$checkAll.data.value));
                const isCheckall = items.every((item) => (item.data.checkAll ? true : valueSet.has(item.data.value)));
                this.$checkAll.setData({
                    checked: valueSet.size > 0,