grid.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <template>
  2. <view class="page">
  3. <view class="grid-wrap" v-for="(list, i) in gridList" :key="i">
  4. <view class="grid-title">{{list.title}}</view>
  5. <view class="grid-item-box" >
  6. <view class="grid-item"
  7. v-for="(item, index) in list.subList"
  8. :key="index" hover-class="hover"
  9. :style="'width:calc(100% / '+column+')'"
  10. :class="{'no-border-right':(index+1)%column==0,'no-border-top':index+1>column, 'no-border-bottom':noBorderBottom(i,index), 'no-border':!border}"
  11. @tap="jump(item.url, index, item)"
  12. >
  13. <image style="padding-bottom: 16rpx;" :src="item.src" ></image>
  14. <view class="name" style="font-size: 26rpx;">{{item.name}}</view>
  15. </view>
  16. </view>
  17. </view>
  18. </view>
  19. </template>
  20. <script>
  21. export default {
  22. props:{
  23. gridList :{
  24. type: Array
  25. },
  26. column:{
  27. type: Number,
  28. default: 4
  29. },
  30. border:{
  31. type: Boolean,
  32. default:true
  33. }
  34. },
  35. data () {
  36. return {}
  37. },
  38. methods : {
  39. //最后一行-取消底部边框
  40. noBorderBottom ( i, index ) {
  41. let len = this.gridList[i].subList.length
  42. let row = parseInt(len/this.column)
  43. if(len % this.column === 0){
  44. return index+1 > (row-1) * this.column
  45. }
  46. return index+1 > row * this.column
  47. },
  48. //跳转
  49. jump( url, index, item ) {
  50. //如果是点击类型的,那么就直接返回当前点击的数据以及索引回去
  51. if(item.type === 'click'){
  52. const obj = {
  53. item,index
  54. }
  55. this.$emit('tapGrid', obj)
  56. return
  57. }else if(item.type === 'switchTab'){
  58. if (url=='/pages/community/community?current=1') {
  59. //跳转到老人关爱页面
  60. //因为switchTab无法附带参数,只能用globalData附带参数
  61. getApp().globalData.subsectionCurrent=1
  62. }
  63. if (url=='/pages/community/community?current=2') {
  64. //跳转到车辆关爱页面
  65. //因为switchTab无法附带参数,只能用globalData附带参数
  66. getApp().globalData.subsectionCurrent=2
  67. }
  68. if (url='/pages/index/index?openDoor') {
  69. //一键开门,跳转到首页并打开开门设备列表
  70. getApp().globalData.openDoor=true
  71. }
  72. uni.switchTab({
  73. url
  74. })
  75. return
  76. }
  77. uni.navigateTo({
  78. url
  79. })
  80. }
  81. }
  82. };
  83. </script>
  84. <style scoped lang="scss">
  85. .grid-wrap{
  86. width: 96%;margin-left: 2%;background: #fff;border-radius: 20upx;box-shadow: 0 0 5upx 2upx #efefef;margin-top: 15upx;font-size: 28upx;
  87. .grid-title{
  88. color: #666;padding: 15upx 2%;font-size: 30upx;width: 96%;margin-left: 20rpx;font-weight: 800;
  89. }
  90. .grid-item-box{
  91. display: flex;align-items: center;flex-wrap: wrap;
  92. .grid-item{
  93. text-align: center;padding: 20upx 0;width: calc(100% / 3);box-sizing: border-box;
  94. border-right: .5upx solid #ccc;border-top: .5upx solid #ccc;border-bottom: .5upx solid #ccc;
  95. image{width:48upx;height: 48upx;}
  96. }
  97. .hover{background: #efefef;}
  98. .no-border-right{border-right: none;}
  99. .no-border-bottom{border-bottom:none}
  100. .no-border-top{border-top:none}
  101. .no-border{border:none !important}
  102. }
  103. }
  104. </style>