微信分享和钉钉分享的设置

在天猫超级粉丝日的H5制作中需要同时能分享到钉钉和微信。见代码 在html的head中加入

//钉钉

//微信

复制代码
let imgUrl = require('./images/shareIcon.jpg');
(function () {
    // alert(dd.isDingtalk());
    dd.ready(function () {
        dd.biz.navigation.setRight({
            show: true,//控制按钮显示, true 显示, false 隐藏, 默认true
            control: true,//是否控制点击事件,true 控制,false 不控制, 默认false
            text: '...',//控制显示文本,空字符串表示显示默认文本
            onSuccess: function (result) {
                //如果control为true,则onSuccess将在发生按钮点击事件被回调
                dd.biz.util.share({
                    type: 0, //分享类型,0:全部组件 默认; 1:只能分享到钉钉;2:不能分享,只有刷新按钮
                    url: window.location.href,
                    content: '分享描述',
                    title: '分享标题',
                    image: 'https://XXXX' + imgUrl,
                    onSuccess: function () {
                        //onSuccess将在分享完成之后回调
                        /**/
                    },
                    onFail: function (err) { }
                })
            },
            onFail: function (err) { }
        });
    })
})();
(function () {

    window.getConfig = function (config) {
        config = Object.assign({}, config, {
            debug: false,
            jsApiList: [
                "onMenuShareTimeline",
                "onMenuShareAppMessage",
                "hideAllNonBaseMenuItem",
                "showMenuItems",
                "showOptionMenu",
                "hideOptionMenu"
            ]
        })
        return config;
    }

    window.wxShareOpt = {
        title: "分享标题",
        imgUrl: 'https://xxx' + imgUrl,
        desc: "分享描述",
    }
    window.wxShareOpt.link = window.location.href;
    window.addEventListener('hashchange', () => {
        window.wxShareOpt.link = window.location.href;
        wx.onMenuShareTimeline(window.wxShareOpt);
        wx.onMenuShareAppMessage(window.wxShareOpt);
    })

    let tkurl='xxxx';//微信验证地址
    axios.get('tkurl', {
        params: {
            appId: 'XXXXXXXXX',
            url: window.location.href,
        }
    }).then((data) => {
        // console.log(data);
        wx.config(window.getConfig(data.data.result));
    })
    wx.ready(() => {
        wx.onMenuShareTimeline(window.wxShareOpt);
        wx.onMenuShareAppMessage(window.wxShareOpt);
    });

    wx.error(() => {
        //alert("微信初始化失败");
    });
})();
复制代码

转载于:https://juejin.im/post/5acac1e15188257cc20d92b5

你可能感兴趣的:(微信分享和钉钉分享的设置)