sex.vue 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  1. <template>
  2. <div>
  3. <van-swipe
  4. ref="swipe"
  5. :touchable="false"
  6. :show-indicators="false"
  7. vertical
  8. indicator-color="white"
  9. >
  10. <van-swipe-item>
  11. <div style="width: 100%; overflow: hidden; position: relative">
  12. <transition name="fade">
  13. <img
  14. v-if="step === 5"
  15. @click="nextPage"
  16. src="../../../assets/img/next.png"
  17. class="next"
  18. />
  19. </transition>
  20. <div class="sex" :style="'background-image: url(' + bgimg + ')'">
  21. <img
  22. :src="kuangimg"
  23. :style="
  24. step === 2
  25. ? 'opacity: 1'
  26. : step >= 3
  27. ? 'width: 25%;transform: translate(0, 0);opacity: 1; top: 1em; left: 1em'
  28. : 'opacity: 0'
  29. "
  30. class="firstImg"
  31. />
  32. <transition name="fade">
  33. <div
  34. class="sImg img"
  35. v-if="step === 1"
  36. :style="'width:' + width + 'px;'"
  37. >
  38. <template v-for="(item, i) in text.texts" :key="i">
  39. <p
  40. v-text="item"
  41. :style="
  42. stepBody >= i
  43. ? 'opacity: 1;color: ' + text.color
  44. : 'color: ' + text.color
  45. "
  46. ></p>
  47. <br />
  48. </template>
  49. </div>
  50. </transition>
  51. <transition name="fade">
  52. <div class="body" @click="changeNextStep" v-if="nextStep === 1">
  53. <div class="loading">
  54. <div class="loading1">
  55. <div class="loading2"></div>
  56. </div>
  57. </div>
  58. </div>
  59. </transition>
  60. <img
  61. :src="text2img"
  62. :style="step >= 4 ? 'opacity: 1' : ''"
  63. class="tImg"
  64. />
  65. <transition name="fade">
  66. <div class="btns" v-if="step === 5">
  67. <div
  68. class="btn"
  69. @click="() => showDown(1)"
  70. style="margin-left: 0"
  71. :stype="'border-color:' + text.color + ';color:' + text.color"
  72. >
  73. 下载壁纸
  74. </div>
  75. <div
  76. class="btn"
  77. @click="() => showDown(2)"
  78. :stype="'border-color:' + text.color + ';color:' + text.color"
  79. >
  80. 生成海报
  81. </div>
  82. </div>
  83. </transition>
  84. </div>
  85. <transition name="fade">
  86. <div class="model" v-if="showImg !== undefined">
  87. <div class="gs">
  88. <img :src="bgimg" style="width: 100%; height: 100%" alt="" />
  89. </div>
  90. <van-icon
  91. color="#fff"
  92. size="26"
  93. name="close"
  94. class="close"
  95. @click="close"
  96. />
  97. <div class="modelImg">
  98. <p>请长按保存图片</p>
  99. <img :src="showImg" style="width: 100%; height: 100%" />
  100. </div>
  101. </div>
  102. </transition>
  103. </div>
  104. </van-swipe-item>
  105. <van-swipe-item style="overflow: auto">
  106. <seven v-if="showSheet" @showVideo="showVideo" />
  107. </van-swipe-item>
  108. </van-swipe>
  109. <transition name="fade">
  110. <div v-if="showOverlay" class="model">
  111. <van-icon
  112. color="#fff"
  113. size="26"
  114. name="close"
  115. class="close"
  116. @click="closeSeven"
  117. />
  118. <video class="sevenvideo" src=""></video>
  119. </div>
  120. </transition>
  121. </div>
  122. </template>
  123. <script setup>
  124. import { ref, reactive, nextTick } from "vue";
  125. import data from "../data/data.json";
  126. import seven from "./seven.vue";
  127. // import { onMounted, reactive } from "vue";
  128. // import { isIpad, isIpod, isIphone } from "../../utils/isTerminal";
  129. /**
  130. * window.$originData.orginParames.title 页面标题
  131. * window.$originData.orginParames.parameters 固定参数值
  132. * window.$originData.urlParames url参数
  133. */
  134. const showImg = ref(undefined);
  135. const swipe = ref(null);
  136. let width = window.$originData.orginParames.availWidth * 0.7;
  137. const type = Math.floor(Math.random() * 12 + 1);
  138. let ori = data[type - 1] || { texts: [] };
  139. let max = 0;
  140. let nextStep = ref(0);
  141. for (let i = 0; i < ori.texts.length; i++) {
  142. max < ori.texts[i].length && (max = ori.texts[i].length);
  143. }
  144. width = 14 * max;
  145. const text = reactive({
  146. ...data[type - 1],
  147. width,
  148. });
  149. const url = {
  150. bg: require("@/assets/img/12/" + type + "-1.png"),
  151. bg2: require("@/assets/img/12/" + type + "-2.png"),
  152. kuang: require("@/assets/img/12/" + type + ".kuang.png"),
  153. text2: require("@/assets/img/12/" + type + ".text2.png"),
  154. };
  155. const bgimg = ref(url.bg);
  156. const kuangimg = ref(url.kuang);
  157. const text2img = ref(url.text2);
  158. const step = ref(1); // 动画步骤
  159. const stepBody = ref(0);
  160. let t = setTimeout(() => {
  161. clearTimeout(t);
  162. step.value += 1;
  163. t = setInterval(() => {
  164. stepBody.value += 1;
  165. if (stepBody.value === text.texts.length) {
  166. nextStep.value = 1;
  167. clearInterval(t);
  168. autoStep();
  169. }
  170. }, 2000);
  171. }, 200);
  172. const showSheet = ref(false);
  173. function nextPage() {
  174. if (step.value !== 5) return;
  175. showSheet.value = true;
  176. swipe.value.next();
  177. }
  178. function changeNextStep() {
  179. nextStep.value += 1;
  180. }
  181. function autoStep() {
  182. t = setInterval(() => {
  183. nextStep.value === 2 && (step.value += 1);
  184. if (step.value === 5) clearInterval(t);
  185. }, 3000);
  186. }
  187. function showDown(type) {
  188. switch (type) {
  189. case 1:
  190. showImg.value = url.bg;
  191. break;
  192. case 2:
  193. showImg.value = url.bg2;
  194. break;
  195. }
  196. // const image = new Image();
  197. // image.setAttribute("crossOrigin", "anonymous"); //设置允许跨域
  198. // image.src = url.bg;
  199. // image.onload = function () {
  200. // //等待图片加载完成创建canvas
  201. // let canvas = document.createElement("canvas");
  202. // //将图片绘制到canvas画布上
  203. // canvas.width = image.width;
  204. // canvas.height = image.height;
  205. // let ctx = canvas.getContext("2d");
  206. // ctx.drawImage(image, 0, 0, image.width, image.height);
  207. // //获取图片文件格式 jpg/jpeg/png
  208. // let ext = image.src.substring(image.src.lastIndexOf(".") + 1).toLowerCase();
  209. // //导出画布快照 此时已越过跨域限制成功取到图片数据
  210. // let dataURL = canvas.toDataURL("image/" + ext);
  211. // //创建a标签
  212. // const a = document.createElement("a");
  213. // // 赋值a标签download属性值,标明该a标签提供下载功能,同时该属性指定了下载时的文件名称
  214. // a.download = "test";
  215. // //赋值a标签下载地址,即canvas导出的画布快照 base64格式的图片地址
  216. // a.href = dataURL;
  217. // //添加a标签到dom中
  218. // document.body.appendChild(a);
  219. // //触发a标签点击事件 触发下载
  220. // a.click();
  221. // //下载完成 删除多余的a标签 保持页面原有元素不动
  222. // document.removeChild(a);
  223. // };
  224. }
  225. function close() {
  226. showImg.value = undefined;
  227. }
  228. const showOverlay = ref(false);
  229. function showVideo(url) {
  230. showOverlay.value = true;
  231. nextTick(() => {
  232. let ele = document.querySelector(".sevenvideo");
  233. ele.src = url;
  234. ele.play();
  235. });
  236. }
  237. function closeSeven(){
  238. showOverlay.value = false;
  239. }
  240. </script>
  241. <style lang="scss" scoped>
  242. .sex {
  243. width: 100%;
  244. height: 100vh;
  245. background-size: 100% 100%;
  246. position: relative;
  247. .body {
  248. position: absolute;
  249. bottom: 10vh;
  250. width: 100vw;
  251. }
  252. img,
  253. .img {
  254. width: 50%;
  255. transition-property: all;
  256. transition-duration: 2s;
  257. opacity: 0;
  258. position: absolute;
  259. top: 50%;
  260. left: 50%;
  261. transform: translate(-50%, -50%);
  262. }
  263. .firstImg {
  264. transition-delay: 1s;
  265. -moz-transition-delay: 1s; /* Firefox 4 */
  266. -webkit-transition-delay: 1s; /* Safari 和 Chrome */
  267. -o-transition-delay: 1s; /* Opera */
  268. }
  269. .sImg {
  270. width: 70%;
  271. color: #ffffff;
  272. font-family: OPPOSans;
  273. font-size: 14px;
  274. line-height: 3em;
  275. opacity: 1;
  276. p {
  277. display: inline-block;
  278. white-space: nowrap;
  279. transition-property: all;
  280. transition-duration: 2s;
  281. opacity: 0;
  282. }
  283. }
  284. .tImg {
  285. width: 80%;
  286. transition-delay: 1s;
  287. -moz-transition-delay: 1s; /* Firefox 4 */
  288. -webkit-transition-delay: 1s; /* Safari 和 Chrome */
  289. -o-transition-delay: 1s; /* Opera */
  290. }
  291. .btns {
  292. position: absolute;
  293. text-align: center;
  294. bottom: 10vh;
  295. width: 100%;
  296. > div {
  297. display: inline-block;
  298. border: 1px solid #fff;
  299. border-radius: 2em;
  300. font-weight: 600;
  301. color: #fff;
  302. padding: 5px 15px;
  303. margin-left: 2em;
  304. }
  305. }
  306. .fade-enter-from,
  307. .fade-leave-to {
  308. opacity: 0;
  309. }
  310. .fade-enter-active,
  311. .fade-leave-active {
  312. transition: opacity 1s ease;
  313. }
  314. .fade-enter-to,
  315. .fade-leave-from {
  316. opacity: 1;
  317. }
  318. }
  319. .next {
  320. bottom: 10px;
  321. left: 50%;
  322. transform: translateX(-50%);
  323. top: inherit;
  324. width: 2em;
  325. z-index: 1;
  326. position: absolute;
  327. animation-name: an;
  328. animation-duration: 1s;
  329. animation-timing-function: linear;
  330. animation-iteration-count: infinite;
  331. animation-direction: alternate;
  332. }
  333. @keyframes an {
  334. from {
  335. bottom: 10px;
  336. }
  337. to {
  338. bottom: 15px;
  339. }
  340. }
  341. .model {
  342. position: fixed;
  343. top: 0;
  344. left: 0;
  345. bottom: 0;
  346. right: 0;
  347. z-index: 10;
  348. background-color: #00000060;
  349. .gs {
  350. width: 100vw;
  351. height: 100vh;
  352. filter: blur(10px);
  353. -webkit-filter: blur(10px);
  354. }
  355. .modelImg {
  356. position: absolute;
  357. top: 50%;
  358. left: 50%;
  359. transform: translate(-50%, -50%);
  360. width: 80%;
  361. text-align: center;
  362. color: #ffffff;
  363. }
  364. .close {
  365. position: absolute;
  366. top: 1em;
  367. right: 1em;
  368. }
  369. .sevenvideo {
  370. top: 50%;
  371. transform: translateY(-50%);
  372. width: 100%;
  373. position: absolute;
  374. }
  375. }
  376. </style>