发布于 9个月前

uni-app 微信H5页面禁止分享

官方文档链接

https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/JS-SDK.html#48

var jweixin = require('@/components/jweixin-module/index.js');
export default {
    data() {
        return {

        }
    },
    onLoad: function() {
        if(this.isWechat) {
            this.hideShare();
        }
    },
    methods: {
        isWechat: function() {
                var ua = window.navigator.userAgent.toLowerCase();
                if (ua.match(/micromessenger/i) == 'micromessenger') {
                        // console.log('是微信客户端')
                        return true;
                } else {
                        // console.log('不是微信客户端')
                        return false;
                }
        },
        //初始化sdk配置
        hideShare: function() {
            jweixin.config({
                    debug: false,
                    appId: '',
                    timestamp: timestamp,
                    nonceStr: '',
                    signature: '',
                    jsApiList: [
                        'hideMenuItems',
                        'hideOptionMenu',
                        'hideAllNonBaseMenuItem',
                    ]
            });

            jweixin.ready(function() {
                jweixin.hideOptionMenu();
                jweixin.hideAllNonBaseMenuItem();
                jweixin.hideMenuItems({// 要隐藏的菜单项,只能隐藏“传播类”和“保护类”按钮,所有menu项见附录3
                menuList: [
                    'menuItem:share:appMessage', //发送给朋友
                    'menuItem:share:timeline', //分享到朋友圈
                    'menuItem:share:qq',
                    'menuItem:share:QZone',
                    'menuItem:openWithQQBrowser',
                    'menuItem:openWithSafari',
                    'menuItem:copyUrl', //复制链接
                    'menuItem:share:email',
                    'menuItem:share:brand',
                    'menuItem:share:facebook'
                ]
            })
            });
        }
        }
    }
}
©2020 edoou.com   京ICP备16001874号-3