showCase.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. <template>
  2. <div class="show-case-container" ref="containerRef">
  3. <audio v-if="audio" ref="audioSound" :src="audio"></audio>
  4. <div class="show-case" v-if="isModel">
  5. <iframe ref="iframeRef" frameborder="0" :src="iframeURL"></iframe>
  6. </div>
  7. <div class="show-case" v-if="isVideo">
  8. <video
  9. ref="videoRef"
  10. :src="video"
  11. autoplay
  12. playsinline
  13. @ended="isVideoPlaying = false"
  14. @playing="isVideoPlaying = true"
  15. @pause="isVideoPlaying = false"
  16. ></video>
  17. <div class="video-icon">
  18. <svg
  19. class="play-icon icon"
  20. xmlns="http://www.w3.org/2000/svg"
  21. xmlns:xlink="http://www.w3.org/1999/xlink"
  22. viewBox="0 0 1024 1024"
  23. @click="videoRef.play()"
  24. v-if="!isVideoPlaying"
  25. >
  26. <path
  27. d="M512 64C264.6 64 64 264.6 64 512s200.6 448 448 448s448-200.6 448-448S759.4 64 512 64zm144.1 454.9L437.7 677.8a8.02 8.02 0 0 1-12.7-6.5V353.7a8 8 0 0 1 12.7-6.5L656.1 506a7.9 7.9 0 0 1 0 12.9z"
  28. fill="currentColor"
  29. ></path>
  30. </svg>
  31. <svg
  32. xmlns="http://www.w3.org/2000/svg"
  33. xmlns:xlink="http://www.w3.org/1999/xlink"
  34. viewBox="0 0 28 28"
  35. v-if="isVideoPlaying"
  36. class="stop-icon icon"
  37. @click="videoRef.pause()"
  38. >
  39. <g fill="none">
  40. <path
  41. d="M14 26c6.627 0 12-5.373 12-12S20.627 2 14 2S2 7.373 2 14s5.373 12 12 12zM10.5 9h7a1.5 1.5 0 0 1 1.5 1.5v7a1.5 1.5 0 0 1-1.5 1.5h-7A1.5 1.5 0 0 1 9 17.5v-7A1.5 1.5 0 0 1 10.5 9z"
  42. fill="currentColor"
  43. ></path>
  44. </g>
  45. </svg>
  46. </div>
  47. </div>
  48. <div class="show-case" v-if="isGallery">
  49. <n-carousel
  50. :draggable="gallery.length > 1"
  51. :show-dots="false"
  52. :show-arrow="gallery.length > 1"
  53. @update:current-index="handleSlideUpdate"
  54. >
  55. <template v-for="img in gallery">
  56. <img class="carousel-img" :src="img" />
  57. </template>
  58. <template #arrow="{ prev, next }" v-if="gallery.length > 1">
  59. <div class="custom-arrow">
  60. <img class="btn-img" src="@/assets/arrow-left.png" @click="prev" />
  61. <img class="btn-img" src="@/assets/arrow-right.png" @click="next" />
  62. </div>
  63. </template>
  64. </n-carousel>
  65. </div>
  66. <div class="tools">
  67. <n-space class="group-type" :size="25">
  68. <n-button
  69. class="model btn"
  70. :class="{
  71. active: isModel,
  72. }"
  73. round
  74. @click="handleSwitchType('model')"
  75. >
  76. <img src="@/assets/icon_model.png" /> 模型
  77. </n-button>
  78. <n-button
  79. v-if="video"
  80. class="video btn"
  81. :class="{
  82. active: isVideo,
  83. }"
  84. round
  85. @click="handleSwitchType('video')"
  86. ><img src="@/assets/icon_video.png" />视频</n-button
  87. >
  88. <n-button
  89. class="gallery btn"
  90. :class="{
  91. active: isGallery,
  92. }"
  93. round
  94. @click="handleSwitchType('gallery')"
  95. >
  96. <img src="@/assets/icon_photo.png" />图片
  97. <span v-if="gallery.length > 0">{{
  98. `${currentSlideIndex}/${gallery.length}`
  99. }}</span></n-button
  100. >
  101. </n-space>
  102. <div class="actions">
  103. <div v-if="isModel">
  104. <img src="@/assets/zoom-in.png" @click="handleFullScreen" />
  105. <img src="@/assets/zoom-out.png" @click="handleExitFullScreen" />
  106. <img src="@/assets/reload.png" @click="reloadIframe" />
  107. </div>
  108. <div v-if="isGallery && audio">
  109. <img src="@/assets/audio-muted.png" @click="audioPause" />
  110. <img src="@/assets/audio-unmuted.png" @click="audioPlay" />
  111. </div>
  112. </div>
  113. </div>
  114. </div>
  115. </template>
  116. <script setup>
  117. import { ref, computed, unref } from "vue";
  118. import { useFullscreen } from "@vueuse/core";
  119. const iframeRef = ref();
  120. const containerRef = ref();
  121. const type = ref("model");
  122. const defaultType = ref(["model", "video", "audio", "gallery"]);
  123. const videoRef = ref();
  124. // const iframeURL = ref("https://www.4dmodel.com/SuperTwo/index.html?m=TEST");
  125. const iframeURL = ref(
  126. "https://model3d.4dage.com/model/showModel.html?m=d558c919-a001-4aef-a719-18af4ed2bd82"
  127. );
  128. const isModel = computed(() => type.value === "model");
  129. const isVideo = computed(() => type.value === "video");
  130. // const isAudio = computed(() => type.value === "audio");
  131. const isGallery = computed(() => type.value === "gallery");
  132. const domain = ref(import.meta.env.VITE_DOMAIN_URL);
  133. const audioSound = ref("");
  134. const currentSlideIndex = ref(1);
  135. const { isFullscreen, enter, exit, toggle } = useFullscreen(containerRef);
  136. const isVideoPlaying = ref(false);
  137. defineOptions({
  138. name: "show-case",
  139. });
  140. const props = defineProps({
  141. model: {
  142. type: String,
  143. default: () => "",
  144. },
  145. video: {
  146. type: String,
  147. default: () => "",
  148. },
  149. audio: {
  150. type: String,
  151. default: () => "",
  152. },
  153. gallery: {
  154. type: Array,
  155. default: () => [""],
  156. },
  157. });
  158. const handleSwitchType = (value) => {
  159. if (defaultType.value.includes(value)) {
  160. type.value = value;
  161. if (value === "gallery") {
  162. audioPlay();
  163. } else {
  164. audioPause();
  165. }
  166. } else {
  167. type.value = "model";
  168. }
  169. };
  170. const audioPlay = () => {
  171. audioSound.value && audioSound.value.play();
  172. };
  173. const audioPause = () => {
  174. audioSound.value && audioSound.value.pause();
  175. };
  176. const handleSlideUpdate = (index) => {
  177. if (unref(props.gallery).length > 1) {
  178. currentSlideIndex.value = index + 1;
  179. }
  180. };
  181. const reloadIframe = () => {
  182. if (iframeRef.value) {
  183. try {
  184. iframeRef.value.src += "";
  185. } catch (error) {}
  186. }
  187. };
  188. const handleFullScreen = () => {
  189. enter();
  190. };
  191. const handleExitFullScreen = () => {
  192. exit();
  193. };
  194. </script>
  195. <style>
  196. .show-case-container {
  197. --show-case-width: 66.8125rem;
  198. --show-case-height: 34.1875rem;
  199. --show-case-border-radius: 0.625rem;
  200. --show-case-background: #c1b2b2;
  201. --show-case-tools-padding: 1rem;
  202. --show-case-btn-font-size: 16px;
  203. --show-case-btn-model-bg: url("/img/show_case_m_bg.png");
  204. --show-case-btn-model-bg-active: url("/img/show_case_m_bg_active.png");
  205. --show-case-btn-video-bg: url("/img/show_case_v_bg.png");
  206. --show-case-btn-video-bg-active: url("/img/show_case_v_bg_active.png");
  207. --show-case-btn-gallery-bg: url("/img/show_case_p_bg.png");
  208. --show-case-btn-gallery-bg-active: url("/img/show_case_p_bg_active.png");
  209. }
  210. </style>
  211. <style lang="scss" scoped>
  212. .show-case-container {
  213. width: var(--show-case-width);
  214. height: var(--show-case-height);
  215. position: relative;
  216. background-color: var(--show-case-background);
  217. border-radius: var(--show-case-border-radius);
  218. .show-case {
  219. width: 100%;
  220. height: 100%;
  221. iframe,
  222. video,
  223. :deep(.n-carousel) {
  224. width: 100%;
  225. height: 100%;
  226. object-fit: cover;
  227. }
  228. :deep(.n-carousel) {
  229. .carousel-img {
  230. width: 100%;
  231. height: 100%;
  232. object-fit: cover;
  233. }
  234. .custom-arrow {
  235. position: absolute;
  236. width: 100%;
  237. height: 100%;
  238. top: 0;
  239. left: 0;
  240. // background: red;
  241. z-index: 111;
  242. pointer-events: none;
  243. display: inline-flex;
  244. justify-content: space-between;
  245. flex-direction: row;
  246. align-items: center;
  247. .btn-img {
  248. width: 3.8125rem;
  249. height: 3.8125rem;
  250. pointer-events: all;
  251. cursor: pointer;
  252. margin: 0 1.25rem;
  253. }
  254. }
  255. }
  256. .video-icon {
  257. width: 100%;
  258. height: 100%;
  259. display: inline-flex;
  260. align-items: center;
  261. justify-content: center;
  262. position: absolute;
  263. opacity: 0;
  264. transition: opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  265. &:hover {
  266. opacity: 1;
  267. }
  268. top: 0;
  269. left: 0;
  270. svg {
  271. width: 80px;
  272. height: 80px;
  273. color: #666;
  274. opacity: 0.9;
  275. pointer-events: auto;
  276. cursor: pointer;
  277. }
  278. }
  279. }
  280. .tools {
  281. display: inline-flex;
  282. position: absolute;
  283. height: 2.25rem;
  284. bottom: 1.25rem;
  285. flex-direction: row;
  286. justify-content: space-between;
  287. align-items: center;
  288. width: calc(100% - var(--show-case-tools-padding) * 2);
  289. padding: 0 var(--show-case-tools-padding);
  290. pointer-events: none;
  291. .actions {
  292. display: inline-flex;
  293. align-items: center;
  294. img {
  295. height: 2.5rem;
  296. width: auto;
  297. margin: 0 0.3125rem;
  298. cursor: pointer;
  299. pointer-events: all;
  300. }
  301. }
  302. .group-type {
  303. :deep(.n-button) {
  304. --n-border: none !important;
  305. --n-border-hover: none !important;
  306. --n-border-pressed: none !important;
  307. --n-border-focus: none !important;
  308. --n-ripple-color: none !important;
  309. transition: none;
  310. background-color: transparent;
  311. color: white;
  312. pointer-events: all;
  313. font-size: var(--show-case-btn-font-size);
  314. // min-width: 80px;
  315. // padding: 10px 40px;
  316. img {
  317. height: 1.0625rem;
  318. margin-right: 0.3125rem;
  319. width: auto;
  320. }
  321. &.btn {
  322. background-size: contain;
  323. background-repeat: no-repeat;
  324. background-position: top center;
  325. border: none;
  326. }
  327. &.model {
  328. background-image: var(--show-case-btn-model-bg);
  329. }
  330. &.video {
  331. background-image: var(--show-case-btn-video-bg);
  332. }
  333. &.gallery {
  334. background-image: var(--show-case-btn-gallery-bg);
  335. }
  336. &.active {
  337. &.model {
  338. background-image: var(--show-case-btn-model-bg-active);
  339. }
  340. &.video {
  341. background-image: var(--show-case-btn-video-bg-active);
  342. }
  343. &.gallery {
  344. background-image: var(--show-case-btn-gallery-bg-active);
  345. }
  346. }
  347. }
  348. }
  349. }
  350. }
  351. </style>