Commit 07b44c33 by 张立顺

fix 分享禁用

1 parent c58b93c3
......@@ -9,6 +9,7 @@
"pages/nothing/nothing",
"pages/webView/webView",
"pages/webView/h5Full",
"pages/webView/h5FullNoShare",
"pages/tabWorkOrder/pages/index/index",
"pages/tabMine/pages/index/index",
"pages/tabDateIndex/pages/tabDateIndex",
......
......@@ -18,7 +18,7 @@ export const appId = "wx570d9331f9ace0bd";
* 4预发布
* 5cdptest
*/
let index = 1;
let index = 2;
const accountInfo = wx.getAccountInfoSync();
const systemInfo = wx.getSystemInfoSync();
const envName = accountInfo.miniProgram.envVersion;
......
......@@ -188,9 +188,9 @@ Component({
wx.$util.hideLoading()
if (!res.data.data) return wx.$util.showToast('功能暂未开放')
}
if (item.webviewUrl) {
const targetUrl = `/pages/webView/h5Full?url=${encodeURIComponent(item.webviewUrl)}`
console.log('[navGo] webviewUrl:', item.webviewUrl, '=> navigateTo:', targetUrl)
if (webviewUrl) {
const targetUrl = `/pages/webView/h5FullNoShare?url=${encodeURIComponent(webviewUrl)}`
console.log('[navGo] webviewUrl:', webviewUrl, '=> navigateTo:', targetUrl)
wx.navigateTo({ url: targetUrl })
return
}
......
// pages/webView/h5FullNoShare.js — 全屏 web-view,无系统转发 / 朋友圈入口
import { createWebViewPageNoShare } from './webViewCommon'
Page(createWebViewPageNoShare())
{
"navigationStyle": "custom",
"usingComponents": {}
}
<!-- pages/webView/h5FullNoShare.wxml — 全屏 web-view,无分享能力 -->
<block wx:if="{{flag}}">
<web-view src="{{url}}" bindmessage="handleMessage"></web-view>
</block>
......@@ -9,7 +9,8 @@ export function createWebViewPage(sharePagePath) {
return {
data: {
flag: true,
isH5Bind: false
isH5Bind: false,
shareDisabled: false
},
getBaseUrl(url) {
......@@ -45,6 +46,8 @@ export function createWebViewPage(sharePagePath) {
},
onLoad: function (options) {
const shareDisabled = options.noShare === '1' || options.noShare === 'true'
this.setData({ shareDisabled })
wx.$util.showLoading('加载中...')
let decodeUrl = decodeURIComponent(options.url)
const baseUrl = this.getBaseUrl(decodeUrl)
......@@ -68,10 +71,18 @@ export function createWebViewPage(sharePagePath) {
url: decodeUrl
})
wx.hideLoading()
wx.showShareMenu({
withShareTicket: true,
menus: ['shareAppMessage', 'shareTimeline']
})
if (shareDisabled) {
// 无参 hideShareMenu 全端隐藏「转发」;带 menus 的能力在部分系统上为 Beta/仅 Android,不能单独依赖
wx.hideShareMenu()
wx.hideShareMenu({
menus: ['shareAppMessage', 'shareTimeline']
})
} else {
wx.showShareMenu({
withShareTicket: true,
menus: ['shareAppMessage', 'shareTimeline']
})
}
if (param.needIntercept) {
wx.enableAlertBeforeUnload &&
wx.enableAlertBeforeUnload({
......@@ -106,6 +117,12 @@ export function createWebViewPage(sharePagePath) {
onReady: function () {},
onShow: function () {
if (this.data.shareDisabled) {
wx.hideShareMenu()
wx.hideShareMenu({
menus: ['shareAppMessage', 'shareTimeline']
})
}
if (this.refresh) {
this.setData(
{
......@@ -176,6 +193,7 @@ export function createWebViewPage(sharePagePath) {
onReachBottom: function () {},
onShareAppMessage() {
if (this.data.shareDisabled) return
const { url } = this.data
const encoded = encodeURIComponent(url || '')
return {
......@@ -185,6 +203,7 @@ export function createWebViewPage(sharePagePath) {
},
onShareTimeline() {
if (this.data.shareDisabled) return
const { url } = this.data
const encoded = encodeURIComponent(url || '')
return {
......@@ -194,3 +213,19 @@ export function createWebViewPage(sharePagePath) {
}
}
}
/**
* 全屏 web-view,且不注册 onShareAppMessage / onShareTimeline。
* 微信规则:只有定义了这两个回调,右上角才会出现「转发 / 朋友圈」;
* 仅靠 return {} 或 hideShareMenu 在部分环境下仍可能可转发。
*/
export function createWebViewPageNoShare() {
const page = createWebViewPage('/pages/webView/h5FullNoShare')
delete page.onShareAppMessage
delete page.onShareTimeline
const origOnLoad = page.onLoad
page.onLoad = function (options) {
return origOnLoad.call(this, { ...options, noShare: '1' })
}
return page
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!