uni-grid-item.vue 2.9 KB

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