2025-06-10 14:06:32 +08:00
|
|
|
<template>
|
2025-06-19 16:09:33 +08:00
|
|
|
<view
|
|
|
|
class="share-page"
|
|
|
|
style="display: flex; flex-direction: column; height: 100vh"
|
|
|
|
>
|
|
|
|
<view id="shareContainer" class="share-container">
|
2025-07-14 14:32:08 +08:00
|
|
|
<!-- 默认场景 -->
|
|
|
|
<DefaultSharePage
|
|
|
|
v-if="isDefaultScene"
|
|
|
|
:qrCodeImage="qrCodeImage"
|
|
|
|
:userInfo="userInfo"
|
|
|
|
:isWechat="isWechat"
|
|
|
|
:isLoaded="isLoaded"
|
|
|
|
@share-generated="handleShareGenerated"
|
|
|
|
ref="defaultSharePage"
|
|
|
|
/>
|
|
|
|
|
|
|
|
<!-- 特殊场景 -->
|
|
|
|
<SpecialSharePage
|
|
|
|
v-if="isSpecialScene"
|
|
|
|
:qrCodeImage="qrCodeImage"
|
|
|
|
:specialBackgroundImage="userInfo.sharePosterImage"
|
|
|
|
:userInfo="userInfo"
|
|
|
|
:isWechat="isWechat"
|
|
|
|
:isLoaded="isLoaded"
|
|
|
|
@share-generated="handleShareGenerated"
|
|
|
|
ref="specialSharePage"
|
|
|
|
/>
|
|
|
|
|
|
|
|
<!-- 微信环境全屏图片显示 -->
|
2025-06-19 16:09:33 +08:00
|
|
|
<view
|
|
|
|
class="wechat-fullscreen-overlay"
|
2025-07-14 14:32:08 +08:00
|
|
|
v-show="(isWechat || userInfo.sharePosterImage) && generatedImageUrl"
|
2025-06-19 16:09:33 +08:00
|
|
|
@click="closeFullscreenImage"
|
|
|
|
>
|
2025-07-14 14:32:08 +08:00
|
|
|
<img
|
2025-06-19 16:09:33 +08:00
|
|
|
class="fullscreen-image"
|
|
|
|
:src="generatedImageUrl"
|
2025-07-14 14:32:08 +08:00
|
|
|
width="100%"
|
|
|
|
height="100%"
|
2025-06-19 16:09:33 +08:00
|
|
|
@load="onGeneratedImageLoad"
|
|
|
|
@error="onGeneratedImageError"
|
|
|
|
@click.stop=""
|
2025-07-14 14:32:08 +08:00
|
|
|
/>
|
2025-06-19 16:09:33 +08:00
|
|
|
</view>
|
2025-06-13 17:16:37 +08:00
|
|
|
</view>
|
2025-06-19 16:09:33 +08:00
|
|
|
<cl-tabbar class="tabbar" :current="2" />
|
2025-06-10 14:06:32 +08:00
|
|
|
</view>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import { getShareCode } from '@/config/share'
|
2025-06-19 09:39:59 +08:00
|
|
|
import clTabbar from '@/components/cl-tabbar.vue'
|
2025-07-14 14:32:08 +08:00
|
|
|
import DefaultSharePage from '@/components/share/DefaultSharePage.vue'
|
|
|
|
import SpecialSharePage from '@/components/share/SpecialSharePage.vue'
|
2025-06-19 16:28:16 +08:00
|
|
|
|
2025-06-10 14:06:32 +08:00
|
|
|
export default {
|
|
|
|
name: 'ShareQRCode',
|
2025-06-19 09:39:59 +08:00
|
|
|
components: {
|
|
|
|
'cl-tabbar': clTabbar,
|
2025-07-14 14:32:08 +08:00
|
|
|
DefaultSharePage,
|
|
|
|
SpecialSharePage,
|
2025-06-19 09:39:59 +08:00
|
|
|
},
|
2025-06-10 14:06:32 +08:00
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
qrCodeImage: '',
|
|
|
|
canvasWidth: 375,
|
2025-06-13 17:16:37 +08:00
|
|
|
canvasHeight: 800,
|
2025-06-10 14:06:32 +08:00
|
|
|
isLoaded: false,
|
2025-07-14 14:32:08 +08:00
|
|
|
isWechat: false,
|
|
|
|
generatedImageUrl: '',
|
2025-06-19 16:09:33 +08:00
|
|
|
userInfo: uni.getStorageSync('User'),
|
2025-06-10 14:06:32 +08:00
|
|
|
}
|
|
|
|
},
|
2025-07-14 14:32:08 +08:00
|
|
|
computed: {
|
|
|
|
isSpecialScene() {
|
|
|
|
return this.userInfo && this.userInfo.sharePosterImage
|
|
|
|
},
|
|
|
|
isDefaultScene() {
|
|
|
|
return !this.isSpecialScene
|
|
|
|
},
|
|
|
|
},
|
2025-06-10 14:06:32 +08:00
|
|
|
onLoad() {
|
2025-06-19 16:09:33 +08:00
|
|
|
this.checkWechatEnvironment()
|
2025-06-10 14:06:32 +08:00
|
|
|
this.handleGetShareCode()
|
2025-07-14 14:32:08 +08:00
|
|
|
// 获取屏幕尺寸
|
2025-06-10 14:06:32 +08:00
|
|
|
uni.getSystemInfo({
|
|
|
|
success: res => {
|
|
|
|
this.canvasWidth = res.windowWidth
|
2025-06-19 16:09:33 +08:00
|
|
|
this.canvasHeight = res.windowHeight
|
2025-06-10 14:06:32 +08:00
|
|
|
},
|
|
|
|
})
|
|
|
|
},
|
|
|
|
onReady() {
|
2025-07-14 14:32:08 +08:00
|
|
|
// 短暂延迟后启用加载动画
|
2025-06-10 14:06:32 +08:00
|
|
|
setTimeout(() => {
|
|
|
|
this.isLoaded = true
|
|
|
|
}, 100)
|
|
|
|
},
|
|
|
|
methods: {
|
2025-06-19 16:09:33 +08:00
|
|
|
// 检测微信环境
|
|
|
|
checkWechatEnvironment() {
|
|
|
|
const ua = navigator.userAgent.toLowerCase()
|
|
|
|
this.isWechat = ua.includes('micromessenger')
|
|
|
|
console.log('微信环境检测:', this.isWechat)
|
|
|
|
},
|
|
|
|
|
2025-07-14 14:32:08 +08:00
|
|
|
// 获取分享二维码
|
2025-06-10 14:06:32 +08:00
|
|
|
handleGetShareCode() {
|
|
|
|
getShareCode()
|
|
|
|
.then(res => {
|
|
|
|
if (res.code === 200 && res.data && res.data.dataStr) {
|
|
|
|
this.qrCodeImage = 'data:image/png;base64,' + res.data.dataStr
|
2025-06-19 16:09:33 +08:00
|
|
|
this.$nextTick(() => {
|
2025-07-14 14:32:08 +08:00
|
|
|
this.generateShareImage()
|
2025-06-19 16:09:33 +08:00
|
|
|
})
|
2025-06-10 14:06:32 +08:00
|
|
|
} else {
|
|
|
|
uni.showToast({
|
|
|
|
title: '获取分享码失败',
|
|
|
|
icon: 'none',
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch(err => {
|
|
|
|
console.error('getShareCode error:', err)
|
|
|
|
uni.showToast({
|
|
|
|
title: '网络错误,请稍后再试',
|
|
|
|
icon: 'none',
|
|
|
|
})
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
2025-07-14 14:32:08 +08:00
|
|
|
// 生成分享图片
|
|
|
|
async generateShareImage() {
|
2025-06-10 14:06:32 +08:00
|
|
|
try {
|
2025-07-14 14:32:08 +08:00
|
|
|
if (this.isSpecialScene) {
|
|
|
|
await this.$refs.specialSharePage.generateShareImage()
|
|
|
|
} else {
|
|
|
|
// 默认场景生成图片
|
|
|
|
await this.$refs.defaultSharePage.sharePage()
|
|
|
|
}
|
2025-06-10 14:06:32 +08:00
|
|
|
} catch (error) {
|
2025-07-14 14:32:08 +08:00
|
|
|
console.error('生成分享图片失败:', error)
|
2025-06-10 14:06:32 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2025-07-14 14:32:08 +08:00
|
|
|
// 处理分享图片生成完成
|
|
|
|
handleShareGenerated(dataUrl) {
|
|
|
|
console.log('handleShareGenerated', dataUrl)
|
|
|
|
uni.hideLoading()
|
|
|
|
|
|
|
|
if (this.isWechat) {
|
|
|
|
// 微信环境:设置图片供长按保存
|
|
|
|
this.generatedImageUrl = dataUrl
|
|
|
|
} else {
|
|
|
|
// 普通浏览器环境
|
|
|
|
if (this.isSpecialScene) {
|
|
|
|
// 特殊场景:设置图片供长按保存(没有下载按钮)
|
|
|
|
this.generatedImageUrl = dataUrl
|
|
|
|
} else {
|
|
|
|
// 默认场景:直接下载图片
|
|
|
|
this.downloadImage(dataUrl)
|
|
|
|
uni.showToast({
|
|
|
|
title: '图片已开始下载',
|
|
|
|
icon: 'success',
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
// 下载图片
|
|
|
|
downloadImage(dataUrl) {
|
|
|
|
const link = document.createElement('a')
|
|
|
|
link.href = dataUrl
|
|
|
|
link.download = `share_page_${Date.now()}.png`
|
|
|
|
document.body.appendChild(link)
|
|
|
|
link.click()
|
|
|
|
document.body.removeChild(link)
|
|
|
|
},
|
|
|
|
|
2025-06-19 16:09:33 +08:00
|
|
|
// 生成的图片加载成功
|
|
|
|
onGeneratedImageLoad() {
|
|
|
|
console.log('生成的图片加载成功')
|
|
|
|
},
|
2025-06-13 17:16:37 +08:00
|
|
|
|
2025-06-19 16:09:33 +08:00
|
|
|
// 生成的图片加载失败
|
|
|
|
onGeneratedImageError(e) {
|
|
|
|
console.error('生成的图片加载失败:', e)
|
|
|
|
uni.showToast({
|
|
|
|
title: '图片显示失败',
|
|
|
|
icon: 'none',
|
2025-06-13 17:16:37 +08:00
|
|
|
})
|
|
|
|
},
|
|
|
|
|
2025-06-19 16:09:33 +08:00
|
|
|
// 关闭全屏图片
|
|
|
|
closeFullscreenImage() {
|
|
|
|
this.generatedImageUrl = ''
|
|
|
|
console.log('关闭全屏图片')
|
2025-06-13 17:16:37 +08:00
|
|
|
},
|
2025-06-10 14:06:32 +08:00
|
|
|
},
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
.share-container {
|
2025-06-19 16:09:33 +08:00
|
|
|
flex: 1;
|
|
|
|
height: 0;
|
2025-06-10 14:06:32 +08:00
|
|
|
box-sizing: border-box;
|
|
|
|
position: relative;
|
|
|
|
overflow: hidden;
|
2025-06-13 17:16:37 +08:00
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
|
|
|
align-items: center;
|
2025-06-10 14:06:32 +08:00
|
|
|
}
|
2025-06-19 16:09:33 +08:00
|
|
|
|
|
|
|
/* 微信环境全屏覆盖样式 */
|
|
|
|
.wechat-fullscreen-overlay {
|
|
|
|
position: absolute;
|
|
|
|
top: 0;
|
|
|
|
left: 0;
|
|
|
|
width: 100vw;
|
2025-07-14 14:32:08 +08:00
|
|
|
height: 100%;
|
|
|
|
background-color: transparent;
|
2025-06-19 16:09:33 +08:00
|
|
|
z-index: 999;
|
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
2025-07-14 14:32:08 +08:00
|
|
|
align-items: stretch;
|
|
|
|
justify-content: stretch;
|
2025-06-19 16:09:33 +08:00
|
|
|
padding: 0;
|
|
|
|
margin: 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
.fullscreen-image {
|
|
|
|
width: 100vw;
|
2025-07-14 14:32:08 +08:00
|
|
|
height: 100%;
|
|
|
|
object-fit: cover;
|
2025-06-19 16:09:33 +08:00
|
|
|
margin: 0;
|
|
|
|
padding: 0;
|
|
|
|
border: none;
|
|
|
|
display: block;
|
|
|
|
}
|
|
|
|
|
|
|
|
.tabbar {
|
|
|
|
position: static;
|
|
|
|
bottom: 0;
|
|
|
|
z-index: 1000;
|
|
|
|
width: 100%;
|
|
|
|
height: 50px;
|
|
|
|
:v-deep .u-tabbar--fixed {
|
|
|
|
height: 100px !important;
|
|
|
|
}
|
2025-07-14 14:32:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
@media screen and (max-height: 667px) {
|
|
|
|
.tabbar {
|
|
|
|
height: 70px !important;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@media screen and (min-height: 812px) {
|
|
|
|
.tabbar {
|
|
|
|
height: 80px !important;
|
|
|
|
}
|
2025-06-10 14:06:32 +08:00
|
|
|
}
|
|
|
|
</style>
|