city-casereport/miniprogram_npm/tdesign-miniprogram/checkbox/checkbox.js
2023-12-06 14:22:42 +08:00

86 lines
3.2 KiB
JavaScript

var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
import { SuperComponent, wxComponent } from '../common/src/index';
import config from '../common/config';
import Props from './props';
const { prefix } = config;
const name = `${prefix}-checkbox`;
let CheckBox = class CheckBox extends SuperComponent {
constructor() {
super(...arguments);
this.externalClasses = [
`${prefix}-class`,
`${prefix}-class-label`,
`${prefix}-class-icon`,
`${prefix}-class-content`,
`${prefix}-class-border`,
];
this.behaviors = ['wx://form-field'];
this.relations = {
'../checkbox-group/checkbox-group': {
type: 'ancestor',
linked(parent) {
const { value, disabled, borderless } = parent.data;
const valueSet = new Set(value);
const data = {
disabled: this.data.disabled == null ? disabled : this.data.disabled,
};
if (borderless) {
data.borderless = true;
}
data.checked = valueSet.has(this.data.value);
if (this.data.checkAll) {
data.checked = valueSet.size > 0;
}
this.setData(data);
},
},
};
this.options = {
multipleSlots: true,
};
this.properties = Object.assign(Object.assign({}, Props), { theme: {
type: String,
value: 'default',
} });
this.data = {
prefix,
classPrefix: name,
};
this.controlledProps = [
{
key: 'checked',
event: 'change',
},
];
this.methods = {
handleTap(e) {
const { disabled, readonly } = this.data;
if (disabled || readonly)
return;
const { target } = e.currentTarget.dataset;
const { contentDisabled } = this.data;
if (target === 'text' && contentDisabled) {
return;
}
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 });
}
},
};
}
};
CheckBox = __decorate([
wxComponent()
], CheckBox);
export default CheckBox;