Commit 07b44c33 by 张立顺

fix 分享禁用

1 parent c58b93c3
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
"pages/nothing/nothing", "pages/nothing/nothing",
"pages/webView/webView", "pages/webView/webView",
"pages/webView/h5Full", "pages/webView/h5Full",
"pages/webView/h5FullNoShare",
"pages/tabWorkOrder/pages/index/index", "pages/tabWorkOrder/pages/index/index",
"pages/tabMine/pages/index/index", "pages/tabMine/pages/index/index",
"pages/tabDateIndex/pages/tabDateIndex", "pages/tabDateIndex/pages/tabDateIndex",
......
...@@ -18,7 +18,7 @@ export const appId = "wx570d9331f9ace0bd"; ...@@ -18,7 +18,7 @@ export const appId = "wx570d9331f9ace0bd";
* 4预发布 * 4预发布
* 5cdptest * 5cdptest
*/ */
let index = 1; let index = 2;
const accountInfo = wx.getAccountInfoSync(); const accountInfo = wx.getAccountInfoSync();
const systemInfo = wx.getSystemInfoSync(); const systemInfo = wx.getSystemInfoSync();
const envName = accountInfo.miniProgram.envVersion; const envName = accountInfo.miniProgram.envVersion;
......
...@@ -188,9 +188,9 @@ Component({ ...@@ -188,9 +188,9 @@ Component({
wx.$util.hideLoading() wx.$util.hideLoading()
if (!res.data.data) return wx.$util.showToast('功能暂未开放') if (!res.data.data) return wx.$util.showToast('功能暂未开放')
} }
if (item.webviewUrl) { if (webviewUrl) {
const targetUrl = `/pages/webView/h5Full?url=${encodeURIComponent(item.webviewUrl)}` const targetUrl = `/pages/webView/h5FullNoShare?url=${encodeURIComponent(webviewUrl)}`
console.log('[navGo] webviewUrl:', item.webviewUrl, '=> navigateTo:', targetUrl) console.log('[navGo] webviewUrl:', webviewUrl, '=> navigateTo:', targetUrl)
wx.navigateTo({ url: targetUrl }) wx.navigateTo({ url: targetUrl })
return 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) { ...@@ -9,7 +9,8 @@ export function createWebViewPage(sharePagePath) {
return { return {
data: { data: {
flag: true, flag: true,
isH5Bind: false isH5Bind: false,
shareDisabled: false
}, },
getBaseUrl(url) { getBaseUrl(url) {
...@@ -45,6 +46,8 @@ export function createWebViewPage(sharePagePath) { ...@@ -45,6 +46,8 @@ export function createWebViewPage(sharePagePath) {
}, },
onLoad: function (options) { onLoad: function (options) {
const shareDisabled = options.noShare === '1' || options.noShare === 'true'
this.setData({ shareDisabled })
wx.$util.showLoading('加载中...') wx.$util.showLoading('加载中...')
let decodeUrl = decodeURIComponent(options.url) let decodeUrl = decodeURIComponent(options.url)
const baseUrl = this.getBaseUrl(decodeUrl) const baseUrl = this.getBaseUrl(decodeUrl)
...@@ -68,10 +71,18 @@ export function createWebViewPage(sharePagePath) { ...@@ -68,10 +71,18 @@ export function createWebViewPage(sharePagePath) {
url: decodeUrl url: decodeUrl
}) })
wx.hideLoading() wx.hideLoading()
if (shareDisabled) {
// 无参 hideShareMenu 全端隐藏「转发」;带 menus 的能力在部分系统上为 Beta/仅 Android,不能单独依赖
wx.hideShareMenu()
wx.hideShareMenu({
menus: ['shareAppMessage', 'shareTimeline']
})
} else {
wx.showShareMenu({ wx.showShareMenu({
withShareTicket: true, withShareTicket: true,
menus: ['shareAppMessage', 'shareTimeline'] menus: ['shareAppMessage', 'shareTimeline']
}) })
}
if (param.needIntercept) { if (param.needIntercept) {
wx.enableAlertBeforeUnload && wx.enableAlertBeforeUnload &&
wx.enableAlertBeforeUnload({ wx.enableAlertBeforeUnload({
...@@ -106,6 +117,12 @@ export function createWebViewPage(sharePagePath) { ...@@ -106,6 +117,12 @@ export function createWebViewPage(sharePagePath) {
onReady: function () {}, onReady: function () {},
onShow: function () { onShow: function () {
if (this.data.shareDisabled) {
wx.hideShareMenu()
wx.hideShareMenu({
menus: ['shareAppMessage', 'shareTimeline']
})
}
if (this.refresh) { if (this.refresh) {
this.setData( this.setData(
{ {
...@@ -176,6 +193,7 @@ export function createWebViewPage(sharePagePath) { ...@@ -176,6 +193,7 @@ export function createWebViewPage(sharePagePath) {
onReachBottom: function () {}, onReachBottom: function () {},
onShareAppMessage() { onShareAppMessage() {
if (this.data.shareDisabled) return
const { url } = this.data const { url } = this.data
const encoded = encodeURIComponent(url || '') const encoded = encodeURIComponent(url || '')
return { return {
...@@ -185,6 +203,7 @@ export function createWebViewPage(sharePagePath) { ...@@ -185,6 +203,7 @@ export function createWebViewPage(sharePagePath) {
}, },
onShareTimeline() { onShareTimeline() {
if (this.data.shareDisabled) return
const { url } = this.data const { url } = this.data
const encoded = encodeURIComponent(url || '') const encoded = encodeURIComponent(url || '')
return { return {
...@@ -194,3 +213,19 @@ export function createWebViewPage(sharePagePath) { ...@@ -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!