uni-group.vue 2.4 KB

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