uni-grid-item.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <template>
  2. <view v-if="width" :style="'width:'+width+';'+(square?'height:'+width:'')" class="uni-grid-item">
  3. <view
  4. :class="{ 'uni-grid-item--border': showBorder, 'uni-grid-item--border-top': showBorder && index < column, 'uni-highlight': highlight }"
  5. :style="{'border-right-color': borderColor ,'border-bottom-color': borderColor ,'border-top-color': borderColor }"
  6. class="uni-grid-item__box" @click="_onClick">
  7. <slot/>
  8. </view>
  9. </view>
  10. </template>
  11. <script>
  12. /**
  13. * GridItem 宫格
  14. * @description 宫格组件
  15. * @tutorial https://ext.dcloud.net.cn/plugin?id=27
  16. * @property {Number} index 子组件的唯一标识 ,点击gird会返回当前的标识
  17. */
  18. export default {
  19. name: 'UniGridItem',
  20. inject: ['grid'],
  21. props: {
  22. index: {
  23. type: Number,
  24. default: 0
  25. }
  26. },
  27. data() {
  28. return {
  29. column: 0,
  30. showBorder: true,
  31. square: true,
  32. highlight: true,
  33. left: 0,
  34. top: 0,
  35. openNum: 2,
  36. width: 0,
  37. borderColor: '#e5e5e5'
  38. }
  39. },
  40. created() {
  41. this.column = this.grid.column
  42. this.showBorder = this.grid.showBorder
  43. this.square = this.grid.square
  44. this.highlight = this.grid.highlight
  45. this.top = this.hor === 0 ? this.grid.hor : this.hor
  46. this.left = this.ver === 0 ? this.grid.ver : this.ver
  47. this.borderColor = this.grid.borderColor
  48. this.grid.children.push(this)
  49. // this.grid.init()
  50. this.width = this.grid.width
  51. },
  52. beforeDestroy() {
  53. this.grid.children.forEach((item, index) => {
  54. if (item === this) {
  55. this.grid.children.splice(index, 1)
  56. }
  57. })
  58. },
  59. methods: {
  60. _onClick() {
  61. this.grid.change({
  62. detail: {
  63. index: this.index
  64. }
  65. })
  66. }
  67. }
  68. }
  69. </script>
  70. <style lang="scss">
  71. .uni-grid-item {
  72. /* #ifndef APP-NVUE */
  73. height: 100%;
  74. display: flex;
  75. /* #endif */
  76. /* #ifdef H5 */
  77. cursor: pointer;
  78. /* #endif */
  79. }
  80. .uni-grid-item__box {
  81. /* #ifndef APP-NVUE */
  82. display: flex;
  83. width: 100%;
  84. /* #endif */
  85. position: relative;
  86. flex: 1;
  87. flex-direction: column;
  88. // justify-content: center;
  89. // align-items: center;
  90. }
  91. .uni-grid-item--border {
  92. position: relative;
  93. /* #ifdef APP-NVUE */
  94. border-bottom-color: #D2D2D2;
  95. border-bottom-style: solid;
  96. border-bottom-width: 0.5px;
  97. border-right-color: #D2D2D2;
  98. border-right-style: solid;
  99. border-right-width: 0.5px;
  100. /* #endif */
  101. /* #ifndef APP-NVUE */
  102. z-index: 0;
  103. border-bottom: 1px #D2D2D2 solid;
  104. border-right: 1px #D2D2D2 solid;
  105. /* #endif */
  106. }
  107. .uni-grid-item--border-top {
  108. position: relative;
  109. /* #ifdef APP-NVUE */
  110. border-top-color: #D2D2D2;
  111. border-top-style: solid;
  112. border-top-width: 0.5px;
  113. /* #endif */
  114. /* #ifndef APP-NVUE */
  115. border-top: 1px #D2D2D2 solid;
  116. z-index: 0;
  117. /* #endif */
  118. }
  119. .uni-highlight:active {
  120. background-color: #f1f1f1;
  121. }
  122. </style>