Img.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. <template>
  2. <div class="Img">
  3. <div class="txt">
  4. <h3>{{ info.name }}</h3>
  5. <p v-show="info.age">年代:{{ info.age }}</p>
  6. <p v-show="info.sort">类别:{{ info.sort }}</p>
  7. <p v-show="info.grain">质地:{{ info.grain }}</p>
  8. <p v-show="info.long">
  9. 长:{{ info.long }}{{ info.type === "Italy" ? "m" : "cm" }}
  10. </p>
  11. <p v-show="info.width">
  12. 宽:{{ info.width }}{{ info.type === "Italy" ? "m" : "cm" }}
  13. </p>
  14. <p v-show="info.tall">
  15. 高:{{ info.tall }}{{ info.type === "Italy" ? "m" : "cm" }}
  16. </p>
  17. <p v-if="info.type === 'Italy'">作者:{{ info.author }}</p>
  18. </div>
  19. <div class="close" @click="$emit('close')"></div>
  20. <viewer class="viewerCla" ref="viewer" :images="lookPics">
  21. <img :src="lookPics[0]" alt="" />
  22. </viewer>
  23. <template v-if="info.imgNum">
  24. <div class="imgMain">
  25. <div class="swiper-container">
  26. <div class="swiper-wrapper">
  27. <div
  28. class="swiper-slide"
  29. v-for="i in info.imgNum"
  30. :key="i"
  31. @click="lookImg(`goodsData/2D/${info.bs}_${i}.JPG`)"
  32. >
  33. <img v-lazy="`goodsData/2D/${info.bs}_${i}.JPG`" alt="" />
  34. </div>
  35. </div>
  36. </div>
  37. <div class="swiper-button-prev swiper-button-white"></div>
  38. <div class="swiper-button-next swiper-button-white"></div>
  39. </div>
  40. <div class="swiper-pagination"></div>
  41. </template>
  42. <div class="imgMain2" v-else>
  43. <img
  44. v-lazy="`goodsData/2D/${info.bs}.JPG`"
  45. alt=""
  46. @click="lookImg(`goodsData/2D/${info.bs}.JPG`)"
  47. />
  48. </div>
  49. </div>
  50. </template>
  51. <script>
  52. import Swiper from "@/assets/Swiper/swiper.js";
  53. export default {
  54. name: "Img",
  55. //import引入的组件需要注入到对象中才能使用
  56. components: {},
  57. props: {
  58. info: {
  59. type: Object,
  60. default: () => {},
  61. },
  62. },
  63. data() {
  64. //这里存放数据
  65. return {
  66. lookPics: [],
  67. };
  68. },
  69. //监听属性 类似于data概念
  70. computed: {},
  71. //监控data中的数据变化
  72. watch: {},
  73. //方法集合
  74. methods: {
  75. // 点击查看大图
  76. lookImg(url) {
  77. let dom = this.$refs.viewer.$viewer;
  78. this.lookPics = [url];
  79. dom.show();
  80. },
  81. },
  82. //生命周期 - 创建完成(可以访问当前this实例)
  83. created() {},
  84. //生命周期 - 挂载完成(可以访问DOM元素)
  85. mounted() {
  86. if (this.info.imgNum) {
  87. new Swiper(".swiper-container", {
  88. slidesPerView: 1,
  89. // 如果需要前进后退按钮
  90. navigation: {
  91. nextEl: ".swiper-button-next",
  92. prevEl: ".swiper-button-prev",
  93. },
  94. pagination: {
  95. el: ".swiper-pagination",
  96. type: "fraction",
  97. },
  98. });
  99. }
  100. },
  101. beforeCreate() {}, //生命周期 - 创建之前
  102. beforeMount() {}, //生命周期 - 挂载之前
  103. beforeUpdate() {}, //生命周期 - 更新之前
  104. updated() {}, //生命周期 - 更新之后
  105. beforeDestroy() {}, //生命周期 - 销毁之前
  106. destroyed() {}, //生命周期 - 销毁完成
  107. activated() {}, //如果页面有keep-alive缓存功能,这个函数会触发
  108. };
  109. </script>
  110. <style lang='less' scoped>
  111. @import "../../../assets/Swiper/swiper.css";
  112. .viewerCla img {
  113. display: none;
  114. }
  115. .Img {
  116. position: fixed;
  117. top: 0;
  118. left: 0;
  119. width: 100%;
  120. height: 100%;
  121. background-image: url("../../../assets/img/Goods/GoodsBac.png");
  122. background-size: 100% 100%;
  123. .swiper-pagination {
  124. width: 100%;
  125. bottom: 40px;
  126. }
  127. /deep/.swiper-pagination-bullet {
  128. margin: 0 4px;
  129. background-color: #930909;
  130. }
  131. .txt {
  132. position: absolute;
  133. top: 44px;
  134. left: 40px;
  135. width: 300px;
  136. h3 {
  137. font-size: 20px;
  138. color: #930909;
  139. line-height: 28px;
  140. }
  141. p {
  142. font-size: 16px;
  143. color: #666666;
  144. margin: 15px 0;
  145. }
  146. }
  147. .close {
  148. position: absolute;
  149. width: 60px;
  150. height: 60px;
  151. cursor: pointer;
  152. top: 44px;
  153. right: 40px;
  154. background-image: url("../../../assets/img/Goods/close2.png");
  155. background-size: 100% 100%;
  156. }
  157. .imgMain {
  158. position: absolute;
  159. top: 50%;
  160. left: 50%;
  161. transform: translate(-50%, -50%);
  162. width: 1400px;
  163. height: 600px;
  164. .swiper-button-next {
  165. outline: none;
  166. width: 40px;
  167. height: 60px;
  168. background-image: url("../../../assets/img/Goods/right.png");
  169. background-size: 100% 100%;
  170. color: transparent;
  171. }
  172. .swiper-button-prev {
  173. outline: none;
  174. width: 40px;
  175. height: 60px;
  176. background-image: url("../../../assets/img/Goods/left.png");
  177. background-size: 100% 100%;
  178. color: transparent;
  179. }
  180. }
  181. .imgMain2 {
  182. position: absolute;
  183. top: 50%;
  184. left: 50%;
  185. transform: translate(-50%, -50%);
  186. width: 1400px;
  187. height: 600px;
  188. text-align: center;
  189. & > img {
  190. cursor: pointer;
  191. width: 900px;
  192. height: 600px;
  193. object-fit: cover;
  194. }
  195. }
  196. .swiper-container {
  197. width: 900px;
  198. height: 600px;
  199. margin: 0 auto;
  200. .swiper-slide {
  201. width: 900px;
  202. height: 600px;
  203. & > img {
  204. cursor: pointer;
  205. width: 100%;
  206. height: 100%;
  207. object-fit: cover;
  208. }
  209. }
  210. }
  211. }
  212. </style>