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>
<view class="default-share-page">
<!-- 背景图片替代CSS background -->
<image
<img
class="share-bg-image"
src="/static/images/share-bg.jpg"
mode="scaleToFill"
crossorigin="anonymous"
@load="onBackgroundImageLoad"
@error="onBackgroundImageError"
></image>
<view class="share-wrapper">
<view class="portal-frame" :class="{ 'is-loaded': isLoaded }">
<!-- 二维码样式区域 - 用户自定义样式位置 -->
<view class="qr-code-outer">
<image
class="qr-code"
:src="qrCodeImage"
mode="aspectFit"
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 class="qr-code-outer">
<image
class="qr-code"
:src="qrCodeImage"
mode="aspectFit"
v-if="qrCodeImage"
></image>
<view v-else class="qr-code-placeholder">
<view class="loader"></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>
</template>
<script>
import html2canvas from 'html2canvas'
import { snapdom } from '@zumer/snapdom'
export default {
name: 'DefaultSharePage',
@ -139,30 +130,23 @@ export default {
return
}
console.log(
'开始html2canvas截取容器尺寸:',
element.offsetWidth,
'x',
element.offsetHeight
)
const scale = 3
html2canvas(element, {
useCORS: true,
allowTaint: true,
// allowTaint: true,
backgroundColor: null,
scale: 2,
dpi: 400,
logging: true,
scale,
// canvas,
width: element.offsetWidth,
height: element.offsetHeight,
windowWidth: element.offsetWidth,
windowHeight: element.offsetHeight,
scrollX: 0,
scrollY: 0,
x: 0,
y: 0,
})
.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)
this.$emit('share-generated', dataUrl)
resolve()
@ -232,8 +216,8 @@ export default {
/* 二维码样式区域 - 用户自定义样式位置 */
.qr-code-outer {
width: 400rpx;
height: 400rpx;
width: 140rpx;
height: 140rpx;
background: rgba(255, 255, 255, 0.98);
border-radius: 20rpx;
box-shadow: 0px 8rpx 20rpx rgba(50, 50, 90, 0.06);
@ -243,6 +227,10 @@ export default {
justify-content: center;
padding: 12rpx;
box-sizing: border-box;
position: absolute;
bottom: 460rpx;
right: 130rpx;
z-index: 10;
}
.qr-code,
@ -280,6 +268,15 @@ export default {
.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 {

View File

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

Binary file not shown.

Before

Width:  |  Height:  |  Size: 985 KiB

After

Width:  |  Height:  |  Size: 1.7 MiB