preview.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. <template id="carousel-img-preview">
  2. <div class="carousel-img-preview" :style="{background: computedStyle.searchBox}">
  3. <div flex="cross:center" style="height: 150px;overflow: hidden;" :style="{...computedStyle.spaceStyle, background: computedStyle.iptBg,}">
  4. <div class="img-one-setyle img-two-setyle" :class="{'img-three-setyle': searchData.buttonData.typeIndex == 1}" v-if="searchData.buttonData && searchData.carouselImgArr">
  5. <!-- 图片位置 -->
  6. <el-image v-show="searchData.buttonData.typeIndex != 0" :style="{...inputStyle,'opacity':searchData.carouselImgArr.length>2?1:0,...marginStyle,...computedStyle.searchIpts}" :class="{'img-two': searchData.buttonData.typeIndex != 0}" :src="searchData.carouselImgArr.length>2?searchData.carouselImgArr[searchData.carouselImgArr.length-1].imgUrl:''">
  7. <div slot="error" class="image-slot"></div>
  8. </el-image>
  9. <el-image :class="{'img-two': searchData.buttonData.typeIndex != 0}" :style="{...inputStyle,...marginStyle,...computedStyle.searchIpts}" :src="searchData.carouselImgArr[0].imgUrl"></el-image>
  10. <el-image v-show="searchData.buttonData.typeIndex != 0" :style="{...inputStyle,'opacity':searchData.carouselImgArr.length>1?1:0,...marginStyle,...computedStyle.searchIpts}" :class="{'img-two': searchData.buttonData.typeIndex != 0}" :src="searchData.carouselImgArr.length>1?searchData.carouselImgArr[1].imgUrl:''">
  11. <div slot="error" class="image-slot"></div>
  12. </el-image>
  13. <div v-if="searchData.buttonPointData.open">
  14. <div class="point-style" flex=""
  15. :class="{'point-style-left': searchData.pointSiteIndex == 0,'point-style-right': searchData.pointSiteIndex == 2,}"
  16. v-if="searchData.buttonPointData && searchData.buttonPointData.pointIndex != 3">
  17. <span class="point"
  18. :class="{
  19. 'point-sel': index == 0,
  20. 'point-two-sel': index == 0 && searchData.buttonPointData && searchData.buttonPointData.pointIndex == 1,
  21. 'point-three': searchData.buttonPointData && searchData.buttonPointData.pointIndex == 2,
  22. }"
  23. v-for="(item,index) in searchData.carouselImgArr" :key="index"></span>
  24. </div>
  25. <div class="point-style point-num" v-else
  26. :class="{'point-style-left': searchData.pointSiteIndex == 0,'point-style-right': searchData.pointSiteIndex == 2,}">
  27. 1 / {{searchData.carouselImgArr.length}}
  28. </div>
  29. </div>
  30. </div>
  31. </div>
  32. </div>
  33. </template>
  34. <script>
  35. /**
  36. * @descriptions
  37. * 1. 组件名字必须对应模板形式 - 递归组件name
  38. * 2. 样式内容方法尽量内部维护 - 前端方便通用
  39. * 3. 父级组件会传预览数据 - activeItem
  40. */
  41. Vue.component('carousel-img-preview', {
  42. name: "carousel-img-preview",
  43. template: '#carousel-img-preview',
  44. props: {
  45. activeItem: {
  46. type: Object,
  47. default () {
  48. return {}
  49. }
  50. }
  51. },
  52. computed: {
  53. computedStyle() {
  54. return this.activeItem.computedStyle
  55. },
  56. searchData() {
  57. console.info(this.activeItem.data);
  58. return this.activeItem.data
  59. },
  60. inputStyle() {
  61. let tabItem = this.computedStyle.tabItem
  62. let style = {
  63. 'background': this.computedStyle.iptBg,
  64. }
  65. if (tabItem && tabItem.value == 'border') style.border = '1px solid ' + (tabItem ? tabItem.color : 'transparent')
  66. if (tabItem && tabItem.value == 'shandow') style.boxShadow = tabItem ? '0 0 10px ' + tabItem.color : '0 0 10px rgba(226, 231, 244, 0.7)'
  67. console.log(style);
  68. return style
  69. },
  70. marginStyle(){
  71. if(this.activeItem.data.spaceInfo && this.activeItem.data.buttonData.typeIndex != 0){
  72. let marginVal = this.activeItem.data.spaceInfo[0].value;
  73. marginVal = marginVal?marginVal/2:0;
  74. let obj = {
  75. 'marginRight': marginVal + 'px',
  76. 'marginLeft': marginVal + 'px'
  77. }
  78. return obj;
  79. }
  80. return {};
  81. }
  82. },
  83. data() {
  84. return {}
  85. }
  86. });
  87. </script>
  88. <style>
  89. .carousel-img-preview {
  90. box-sizing: border-box;
  91. overflow: hidden;
  92. }
  93. .img-one-setyle{
  94. position: relative;
  95. height: 100%;
  96. width: 100%;
  97. }
  98. .img-two-setyle{
  99. display: flex;
  100. height: 100%;
  101. justify-content: center;
  102. align-items: center;
  103. }
  104. .img-one-setyle .el-image{
  105. height: 100%;
  106. }
  107. /* .img-three-setyle .el-image{
  108. height: 80%;
  109. } */
  110. .img-three-setyle .el-image:nth-child(2n - 1){
  111. height: 80%;
  112. }
  113. .img-two{
  114. width: 70%;
  115. flex-shrink: 0;
  116. /* margin: 0 6px; */
  117. }
  118. .point-style{
  119. position: absolute;
  120. left: 50%;
  121. bottom: 10px;
  122. transform: translateX(-50%);
  123. }
  124. .point-style-left{
  125. left: 10px;
  126. transform: translateX(0);
  127. }
  128. .point-style-right{
  129. right: 10px;
  130. left: auto;
  131. transform: translateX(0);
  132. }
  133. .point-style .point{
  134. display: inline-block;
  135. height: 6px;
  136. width: 6px;
  137. border-radius: 10px;
  138. background: #CCC;
  139. margin: 0 4px;
  140. }
  141. .point-style .point-three{
  142. height: 3px;
  143. width: 16px;
  144. border-radius: 0;
  145. }
  146. .point-style .point-sel{
  147. background: #FFF;
  148. }
  149. .point-style .point-two-sel{
  150. height: 6px;
  151. width: 14px;
  152. border-radius: 6px;
  153. }
  154. .point-num{
  155. display: inline-block;
  156. text-align: center;
  157. border-radius: 10px;
  158. background: rgba(0,0,0,.5);
  159. color: #fff;
  160. padding: 2px 6px;
  161. }
  162. .carousel-img-preview .el-carousel--horizontal{
  163. height: 100%;
  164. width: 100%;
  165. }
  166. </style>