SlyCube.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <template>
  2. <view :style="[$wrapStyle(styles)]">
  3. <view class="cap-cube-wrap" :style="[getWrapStyle()]">
  4. <view v-for="(item, index) in attrs.layout.list" :key="index" class="absolute cap-cube-item"
  5. :style="[getMainStyle(item)]">
  6. <view class="cap-cube-item-wrap" :style="[getItemStyle()]">
  7. <image class="cap-cube-img" mode="aspectFill" :src="item.image" @click="$jump(item.jump)" />
  8. </view>
  9. </view>
  10. </view>
  11. </view>
  12. </template>
  13. <script>
  14. export default {
  15. data() {
  16. return {
  17. }
  18. },
  19. props: {
  20. // dataVal: {
  21. // type: Object,
  22. // default: null
  23. // },
  24. attrs: {
  25. type: Object,
  26. default: null
  27. },
  28. styles: {
  29. type: Object,
  30. default: null
  31. },
  32. },
  33. watch: {},
  34. computed: {
  35. // 单元块尺度
  36. itemUnit() {
  37. return (375 - this.styles.pagePadding * 2) / 6;
  38. },
  39. // 容器宽度
  40. wrapHeight() {
  41. return this.attrs.layout.row * this.itemUnit;
  42. },
  43. // 单项间距
  44. margin() {
  45. return this.styles.imgMargin;
  46. },
  47. },
  48. methods: {
  49. // 单项容器样式
  50. getItemStyle() {
  51. return {
  52. borderRadius: this.$unit(this.styles.imgRadius),
  53. };
  54. },
  55. // 容器样式
  56. getWrapStyle() {
  57. let result = {};
  58. if (this.attrs.layout.list.length > 0) {
  59. result.height = this.$unit(this.wrapHeight);
  60. } else {
  61. result.backgroundImage =
  62. "url('http://110.41.150.71:8090/img/1667354829715.jpg')";
  63. result.backgroundSize = `100% 100%`;
  64. result.height = this.$unit(190);
  65. }
  66. console.log(result)
  67. return {
  68. ...this.$cmpStyle(this.styles),
  69. ...result,
  70. };
  71. },
  72. // 主体样式
  73. getMainStyle(styles) {
  74. let result = {};
  75. Object.keys(styles).map((key) => {
  76. let tmep = styles[key] * this.itemUnit;
  77. switch (key) {
  78. case "top":
  79. let paddingTop = tmep == 0 ? this.margin : this.margin / 2;
  80. result.paddingTop = this.$unit(paddingTop);
  81. break;
  82. case "left":
  83. let paddingLeft = tmep == 0 ? this.margin : this.margin / 2;
  84. result.paddingLeft = this.$unit(paddingLeft);
  85. break;
  86. case "bottom":
  87. let paddingBottom =
  88. tmep == this.wrapHeight ? this.margin : this.margin / 2;
  89. result.paddingBottom = this.$unit(paddingBottom);
  90. break;
  91. case "right":
  92. let paddingRight =
  93. tmep == 375 - this.styles.pagePadding * 2 ?
  94. this.margin :
  95. this.margin / 2;
  96. result.paddingRight = this.$unit(paddingRight);
  97. break;
  98. }
  99. result[key] = this.$unit(tmep);
  100. });
  101. console.log('result', result, styles)
  102. return result;
  103. },
  104. setInit(val) {
  105. this.list = val.data.map(el => {
  106. if (el.image.value) {
  107. // 只有存在图片才能显示
  108. return {}
  109. }
  110. })
  111. }
  112. }
  113. }
  114. </script>
  115. <style lang="scss" scoped>
  116. .cap-cube-wrap {
  117. overflow: hidden;
  118. position: relative;
  119. .cap-cube-item {
  120. display: flex;
  121. .cap-cube-item-wrap {
  122. width: 100%;
  123. height: 100%;
  124. overflow: hidden;
  125. .cap-cube-img {
  126. width: 100%;
  127. height: 100%;
  128. }
  129. }
  130. }
  131. }
  132. .absolute {
  133. position: absolute !important;
  134. }
  135. </style>