uni-group.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <template>
  2. <view class="uni-group" :class="['uni-group--'+mode ,margin?'group-margin':'']" :style="{marginTop: `${top}px` }">
  3. <slot name="title">
  4. <view v-if="title" class="uni-group__title" :style="{'padding-left':border?'30px':'15px'}">
  5. <text class="uni-group__title-text">{{ title }}</text>
  6. </view>
  7. </slot>
  8. <view class="uni-group__content" :class="{'group-conent-padding':border}">
  9. <slot />
  10. </view>
  11. </view>
  12. </template>
  13. <script>
  14. /**
  15. * Group 分组
  16. * @description 表单字段分组
  17. * @tutorial https://ext.dcloud.net.cn/plugin?id=3281
  18. * @property {String} title 主标题
  19. * @property {Number} top 分组间隔
  20. */
  21. export default {
  22. name: 'uniGroup',
  23. props: {
  24. title: {
  25. type: String,
  26. default: ''
  27. },
  28. top: {
  29. type: [Number, String],
  30. default: 10
  31. },
  32. mode: {
  33. type: String,
  34. default: 'default'
  35. }
  36. },
  37. data() {
  38. return {
  39. margin: false,
  40. border: false
  41. }
  42. },
  43. watch: {
  44. title(newVal) {
  45. if (uni.report && newVal !== '') {
  46. uni.report('title', newVal)
  47. }
  48. }
  49. },
  50. created() {
  51. this.form = this.getForm()
  52. if (this.form) {
  53. this.margin = true
  54. this.border = this.form.border
  55. }
  56. },
  57. methods: {
  58. /**
  59. * 获取父元素实例
  60. */
  61. getForm() {
  62. let parent = this.$parent;
  63. let parentName = parent.$options.name;
  64. while (parentName !== 'uniForms') {
  65. parent = parent.$parent;
  66. if (!parent) return false
  67. parentName = parent.$options.name;
  68. }
  69. return parent;
  70. },
  71. onClick() {
  72. this.$emit('click')
  73. }
  74. }
  75. }
  76. </script>
  77. <style lang="scss" scoped>
  78. .uni-group {
  79. background: #fff;
  80. margin-top: 10px;
  81. // border: 1px red solid;
  82. }
  83. .group-margin {
  84. // margin: 0 -15px;
  85. }
  86. .uni-group__title {
  87. /* #ifndef APP-NVUE */
  88. display: flex;
  89. /* #endif */
  90. flex-direction: row;
  91. align-items: center;
  92. padding-left: 15px;
  93. height: 40px;
  94. background-color: $uni-bg-color-grey;
  95. font-weight: normal;
  96. color: $uni-text-color;
  97. }
  98. .uni-group__content {
  99. padding: 15px;
  100. // padding-bottom: 5px;
  101. // background-color: #FFF;
  102. }
  103. .group-conent-padding {
  104. padding: 0 15px;
  105. }
  106. .uni-group__title-text {
  107. font-size: $uni-font-size-base;
  108. color: $uni-text-color;
  109. }
  110. .distraction {
  111. flex-direction: row;
  112. align-items: center;
  113. }
  114. .uni-group--card {
  115. margin: 10px;
  116. border-radius: 5px;
  117. overflow: hidden;
  118. box-shadow: 0 0 5px 1px rgba($color: #000000, $alpha: 0.08);
  119. }
  120. </style>