Opening.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494
  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 isToApp = ref(false);
  148. const currentScene = computed(() => store.getters["scene/currentScene"]);
  149. //手动跳转
  150. /**
  151. * 跳转逻辑PM设定非奇怪,要注意
  152. * @TODO 图片模式 button 3秒倒只作装饰显示,不参与逻辑
  153. *
  154. * */
  155. const jumpImage = (from = 0) => {
  156. // 0 来自元素click, 1.来自跳转按钮
  157. if (unref(isMixinMode)) {
  158. if (unref(showImageFirst)) {
  159. imgShow.value = false;
  160. videoShow.value = true;
  161. startVideoCount();
  162. } else {
  163. // 强制跳转
  164. // 非自动模式强制跳转
  165. if (from === 0 && !unref(isImageAutoNext)) {
  166. toApp();
  167. }
  168. if (from === 1) {
  169. toApp();
  170. }
  171. if (unref(isImageAutoNext) && unref(isImageCountDone)) {
  172. toApp();
  173. }
  174. }
  175. } else {
  176. // 非自动模式强制跳转
  177. if (from === 0 && !unref(isImageAutoNext)) {
  178. toApp();
  179. }
  180. // 非自动模式强制跳转
  181. if (from === 1) {
  182. toApp();
  183. }
  184. if (unref(isImageAutoNext) && unref(isImageCountDone)) {
  185. toApp();
  186. }
  187. }
  188. };
  189. //手动跳转
  190. const jumpVideo = () => {
  191. if (unref(isMixinMode)) {
  192. if (!unref(showImageFirst)) {
  193. imgShow.value = true;
  194. videoShow.value = false;
  195. startImageCount();
  196. } else {
  197. if (unref(isVideoCountDone)) {
  198. toApp();
  199. }
  200. }
  201. } else {
  202. if (unref(isVideoCountDone)) {
  203. toApp();
  204. }
  205. }
  206. };
  207. const handleVideoPlay = () => {
  208. let video = unref(openvideo$);
  209. video && video.play();
  210. };
  211. const startImageCount = () => {
  212. imgTimer.value = setInterval(() => {
  213. countdownImg.value--;
  214. if (countdownImg.value == 0) {
  215. clearInterval(imgTimer.value);
  216. isImageCountDone.value = true;
  217. imgTimer.value = null;
  218. return;
  219. }
  220. }, 1000);
  221. };
  222. const startVideoCount = () => {
  223. const nextIndex = useZIndex();
  224. videoIndex.value = nextIndex;
  225. videotimer.value = setInterval(() => {
  226. countdownVideo.value--;
  227. if (countdownVideo.value == 0) {
  228. clearInterval(videotimer.value);
  229. isVideoCountDone.value = true;
  230. videotimer.value = null;
  231. return;
  232. }
  233. }, 1000);
  234. };
  235. //开始全监听
  236. watch(
  237. [isMixinMode, isImageMode, isVideoMode, showImageFirst],
  238. ([val1, val2, val3, val4]) => {
  239. //混合模式
  240. if (unref(val1)) {
  241. //图片优先
  242. if (unref(val4)) {
  243. imgShow.value = true;
  244. startImageCount();
  245. } else {
  246. videoShow.value = true;
  247. startVideoCount();
  248. }
  249. } else {
  250. if (unref(val2)) {
  251. imgShow.value = true;
  252. startImageCount();
  253. }
  254. if (unref(val3)) {
  255. videoShow.value = true;
  256. startVideoCount();
  257. }
  258. //非混合模式
  259. }
  260. },
  261. {
  262. deep: true,
  263. immediate: true,
  264. }
  265. );
  266. //倒数完全监听
  267. watch(
  268. [isMixinMode, isImageCountDone, isVideoCountDone, showImageFirst],
  269. ([val1, val2, val3, val4]) => {
  270. //混合模式
  271. if (unref(val1)) {
  272. //图片优先
  273. if (unref(val4)) {
  274. //图片倒数完
  275. if (unref(val2)) {
  276. if (unref(isImageAutoNext)) {
  277. imgShow.value = false;
  278. videoShow.value = true;
  279. startVideoCount();
  280. }
  281. }
  282. } else {
  283. //图片非优先
  284. if (unref(val2)) {
  285. if (unref(isImageAutoNext)) {
  286. toApp();
  287. }
  288. }
  289. }
  290. } else {
  291. //非混合模式
  292. if (unref(val2)) {
  293. if (unref(isImageAutoNext)) {
  294. toApp();
  295. }
  296. }
  297. }
  298. },
  299. {
  300. deep: true,
  301. immediate: true,
  302. }
  303. );
  304. //跳转到app
  305. const toApp = () => {
  306. if (!unref(isToApp)) {
  307. console.log("跳转到app");
  308. imgShow.value = false;
  309. videoShow.value = false;
  310. isToApp.value;
  311. useApp().then((app) => {
  312. setTimeout(() => {
  313. app.render();
  314. }, 1000);
  315. });
  316. }
  317. };
  318. onMounted(() => {
  319. console.log("coverData", unref(props.coverData));
  320. if (openvideo$.value) {
  321. openvideo$.value.addEventListener("ended", () => {
  322. if (isVideoAutoNext.value) {
  323. //混合模式
  324. if (unref(isMixinMode)) {
  325. //视频优先 直达图片
  326. if (!unref(showImageFirst)) {
  327. videoShow.value = false;
  328. imgShow.value = true;
  329. startImageCount();
  330. } else {
  331. toApp();
  332. }
  333. } else {
  334. toApp();
  335. }
  336. }
  337. });
  338. openvideo$.value.addEventListener("playing", () => {
  339. if (videoNeedPlay.value) {
  340. videoNeedPlay.value = false;
  341. }
  342. });
  343. openvideo$.value.addEventListener("pause", () => {
  344. if (!videoNeedPlay.value) {
  345. videoNeedPlay.value = true;
  346. }
  347. });
  348. // document.addEventListener(
  349. // "WeixinJSBridgeReady",
  350. // () => {
  351. // openvideo$.value.play();
  352. // },
  353. // false
  354. // );
  355. }
  356. }),
  357. useApp().then((app) => {
  358. app.Scene.on("ready", () => {
  359. if (show.value) {
  360. show.value = false;
  361. }
  362. });
  363. });
  364. </script>
  365. <style lang="scss" scoped>
  366. .imgcon,
  367. .videocon {
  368. position: fixed;
  369. left: 0;
  370. right: 0;
  371. top: 0;
  372. bottom: 0;
  373. width: 100%;
  374. height: 100%;
  375. z-index: 1;
  376. }
  377. .video-background {
  378. background-repeat: repeat;
  379. position: absolute;
  380. left: 0;
  381. right: 0;
  382. top: 0;
  383. bottom: 0;
  384. width: 100%;
  385. height: 100%;
  386. z-index: 1;
  387. }
  388. .imgcon {
  389. // z-index: 10;
  390. .image-front,
  391. .img-background {
  392. background-position: center;
  393. width: 100%;
  394. height: 100%;
  395. position: absolute;
  396. top: 0;
  397. z-index: 1;
  398. bottom: 0;
  399. left: 0;
  400. }
  401. .img-background {
  402. background-repeat: repeat;
  403. }
  404. .image-front {
  405. z-index: 10;
  406. }
  407. }
  408. .videocon {
  409. text-align: center;
  410. > video {
  411. max-width: inherit;
  412. height: auto;
  413. min-height: 100%;
  414. top: 50%;
  415. left: 50%;
  416. z-index: 99;
  417. display: inline-block;
  418. transform: translate(-50%, -50%);
  419. position: absolute;
  420. }
  421. .contain {
  422. height: 100%;
  423. }
  424. .cover {
  425. height: 100%;
  426. width: 100%;
  427. object-fit: cover;
  428. }
  429. .videoPlay {
  430. position: absolute;
  431. top: 50%;
  432. transform: translate(-50%, -50%);
  433. left: 50%;
  434. width: 80px;
  435. height: 80px;
  436. z-index: 99999;
  437. }
  438. }
  439. .videoPlayFirst {
  440. z-index: 99;
  441. }
  442. .jump {
  443. position: absolute;
  444. right: 15px;
  445. top: 20px;
  446. background: rgba(255, 255, 255, 0.5);
  447. text-align: center;
  448. line-height: 28px;
  449. font-size: 16px;
  450. z-index: 999;
  451. color: #333333;
  452. border-radius: 1px;
  453. padding: 4px 12px;
  454. cursor: pointer;
  455. }
  456. @keyframes loading {
  457. 100% {
  458. left: -900px;
  459. }
  460. }
  461. </style>