u-cell-group.vue 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <template>
  2. <view :style="wrapperStyle" :class="[customClass]" class="u-cell-group">
  3. <view v-if="title" class="u-cell-group__title">
  4. <slot name="title">
  5. <text class="u-cell-group__title__text">{{ title }}</text>
  6. </slot>
  7. </view>
  8. <view class="u-cell-group__wrapper">
  9. <u-line v-if="border"></u-line>
  10. <slot />
  11. </view>
  12. </view>
  13. </template>
  14. <script>
  15. import props from './props.js';
  16. import mixin from '../../libs/mixin/mixin'
  17. import mpMixin from '../../libs/mixin/mpMixin';
  18. /**
  19. * cellGroup 单元格
  20. * @description cell单元格一般用于一组列表的情况,比如个人中心页,设置页等。
  21. * @tutorial https://uviewui.com/components/cell.html
  22. *
  23. * @property {String} title 分组标题
  24. * @property {Boolean} border 是否显示外边框 (默认 true )
  25. * @property {Object} customStyle 定义需要用到的外部样式
  26. *
  27. * @event {Function} click 点击cell列表时触发
  28. * @example <u-cell-group title="设置喜好">
  29. */
  30. export default {
  31. name: 'u-cell-group',
  32. mixins: [mpMixin, mixin, props],
  33. computed: {
  34. parentData() {
  35. return [this.borderColor]
  36. },
  37. // 组件的样式
  38. wrapperStyle() {
  39. const style = {};
  40. style.backgroundColor = this.backgroundColor;
  41. style.borderRadius = uni.$u.addUnit(this.round)
  42. return uni.$u.deepMerge(style, uni.$u.addStyle(this.customStyle));
  43. }
  44. },
  45. watch: {
  46. // 当父组件需要子组件需要共享的参数发生了变化,手动通知子组件
  47. parentData() {
  48. if (this.children.length) {
  49. this.children.map(child => {
  50. // 判断子组件(u-checkbox)如果有init方法的话,就就执行(执行的结果是子组件重新从父组件拉取了最新的值)
  51. typeof(child.init) === 'function' && child.init()
  52. })
  53. }
  54. },
  55. },
  56. created() {
  57. this.children = []
  58. }
  59. }
  60. </script>
  61. <style lang="scss" scoped>
  62. @import "../../libs/css/components.scss";
  63. $u-cell-group-title-padding: 16px 16px 8px !default;
  64. $u-cell-group-title-font-size: 15px !default;
  65. $u-cell-group-title-line-height: 16px !default;
  66. $u-cell-group-title-color: $u-main-color !default;
  67. .u-cell-group {
  68. flex: 1;
  69. &__title {
  70. padding: $u-cell-group-title-padding;
  71. &__text {
  72. font-size: $u-cell-group-title-font-size;
  73. line-height: $u-cell-group-title-line-height;
  74. color: $u-cell-group-title-color;
  75. }
  76. }
  77. &__wrapper {
  78. position: relative;
  79. }
  80. }
  81. </style>