From 00a96d6881dd10ae7d3c4f5437bfceaabe677723 Mon Sep 17 00:00:00 2001 From: riku <risaku@163.com> Date: 星期四, 14 十一月 2024 10:55:29 +0800 Subject: [PATCH] bug修复 --- miniprogram_npm/tdesign-miniprogram/checkbox-group/checkbox-group.js | 33 ++++++++++++++++++++------------- 1 files changed, 20 insertions(+), 13 deletions(-) diff --git a/miniprogram_npm/tdesign-miniprogram/checkbox-group/checkbox-group.js b/miniprogram_npm/tdesign-miniprogram/checkbox-group/checkbox-group.js index 9d76a0c..8a4d520 100644 --- a/miniprogram_npm/tdesign-miniprogram/checkbox-group/checkbox-group.js +++ b/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, -- Gitblit v1.9.3