新增:分享、下载图片、视频功能登
This commit is contained in:
@@ -56,12 +56,49 @@
|
||||
// 显示海报弹窗
|
||||
onShowPopup() {
|
||||
const app = this
|
||||
app.apiCall({ ...app.apiParam, channel: app.platform })
|
||||
console.log('GoodsPosterPopup onShowPopup 被调用');
|
||||
console.log('apiCall 类型:', typeof app.apiCall);
|
||||
console.log('apiCall 函数:', app.apiCall);
|
||||
console.log('apiParam:', app.apiParam);
|
||||
console.log('platform:', app.platform);
|
||||
|
||||
if (typeof app.apiCall !== 'function') {
|
||||
console.error('apiCall 不是一个函数!');
|
||||
uni.showToast({
|
||||
title: '海报生成功能异常',
|
||||
icon: 'none'
|
||||
});
|
||||
app.onClose();
|
||||
return;
|
||||
}
|
||||
|
||||
const params = { ...app.apiParam, channel: app.platform };
|
||||
console.log('调用 apiCall,参数:', params);
|
||||
|
||||
app.apiCall(params)
|
||||
.then(result => {
|
||||
app.imageUrl = result.data.imageUrl
|
||||
app.show = true
|
||||
console.log('apiCall 调用成功,结果:', result);
|
||||
if (result && result.data && result.data.imageUrl) {
|
||||
app.imageUrl = result.data.imageUrl;
|
||||
app.show = true;
|
||||
console.log('海报图片URL设置成功:', app.imageUrl);
|
||||
} else {
|
||||
console.error('apiCall 返回的数据格式不正确:', result);
|
||||
uni.showToast({
|
||||
title: '海报生成失败',
|
||||
icon: 'none'
|
||||
});
|
||||
app.onClose();
|
||||
}
|
||||
})
|
||||
.catch(err => app.onClose())
|
||||
.catch(err => {
|
||||
console.error('apiCall 调用失败:', err);
|
||||
uni.showToast({
|
||||
title: '海报生成失败',
|
||||
icon: 'none'
|
||||
});
|
||||
app.onClose();
|
||||
});
|
||||
},
|
||||
|
||||
// 关闭弹窗
|
||||
|
||||
@@ -37,22 +37,22 @@
|
||||
</view>
|
||||
</view>
|
||||
<!-- #endif -->
|
||||
<view class="share-item" @click="handlePoster()">
|
||||
<view class="item-image" :style="{ backgroundColor: '#38beec' }">
|
||||
<text class="iconfont icon-poster"></text>
|
||||
</view>
|
||||
<view class="item-name">
|
||||
<text>生成海报</text>
|
||||
</view>
|
||||
</view>
|
||||
<view class="share-item" @click="handleCopyLink()">
|
||||
<!-- <view class="share-item" @click="handlePoster()">-->
|
||||
<!-- <view class="item-image" :style="{ backgroundColor: '#38beec' }">-->
|
||||
<!-- <text class="iconfont icon-poster"></text>-->
|
||||
<!-- </view>-->
|
||||
<!-- <view class="item-name">-->
|
||||
<!-- <text>生成海报</text>-->
|
||||
<!-- </view>-->
|
||||
<!-- </view>-->
|
||||
<!-- <view class="share-item" @click="handleCopyLink()">
|
||||
<view class="item-image" :style="{ backgroundColor: '#38beec' }">
|
||||
<text class="iconfont icon-link"></text>
|
||||
</view>
|
||||
<view class="item-name">
|
||||
<text>复制链接</text>
|
||||
</view>
|
||||
</view>
|
||||
</view> -->
|
||||
<!-- <view class="share-item">
|
||||
<view class="item-image" :style="{ backgroundColor: '#FE8A4F' }">
|
||||
<text class="iconfont icon-weibo"></text>
|
||||
@@ -185,9 +185,20 @@
|
||||
// 获取h5站点地址
|
||||
SettingModel.h5Url(true)
|
||||
.then(baseUrl => {
|
||||
// 生成完整的分享链接
|
||||
const shareUrl = buildUrL(baseUrl, path, query)
|
||||
resolve(shareUrl)
|
||||
// 检查baseUrl是否有效
|
||||
if (baseUrl && typeof baseUrl === 'string' && baseUrl.trim() !== '') {
|
||||
// 生成完整的分享链接
|
||||
const shareUrl = buildUrL(baseUrl, path, query)
|
||||
resolve(shareUrl)
|
||||
} else {
|
||||
// 如果H5地址无效,抛出错误进入catch处理
|
||||
throw new Error('H5地址无效')
|
||||
}
|
||||
})
|
||||
.catch(err => {
|
||||
// 如果获取H5地址失败,使用默认域名或当前页面路径
|
||||
console.log('获取H5地址失败:', err)
|
||||
reject(err)
|
||||
})
|
||||
})
|
||||
},
|
||||
@@ -196,11 +207,47 @@
|
||||
handleCopyLink() {
|
||||
const app = this
|
||||
app.getShareUrl().then(shareUrl => {
|
||||
console.log('获取到分享链接:', shareUrl)
|
||||
// 复制到剪贴板
|
||||
uni.setClipboardData({
|
||||
data: shareUrl,
|
||||
success: () => app.$toast('链接复制成功,快去发送给朋友吧~'),
|
||||
fail: err => app.$toast('很遗憾,复制失败'),
|
||||
fail: (error) => {
|
||||
console.error('复制失败:', error)
|
||||
app.$toast('很遗憾,复制失败')
|
||||
},
|
||||
complete: () => app.handleCancel()
|
||||
})
|
||||
}).catch(err => {
|
||||
// 如果获取分享链接失败,使用当前页面路径
|
||||
const { path, query } = getCurrentPage()
|
||||
console.log('当前页面信息:', { path, query })
|
||||
|
||||
// 构建查询参数字符串
|
||||
let queryString = ''
|
||||
if (query && Object.keys(query).length > 0) {
|
||||
const queryParts = []
|
||||
for (const key in query) {
|
||||
if (query.hasOwnProperty(key)) {
|
||||
queryParts.push(key + '=' + query[key])
|
||||
}
|
||||
}
|
||||
queryString = queryParts.join('&')
|
||||
}
|
||||
|
||||
// 构建当前页面URL
|
||||
const currentUrl = path + (queryString ? '?' + queryString : '')
|
||||
const shareText = app.shareTitle + '\n\n查看详情:' + currentUrl
|
||||
|
||||
console.log('生成的分享文本:', shareText)
|
||||
|
||||
uni.setClipboardData({
|
||||
data: shareText,
|
||||
success: () => app.$toast('链接复制成功,快去发送给朋友吧~'),
|
||||
fail: (error) => {
|
||||
console.error('复制失败:', error)
|
||||
app.$toast('很遗憾,复制失败')
|
||||
},
|
||||
complete: () => app.handleCancel()
|
||||
})
|
||||
})
|
||||
@@ -262,9 +309,34 @@
|
||||
},
|
||||
|
||||
// 生成二维码海报
|
||||
handlePoster() {
|
||||
this.showGoodsPosterPopup = true
|
||||
this.handleCancel()
|
||||
async handlePoster() {
|
||||
console.log('ShareSheet handlePoster 被调用');
|
||||
console.log('posterApiCall 类型:', typeof this.posterApiCall);
|
||||
console.log('posterApiCall 函数:', this.posterApiCall);
|
||||
console.log('posterApiParam:', this.posterApiParam);
|
||||
|
||||
// 先关闭分享菜单
|
||||
this.handleCancel();
|
||||
|
||||
// 检查是否有海报生成方法
|
||||
if (typeof this.posterApiCall !== 'function') {
|
||||
console.error('posterApiCall 不是一个函数!');
|
||||
uni.showToast({
|
||||
title: '海报生成功能异常',
|
||||
icon: 'none'
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
// 直接调用海报生成方法,让父组件处理海报显示
|
||||
const result = await this.posterApiCall(this.posterApiParam);
|
||||
console.log('海报生成完成:', result);
|
||||
|
||||
} catch (error) {
|
||||
console.error('海报生成失败:', error);
|
||||
// 错误处理已经在 posterApiCall 中处理了,这里不需要重复显示
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user