feat(share): default share bg

This commit is contained in:
woody 2025-07-24 10:47:40 +08:00
parent 645c1abad4
commit 8e1fc10696
3 changed files with 53 additions and 56 deletions

View File

@ -1,51 +1,42 @@
<template> <template>
<view class="default-share-page"> <view class="default-share-page">
<!-- 背景图片替代CSS background --> <!-- 背景图片替代CSS background -->
<image <img
class="share-bg-image" class="share-bg-image"
src="/static/images/share-bg.jpg" src="/static/images/share-bg.jpg"
mode="scaleToFill"
crossorigin="anonymous" crossorigin="anonymous"
@load="onBackgroundImageLoad" @load="onBackgroundImageLoad"
@error="onBackgroundImageError" @error="onBackgroundImageError"
></image> />
<view class="qr-code-outer">
<view class="share-wrapper"> <image
<view class="portal-frame" :class="{ 'is-loaded': isLoaded }"> class="qr-code"
<!-- 二维码样式区域 - 用户自定义样式位置 --> :src="qrCodeImage"
<view class="qr-code-outer"> mode="aspectFit"
<image v-if="qrCodeImage"
class="qr-code" ></image>
:src="qrCodeImage" <view v-else class="qr-code-placeholder">
mode="aspectFit" <view class="loader"></view>
v-if="qrCodeImage"
></image>
<view v-else class="qr-code-placeholder">
<view class="loader"></view>
</view>
</view>
<!-- 会员编号样式区域 - 用户自定义样式位置 -->
<text
class="member-code-text"
style="
font-size: 30rpx;
color: #fff;
font-weight: bold;
margin-top: 20rpx;
"
>{{ desensitization(userInfo.memberCode) }}</text
>
<!-- 下载按钮 - 仅在非微信环境显示 -->
<!-- <button class="share-button">长按保存图片</button> -->
</view> </view>
</view> </view>
<view class="member-code-outer">
<text
class="member-code-text"
style="
font-size: 30rpx;
color: #fff;
font-weight: bold;
margin-top: 20rpx;
"
>{{ desensitization(userInfo.memberCode) }}</text
>
</view>
</view> </view>
</template> </template>
<script> <script>
import html2canvas from 'html2canvas' import html2canvas from 'html2canvas'
import { snapdom } from '@zumer/snapdom'
export default { export default {
name: 'DefaultSharePage', name: 'DefaultSharePage',
@ -139,30 +130,23 @@ export default {
return return
} }
console.log( const scale = 3
'开始html2canvas截取容器尺寸:',
element.offsetWidth,
'x',
element.offsetHeight
)
html2canvas(element, { html2canvas(element, {
useCORS: true, useCORS: true,
allowTaint: true, // allowTaint: true,
backgroundColor: null, backgroundColor: null,
scale: 2, scale,
dpi: 400, // canvas,
logging: true,
width: element.offsetWidth, width: element.offsetWidth,
height: element.offsetHeight, height: element.offsetHeight,
windowWidth: element.offsetWidth,
windowHeight: element.offsetHeight,
scrollX: 0,
scrollY: 0,
x: 0,
y: 0,
}) })
.then(canvas => { .then(canvas => {
const context = canvas.getContext('2d')
// context.scale(2, 2)
context.mozImageSmoothingEnabled = false
context.webkitImageSmoothingEnabled = false
context.msImageSmoothingEnabled = false
context.imageSmoothingEnabled = false
const dataUrl = canvas.toDataURL('image/jpeg', 1) const dataUrl = canvas.toDataURL('image/jpeg', 1)
this.$emit('share-generated', dataUrl) this.$emit('share-generated', dataUrl)
resolve() resolve()
@ -232,8 +216,8 @@ export default {
/* 二维码样式区域 - 用户自定义样式位置 */ /* 二维码样式区域 - 用户自定义样式位置 */
.qr-code-outer { .qr-code-outer {
width: 400rpx; width: 140rpx;
height: 400rpx; height: 140rpx;
background: rgba(255, 255, 255, 0.98); background: rgba(255, 255, 255, 0.98);
border-radius: 20rpx; border-radius: 20rpx;
box-shadow: 0px 8rpx 20rpx rgba(50, 50, 90, 0.06); box-shadow: 0px 8rpx 20rpx rgba(50, 50, 90, 0.06);
@ -243,6 +227,10 @@ export default {
justify-content: center; justify-content: center;
padding: 12rpx; padding: 12rpx;
box-sizing: border-box; box-sizing: border-box;
position: absolute;
bottom: 460rpx;
right: 130rpx;
z-index: 10;
} }
.qr-code, .qr-code,
@ -280,6 +268,15 @@ export default {
.member-code-text { .member-code-text {
/* 用户可以在这里自定义会员编号的样式 */ /* 用户可以在这里自定义会员编号的样式 */
} }
.member-code-outer {
position: absolute;
bottom: 160rpx;
width: 500rpx;
text-align: center;
background: rgb(217, 24, 25);
border-radius: 20rpx;
z-index: 10;
}
/* 下载按钮样式 */ /* 下载按钮样式 */
.share-button { .share-button {

View File

@ -85,10 +85,10 @@ export default {
this.canvasHeight = res.windowHeight this.canvasHeight = res.windowHeight
}, },
}) })
uni.showLoading({ // uni.showLoading({
title: '加载中...', // title: '...',
mask: true, // mask: true,
}) // })
}, },
onReady() { onReady() {
// //

Binary file not shown.

Before

Width:  |  Height:  |  Size: 985 KiB

After

Width:  |  Height:  |  Size: 1.7 MiB