uni-group.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. * @property {Number} mode 模式
  21. */
  22. export default {
  23. name: 'uniGroup',
  24. emits:['click'],
  25. props: {
  26. title: {
  27. type: String,
  28. default: ''
  29. },
  30. top: {
  31. type: [Number, String],
  32. default: 10
  33. },
  34. mode: {
  35. type: String,
  36. default: 'default'
  37. },
  38. stat:{
  39. type: Boolean,
  40. default: false
  41. }
  42. },
  43. data() {
  44. return {
  45. margin: false,
  46. border: false
  47. }
  48. },
  49. watch: {
  50. title(newVal) {
  51. if (uni.report && this.stat && newVal !== '') {
  52. uni.report('title', newVal)
  53. }
  54. }
  55. },
  56. created() {
  57. this.form = this.getForm()
  58. if (this.form) {
  59. this.margin = true
  60. this.border = this.form.border
  61. }
  62. },
  63. methods: {
  64. /**
  65. * 获取父元素实例
  66. */
  67. getForm() {
  68. let parent = this.$parent;
  69. let parentName = parent.$options.name;
  70. while (parentName !== 'uniForms') {
  71. parent = parent.$parent;
  72. if (!parent) return false
  73. parentName = parent.$options.name;
  74. }
  75. return parent;
  76. },
  77. onClick() {
  78. this.$emit('click')
  79. }
  80. }
  81. }
  82. </script>
  83. <style lang="scss" >
  84. .uni-group {
  85. background: #fff;
  86. margin-top: 10px;
  87. // border: 1px red solid;
  88. }
  89. .group-margin {
  90. // margin: 0 -15px;
  91. }
  92. .uni-group__title {
  93. /* #ifndef APP-NVUE */
  94. display: flex;
  95. /* #endif */
  96. flex-direction: row;
  97. align-items: center;
  98. padding-left: 15px;
  99. height: 40px;
  100. background-color: #eee;
  101. font-weight: normal;
  102. color: #666;
  103. }
  104. .uni-group__content {
  105. padding: 15px;
  106. // padding-bottom: 5px;
  107. // background-color: #FFF;
  108. }
  109. .group-conent-padding {
  110. padding: 0 15px;
  111. }
  112. .uni-group__title-text {
  113. font-size: 14px;
  114. color: #666;
  115. }
  116. .distraction {
  117. flex-direction: row;
  118. align-items: center;
  119. }
  120. .uni-group--card {
  121. margin: 10px;
  122. border-radius: 5px;
  123. overflow: hidden;
  124. box-shadow: 0 0 5px 1px rgba($color: #000000, $alpha: 0.08);
  125. }
  126. </style>