image.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. <template>
  2. <div class="hotspot" v-if="!isMobile">
  3. <img class="aa" v-if="hotspot.images.length > 1" :src="require('@/assets/images/proj2022/pc/left_1.png')" alt="" @click="handlePage('prev')" />
  4. <div class="vhotspotcon">
  5. <div class="vtitle" v-if="hotspot.title" v-html="hotspot.title"></div>
  6. <div class="hotspotcon" :class="{hotconfull:!hotspot.title&&!(hotspot.title||hotspot.imagesDesc[active])}">
  7. <div class="img-con">
  8. <div class="imgmain">
  9. <img id="map" :src="g_fixUrl(hotspot.images[active])" alt="" />
  10. </div>
  11. <div class="pagna" v-if="hotspot.images.length > 1">
  12. <span>{{ active + 1 }}</span>
  13. /
  14. <span>{{ hotspot.images.length }}</span>
  15. </div>
  16. </div>
  17. <div class="desc" v-html="handleContent(hotspot.imagesDesc[active] || hotspot.contents[active])"></div>
  18. </div>
  19. </div>
  20. <img class="aa" v-if="hotspot.images.length > 1" :src="require('@/assets/images/proj2022/pc/right_1.png')" alt="" @click="handlePage('next')" />
  21. </div>
  22. <div v-else class="mbhotspot">
  23. <div class="mbhcon" :class="{ fullcon: !hotspot.content || !hotspot.contents[active] }">
  24. <div class="img-con">
  25. <img class="aa" v-if="hotspot.images.length > 1" :src="require('@/assets/images/proj2022/mobile/prev.png')" alt="" @click="handlePage('prev')" />
  26. <div class="imgmain" >
  27. <img id="map" :src="g_fixUrl(hotspot.images[active])" alt="" />
  28. </div>
  29. <img class="aa" v-if="hotspot.images.length > 1" :src="require('@/assets/images/proj2022/mobile/next.png')" alt="" @click="handlePage('next')" />
  30. </div>
  31. <div class="desc" v-if="hotspot.imagesDesc[active] || hotspot.contents[active]">
  32. <div class="title" v-html="hotspot.title"></div>
  33. <div v-html="handleContent(hotspot.imagesDesc[active] || hotspot.contents[active], 14)"></div>
  34. </div>
  35. </div>
  36. </div>
  37. </template>
  38. <script>
  39. import Panzoom from "@panzoom/panzoom";
  40. export default {
  41. props: ["hotspot", "type"],
  42. data() {
  43. return {
  44. panzoom: "",
  45. active: 0,
  46. to: null,
  47. };
  48. },
  49. watch: {
  50. active() {
  51. setTimeout(() => {
  52. this.$showLoading();
  53. });
  54. if (this.to) {
  55. clearTimeout(this.to);
  56. this.to = null;
  57. }
  58. this.to = setTimeout(() => {
  59. this.$hideLoading();
  60. }, 1500);
  61. },
  62. },
  63. methods: {
  64. handlePage(type) {
  65. if (type === "next") {
  66. if (this.active >= this.hotspot.images.length - 1) {
  67. this.active = 0;
  68. return;
  69. }
  70. this.active += 1;
  71. } else {
  72. if (this.active == 0) {
  73. this.active = this.hotspot.images.length - 1;
  74. return;
  75. }
  76. this.active -= 1;
  77. }
  78. },
  79. reset() {
  80. this.panzoom.pan(0, 0);
  81. this.panzoom.zoom(this.isMobile ? 1 : !this.hotspot.content ? 0.8 : 1);
  82. this.$hideLoading();
  83. },
  84. },
  85. computed: {
  86. },
  87. mounted() {
  88. const elem = document.getElementById("map");
  89. this.panzoom = Panzoom(elem, {
  90. maxScale: 10,
  91. startScale: this.isMobile ? 1 : !this.hotspot.content ? 0.8 : 1,
  92. });
  93. const parent = elem.parentElement
  94. // No function bind needed
  95. parent.addEventListener("wheel", this.panzoom.zoomWithWheel);
  96. parent.addEventListener("load", () => {
  97. this.reset();
  98. });
  99. parent.addEventListener("abort", () => {
  100. this.reset();
  101. });
  102. parent.addEventListener("error", () => {
  103. this.reset();
  104. });
  105. },
  106. };
  107. </script>
  108. <style lang="less" scoped>
  109. .noshow {
  110. opacity: 0 !important;
  111. pointer-events: none !important;
  112. }
  113. @w: 75%;
  114. @fixw: 8px;
  115. .hotspot {
  116. .vhotspotcon{
  117. width: 100%;
  118. }
  119. }
  120. .mbhotspot {
  121. width: 100%;
  122. height: 100%;
  123. position: fixed;
  124. left: 0;
  125. top: 0;
  126. z-index: 9999;
  127. .close {
  128. position: absolute;
  129. top: 26px;
  130. right: 16px;
  131. width: 20px;
  132. z-index: 1000;
  133. }
  134. .mbhcon {
  135. position: absolute;
  136. top: 50%;
  137. width: 100%;
  138. left: 50%;
  139. transform: translate(-50%, -50%);
  140. height: 100%;
  141. .img-con {
  142. display: flex;
  143. height: 100%;
  144. align-items: center;
  145. justify-content: space-between;
  146. position: relative;
  147. overflow: hidden;
  148. .imgmain {
  149. width: 100%;
  150. height: auto;
  151. min-height: 100%;
  152. display: flex;
  153. align-items: center;
  154. justify-content: center;
  155. text-align: center;
  156. img {
  157. cursor: pointer;
  158. max-width: 100%;
  159. }
  160. }
  161. @pos: 10px;
  162. .aa {
  163. position: absolute;
  164. width: 30px;
  165. height: auto;
  166. cursor: pointer;
  167. top: 50%;
  168. transform: translateY(-50%);
  169. left: @pos;
  170. z-index: 999;
  171. &:last-of-type {
  172. right: @pos;
  173. left: unset;
  174. }
  175. }
  176. }
  177. .desc {
  178. overflow-y: auto;
  179. position: absolute;
  180. z-index: 99999;
  181. bottom: 0;
  182. left: 50%;
  183. width: 100%;
  184. padding: 2% 5%;
  185. transform: translateX(-50%);
  186. margin: 0;
  187. min-height: 10vh;
  188. max-height: 34vh;
  189. background: rgba(0, 0, 0, 0.5);
  190. text-align: left;
  191. word-break: break-all;
  192. .title {
  193. width: 100%;
  194. display: inline-block;
  195. font-size: 16px;
  196. margin-bottom: 10px;
  197. }
  198. }
  199. }
  200. .fullcon {
  201. width: 100%;
  202. height: 100%;
  203. .img-con {
  204. height: 100%;
  205. .imgmain {
  206. width: 100%;
  207. height: auto;
  208. min-height: 100%;
  209. display: flex;
  210. align-items: center;
  211. text-align: center;
  212. }
  213. }
  214. }
  215. }
  216. </style>