ann0707
2018-08-16 c9bc8ec61cff4076132f6396d99d383a2cdf5a03
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/**
 * Created by c.y on 2018/3/17.
 * 项目的入口文件
 */
import Vue from 'vue';
import App from './App';
import store from './store/index';
import router from './router/index';
import FastClick from 'fastclick'; // 引入fastclick 解决移动端点击问题
import { AjaxPlugin, ConfirmPlugin, ToastPlugin } from 'vux';
import androidBack from './tool/pageBackByAndroid';
 
require('core-js/library/fn/promise'); // 兼容安卓4.4打包的问题
require('./assets/iconfont/iconfont'); // 加载iconfontsvg
Vue.config.productionTip = false; // 关闭生产的提示
Vue.use(AjaxPlugin); // axios 模块
Vue.use(ConfirmPlugin);
Vue.use(ToastPlugin);
FastClick.attach(document.body); //  配置fastclick
import SystApi from './api/api';
 
/* eslint-disable no-new */
new Vue({
    store,
    router,
    render: h => h(App)
}).$mount('#app-box');
 
 
//  加载微信 分享功能  如果不是微信环境 就不执行以下代码 TODO
let _WXurl = window.location.origin +  window.location.pathname;
// let _WXurl = 'https://loan.finlean.top/';
// let _WXurl = window.location.origin;
SystApi.getWXToken({url:_WXurl}).then(function (res) {
    if (res.errorCode === 0) {
        // 第二步骤   只需要首页地址分享 ,需要在每次变化时调用
        wx.config({
            debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
            appId: res.body.appId,
            timestamp: res.body.timestamp, // 必填,生成签名的时间戳
            nonceStr: res.body.nonceStr, // 必填,生成签名的随机串
            signature: res.body.signature,// 必填,签名,见附录1
            jsApiList: ['checkJsApi', 'onMenuShareTimeline', 'onMenuShareAppMessage'] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2
        });
 
        wx.hideMenuItems({
            menuList: ['menuItem:copyUrl'], // 要隐藏的菜单项,只能隐藏“传播类”和“保护类”按钮,所有menu项见附录3
            success:function(res){
 
            }
        });
 
        // 必须放在 回调函数里,不然当在注册的时候 ,有可能还没有返回数据回来,例如刷新问题
        //            微信检查接口列表
        wx.checkJsApi({
            jsApiList: ['checkJsApi','hideMenuItems', 'onMenuShareTimeline', 'onMenuShareAppMessage'], // 需要检测的JS接口列表
            success: function (res) {
                // console.log(res);
            }
        });
 
        wx.ready(function () {   // 页面加载完成后用户就有可能调用微信的分享,所以当页面ready 完后就加载
            // 拼接分享链接
            // 获取cn 值
 
            let _cn = '';
            if(_cn == null || _cn == undefined || _cn==''){
                let _tempNewClientInfoUrl = window.localStorage.getItem('newClientInfo');
                if(_tempNewClientInfoUrl){
                    _tempNewClientInfoUrl = JSON.parse(_tempNewClientInfoUrl);
                    _cn = _tempNewClientInfoUrl.cn;
                }
            }
            let _shareLink = window.location.origin + window.location.pathname + '#/f-main?cn=' + _cn;
            // let _shareLink ='https://loan.finlean.top/commerce/wechat/S4Xn';
 
            wx.onMenuShareTimeline({  //例如分享到朋友圈的API
                title: '纷领钱包', // 分享标题
                link: _shareLink, // 分享链接
                imgUrl: 'https://loan.finlean.top/image/share/finlean_wallets.png', // 分享图标
                success: function () {
                    // 用户确认分享后执行的回调函数
                    console.log('分享回调函数');
                },
                cancel: function () {
                    console.log('取消分享回调函数');
                }
            });
 
            wx.onMenuShareAppMessage({  // 分享好友
                title: '纷领钱包', // 分享标题
                link: _shareLink, // 分享链接
                desc: '我在用纷领钱包,线上借款,审批神速,额度最高20万,2分钟极速下款,推荐你试试', // 分享描述
                imgUrl: 'https://loan.finlean.top/image/share/finlean_wallets.png', // 分享图标
                success: function () {
                    console.log('分享回调函数');
                },
                cancel: function () {
                    console.log('取消分享回调函数');
                    // 用户取消分享后执行的回调函数
                }
            });
        });
//              微信预加载失败回调
        wx.error(function (res) {
            console.log(res);
        });
 
    }
}, function (error) {
    if (error.response) {
        // console.log(error.response);
    }
});
 
androidBack.androidBackBtn();