cshenfu
2024-06-27 58aa6e282bb343503be3cb198948328ea3ed7b79
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import utils from '../../utils/util.js';
 
module.exports = {
    methods: {
        wechatH5Share(title, desc, icon) {
            if (!utils.isWechat()) {
                return;
            }
            let link = window.location.href;
            // #ifdef H5
            this.$u.api.TemplateOne.Jssdk({
                path: link,
            }).then(data => {
                let jsapiConfig = data.data;
                window.wx1.config({
                    debug: jsapiConfig.debug,
                    appId: jsapiConfig.appId,
                    timestamp: jsapiConfig.timestamp,
                    nonceStr: jsapiConfig.nonceStr,
                    signature: jsapiConfig.signature,
                    jsApiList: jsapiConfig.jsApiList
                });
 
                if (typeof title === 'undefined') {
                    title = data.share.title;
                }
                if (typeof desc === 'undefined') {
                    desc = data.share.desc;
                }
                if (typeof icon === 'undefined') {
                    icon = data.share.icon;
                }
 
                window.wx1.ready(() => {
                    window.wx1.updateAppMessageShareData({
                        title: title,
                        desc: desc,
                        link: link,
                        imgUrl: icon,
                        success: () => { }
                    });
                    window.wx1.updateTimelineShareData({
                        title: title,
                        link: link,
                        imgUrl: icon,
                        success: () => { }
                    })
                });
            })
            // #endif
        }
    }
}