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
/**
 *   c.k  2017/11/15 创建
 *   c.y  2018/3/16 修改 (把增加了获取项目的动态配置的方法)
 *   获取设备的信息以及渠道号
 *   获取项目的名称,logo,协议等等动态配置
 */
 
import device from '../tool/deviceInfo'; // 设备信息
import channel from '../tool/channel'; // 获取渠道编号
import jsBridge from '../tool/jsBridge'; // 安卓/iOS获取设备的信息已经cn值
import systemApi from '../api/api';
import codeManage from '../api/statusCodeManage';
 
// 设置客户端的信息
function setClientInfo () {
    // 当前的设备信息
    let currentDeviceInfo = {
        'ostype': device.getDeviceType(),  // 系统类型
        'cn': '',
        'resolution': window.screen.height + '*' + window.screen.width,
        'chanNo': '',   // jtjinfu  100  channel.GetUrlParam('chanNo')
        'childChan': '', // '308'  100,  appStore
        'isApp': '0',
        'areaCode':'510100'
        // 'appVersion':"1.0.0"
    };
    let _newClientInfo = window.localStorage.getItem('newClientInfo');
    if(_newClientInfo){
        _newClientInfo = JSON.parse(_newClientInfo);
        _newClientInfo.cn = channel.getCnVal();
        if(!_newClientInfo.areaCode){
            _newClientInfo.areaCode = '510100';  // 界面刷新覆盖默认值
        }
        window.localStorage.setItem('newClientInfo', JSON.stringify(_newClientInfo));
    }else{
        currentDeviceInfo.cn = channel.getCnVal();
        window.localStorage.setItem('newClientInfo', JSON.stringify(currentDeviceInfo));
    }
 
 
    // 如果设置是安卓/iOS的话,就通过jsBridge来获取设备信息,以及cn值
    jsBridge.fetchDeviceInfo();
    // let _deviceInfo = window.localStorage.getItem('deviceInfo');
    // if (_deviceInfo) {
    //     _deviceInfo = JSON.parse(_deviceInfo);
    //     for (let key in _deviceInfo) {
    //         currentDeviceInfo[key] = _deviceInfo[key];
    //     }
    // } else {
    //     currentDeviceInfo.ostype = '03';
    // }
 
}
 
 
 
// 获取项目的配置信息,项目的标题,logo,协议
function fetchProductConfig () {
    return systemApi.getProductConfig();
}
 
// 配置产品信息
function setProductInfo (prodConfig, prodTitle) {
    window.localStorage.setItem('newProdConfig', prodConfig.replace(/commerce/g,'finlean_wallet'));
    document.getElementById('productTitle').innerHTML = prodTitle;
}
 
// 设置项目配置信息
async function setProductConfig () {
    // 获取当前渠道号
    let clientInfo = JSON.parse(window.localStorage.getItem('newClientInfo'));
    let localChannelNo = clientInfo.cn;
    let localChannelNum = clientInfo.chanNo;
    try {
        let productConfig = await fetchProductConfig();
        // 如果本地有chanNo
        if (localChannelNum) {
            let currentProdConfig = productConfig.chanBaseInfo[localChannelNum];
            setProductInfo(JSON.stringify(currentProdConfig), currentProdConfig.title);
        } else {
            // 根据本地渠道号 LAf4,获取渠道编号 100
            let currentChannelNum = productConfig.chanSign[localChannelNo];
            // 根据当前渠道获取对应的产品信息, 并进行设置
            if (currentChannelNum) {
                let currentProdConfig = productConfig.chanBaseInfo[currentChannelNum];
                setProductInfo(JSON.stringify(currentProdConfig), currentProdConfig.title);
            }
        }
    } catch (error) {
        codeManage.showTipOfStatusCode(error);
    }
}
 
export {
    setClientInfo,
    setProductConfig
}