OpeningMobile.vue 8.9 KB

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