tdesign-vue
Version:
192 lines (188 loc) • 7.31 kB
JavaScript
/**
* tdesign v1.12.1
* (c) 2025 tdesign
* @license MIT
*/
import { h as helper } from '../_chunks/dep-323b993c.js';
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
import _typeof from '@babel/runtime/helpers/typeof';
import { defineComponent, toRefs, computed } from '@vue/composition-api';
import { intersection } from 'lodash-es';
import { Checkbox, CheckboxGroup } from '../checkbox/index.js';
import '../hooks/index.js';
import { usePrefixClass } from '../hooks/useConfig.js';
import '../checkbox/group.js';
import '@babel/runtime/helpers/slicedToArray';
import '../utils/helper.js';
import '@babel/runtime/helpers/objectWithoutProperties';
import '../checkbox/checkbox.js';
import '../checkbox/props.js';
import '../checkbox/constants.js';
import '../checkbox/store.js';
import '@babel/runtime/helpers/classCallCheck';
import '@babel/runtime/helpers/createClass';
import '../checkbox/hooks/useKeyboardEvent.js';
import '../_common/js/common.js';
import '../hooks/useVModel.js';
import '../hooks/useFormDisabled.js';
import '../hooks/useElementLazyRender.js';
import '../_common/js/utils/observe.js';
import '../utils/render-tnode.js';
import '@babel/runtime/helpers/readOnlyError';
import 'vue';
import '../hooks/slots.js';
import '../hooks/useCommonClassName.js';
import '../config-provider/useConfig.js';
import '../config-provider/context.js';
import '../_common/js/global-config/default-config.js';
import '../_common/js/global-config/locale/zh_CN.js';
import '../_chunks/dep-c44a474d.js';
import '../_chunks/dep-d639fbd7.js';
import 'dayjs';
import '../_chunks/dep-3c66615e.js';
import '../config-provider/type.js';
import '../_common/js/global-config/t.js';
import '../hooks/useDefaultValue.js';
import '../hooks/useDestroyOnClose.js';
import '../hooks/useGlobalIcon.js';
import '../hooks/useLazyLoad.js';
import '../hooks/useResizeObserver.js';
import '../hooks/useVirtualScrollNew.js';
import '../hooks/useImagePreviewUrl.js';
import '../_common/js/upload/utils.js';
import '../_common/js/log/log.js';
import '../checkbox/checkbox-group-props.js';
import '../utils/withInstall.js';
import './style/css.js';
import '../checkbox/type.js';
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
var ColumnCheckboxGroup = defineComponent({
name: "ColumnCheckboxGroup",
props: {
checkboxProps: Object,
options: {
type: Array,
"default": function _default() {
return [];
}
},
label: String,
uniqueKey: String,
value: Array,
onChange: Function
},
setup: function setup(props, context) {
var _toRefs = toRefs(props),
value = _toRefs.value,
options = _toRefs.options;
var classPrefix = usePrefixClass();
var allCheckedColumnKeys = computed(function () {
var allCheckedKeys = [];
options.value.forEach(function (option) {
if (_typeof(option) === "object") {
if (option.disabled) return;
if (option.value) {
allCheckedKeys.push(option.value);
} else if (typeof option.label === "string") {
allCheckedKeys.push(option.label);
}
} else {
allCheckedKeys.push(option);
}
});
return allCheckedKeys;
});
var intersectionKeys = computed(function () {
return intersection(allCheckedColumnKeys.value, value.value);
});
var isCheckedAll = computed(function () {
var len = intersectionKeys.value.length;
return Boolean(len && allCheckedColumnKeys.value.length === len);
});
var isIndeterminate = computed(function () {
var len = intersectionKeys.value.length;
return Boolean(len < allCheckedColumnKeys.value.length && len);
});
var onCheckAllColumnsChange = function onCheckAllColumnsChange(checkAll, ctx) {
var changeParams = {
e: ctx.e,
type: "check",
current: void 0,
option: void 0
};
if (checkAll) {
var _props$onChange;
var newKeys = _toConsumableArray(new Set(value.value.concat(allCheckedColumnKeys.value)));
(_props$onChange = props.onChange) === null || _props$onChange === void 0 || _props$onChange.call(props, newKeys, changeParams);
context.emit("change", newKeys, changeParams);
} else {
var _props$onChange2;
var _newKeys = value.value.filter(function (val) {
return !allCheckedColumnKeys.value.includes(val);
});
(_props$onChange2 = props.onChange) === null || _props$onChange2 === void 0 || _props$onChange2.call(props, _newKeys, _objectSpread(_objectSpread({}, changeParams), {}, {
type: "uncheck"
}));
context.emit("change", _newKeys, _objectSpread(_objectSpread({}, changeParams), {}, {
type: "uncheck"
}));
}
};
var handleCheckChange = function handleCheckChange(val, ctx) {
var _props$onChange3;
(_props$onChange3 = props.onChange) === null || _props$onChange3 === void 0 || _props$onChange3.call(props, val, ctx);
context.emit("change", val, ctx);
};
var classes = computed(function () {
return ["".concat(classPrefix.value, "-table__column-controller-item"), _defineProperty({}, "".concat(classPrefix.value, "-table__").concat(props.uniqueKey), props.uniqueKey)];
});
return {
classes: classes,
classPrefix: classPrefix,
isIndeterminate: isIndeterminate,
isCheckedAll: isCheckedAll,
allCheckedColumnKeys: allCheckedColumnKeys,
onCheckAllColumnsChange: onCheckAllColumnsChange,
handleCheckChange: handleCheckChange
};
},
render: function render() {
var h = arguments[0];
return h("div", {
"class": this.classes
}, [h("div", {
"class": "".concat(this.classPrefix, "-table__column-controller-block")
}, [h(Checkbox, helper([{
"attrs": {
"indeterminate": this.isIndeterminate,
"checked": this.isCheckedAll
}
}, {
"on": {
change: this.onCheckAllColumnsChange
}
}, {
"attrs": {
"disabled": !this.allCheckedColumnKeys.length
}
}]), [this.label])]), h("div", {
"class": "".concat(this.classPrefix, "-table__column-controller-block")
}, [h(CheckboxGroup, helper([{
"attrs": {
"options": this.options
}
}, this.checkboxProps, {
"attrs": {
"value": this.value
}
}, {
"on": {
change: this.handleCheckChange
}
}]))])]);
}
});
export { ColumnCheckboxGroup as default };
//# sourceMappingURL=column-checkbox-group.js.map