custom.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. <template>
  2. <div class="custom" :class="'terminal' + terminal">
  3. <div class="rowLayout" v-if="componentContent.layoutType ==='L1' || componentContent.layoutType ==='L2' || componentContent.layoutType ==='L3' || componentContent.layoutType ==='L4'">
  4. <div class="customLayout" :style="{'padding':'0 ' + componentContent.pageSpacing + 'px','marginLeft':(-componentContent.imgClearance) +'px'}">
  5. <div class="ul clearfix" :class="'layout'+componentContent.layoutType">
  6. <div class='li' v-for="(item,index) of componentContent.imgData" :key="index" :style="{'width':getItemValue(item.width) + '%','height':getItemValue(item.height) + '%','left':getItemValue(item.left) + '%','top':getItemValue(item.top) + '%','paddingLeft':componentContent.imgClearance +'px'}">
  7. <a class="a-link" @click="jumpLink(item.linkObj)"><img class="img" :src="item.src" v-if="item.src" mode="widthFix"></a>
  8. </div>
  9. </div>
  10. </div>
  11. </div>
  12. <div v-else :style="{'padding':'0 ' + componentContent.pageSpacing + 'upx'}">
  13. <div class="boxLayout" :style="{'paddingBottom':componentContent.maxH !== 0?getItemValue(componentContent.maxH) + '%': '100%'}">
  14. <div class="boxLayoutInner">
  15. <div class="boxWarp">
  16. <div class="customLayout" :style="{'marginLeft':(-componentContent.imgClearance) +'px','top':(-componentContent.imgClearance) +'px'}">
  17. <div class="ul clearfix" :class="'layout'+componentContent.layoutType">
  18. <div class='li' v-for="(item,index) of componentContent.imgData" :key="index" :style="{'width':getItemValue(item.width) + '%','height':getItemValue(item.height) + '%','left':getItemValue(item.left) + '%','top':getItemValue(item.top) + '%','padding':componentContent.imgClearance +'px 0 0 ' + componentContent.imgClearance +'px'}">
  19. <a class="a-link" @click="jumpLink(item.linkObj)"><img class="img" :src="item.src" v-if="item.src" mode="widthFix"></a>
  20. </div>
  21. </div>
  22. </div>
  23. </div>
  24. </div>
  25. </div>
  26. </div>
  27. </div>
  28. </template>
  29. <script>
  30. import {funMixin} from '../config/mixin'
  31. export default {
  32. name: 'customComponent',
  33. mixins: [funMixin],
  34. data () {
  35. return {
  36. }
  37. },
  38. props: {
  39. terminal: {
  40. type: Number,
  41. default: 4
  42. },
  43. componentContent: {
  44. type: Object
  45. }
  46. },
  47. methods: {
  48. // 计算生成格子百分比
  49. getItemValue (val) {
  50. const density = parseInt(this.componentContent.density)
  51. if (val === 0 || density === 0) {
  52. return 0
  53. }
  54. return (val / density * 10000 / 100.00)// 小数点后两位百分比
  55. }
  56. }
  57. }
  58. </script>
  59. <style lang="scss" scoped>
  60. .custom{
  61. //width: 710upx;
  62. //margin: 0 auto;
  63. .boxLayout{
  64. position: relative;
  65. .boxLayoutInner{
  66. padding-bottom: 100%;
  67. position: absolute;
  68. width: 100%;
  69. left: 0;
  70. top: 0;
  71. }
  72. .boxWarp{
  73. position: absolute;
  74. width: 100%;
  75. height: 100%;
  76. left: 0;
  77. top: 0;
  78. overflow: hidden;
  79. }
  80. }
  81. .customLayout{
  82. position: relative;
  83. .ul{
  84. display: flex;
  85. flex-wrap: wrap;
  86. position: relative;
  87. }
  88. .li{
  89. box-sizing: border-box;
  90. .img{
  91. width: 100%;
  92. display: block;
  93. }
  94. }
  95. .layoutL1 .li{
  96. flex: 0 0 100%;
  97. }
  98. .layoutL2 .li{
  99. flex: 0 0 50%;
  100. }
  101. .layoutL3 .li{
  102. flex: 0 0 33.3%;
  103. }
  104. .layoutL4 .li{
  105. flex: 0 0 25%;
  106. }
  107. .layoutT2B2{
  108. padding-bottom: 100%;
  109. .li{
  110. width: 50%;
  111. height: 50%;
  112. position: absolute;
  113. .img{
  114. width: 100%;
  115. height: 100%;
  116. }
  117. &:nth-child(1){
  118. left: 0;
  119. top: 0;
  120. }
  121. &:nth-child(2){
  122. right: 0;
  123. top: 0;
  124. }
  125. &:nth-child(3){
  126. left: 0;
  127. bottom: 0;
  128. }
  129. &:nth-child(4){
  130. right: 0;
  131. bottom: 0;
  132. }
  133. }
  134. }
  135. .layoutL1R2{
  136. padding-bottom: 100%;
  137. .li{
  138. width: 50%;
  139. height: 50%;
  140. position: absolute;
  141. .img{
  142. width: 100%;
  143. height: 100%;
  144. }
  145. &:nth-child(1){
  146. height: 100%;
  147. left: 0;
  148. top: 0;
  149. }
  150. &:nth-child(2){
  151. right: 0;
  152. top: 0;
  153. }
  154. &:nth-child(3){
  155. right: 0;
  156. bottom: 0;
  157. }
  158. }
  159. }
  160. .layoutT1B2{
  161. padding-bottom: 100%;
  162. .li{
  163. width: 50%;
  164. height: 50%;
  165. position: absolute;
  166. .img{
  167. width: 100%;
  168. height: 100%;
  169. }
  170. &:nth-child(1){
  171. width: 100%;
  172. left: 0;
  173. top: 0;
  174. }
  175. &:nth-child(2){
  176. left: 0;
  177. bottom: 0;
  178. }
  179. &:nth-child(3){
  180. right: 0;
  181. bottom: 0;
  182. }
  183. }
  184. }
  185. .layoutL1T1B2{
  186. padding-bottom: 50%;
  187. .li{
  188. position: absolute;
  189. .img{
  190. width: 100%;
  191. height: 100%;
  192. }
  193. &:nth-child(1){
  194. width: 50%;
  195. height: 100%;
  196. left: 0;
  197. top: 0;
  198. }
  199. &:nth-child(2){
  200. right: 0;
  201. top: 0;
  202. width: 50%;
  203. height: 50%;
  204. }
  205. &:nth-child(3){
  206. left: 50%;
  207. bottom: 0;
  208. width: 25%;
  209. height: 50%;
  210. }
  211. &:nth-child(4){
  212. right: 0;
  213. bottom: 0;
  214. width: 25%;
  215. height: 50%;
  216. }
  217. }
  218. }
  219. .layoutaverage{
  220. padding-bottom: 100%;
  221. .li{
  222. position: absolute;
  223. .img{
  224. width: 100%;
  225. height: 100%;
  226. }
  227. }
  228. }
  229. // #ifdef MP
  230. .layoutaverage{
  231. padding-bottom: 91%;
  232. }
  233. // #endif
  234. }
  235. }
  236. </style>