u-checkbox-group.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. "use strict";
  2. const common_vendor = require("../../../../common/vendor.js");
  3. const _sfc_main = {
  4. name: "u-checkbox-group",
  5. mixins: [common_vendor.mpMixin, common_vendor.mixin, common_vendor.props$1],
  6. computed: {
  7. // 这里computed的变量,都是子组件u-checkbox需要用到的,由于头条小程序的兼容性差异,子组件无法实时监听父组件参数的变化
  8. // 所以需要手动通知子组件,这里返回一个parentData变量,供watch监听,在其中去通知每一个子组件重新从父组件(u-checkbox-group)
  9. // 拉取父组件新的变化后的参数
  10. parentData() {
  11. return [
  12. this.modelValue,
  13. this.disabled,
  14. this.inactiveColor,
  15. this.activeColor,
  16. this.size,
  17. this.labelDisabled,
  18. this.shape,
  19. this.iconSize,
  20. this.borderBottom,
  21. this.placement
  22. ];
  23. },
  24. bemClass() {
  25. return this.bem("checkbox-group", ["placement"]);
  26. }
  27. },
  28. watch: {
  29. // 当父组件需要子组件需要共享的参数发生了变化,手动通知子组件
  30. parentData: {
  31. handler() {
  32. if (this.children.length) {
  33. this.children.map((child) => {
  34. typeof child.init === "function" && child.init();
  35. });
  36. }
  37. },
  38. deep: true
  39. }
  40. },
  41. data() {
  42. return {};
  43. },
  44. created() {
  45. this.children = [];
  46. },
  47. emits: ["update:modelValue", "change"],
  48. methods: {
  49. // 将其他的checkbox设置为未选中的状态
  50. unCheckedOther(childInstance) {
  51. const values = [];
  52. this.children.map((child) => {
  53. if (child.isChecked) {
  54. values.push(child.name);
  55. }
  56. });
  57. this.$emit("change", values);
  58. this.$emit("update:modelValue", values);
  59. }
  60. }
  61. };
  62. function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  63. return {
  64. a: common_vendor.n($options.bemClass)
  65. };
  66. }
  67. const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-504cd728"], ["__file", "F:/兴元/开门柜项目/平台端管理系统小程序/node_modules/uview-plus/components/u-checkbox-group/u-checkbox-group.vue"]]);
  68. wx.createComponent(Component);