|
|
@@ -58,6 +58,11 @@
|
|
|
type: String,
|
|
|
default: ''
|
|
|
},
|
|
|
+ // 目前只是给海报用 (华为 卓网通问题)
|
|
|
+ currentPage: {
|
|
|
+ type: String,
|
|
|
+ default: ''
|
|
|
+ },
|
|
|
|
|
|
})
|
|
|
|
|
|
@@ -81,7 +86,11 @@
|
|
|
//emit('select', scene)
|
|
|
|
|
|
try {
|
|
|
- shareToWeChat(scene)
|
|
|
+ if (props.currentPage == 'haibao') {
|
|
|
+ shareToWeChatHaibao(scene)
|
|
|
+ } else {
|
|
|
+ shareToWeChat(scene)
|
|
|
+ }
|
|
|
close()
|
|
|
} catch (error) {
|
|
|
emit('error', error)
|
|
|
@@ -94,105 +103,143 @@
|
|
|
|
|
|
// 分享到微信
|
|
|
const shareToWeChat = (scene) => {
|
|
|
+ // 获取分享类型,确保是数字类型
|
|
|
+ const shareType = Number(props.type)
|
|
|
+
|
|
|
+ // 构建基础分享配置
|
|
|
+ const shareConfig = {
|
|
|
+ provider: 'weixin',
|
|
|
+ scene: scene === 'timeline' ? 'WXSceneTimeline' : 'WXSceneSession',
|
|
|
+ type: shareType,
|
|
|
+ success: function(res) {
|
|
|
+ emit('success', {
|
|
|
+ scene
|
|
|
+ })
|
|
|
+ },
|
|
|
+ fail: function(err) {
|
|
|
+ emit('error', err)
|
|
|
+ handleShareError(err)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 根据类型添加不同的参数
|
|
|
+ if (shareType == 2) {
|
|
|
+ // 纯图片分享
|
|
|
+ shareConfig.imageUrl = props.image
|
|
|
+ } else {
|
|
|
+ // 图文或链接分享(兼容原有逻辑)
|
|
|
+ shareConfig.title = props.title
|
|
|
+ shareConfig.summary = props.desc
|
|
|
+ shareConfig.imageUrl = props.image
|
|
|
+ shareConfig.href = props.link
|
|
|
+ }
|
|
|
|
|
|
- uni.downloadFile({
|
|
|
- url: props.image, // 你的网络图片地址
|
|
|
- success: (downloadRes) => {
|
|
|
- // 获取分享类型,确保是数字类型
|
|
|
- const shareType = Number(props.type)
|
|
|
- // 构建基础分享配置
|
|
|
- const shareConfig = {
|
|
|
- provider: 'weixin',
|
|
|
- scene: scene === 'timeline' ? 'WXSceneTimeline' : 'WXSceneSession',
|
|
|
- type: shareType,
|
|
|
- success: function(res) {
|
|
|
- emit('success', {
|
|
|
- scene
|
|
|
- })
|
|
|
- },
|
|
|
- fail: function(err) {
|
|
|
- emit('error', err)
|
|
|
- handleShareError(err)
|
|
|
- }
|
|
|
- }
|
|
|
- // 根据类型添加不同的参数
|
|
|
- if (shareType == 2) {
|
|
|
- // 纯图片分享
|
|
|
- // shareConfig.imageUrl = props.image
|
|
|
- shareConfig.imageUrl = downloadRes.tempFilePath
|
|
|
- } else {
|
|
|
- // 图文或链接分享(兼容原有逻辑)
|
|
|
- shareConfig.title = props.title
|
|
|
- shareConfig.summary = props.desc
|
|
|
- shareConfig.imageUrl = props.image
|
|
|
- shareConfig.href = props.link
|
|
|
- }
|
|
|
- console.log('分享配置:', shareConfig)
|
|
|
- uni.share(shareConfig)
|
|
|
+ console.log('分享配置:', shareConfig)
|
|
|
+ uni.share(shareConfig)
|
|
|
+ }
|
|
|
+ // 分享针对海报
|
|
|
+ const shareToWeChatHaibao = (scene) => {
|
|
|
+ uni.downloadFile({
|
|
|
+ url: props.image, // 你的网络图片地址
|
|
|
+ success: (downloadRes) => {
|
|
|
+ // 获取分享类型,确保是数字类型
|
|
|
+ const shareType = Number(props.type)
|
|
|
+ // 构建基础分享配置
|
|
|
+ const shareConfig = {
|
|
|
+ provider: 'weixin',
|
|
|
+ scene: scene === 'timeline' ? 'WXSceneTimeline' : 'WXSceneSession',
|
|
|
+ type: shareType,
|
|
|
+ success: function(res) {
|
|
|
+ emit('success', {
|
|
|
+ scene
|
|
|
+ })
|
|
|
},
|
|
|
- fail: (err) => {
|
|
|
+ fail: function(err) {
|
|
|
emit('error', err)
|
|
|
handleShareError(err)
|
|
|
- })
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 根据类型添加不同的参数
|
|
|
+ if (shareType == 2) {
|
|
|
+ // 纯图片分享
|
|
|
+ // shareConfig.imageUrl = props.image
|
|
|
+ shareConfig.imageUrl = downloadRes.tempFilePath
|
|
|
+ } else {
|
|
|
+ // 图文或链接分享(兼容原有逻辑)
|
|
|
+ shareConfig.title = props.title
|
|
|
+ shareConfig.summary = props.desc
|
|
|
+ shareConfig.imageUrl = props.image
|
|
|
+ shareConfig.href = props.link
|
|
|
+ }
|
|
|
+ console.log('分享配置:', shareConfig)
|
|
|
+ uni.share(shareConfig)
|
|
|
}
|
|
|
+ }).fail(() => {
|
|
|
+ // 其他错误
|
|
|
+ uni.showToast({
|
|
|
+ title: '海报分享失败,请检测网络状态',
|
|
|
+ icon: 'none',
|
|
|
+ duration: 3000
|
|
|
+ })
|
|
|
+ })
|
|
|
+ }
|
|
|
|
|
|
|
|
|
- // const shareToWeChat = (scene) => {
|
|
|
- // console.log('props.link',props.link);
|
|
|
- // uni.share({
|
|
|
- // provider: 'weixin',
|
|
|
- // scene: scene === 'timeline' ? 'WXSceneTimeline' : 'WXSceneSession',
|
|
|
- // type: Number(props.type),
|
|
|
- // title: props.title,
|
|
|
- // summary: props.desc,
|
|
|
- // href: props.link,
|
|
|
- // imageUrl: props.image || 'https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/uni@2x.png',
|
|
|
- // success: function(res) {
|
|
|
- // emit('success', {
|
|
|
- // scene
|
|
|
- // })
|
|
|
- // },
|
|
|
- // fail: function(err) {
|
|
|
- // emit('error', err)
|
|
|
- // handleShareError(err)
|
|
|
- // }
|
|
|
- // })
|
|
|
- // }
|
|
|
-
|
|
|
-
|
|
|
- // 错误处理
|
|
|
- const handleShareError = (error) => {
|
|
|
- console.error('分享失败:', error)
|
|
|
-
|
|
|
- const errCode = error.errCode || error.code
|
|
|
- const errMsg = error.errMsg || error.message
|
|
|
-
|
|
|
- // 微信未安装
|
|
|
- if (errCode === 1004 || errCode === -4004) {
|
|
|
- uni.showModal({
|
|
|
- title: '提示',
|
|
|
- content: '请先安装微信',
|
|
|
- showCancel: false
|
|
|
- })
|
|
|
- return
|
|
|
- }
|
|
|
+ // const shareToWeChat = (scene) => {
|
|
|
+ // console.log('props.link',props.link);
|
|
|
+ // uni.share({
|
|
|
+ // provider: 'weixin',
|
|
|
+ // scene: scene === 'timeline' ? 'WXSceneTimeline' : 'WXSceneSession',
|
|
|
+ // type: Number(props.type),
|
|
|
+ // title: props.title,
|
|
|
+ // summary: props.desc,
|
|
|
+ // href: props.link,
|
|
|
+ // imageUrl: props.image || 'https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/uni@2x.png',
|
|
|
+ // success: function(res) {
|
|
|
+ // emit('success', {
|
|
|
+ // scene
|
|
|
+ // })
|
|
|
+ // },
|
|
|
+ // fail: function(err) {
|
|
|
+ // emit('error', err)
|
|
|
+ // handleShareError(err)
|
|
|
+ // }
|
|
|
+ // })
|
|
|
+ // }
|
|
|
+
|
|
|
+
|
|
|
+ // 错误处理
|
|
|
+ const handleShareError = (error) => {
|
|
|
+ console.error('分享失败:', error)
|
|
|
+
|
|
|
+ const errCode = error.errCode || error.code
|
|
|
+ const errMsg = error.errMsg || error.message
|
|
|
+
|
|
|
+ // 微信未安装
|
|
|
+ if (errCode === 1004 || errCode === -4004) {
|
|
|
+ uni.showModal({
|
|
|
+ title: '提示',
|
|
|
+ content: '请先安装微信',
|
|
|
+ showCancel: false
|
|
|
+ })
|
|
|
+ return
|
|
|
+ }
|
|
|
|
|
|
- // 用户取消不提示
|
|
|
- if (errCode === 1001 || errCode === -4001) {
|
|
|
- return
|
|
|
- }
|
|
|
+ // 用户取消不提示
|
|
|
+ if (errCode === 1001 || errCode === -4001) {
|
|
|
+ return
|
|
|
+ }
|
|
|
|
|
|
- // 其他错误
|
|
|
- uni.showToast({
|
|
|
- title: errMsg || '分享失败,请重试',
|
|
|
- icon: 'none',
|
|
|
- duration: 3000
|
|
|
- })
|
|
|
- }
|
|
|
+ // 其他错误
|
|
|
+ uni.showToast({
|
|
|
+ title: errMsg || '分享失败,请重试',
|
|
|
+ icon: 'none',
|
|
|
+ duration: 3000
|
|
|
+ })
|
|
|
+ }
|
|
|
|
|
|
- // 暴露方法给父组件
|
|
|
- defineExpose({
|
|
|
- open,
|
|
|
- close
|
|
|
- })
|
|
|
+ // 暴露方法给父组件
|
|
|
+ defineExpose({
|
|
|
+ open,
|
|
|
+ close
|
|
|
+ })
|
|
|
</script>
|