足力健前端,vue版本

uni-grid-item copy.vue 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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. }
  76. .uni-grid-item__box {
  77. /* #ifndef APP-NVUE */
  78. display: flex;
  79. width: 100%;
  80. /* #endif */
  81. position: relative;
  82. flex: 1;
  83. flex-direction: column;
  84. // justify-content: center;
  85. // align-items: center;
  86. }
  87. .uni-grid-item--border {
  88. position: relative;
  89. /* #ifdef APP-NVUE */
  90. border-bottom-color: $uni-border-color;
  91. border-bottom-style: solid;
  92. border-bottom-width: 0.5px;
  93. border-right-color: $uni-border-color;
  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: $uni-border-color;
  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: $uni-bg-color-hover;
  157. }
  158. </style>