uni-group.vue 2.6 KB

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