showCase.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. <template>
  2. <div class="show-case-container">
  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 :src="video" autoplay playsinline></video>
  9. </div>
  10. <div class="show-case" v-if="isGallery">
  11. <n-carousel
  12. draggable
  13. :show-dots="false"
  14. show-arrow
  15. @update:current-index="handleSlideUpdate"
  16. >
  17. <template v-for="img in gallery">
  18. <img class="carousel-img" :src="img" />
  19. </template>
  20. <template #arrow="{ prev, next }" v-if="gallery.length > 1">
  21. <div class="custom-arrow">
  22. <img class="btn-img" src="@/assets/arrow-left.png" @click="prev" />
  23. <img class="btn-img" src="@/assets/arrow-right.png" @click="next" />
  24. </div>
  25. </template>
  26. </n-carousel>
  27. </div>
  28. <div class="tools">
  29. <n-space class="group-type" :size="25">
  30. <n-button
  31. class="model btn"
  32. :class="{
  33. active: isModel,
  34. }"
  35. round
  36. @click="handleSwitchType('model')"
  37. >
  38. <img src="@/assets/icon_model.png" /> 模型
  39. </n-button>
  40. <n-button
  41. v-if="video"
  42. class="video btn"
  43. :class="{
  44. active: isVideo,
  45. }"
  46. round
  47. @click="handleSwitchType('video')"
  48. ><img src="@/assets/icon_video.png" />视频</n-button
  49. >
  50. <n-button
  51. class="gallery btn"
  52. :class="{
  53. active: isGallery,
  54. }"
  55. round
  56. @click="handleSwitchType('gallery')"
  57. >
  58. <img src="@/assets/icon_photo.png" />图片
  59. <span v-if="gallery.length > 0">{{
  60. `${currentSlideIndex}/${gallery.length}`
  61. }}</span></n-button
  62. >
  63. </n-space>
  64. <div class="actions">
  65. <div v-if="isModel">
  66. <img src="@/assets/zoom-in.png" />
  67. <img src="@/assets/zoom-out.png" />
  68. <img src="@/assets/reload.png" @click="reloadIframe" />
  69. </div>
  70. <div v-if="isGallery && audio">
  71. <img src="@/assets/audio-muted.png" @click="audioPause" />
  72. <img src="@/assets/audio-unmuted.png" @click="audioPlay" />
  73. </div>
  74. </div>
  75. </div>
  76. </div>
  77. </template>
  78. <script setup>
  79. import { ref, computed, unref, watch } from "vue";
  80. const iframeRef = ref();
  81. const type = ref("model");
  82. const defaultType = ref(["model", "video", "audio", "gallery"]);
  83. const iframeURL = ref("https://www.4dmodel.com/SuperTwo/index.html?m=TEST");
  84. const isModel = computed(() => type.value === "model");
  85. const isVideo = computed(() => type.value === "video");
  86. // const isAudio = computed(() => type.value === "audio");
  87. const isGallery = computed(() => type.value === "gallery");
  88. const domain = ref(import.meta.env.VITE_DOMAIN_URL);
  89. const audioSound = ref("");
  90. const currentSlideIndex = ref(1);
  91. defineOptions({
  92. name: "show-case",
  93. });
  94. const props = defineProps({
  95. model: {
  96. type: String,
  97. default: () => "",
  98. },
  99. video: {
  100. type: String,
  101. default: () => "",
  102. },
  103. audio: {
  104. type: String,
  105. default: () => "",
  106. },
  107. gallery: {
  108. type: Array,
  109. default: () => [""],
  110. },
  111. });
  112. const handleSwitchType = (value) => {
  113. if (defaultType.value.includes(value)) {
  114. type.value = value;
  115. if (value === "gallery") {
  116. audioPlay();
  117. } else {
  118. audioPause();
  119. }
  120. } else {
  121. type.value = "model";
  122. }
  123. };
  124. const audioPlay = () => {
  125. audioSound.value && audioSound.value.play();
  126. };
  127. const audioPause = () => {
  128. audioSound.value && audioSound.value.pause();
  129. };
  130. const handleSlideUpdate = (index) => {
  131. if (unref(props.gallery).length > 1) {
  132. currentSlideIndex.value = index + 1;
  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: 16px;
  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. --n-border: none !important;
  230. --n-border-hover: none !important;
  231. --n-border-pressed: none !important;
  232. --n-border-focus: none !important;
  233. --n-ripple-color: none !important;
  234. transition: none;
  235. background-color: transparent;
  236. color: white;
  237. pointer-events: all;
  238. font-size: var(--show-case-btn-font-size);
  239. // min-width: 80px;
  240. // padding: 10px 40px;
  241. img {
  242. height: 1.0625rem;
  243. margin-right: 0.3125rem;
  244. width: auto;
  245. }
  246. &.btn {
  247. background-size: contain;
  248. background-repeat: no-repeat;
  249. background-position: top center;
  250. border: none;
  251. }
  252. &.model {
  253. background-image: var(--show-case-btn-model-bg);
  254. }
  255. &.video {
  256. background-image: var(--show-case-btn-video-bg);
  257. }
  258. &.gallery {
  259. background-image: var(--show-case-btn-gallery-bg);
  260. }
  261. &.active {
  262. &.model {
  263. background-image: var(--show-case-btn-model-bg-active);
  264. }
  265. &.video {
  266. background-image: var(--show-case-btn-video-bg-active);
  267. }
  268. &.gallery {
  269. background-image: var(--show-case-btn-gallery-bg-active);
  270. }
  271. }
  272. }
  273. }
  274. }
  275. }
  276. </style>