hookehuyr

新增全亮后分享页

1 /* 1 /*
2 * @Date: 2024-04-07 10:14:17 2 * @Date: 2024-04-07 10:14:17
3 * @LastEditors: hookehuyr hookehuyr@gmail.com 3 * @LastEditors: hookehuyr hookehuyr@gmail.com
4 - * @LastEditTime: 2024-04-11 09:39:29 4 + * @LastEditTime: 2024-04-11 15:36:49
5 * @FilePath: /fxPark/src/router/routes/modules/fxPark/index.js 5 * @FilePath: /fxPark/src/router/routes/modules/fxPark/index.js
6 * @Description: 文件描述 6 * @Description: 文件描述
7 */ 7 */
...@@ -50,6 +50,15 @@ const index = [{ ...@@ -50,6 +50,15 @@ const index = [{
50 title: '生成海报', 50 title: '生成海报',
51 }, 51 },
52 children: [], 52 children: [],
53 -},] 53 +}, {
54 + path: '/finish',
55 + name: '分享海报',
56 + component: () => import('@/views/fxPark/finish.vue'),
57 + redirect: '',
58 + meta: {
59 + title: '分享海报',
60 + },
61 + children: [],
62 +}]
54 63
55 export default index; 64 export default index;
......
1 +<!--
2 + * @Date: 2024-04-11 15:33:54
3 + * @LastEditors: hookehuyr hookehuyr@gmail.com
4 + * @LastEditTime: 2024-04-11 15:43:46
5 + * @FilePath: /fxPark/src/views/fxPark/finish.vue
6 + * @Description: 文件描述
7 +-->
8 +<template>
9 + <div class="finish-page">
10 + <div style="height: calc(90vh - 2rem); padding: 1rem;">
11 + <div v-if="flag" ref="canvasRef" style="position: relative; padding: 1rem; background-color: #fff;">
12 + <!-- <div style="position: absolute; top: 3rem; left: 2rem; color: #FFF; writing-mode: vertical-lr; text-orientation: upright;">
13 + <div style="position: relative;">
14 + <span style="font-size: 2.5rem; font-weight: bolder; letter-spacing: 5px;">悬铃木</span>
15 + <div style="position: absolute; bottom: -1rem; letter-spacing: 5px;">智者长老</div>
16 + </div>
17 + </div> -->
18 + <img :src="imgSrc" style="width: 100%; height: 78vh;">
19 + <div style="color: #CCCCCC; margin-top: 1rem;">
20 +
21 + </div>
22 + </div>
23 + <div v-if="imgUrl">
24 + <img :src="imgUrl" alt="" crossOrigin="anonymous" :style="{ width: ref_width, height: ref_height }">
25 + </div>
26 + </div>
27 + <p style="text-align: center; color: #fff; margin-top: 1rem;">长按保存到相册</p>
28 + </div>
29 +</template>
30 +
31 +<script setup>
32 +import { ref } from 'vue'
33 +import { useRoute, useRouter } from 'vue-router'
34 +import html2canvas from "html2canvas";
35 +import { Cookies, $, _, axios, storeToRefs, mainStore, Toast, useTitle } from '@/utils/generatePackage.js'
36 +//import { } from '@/utils/generateModules.js'
37 +//import { } from '@/utils/generateIcons.js'
38 +//import { } from '@/composables'
39 +const $route = useRoute();
40 +const $router = useRouter();
41 +useTitle($route.meta.title);
42 +
43 +const canvasRef = ref(null);
44 +const imgUrl = ref('');
45 +const imgSrc = ref('https://picsum.photos/800');
46 +const flag = ref(true);
47 +const ref_width = ref('');
48 +const ref_height = ref('');
49 +
50 +onMounted(async () => {
51 + nextTick(() => {
52 + let canvasDom = canvasRef.value;
53 + ref_width.value = canvasDom.offsetWidth + 'px';
54 + ref_height.value = canvasDom.offsetHeight + 'px';
55 + // const screenWidth = window.innerWidth;
56 + // alert(screenWidth); // 输出移动设备屏幕的宽度
57 + });
58 + createImage();
59 +});
60 +
61 +// 获取像素比
62 +const DPR = () => {
63 + // 获取设备dpi
64 + if (window.devicePixelRatio && window.devicePixelRatio > 1) {
65 + return window.devicePixelRatio * 2
66 + }
67 + // 直接返回高像素比
68 + return 8
69 +}
70 +
71 +const createImage = () => {
72 + nextTick(() => {
73 + // 获取要生成图片的 DOM 元素
74 + let canvasDom = canvasRef.value;
75 + const options = {
76 + backgroundColor: '#fff',
77 + // canvas: canvas,
78 + useCORS: true,//配置允许跨域
79 + scale: DPR(),
80 + // windowWidth: document.body.scrollWidth,
81 + // windowHeight: document.body.scrollHeight,
82 + // x: 0,
83 + // y: window.pageYOffset,
84 + // allowTaint: true,
85 + // background: "#d21f2c", // 一定要添加背景颜色,否则出来的图片,背景全部都是透明的
86 + // dpi: 300 // 处理模糊问题
87 + };
88 + // console.log("获取指定的宽高", width, height, canvas);
89 + html2canvas(canvasDom, options)
90 + .then(canvas => {
91 + try {
92 + // 生成图片地址
93 + imgUrl.value = canvas.toDataURL("image/png");
94 + // console.log("canvas.toDataURL('image/png')", this.imgUrl);
95 + flag.value = false;
96 + } catch (e) {
97 + alert("图片跨域,保存失败");
98 + }
99 + })
100 + .catch(error => {
101 + console.error("绘制失败");
102 + console.error(error);
103 + });
104 + });
105 +}
106 +
107 +</script>
108 +
109 +<style lang="less" scoped>
110 +.finish-page {
111 + height: 100vh;
112 + background-color: green;
113 +}
114 +</style>
1 <!-- 1 <!--
2 * @Date: 2024-04-07 10:15:55 2 * @Date: 2024-04-07 10:15:55
3 * @LastEditors: hookehuyr hookehuyr@gmail.com 3 * @LastEditors: hookehuyr hookehuyr@gmail.com
4 - * @LastEditTime: 2024-04-11 14:52:47 4 + * @LastEditTime: 2024-04-11 15:38:58
5 * @FilePath: /fxPark/src/views/fxPark/index.vue 5 * @FilePath: /fxPark/src/views/fxPark/index.vue
6 * @Description: 文件描述 6 * @Description: 文件描述
7 --> 7 -->
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
17 <img :src="item.src" class="img"> 17 <img :src="item.src" class="img">
18 </div> 18 </div>
19 <div style="position: fixed; bottom: 1rem; left: 0; right: 0; display: flex; z-index: 25;justify-content: space-evenly;"> 19 <div style="position: fixed; bottom: 1rem; left: 0; right: 0; display: flex; z-index: 25;justify-content: space-evenly;">
20 - <div style="display: inline-flex; padding: 0.6rem 2rem; color: #F68015; background-color: #fff; align-items: center; border-radius: 1.5rem;">分享海报</div> 20 + <div @click="onShare" style="display: inline-flex; padding: 0.6rem 2rem; color: #F68015; background-color: #fff; align-items: center; border-radius: 1.5rem;">分享海报</div>
21 <div @click="commentsBtn" style="display: inline-flex; padding: 0.6rem 2rem; color: #fff; background-color: #F68015;align-items: center; border-radius: 1.5rem;">弹幕留言</div> 21 <div @click="commentsBtn" style="display: inline-flex; padding: 0.6rem 2rem; color: #fff; background-color: #F68015;align-items: center; border-radius: 1.5rem;">弹幕留言</div>
22 </div> 22 </div>
23 23
...@@ -62,6 +62,8 @@ import danmaku from '@/components/danmaku.vue' ...@@ -62,6 +62,8 @@ import danmaku from '@/components/danmaku.vue'
62 62
63 // 初始化WX环境 63 // 初始化WX环境
64 import wx from 'weixin-js-sdk' 64 import wx from 'weixin-js-sdk'
65 +import { useGo } from '@/hooks/useGo'
66 +const go = useGo();
65 67
66 const $route = useRoute(); 68 const $route = useRoute();
67 const $router = useRouter(); 69 const $router = useRouter();
...@@ -127,6 +129,10 @@ const onFocus = () => { ...@@ -127,6 +129,10 @@ const onFocus = () => {
127 const onCancel = () => { 129 const onCancel = () => {
128 console.warn(0); 130 console.warn(0);
129 } 131 }
132 +
133 +const onShare = () => {
134 + go('/finish')
135 +}
130 </script> 136 </script>
131 137
132 <style lang="less" scoped> 138 <style lang="less" scoped>
......