| | |
| | | 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 = { |
| | |
| | | ]; |
| | | this.$checkAll = null; |
| | | this.methods = { |
| | | getChilds() { |
| | | getChildren() { |
| | | let items = this.$children; |
| | | if (!items.length) { |
| | | items = this.selectAllComponents(`.${prefix}-checkbox-option`); |
| | |
| | | return items || []; |
| | | }, |
| | | updateChildren() { |
| | | const items = this.getChilds(); |
| | | const items = this.getChildren(); |
| | | const { value } = this.data; |
| | | if (items.length > 0) { |
| | | items.forEach((item) => { |
| | |
| | | } |
| | | } |
| | | }, |
| | | 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 |
| | |
| | | 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; |
| | |
| | | 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, |