uni-grid-item.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. export default {
  12. name: 'UniGridItem',
  13. inject: ['grid'],
  14. props: {
  15. index:{
  16. type: Number,
  17. default: 0
  18. }
  19. },
  20. data() {
  21. return {
  22. column: 0,
  23. showBorder: true,
  24. square: true,
  25. highlight: true,
  26. left: 0,
  27. top: 0,
  28. openNum: 2,
  29. width: 0,
  30. borderColor: '#e5e5e5'
  31. }
  32. },
  33. created() {
  34. this.column = this.grid.column
  35. this.showBorder = this.grid.showBorder
  36. this.square = this.grid.square
  37. this.highlight = this.grid.highlight
  38. this.top = this.hor === 0 ? this.grid.hor : this.hor
  39. this.left = this.ver === 0 ? this.grid.ver : this.ver
  40. this.borderColor = this.grid.borderColor
  41. this.grid.children.push(this)
  42. // this.grid.init()
  43. this.width = this.grid.width
  44. },
  45. beforeDestroy() {
  46. this.grid.children.forEach((item, index) => {
  47. if (item === this) {
  48. this.grid.children.splice(index, 1)
  49. }
  50. })
  51. },
  52. methods: {
  53. _onClick() {
  54. this.grid.change({
  55. detail: {
  56. index: this.index
  57. }
  58. })
  59. }
  60. }
  61. }
  62. </script>
  63. <style lang="scss" scoped>
  64. .uni-grid-item {
  65. /* #ifndef APP-NVUE */
  66. height: 100%;
  67. display: flex;
  68. /* #endif */
  69. }
  70. .uni-grid-item__box {
  71. /* #ifndef APP-NVUE */
  72. display: flex;
  73. width: 100%;
  74. /* #endif */
  75. position: relative;
  76. flex: 1;
  77. flex-direction: column;
  78. // justify-content: center;
  79. // align-items: center;
  80. }
  81. .uni-grid-item--border {
  82. position: relative;
  83. border-bottom-color: $uni-border-color;
  84. border-bottom-style: solid;
  85. border-bottom-width: 1px;
  86. border-right-color: $uni-border-color;
  87. border-right-style: solid;
  88. border-right-width: 1px;
  89. }
  90. .uni-grid-item--border-top {
  91. border-top-color: $uni-border-color;
  92. border-top-style: solid;
  93. border-top-width: 1px;
  94. /* #ifndef APP-NVUE */
  95. height: 100%;
  96. box-sizing: border-box;
  97. /* #endif */
  98. }
  99. .uni-highlight:active {
  100. background-color: $uni-bg-color-hover;
  101. }
  102. </style>