Opening.vue 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490
  1. <template>
  2. <!-- 视频 -->
  3. <div
  4. class="videocon"
  5. v-if="isVideoMode || isMixinMode"
  6. v-show="videoShow"
  7. :style="{
  8. zIndex: videoIndex,
  9. }"
  10. >
  11. <div
  12. class="video-background"
  13. v-if="coverData.videoPcLoc !== 'full'"
  14. :style="{
  15. backgroundImage:
  16. coverData.coverVideoBac === 'imgTile'
  17. ? `url(${coverData.videoBacImg})`
  18. : 'none',
  19. backgroundColor:
  20. coverData.coverVideoBac === 'imgTile'
  21. ? `rgba(0,0,0,1)`
  22. : `${coverData.videoColorSelec}`,
  23. }"
  24. ></div>
  25. <video
  26. v-if="coverData.videoPc"
  27. x5-playsinline="true"
  28. playsinline="true"
  29. webkit-playsinline="true"
  30. class="video"
  31. ref="openvideo$"
  32. autoplay
  33. preload
  34. :poster="coverData.videoPcIcon"
  35. :class="coverData.videoPcLoc == 'center' ? 'contain' : 'cover'"
  36. :src="coverData.videoPc"
  37. :controls="Boolean(coverData.coverVideoControl)"
  38. muted
  39. ></video>
  40. <img
  41. v-show="videoNeedPlay"
  42. @click.stop="handleVideoPlay"
  43. class="videoPlay"
  44. :src="require('@/assets/images/default/bofang.png')"
  45. alt=""
  46. />
  47. <div @click.stop="jumpVideo" class="jump" v-if="countdownVideo == 0">
  48. {{ $t("common.jump") }}
  49. </div>
  50. </div>
  51. <!-- 图片 -->
  52. <div
  53. class="imgcon"
  54. v-if="isImageMode || isMixinMode"
  55. v-show="imgShow"
  56. :style="{
  57. zIndex: imgIndex,
  58. }"
  59. >
  60. <div
  61. @click="jumpImage(0)"
  62. class="image-front"
  63. :style="{
  64. backgroundImage: `url(${coverData.coverPc})`,
  65. backgroundSize: coverData.coverPcLoc == 'center' ? 'contain' : 'cover',
  66. }"
  67. ></div>
  68. <div
  69. class="img-background"
  70. v-if="coverData.coverPcLoc !== 'full'"
  71. :style="{
  72. backgroundImage:
  73. coverData.coverImgBac == 'imgTile'
  74. ? `url(${coverData.coverBac})`
  75. : `none`,
  76. backgroundColor:
  77. coverData.coverImgBac == 'imgTile'
  78. ? `none`
  79. : `${coverData.imgColorSelec}`,
  80. }"
  81. ></div>
  82. <div @click.stop="jumpImage(1)" class="jump" v-if="isImageAutoNext">
  83. {{
  84. countdownImg > 0
  85. ? $t("common.jumpTips", { second: countdownImg })
  86. : $t("common.jump")
  87. }}
  88. </div>
  89. </div>
  90. </template>
  91. <script setup>
  92. import {
  93. ref,
  94. watch,
  95. computed,
  96. onMounted,
  97. defineProps,
  98. unref,
  99. watchEffect,
  100. } from "vue";
  101. import { useStore } from "vuex";
  102. import { useApp } from "@/app";
  103. import { useI18n, getLocale } from "@/i18n";
  104. const { t } = useI18n({ useScope: "global" });
  105. const zIndex = ref(1);
  106. const useZIndex = () => {
  107. zIndex.value++;
  108. return unref(zIndex);
  109. };
  110. const props = defineProps({
  111. coverData: {
  112. type: [Boolean, Object],
  113. default: () => {
  114. return {};
  115. },
  116. },
  117. });
  118. const store = useStore();
  119. const openvideo$ = ref(null);
  120. const videoNeedPlay = ref(true);
  121. const isMixinMode = computed(
  122. () => props.coverData.coverSelect.toLowerCase().indexOf("and") > -1
  123. );
  124. const isImageMode = computed(
  125. () => props.coverData.coverSelect.toLowerCase() === "img"
  126. );
  127. const isVideoMode = computed(
  128. () => props.coverData.coverSelect.toLowerCase() === "video"
  129. );
  130. // 字段意思有误
  131. const showImageFirst = computed(
  132. () => props.coverData.coverImageOrder === "before"
  133. );
  134. const show = ref(true);
  135. const countdownImg = ref(3);
  136. const countdownVideo = ref(3);
  137. const imgTimer = ref(null);
  138. const videotimer = ref(null);
  139. const isImageCountDone = ref(false);
  140. const isVideoCountDone = ref(false);
  141. const isImageAutoNext = computed(() => props.coverData.coverImageInWay === 1);
  142. const isVideoAutoNext = computed(() => props.coverData.coverVideoInWay === 1);
  143. const imgShow = ref(false);
  144. const videoShow = ref(false);
  145. const imgIndex = ref(1);
  146. const videoIndex = ref(1);
  147. const currentScene = computed(() => store.getters["scene/currentScene"]);
  148. //手动跳转
  149. /**
  150. * 跳转逻辑PM设定非奇怪,要注意
  151. * @TODO 图片模式 button 3秒倒只作装饰显示,不参与逻辑
  152. *
  153. * */
  154. const jumpImage = (from = 0) => {
  155. // 0 来自元素click, 1.来自跳转按钮
  156. if (unref(isMixinMode)) {
  157. if (unref(showImageFirst)) {
  158. imgShow.value = false;
  159. videoShow.value = true;
  160. startVideoCount();
  161. } else {
  162. // 强制跳转
  163. // 非自动模式强制跳转
  164. if (from === 0 && !unref(isImageAutoNext)) {
  165. toApp();
  166. }
  167. if (from === 1) {
  168. toApp();
  169. }
  170. if (unref(isImageAutoNext) && unref(isImageCountDone)) {
  171. toApp();
  172. }
  173. }
  174. } else {
  175. // 非自动模式强制跳转
  176. if (from === 0 && !unref(isImageAutoNext)) {
  177. toApp();
  178. }
  179. // 非自动模式强制跳转
  180. if (from === 1) {
  181. toApp();
  182. }
  183. if (unref(isImageAutoNext) && unref(isImageCountDone)) {
  184. toApp();
  185. }
  186. }
  187. };
  188. //手动跳转
  189. const jumpVideo = () => {
  190. if (unref(isMixinMode)) {
  191. if (!unref(showImageFirst)) {
  192. imgShow.value = true;
  193. videoShow.value = false;
  194. startImageCount();
  195. } else {
  196. if (unref(isVideoCountDone)) {
  197. toApp();
  198. }
  199. }
  200. } else {
  201. if (unref(isVideoCountDone)) {
  202. toApp();
  203. }
  204. }
  205. };
  206. const handleVideoPlay = () => {
  207. let video = unref(openvideo$);
  208. video && video.play();
  209. };
  210. const startImageCount = () => {
  211. imgTimer.value = setInterval(() => {
  212. countdownImg.value--;
  213. if (countdownImg.value == 0) {
  214. clearInterval(imgTimer.value);
  215. isImageCountDone.value = true;
  216. imgTimer.value = null;
  217. return;
  218. }
  219. }, 1000);
  220. };
  221. const startVideoCount = () => {
  222. const nextIndex = useZIndex();
  223. videoIndex.value = nextIndex;
  224. videotimer.value = setInterval(() => {
  225. countdownVideo.value--;
  226. if (countdownVideo.value == 0) {
  227. clearInterval(videotimer.value);
  228. isVideoCountDone.value = true;
  229. videotimer.value = null;
  230. return;
  231. }
  232. }, 1000);
  233. };
  234. //开始全监听
  235. watch(
  236. [isMixinMode, isImageMode, isVideoMode, showImageFirst],
  237. ([val1, val2, val3, val4]) => {
  238. //混合模式
  239. if (unref(val1)) {
  240. //图片优先
  241. if (unref(val4)) {
  242. imgShow.value = true;
  243. startImageCount();
  244. } else {
  245. videoShow.value = true;
  246. startVideoCount();
  247. }
  248. } else {
  249. if (unref(val2)) {
  250. imgShow.value = true;
  251. startImageCount();
  252. }
  253. if (unref(val3)) {
  254. videoShow.value = true;
  255. startVideoCount();
  256. }
  257. //非混合模式
  258. }
  259. },
  260. {
  261. deep: true,
  262. immediate: true,
  263. }
  264. );
  265. //倒数完全监听
  266. watch(
  267. [isMixinMode, isImageCountDone, isVideoCountDone, showImageFirst],
  268. ([val1, val2, val3, val4]) => {
  269. //混合模式
  270. if (unref(val1)) {
  271. //图片优先
  272. if (unref(val4)) {
  273. //图片倒数完
  274. if (unref(val2)) {
  275. if (unref(isImageAutoNext)) {
  276. imgShow.value = false;
  277. videoShow.value = true;
  278. startVideoCount();
  279. }
  280. }
  281. } else {
  282. //图片非优先
  283. if (unref(val2)) {
  284. if (unref(isImageAutoNext)) {
  285. toApp();
  286. }
  287. }
  288. }
  289. } else {
  290. //非混合模式
  291. if (unref(val2)) {
  292. if (unref(isImageAutoNext)) {
  293. toApp();
  294. }
  295. }
  296. }
  297. },
  298. {
  299. deep: true,
  300. immediate: true,
  301. }
  302. );
  303. //跳转到app
  304. const toApp = () => {
  305. imgShow.value = false;
  306. videoShow.value = false;
  307. useApp().then((app) => {
  308. setTimeout(() => {
  309. app.render();
  310. }, 1000);
  311. });
  312. };
  313. onMounted(() => {
  314. console.log("coverData", unref(props.coverData));
  315. if (openvideo$.value) {
  316. openvideo$.value.addEventListener("ended", () => {
  317. if (isVideoAutoNext.value) {
  318. //混合模式
  319. if (unref(isMixinMode)) {
  320. //视频优先 直达图片
  321. if (!unref(showImageFirst)) {
  322. videoShow.value = false;
  323. imgShow.value = true;
  324. startImageCount();
  325. } else {
  326. toApp();
  327. }
  328. } else {
  329. toApp();
  330. }
  331. }
  332. });
  333. openvideo$.value.addEventListener("playing", () => {
  334. if (videoNeedPlay.value) {
  335. videoNeedPlay.value = false;
  336. }
  337. });
  338. openvideo$.value.addEventListener("pause", () => {
  339. if (!videoNeedPlay.value) {
  340. videoNeedPlay.value = true;
  341. }
  342. });
  343. // document.addEventListener(
  344. // "WeixinJSBridgeReady",
  345. // () => {
  346. // openvideo$.value.play();
  347. // },
  348. // false
  349. // );
  350. }
  351. }),
  352. useApp().then((app) => {
  353. app.Scene.on("ready", () => {
  354. if (show.value) {
  355. show.value = false;
  356. }
  357. });
  358. });
  359. </script>
  360. <style lang="scss" scoped>
  361. .imgcon,
  362. .videocon {
  363. position: fixed;
  364. left: 0;
  365. right: 0;
  366. top: 0;
  367. bottom: 0;
  368. width: 100%;
  369. height: 100%;
  370. z-index: 1;
  371. }
  372. .video-background {
  373. background-repeat: repeat;
  374. position: absolute;
  375. left: 0;
  376. right: 0;
  377. top: 0;
  378. bottom: 0;
  379. width: 100%;
  380. height: 100%;
  381. z-index: 1;
  382. }
  383. .imgcon {
  384. // z-index: 10;
  385. .image-front,
  386. .img-background {
  387. background-position: center;
  388. width: 100%;
  389. height: 100%;
  390. position: absolute;
  391. top: 0;
  392. z-index: 1;
  393. bottom: 0;
  394. left: 0;
  395. }
  396. .img-background {
  397. background-repeat: repeat;
  398. }
  399. .image-front {
  400. z-index: 10;
  401. }
  402. }
  403. .videocon {
  404. text-align: center;
  405. > video {
  406. max-width: inherit;
  407. height: auto;
  408. min-height: 100%;
  409. top: 50%;
  410. left: 50%;
  411. z-index: 99;
  412. display: inline-block;
  413. transform: translate(-50%, -50%);
  414. position: absolute;
  415. }
  416. .contain {
  417. height: 100%;
  418. }
  419. .cover {
  420. height: 100%;
  421. width: 100%;
  422. object-fit: cover;
  423. }
  424. .videoPlay {
  425. position: absolute;
  426. top: 50%;
  427. transform: translate(-50%, -50%);
  428. left: 50%;
  429. width: 80px;
  430. height: 80px;
  431. z-index: 99999;
  432. }
  433. }
  434. .videoPlayFirst {
  435. z-index: 99;
  436. }
  437. .jump {
  438. position: absolute;
  439. right: 15px;
  440. top: 20px;
  441. background: rgba(255, 255, 255, 0.5);
  442. text-align: center;
  443. line-height: 28px;
  444. font-size: 16px;
  445. z-index: 999;
  446. color: #333333;
  447. border-radius: 1px;
  448. padding: 4px 12px;
  449. cursor: pointer;
  450. }
  451. @keyframes loading {
  452. 100% {
  453. left: -900px;
  454. }
  455. }
  456. </style>