showCase.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. <template>
  2. <div class="show-case-container">
  3. <div class="show-case" v-if="isModel">
  4. <iframe ref="iframeRef" frameborder="0" :src="iframeURL"></iframe>
  5. </div>
  6. <div class="show-case" v-if="isVideo">
  7. <video
  8. src="https://4dscene.4dage.com/new4dkk/v2/video/homeVideoNew.mp4"
  9. autoplay
  10. playsinline
  11. ></video>
  12. </div>
  13. <div class="show-case" v-if="isGallery">
  14. <n-carousel draggable :show-dots="false" show-arrow>
  15. <img
  16. class="carousel-img"
  17. src="https://naive-ui.oss-cn-beijing.aliyuncs.com/carousel-img/carousel1.jpeg"
  18. />
  19. <img
  20. class="carousel-img"
  21. src="https://naive-ui.oss-cn-beijing.aliyuncs.com/carousel-img/carousel2.jpeg"
  22. />
  23. <img
  24. class="carousel-img"
  25. src="https://naive-ui.oss-cn-beijing.aliyuncs.com/carousel-img/carousel3.jpeg"
  26. />
  27. <img
  28. class="carousel-img"
  29. src="https://naive-ui.oss-cn-beijing.aliyuncs.com/carousel-img/carousel4.jpeg"
  30. />
  31. <template #arrow="{ prev, next }">
  32. <div class="custom-arrow">
  33. <img class="btn-img" src="/img/arrow-left.png" @click="prev" />
  34. <img class="btn-img" src="/img/arrow-right.png" @click="next" />
  35. </div>
  36. </template>
  37. </n-carousel>
  38. </div>
  39. <div class="tools">
  40. <n-space class="group-type" :size="25">
  41. <n-button
  42. class="model btn"
  43. :class="{
  44. active: isModel,
  45. }"
  46. round
  47. @click="handleSwitchType('model')"
  48. >
  49. <img src="/img/icon_model.png" /> 模型
  50. </n-button>
  51. <n-button
  52. class="video btn"
  53. :class="{
  54. active: isVideo,
  55. }"
  56. round
  57. @click="handleSwitchType('video')"
  58. ><img src="/img/icon_video.png" />视频</n-button
  59. >
  60. <n-button
  61. class="gallery btn"
  62. :class="{
  63. active: isGallery,
  64. }"
  65. round
  66. @click="handleSwitchType('gallery')"
  67. >
  68. <img src="/img/icon_photo.png" />图片</n-button
  69. >
  70. </n-space>
  71. <div class="actions">
  72. <div v-if="isModel">
  73. <img src="/img/zoom-in.png" />
  74. <img src="/img/zoom-out.png" />
  75. <img src="/img/reload.png" @click="reloadIframe" />
  76. </div>
  77. <div v-if="isGallery">
  78. <img src="/img/audio-muted.png" @click="stop" />
  79. <img
  80. src="/img/audio-unmuted.png"
  81. @click="!isPlaying ? play() : () => {}"
  82. />
  83. </div>
  84. </div>
  85. </div>
  86. </div>
  87. </template>
  88. <script setup>
  89. import { ref, computed } from "vue";
  90. import { useSound } from "@vueuse/sound";
  91. const iframeRef = ref();
  92. const type = ref("model");
  93. const defaultType = ref(["model", "video", "audio", "gallery"]);
  94. const iframeURL = ref("https://www.4dmodel.com/SuperTwo/index.html?m=TEST");
  95. const isModel = computed(() => type.value === "model");
  96. const isVideo = computed(() => type.value === "video");
  97. const isAudio = computed(() => type.value === "audio");
  98. const isGallery = computed(() => type.value === "gallery");
  99. const { play, isPlaying, stop } = useSound(
  100. "//samplelib.com/lib/preview/mp3/sample-15s.mp3"
  101. );
  102. const handleSwitchType = (value) => {
  103. if (defaultType.value.includes(value)) {
  104. type.value = value;
  105. if (value === "gallery") {
  106. play();
  107. } else {
  108. stop();
  109. }
  110. } else {
  111. type.value = "model";
  112. }
  113. };
  114. defineOptions({
  115. name: "show-case",
  116. });
  117. const props = defineProps({
  118. model: {
  119. type: String,
  120. default: () => "",
  121. },
  122. video: {
  123. type: String,
  124. default: () => "",
  125. },
  126. audio: {
  127. type: String,
  128. default: () => "",
  129. },
  130. photos: {
  131. type: Array,
  132. default: () => [""],
  133. },
  134. });
  135. const reloadIframe = () => {
  136. if (iframeRef.value) {
  137. try {
  138. iframeRef.value.src += "";
  139. } catch (error) {}
  140. }
  141. };
  142. </script>
  143. <style>
  144. .show-case-container {
  145. --show-case-width: 66.8125rem;
  146. --show-case-height: 34.1875rem;
  147. --show-case-border-radius: 0.625rem;
  148. --show-case-background: #c1b2b2;
  149. --show-case-tools-padding: 1rem;
  150. --show-case-btn-font-size: 1.125rem;
  151. --show-case-btn-model-bg: url("/img/show_case_m_bg.png");
  152. --show-case-btn-model-bg-active: url("/img/show_case_m_bg_active.png");
  153. --show-case-btn-video-bg: url("/img/show_case_v_bg.png");
  154. --show-case-btn-video-bg-active: url("/img/show_case_v_bg_active.png");
  155. --show-case-btn-gallery-bg: url("/img/show_case_p_bg.png");
  156. --show-case-btn-gallery-bg-active: url("/img/show_case_p_bg_active.png");
  157. }
  158. </style>
  159. <style lang="scss" scoped>
  160. .show-case-container {
  161. width: var(--show-case-width);
  162. height: var(--show-case-height);
  163. position: relative;
  164. background-color: var(--show-case-background);
  165. border-radius: var(--show-case-border-radius);
  166. .show-case {
  167. width: 100%;
  168. height: 100%;
  169. iframe,
  170. video,
  171. :deep(.n-carousel) {
  172. width: 100%;
  173. height: 100%;
  174. object-fit: cover;
  175. }
  176. :deep(.n-carousel) {
  177. .carousel-img {
  178. width: 100%;
  179. height: 100%;
  180. object-fit: cover;
  181. }
  182. .custom-arrow {
  183. position: absolute;
  184. width: 100%;
  185. height: 100%;
  186. top: 0;
  187. left: 0;
  188. // background: red;
  189. z-index: 111;
  190. pointer-events: none;
  191. display: inline-flex;
  192. justify-content: space-between;
  193. flex-direction: row;
  194. align-items: center;
  195. .btn-img {
  196. width: 3.8125rem;
  197. height: 3.8125rem;
  198. pointer-events: all;
  199. cursor: pointer;
  200. margin: 0 1.25rem;
  201. }
  202. }
  203. }
  204. }
  205. .tools {
  206. display: inline-flex;
  207. position: absolute;
  208. height: 2.25rem;
  209. bottom: 1.25rem;
  210. flex-direction: row;
  211. justify-content: space-between;
  212. align-items: center;
  213. width: calc(100% - var(--show-case-tools-padding) * 2);
  214. padding: 0 var(--show-case-tools-padding);
  215. pointer-events: none;
  216. .actions {
  217. display: inline-flex;
  218. align-items: center;
  219. img {
  220. height: 2.5rem;
  221. width: auto;
  222. margin: 0 0.3125rem;
  223. cursor: pointer;
  224. pointer-events: all;
  225. }
  226. }
  227. .group-type {
  228. :deep(.n-button) {
  229. background-color: #ababab;
  230. color: white;
  231. pointer-events: all;
  232. font-size: var(--show-case-btn-font-size);
  233. padding: 10px 40px;
  234. img {
  235. height: 1.25rem;
  236. margin-right: 0.5rem;
  237. width: auto;
  238. }
  239. &.btn {
  240. background-size: cover;
  241. background-repeat: no-repeat;
  242. }
  243. &.model {
  244. // background-image: var(--show-case-btn-model-bg);
  245. }
  246. &.active {
  247. background-color: var(--main-primary-color);
  248. border-color: var(--main-primary-color);
  249. }
  250. }
  251. }
  252. }
  253. }
  254. </style>