uni-grid-item copy.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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. /* #endif */
  100. }
  101. /* #ifndef APP-NVUE */
  102. .uni-grid-item--border:after {
  103. content: '';
  104. position: absolute;
  105. bottom: 0;
  106. left: 0;
  107. top: 0;
  108. right: 0;
  109. border-bottom-style: solid;
  110. border-bottom-width: 1px;
  111. border-bottom-color: inherit;
  112. border-right-style: solid;
  113. border-right-width: 1px;
  114. border-right-color: inherit;
  115. box-sizing: border-box;
  116. width: 200%;
  117. height: 200%;
  118. transform: scale(0.5);
  119. transform-origin: left top;
  120. z-index: -1;
  121. }
  122. /* #endif */
  123. .uni-grid-item--border-top {
  124. position: relative;
  125. /* #ifdef APP-NVUE */
  126. border-top-color: #e5e5e5;
  127. border-top-style: solid;
  128. border-top-width: 0.5px;
  129. /* #endif */
  130. /* #ifndef APP-NVUE */
  131. height: 100%;
  132. box-sizing: border-box;
  133. z-index: 0;
  134. /* #endif */
  135. }
  136. /* #ifndef APP-NVUE */
  137. .uni-grid-item--border-top:after {
  138. content: '';
  139. position: absolute;
  140. bottom: 0;
  141. left: 0;
  142. top: 0;
  143. right: 0;
  144. border-top-style: solid;
  145. border-top-width: 1px;
  146. border-top-color: inherit;
  147. box-sizing: border-box;
  148. width: 200%;
  149. height: 200%;
  150. transform: scale(0.5);
  151. transform-origin: left top;
  152. z-index: -1;
  153. }
  154. /* #endif */
  155. .uni-highlight:active {
  156. background-color: #f1f1f1;
  157. }
  158. </style>