showCase.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  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. v-if="model"
  70. class="model btn"
  71. :class="{
  72. active: isModel,
  73. }"
  74. round
  75. @click="handleSwitchType('model')"
  76. >
  77. <img src="@/assets/icon_model.png" /> 模型
  78. </n-button>
  79. <n-button
  80. v-if="video"
  81. class="video btn"
  82. :class="{
  83. active: isVideo,
  84. }"
  85. round
  86. @click="handleSwitchType('video')"
  87. ><img src="@/assets/icon_video.png" />视频</n-button
  88. >
  89. <n-button
  90. v-if="gallery.length > 0"
  91. class="gallery btn"
  92. :class="{
  93. active: isGallery,
  94. }"
  95. round
  96. @click="handleSwitchType('gallery')"
  97. >
  98. <img src="@/assets/icon_photo.png" />图片
  99. <span v-if="gallery.length > 0">{{
  100. `${currentSlideIndex}/${gallery.length}`
  101. }}</span></n-button
  102. >
  103. </n-space>
  104. <div class="actions">
  105. <div v-if="isModel && model">
  106. <img src="@/assets/zoom-in.png" @click="handleFullScreen" />
  107. <img src="@/assets/zoom-out.png" @click="handleExitFullScreen" />
  108. <img src="@/assets/reload.png" @click="reloadIframe" />
  109. </div>
  110. <div v-if="isGallery && audio">
  111. <img src="@/assets/audio-muted.png" @click="audioPause" />
  112. <img src="@/assets/audio-unmuted.png" @click="audioPlay" />
  113. </div>
  114. </div>
  115. </div>
  116. </div>
  117. </template>
  118. <script setup>
  119. import { ref, computed, unref, watchEffect } from "vue";
  120. import { useFullscreen } from "@vueuse/core";
  121. defineOptions({
  122. name: "show-case",
  123. });
  124. const props = defineProps({
  125. active: {
  126. type: String,
  127. default: () => "",
  128. },
  129. model: {
  130. type: String,
  131. default: () => "",
  132. },
  133. video: {
  134. type: String,
  135. default: () => "",
  136. },
  137. audio: {
  138. type: String,
  139. default: () => "",
  140. },
  141. gallery: {
  142. type: Array,
  143. default: () => [""],
  144. },
  145. });
  146. const iframeRef = ref();
  147. const containerRef = ref();
  148. const type = ref("model");
  149. const defaultType = ref(["model", "video", "audio", "gallery"]);
  150. const videoRef = ref();
  151. const modelUrl = import.meta.env.VITE_MODEL_URL;
  152. const iframeURL = computed(() => modelUrl + props.model);
  153. const isModel = computed(() => type.value === "model");
  154. const isVideo = computed(() => type.value === "video");
  155. // const isAudio = computed(() => type.value === "audio");
  156. const isGallery = computed(() => type.value === "gallery");
  157. const domain = ref(import.meta.env.VITE_DOMAIN_URL);
  158. const audioSound = ref("");
  159. const currentSlideIndex = ref(1);
  160. const { isFullscreen, enter, exit } = useFullscreen(containerRef);
  161. const isVideoPlaying = ref(false);
  162. const handleSwitchType = (value) => {
  163. if (defaultType.value.includes(value)) {
  164. type.value = value;
  165. if (value === "gallery") {
  166. audioPlay();
  167. } else {
  168. audioPause();
  169. }
  170. } else {
  171. type.value = "model";
  172. }
  173. };
  174. const audioPlay = () => {
  175. audioSound.value && audioSound.value.play();
  176. };
  177. const audioPause = () => {
  178. audioSound.value && audioSound.value.pause();
  179. };
  180. const handleSlideUpdate = (index) => {
  181. if (unref(props.gallery).length > 1) {
  182. currentSlideIndex.value = index + 1;
  183. }
  184. };
  185. const reloadIframe = () => {
  186. if (iframeRef.value) {
  187. try {
  188. iframeRef.value.src += "";
  189. } catch (error) {}
  190. }
  191. };
  192. const handleFullScreen = () => {
  193. enter();
  194. };
  195. const handleExitFullScreen = () => {
  196. exit();
  197. };
  198. watchEffect(() => {
  199. if (props.active) {
  200. let tempType = "";
  201. if (props.active === "img") {
  202. tempType = "gallery";
  203. } else {
  204. tempType = props.active;
  205. }
  206. handleSwitchType(tempType);
  207. }
  208. });
  209. </script>
  210. <style>
  211. .show-case-container {
  212. --show-case-width: 66.8125rem;
  213. --show-case-height: 34.1875rem;
  214. --show-case-border-radius: 0.625rem;
  215. --show-case-background: #c1b2b2;
  216. --show-case-tools-padding: 1rem;
  217. --show-case-btn-font-size: 16px;
  218. --show-case-btn-model-bg: url("/img/show_case_m_bg.png");
  219. --show-case-btn-model-bg-active: url("/img/show_case_m_bg_active.png");
  220. --show-case-btn-video-bg: url("/img/show_case_v_bg.png");
  221. --show-case-btn-video-bg-active: url("/img/show_case_v_bg_active.png");
  222. --show-case-btn-gallery-bg: url("/img/show_case_p_bg.png");
  223. --show-case-btn-gallery-bg-active: url("/img/show_case_p_bg_active.png");
  224. }
  225. </style>
  226. <style lang="scss" scoped>
  227. .show-case-container {
  228. width: var(--show-case-width);
  229. height: var(--show-case-height);
  230. position: relative;
  231. background-color: var(--show-case-background);
  232. border-radius: var(--show-case-border-radius);
  233. .show-case {
  234. width: 100%;
  235. height: 100%;
  236. iframe,
  237. video,
  238. :deep(.n-carousel) {
  239. width: 100%;
  240. height: 100%;
  241. object-fit: cover;
  242. }
  243. :deep(.n-carousel) {
  244. .carousel-img {
  245. width: 100%;
  246. height: 100%;
  247. object-fit: cover;
  248. }
  249. .custom-arrow {
  250. position: absolute;
  251. width: 100%;
  252. height: 100%;
  253. top: 0;
  254. left: 0;
  255. // background: red;
  256. z-index: 111;
  257. pointer-events: none;
  258. display: inline-flex;
  259. justify-content: space-between;
  260. flex-direction: row;
  261. align-items: center;
  262. .btn-img {
  263. width: 3.8125rem;
  264. height: 3.8125rem;
  265. pointer-events: all;
  266. cursor: pointer;
  267. margin: 0 1.25rem;
  268. }
  269. }
  270. }
  271. .video-icon {
  272. width: 100%;
  273. height: 100%;
  274. display: inline-flex;
  275. align-items: center;
  276. justify-content: center;
  277. position: absolute;
  278. opacity: 0;
  279. transition: opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  280. &:hover {
  281. opacity: 1;
  282. }
  283. top: 0;
  284. left: 0;
  285. svg {
  286. width: 80px;
  287. height: 80px;
  288. color: #666;
  289. opacity: 0.9;
  290. pointer-events: auto;
  291. cursor: pointer;
  292. }
  293. }
  294. }
  295. .tools {
  296. display: inline-flex;
  297. position: absolute;
  298. height: 2.25rem;
  299. bottom: 1.25rem;
  300. flex-direction: row;
  301. justify-content: space-between;
  302. align-items: center;
  303. width: calc(100% - var(--show-case-tools-padding) * 2);
  304. padding: 0 var(--show-case-tools-padding);
  305. pointer-events: none;
  306. .actions {
  307. display: inline-flex;
  308. align-items: center;
  309. img {
  310. height: 2.5rem;
  311. width: auto;
  312. margin: 0 0.3125rem;
  313. cursor: pointer;
  314. pointer-events: all;
  315. }
  316. }
  317. .group-type {
  318. :deep(.n-button) {
  319. --n-border: none !important;
  320. --n-border-hover: none !important;
  321. --n-border-pressed: none !important;
  322. --n-border-focus: none !important;
  323. --n-ripple-color: none !important;
  324. transition: none;
  325. background-color: transparent;
  326. color: white;
  327. pointer-events: all;
  328. font-size: var(--show-case-btn-font-size);
  329. // min-width: 80px;
  330. // padding: 10px 40px;
  331. img {
  332. height: 1.0625rem;
  333. margin-right: 0.3125rem;
  334. width: auto;
  335. }
  336. &.btn {
  337. background-size: contain;
  338. background-repeat: no-repeat;
  339. background-position: top center;
  340. border: none;
  341. }
  342. &.model {
  343. background-image: var(--show-case-btn-model-bg);
  344. }
  345. &.video {
  346. background-image: var(--show-case-btn-video-bg);
  347. }
  348. &.gallery {
  349. background-image: var(--show-case-btn-gallery-bg);
  350. }
  351. &.active {
  352. &.model {
  353. background-image: var(--show-case-btn-model-bg-active);
  354. }
  355. &.video {
  356. background-image: var(--show-case-btn-video-bg-active);
  357. }
  358. &.gallery {
  359. background-image: var(--show-case-btn-gallery-bg-active);
  360. }
  361. }
  362. }
  363. }
  364. }
  365. }
  366. </style>