Commit 81c82aed authored by spc's avatar spc

sywebview

parent 3287c605
......@@ -28,8 +28,7 @@ Webview页面使用说明:
<template>
<view class="webview-container">
<!-- Webview内容 -->
<web-view :src="webviewUrl" @message="getMessage" @load="onWebviewLoad" @error="onWebviewError"
class="webview-content"></web-view>
<web-view :src="webviewUrl" @message="getMessage" class="webview-content"></web-view>
</view>
</template>
......@@ -38,6 +37,8 @@ import { ref, onMounted } from 'vue'
import { useUserStore } from '@/stores/user.js'
import { useGlobalStore } from '../../stores/global'
import { fetchSyWebviewJSON } from '../../api/sywebview'
import { onLoad, onShareAppMessage, onShareTimeline, onPageScroll } from "@dcloudio/uni-app";
// 响应式数据
const statusBarHeight = ref(0)
......@@ -81,30 +82,6 @@ const getMessage = (e) => {
}
// Webview加载完成
const onWebviewLoad = (e) => {
console.log('Webview加载完成:', e)
if (pageTitle.value === '加载中...') {
pageTitle.value = '网页'
}
}
// Webview加载错误
const onWebviewError = (e) => {
console.error('Webview加载错误:', e)
uni.showToast({
title: '页面加载失败',
icon: 'none'
})
}
// 返回上一页
const goBack = () => {
uni.navigateBack({
delta: 1
})
}
// 页面加载
onMounted(async () => {
// 获取状态栏高度
......@@ -133,7 +110,6 @@ onMounted(async () => {
// 将 options 的所有参数原样作为查询参数传给 H5,并补齐 cuk
const params = { ...(pageOptions.value || {}) }
if (cuk && !params.cuk) params.cuk = cuk
// 添加用户信息参数
if (openId && !params.openId) params.openId = openId
if (unionId && !params.unionId) params.unionId = unionId
......@@ -161,41 +137,71 @@ onMounted(async () => {
})
// 分享功能
defineExpose({
onShareAppMessage: (options) => {
console.log('分享数据:', share.value)
console.log('分享选项:', options)
if (share.value) {
const shareurl = share.value.shareUrl
const title = share.value.shareTitle
const imageUrl = share.value.shareImageUrl
console.log('使用分享数据:', { title, shareurl, imageUrl })
return {
title: title || '分享',
path: shareurl || '/pages/index/index',
imageUrl: imageUrl || '',
success: function (res) {
console.log('分享成功:', res)
},
fail: function (res) {
console.log('分享失败:', res)
},
complete: function (res) {
console.log('分享完成:', res)
}
onShareAppMessage((options) => {
console.log('分享数据:', share.value)
console.log('分享选项:', options)
if (share.value) {
const shareurl = share.value.shareUrl
const title = share.value.shareTitle
const imageUrl = share.value.shareImageUrl
console.log('使用分享数据:', { title, shareurl, imageUrl })
return {
title: title,
path: shareurl || '/pages/index/index',
imageUrl: imageUrl || '',
success: function (res) {
console.log('分享成功:', res)
},
fail: function (res) {
console.log('分享失败:', res)
},
complete: function (res) {
console.log('分享完成:', res)
}
}
}
// 如果没有分享数据,返回默认分享
return {
path: '/pages/index/index'
}
})
onShareTimeline((options) => {
console.log('分享朋友圈数据:', share.value)
console.log('分享朋友圈选项:', options)
if (share.value) {
const shareurl = share.value.shareUrl
const title = share.value.shareTitle
const imageUrl = share.value.shareImageUrl
console.log('使用分享数据:', { title, shareurl, imageUrl })
// 如果没有分享数据,返回默认分享
return {
title: '分享',
path: '/pages/index/index'
title: title || '分享',
path: shareurl || '/pages/index/index',
imageUrl: imageUrl || '',
success: function (res) {
console.log('分享成功:', res)
},
fail: function (res) {
console.log('分享失败:', res)
},
complete: function (res) {
console.log('分享完成:', res)
}
}
}
// 如果没有分享数据,返回默认分享
return {
path: '/pages/index/index'
}
})
</script>
<style lang="less" scoped>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment