uni-grid-item.vue 2.7 KB

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