tm-grid.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. <template>
  2. <view class="tm-grid ">
  3. <tm-row :custom-class="border ? ' border-grey-lighten-4-a-1 round-5 overflow ' +(black_tmeme?' bk ':'') : ''">
  4. <tm-col
  5. :maxCol="maxGrid"
  6. :custom-class="(border ? ((index+1)<=(colNum-1)*grid?'border-grey-lighten-4-b-1 ':'') + ((index + 1) % grid ? 'border-grey-lighten-4-r-1 ' : ' ') : '') + (black_tmeme?' bk ':'')"
  7. v-for="(item, index) in listData" :key="index" :grid="col" justify="center"
  8. align="middle"
  9. :color="bgColor"
  10. >
  11. <view @click.stop="onclick(index,item)" class="tm-grid-hover flex-center flex-col " :style="{height:height_s+'px'}">
  12. <view class=" pb-6 flex-shrink px-10 " style="">
  13. <view class="tm-grid-icon flex-shrink" v-if="item.dot" >
  14. <tm-badges :color="item.color?item.color:color_tmeme" @click="clickDot(index,item)" v-if="item.dotIcon" :offset="[10,0]" :dot="false" :icon="item.dotIcon" ></tm-badges>
  15. <tm-badges @click="clickDot(index,item)" v-if="!item.dotIcon" :offset="[10,0]" :dot="true" ></tm-badges>
  16. </view>
  17. <tm-icons :prefx="item['prefx']?item['prefx']:''" :color="item.color?item.color:color_tmeme" :size="item.iconSize?item.iconSize:iconSize"
  18. :name="item.icon?item.icon:''"></tm-icons>
  19. </view>
  20. <view class="flex-center fulled">
  21. <text class="text-size-s text-align-center"
  22. :class="[item.fontColor?'text-'+item.fontColor:'text-'+fontColor]">{{ item.text?item.text:'' }}</text>
  23. </view>
  24. </view>
  25. </tm-col>
  26. </tm-row>
  27. </view>
  28. </template>
  29. <script>
  30. /**
  31. * 九宫格
  32. * @description 九宫格,快速建立宫格列表,如果想要个性化推荐tm-row tm-col建立。
  33. * @property {Boolean} border = [] 默认:false,是否显示边框
  34. * @property {Boolean} black = [] 默认:null,暗黑模式
  35. * @property {String} color = [] 默认:primary,图标主题色。
  36. * @property {String} bg-color = [grey-lighten-5] 默认:'',宫格背景主题色。
  37. * @property {String} font-color = [] 默认:grey-darken-1,文字颜色
  38. * @property {Number} icon-size = [] 默认:40,图标大小
  39. * @property {Number} height = [] 默认:140,高度,单位upx
  40. * @property {Number} maxGrid = [] 默认:12,布局的列表,比如我想一行5个,就可以用到此属性,设置为10,然后grid=2即可。
  41. * @property {Number} grid = [] 默认:4,一行几个。
  42. * @property {Array} list = [] 默认:[],列表数据。
  43. * @property {Function} change 项目被点击,返回的参数:{index:索引,data:项目的数据}
  44. * @property {Function} click-dot 右上角的角标被点击触发。
  45. * @example <tm-grid :list="[{ text: '应用配置', icon: 'icon-aliwangwang' , size:40 }]"></tm-grid>
  46. */
  47. import tmRow from "@/tm-vuetify/components/tm-row/tm-row.vue"
  48. import tmCol from "@/tm-vuetify/components/tm-col/tm-col.vue"
  49. import tmBadges from "@/tm-vuetify/components/tm-badges/tm-badges.vue"
  50. import tmIcons from "@/tm-vuetify/components/tm-icons/tm-icons.vue"
  51. export default {
  52. components:{tmRow,tmCol,tmBadges,tmIcons},
  53. name: 'tm-grid',
  54. props: {
  55. black:{
  56. type:String|Boolean,
  57. default:null
  58. },
  59. // 是否显示边框。
  60. border: {
  61. type: Boolean,
  62. default: false
  63. },
  64. // 主题色。
  65. color: {
  66. type: String,
  67. default: 'primary'
  68. },
  69. // 背景主题色。
  70. bgColor: {
  71. type: String,
  72. default: ''
  73. },
  74. fontColor: {
  75. type: String,
  76. default: 'grey-darken-1'
  77. },
  78. // 一行几个。
  79. grid: {
  80. type: Number,
  81. default: 4
  82. },
  83. iconSize: {
  84. type: Number,
  85. default: 40
  86. },
  87. height: {
  88. type: Number,
  89. default: 140
  90. },
  91. list: {
  92. type: Array,
  93. default: () => {
  94. return [];
  95. }
  96. },
  97. // 跟随主题色的改变而改变。
  98. fllowTheme:{
  99. type:Boolean|String,
  100. default:true
  101. },
  102. //默认计算方式是12列布局。
  103. maxGrid:{
  104. type:Number,
  105. default:12
  106. }
  107. },
  108. computed: {
  109. black_tmeme: function() {
  110. if (this.black !== null) return this.black;
  111. return this.$tm.vx.state().tmVuetify.black;
  112. },
  113. color_tmeme:function(){
  114. if(this.$tm.vx.state().tmVuetify.color!==null&&this.$tm.vx.state().tmVuetify.color && this.fllowTheme){
  115. return this.$tm.vx.state().tmVuetify.color;
  116. }
  117. return this.color;
  118. },
  119. col: function() {
  120. return isNaN(this.maxGrid / this.grid) ? 4 : this.maxGrid / this.grid;
  121. },
  122. listData: function() {
  123. let gs = this.grid - Math.floor(this.list.length / this.grid);
  124. return this.list;
  125. },
  126. gridNum:function(){
  127. return this.grid;
  128. },
  129. colNum:function(){
  130. let ts = parseInt(this.listData.length/this.grid);
  131. ts = this.listData.length/this.grid>ts?ts+1:ts;
  132. return ts;
  133. },
  134. height_s:function(){
  135. return uni.upx2px(this.height)||70
  136. }
  137. },
  138. data() {
  139. return {
  140. hoverClass: ''
  141. };
  142. },
  143. methods: {
  144. onclick(index, item) {
  145. this.$emit('change', {
  146. index: index,
  147. data: item
  148. })
  149. },
  150. clickDot(index, item) {
  151. this.$emit('click-dot', {
  152. index: index,
  153. data: item
  154. })
  155. }
  156. },
  157. };
  158. </script>
  159. <style lang="scss" scoped>
  160. .tm-grid{
  161. .tm-grid-icon{
  162. }
  163. }
  164. </style>