zhaojs
2023-06-01 36742f33a2a73a88c8407c872cf9c5a29a3fbd19
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
import APPUpdate from "./appUpdate.js";
var common = {};
common.getCache = function(key) {
    return new Promise((succ, error) => {
        uni.getStorage({
            key: key,
            success: res => {
                succ(res.data)
            },
            fail: res => {
                console.log(res);
                error(res)
            }
        })
    })
}
 
common.getCacheSync = function(key) {
    try {
        const value = uni.getStorageSync(key);
        if (value) {
            return value
        }
    } catch (e) {
        return e
    }
}
 
common.setCache = function(key, data) {
    return new Promise((succ, error) => {
        uni.setStorage({
            key: key,
            data: data,
            success: res => {
                succ(res.data)
            },
            fail: res => {
                console.log(res);
                error(res)
            }
        })
    })
}
 
 
 
common.goUrl = function(info, _this) {
    var userinfo = common.getCacheSync('userInfo')
    var that = _this;
    if (userinfo) {
        if (info.url_type == '0') {
            let url = info.parameter_json.url == undefined ? '' : info.parameter_json.url;
            if(url == '') return false;
            uni.navigateTo({
                url: '/pages/webView/webView?url=' + info.parameter_json.url
            })
        } else if (info.url_type == 1) {
            let url = info.parameter_json.url == undefined ? '' : info.parameter_json.url;
            if(url == '') return false;
            uni.navigateTo({
                url: url
            })
        } else if (info.url_type == '2') {
            let promotionSceneId = info.parameter_json.activityId == undefined ? '' : info.parameter_json.activityId;
            if(promotionSceneId == '') return false;
            that.$u.api.activityLink({promotionSceneId: promotionSceneId}).then(e => {
                if(e.code == 1)return that.$alert(e.msg);
                var res = e.data;
                const plug = uni.requireNativePlugin('xiguazhu-baichuan')
                plug.detailPage({
                    url: res.click_url,
                    "openType": 0
                }, result => {
                    console.log(result);
                });
                
            }).catch(function (err) {
                console.log(err)
            })
        } else if (info.url_type == 3) { //商品详情
        let parameter = info.parameter_json;
        if(parameter.goodsId == '') return false;
            const data = {}
            data.goodsId = parameter.goodsId;
            data.sourceType = parameter.goods_platform;
            uni.navigateTo({
                url: '/pages/goods/goodsDetail?info=' + encodeURIComponent(JSON.stringify(data))
            })
        } else if (info.url_type == 7) {
            let parameter = info.parameter_json;
            if(parameter.url == '') return false;
            that.$u.api.getPrivilegeLink({type:1,goodsId:parameter.url}).then(e => {
                if(e.code == 1)return that.$alert(e.msg);
                var url = e.data.info;
                // #ifdef APP-PLUS
                plus.runtime.openURL('openApp.jdMobile://virtual?params=' + encodeURIComponent(
                    '{"des":"m","url":"' + url +
                    '","category":"jump"}'), res => {
                    uni.navigateTo({
                        url: '../webView/webView?url=' + url
                    })
                }, 'com.jingdong.app.mall');
                // #endif
            }).catch(function (err) {
            })
        } else if (info.url_type == 11 || info.url_type == 13) {
            let parameter = info.parameter_json;
            if(parameter.jtk_act_id == '') return false;
            that.$u.api.unionAct({jtk_act_id: parameter.jtk_act_id}).then(e => {
                if(e.code == 1)return that.$alert(e.msg);
                var zhuanlianres = e.data;
                if (info.url_type == 11) {
                    uni.navigateTo({
                        url: '../webView/webView?url=' + encodeURIComponent(zhuanlianres.long_h5 == '' ? zhuanlianres.h5 : zhuanlianres.long_h5)
                    })
                } else {
                    var isAppletJump = getApp().globalData.appinfo.isAppletJump;
                    if (isAppletJump) {
                        plus.share.getServices(function(res) {
                            var sweixin = null;
                            for (var i = 0; i < res.length; i++) {
                                var t = res[i];
                                if (t.id == 'weixin') {
                                    sweixin = t;
                                }
                            }
                            if (sweixin) {
                                sweixin.launchMiniProgram({
                                    id: zhuanlianres.original_id,
                                    type: 0, //0 正式 1 测试 2 体验  小程序的版本
                                    path: zhuanlianres.we_app_info.page_path //这里你要跳的路径,可以传值
                                });
                            }
                        }, function(res) {
                            console.log(JSON.stringify(res));
                        });
                    } else {
                        if (zhuanlianres.deeplink) {
                            plus.runtime.openURL(zhuanlianres.deeplink, res => {
                                uni.navigateTo({
                                    url: '../webView/webView?url=' + encodeURIComponent(zhuanlianres.long_h5 == '' ? zhuanlianres.h5 : zhuanlianres.long_h5)
                                })
                            });
                        } else {
                            uni.navigateTo({
                                url: '../webView/webView?url=' + encodeURIComponent(zhuanlianres.long_h5 == '' ? zhuanlianres.h5 : zhuanlianres.long_h5)
                            })
                        }
                    }
                }
                
            }).catch(function (err) {
            })
        } else if (info.url_type == 12) {
            let parameter = info.parameter_json;
            plus.share.getServices(function(res) {
                var sweixin = null;
                for (var i = 0; i < res.length; i++) {
                    var t = res[i];
                    if (t.id == 'weixin') {
                        sweixin = t;
                    }
                }
                if(parameter.appId == '' || parameter.route == '') return false;
                if (sweixin) {
                    sweixin.launchMiniProgram({
                        id: parameter.appId,
                        type: 0, //0 正式 1 测试 2 体验  小程序的版本
                        path: parameter.route //这里你要跳的路径,可以传值
                    });
                }
            }, function(res) {
                console.log(JSON.stringify(res));
            });
        }else if (info.url_type == 14) {
            let parameter = info.parameter_json;
            if(parameter.template_id == '') return false;
            that.$u.api.singlePageLink({template_id: parameter.template_id}).then(e => {
                if(e.code == 1)return that.$alert(e.msg);
                uni.navigateTo({
                    url: '../webView/webView?url=' + e.data.url
                })
                
            }).catch(function (err) {
            })
        }else if(info.url_type == 999){
            let parameter = info.parameter_json;
            if (parameter.cmark == 'share') {
                common.shareApp()
            } else if (parameter.cmark == 'version_update') {
                that.$u.api.getAppVersion({
                    equipmentType: (uni.getSystemInfoSync().platform == "android") ? 1 : 2
                }).then(e => {
                    if(e.code != 0) return that.$alert(e.msg)
                    var res = e.data.info;
                    if (res.version_number) {
                        console.log(res.version_number)
                        console.log(plus.runtime.version)
                        console.log(common.cpr_version(res.version_number, plus.runtime.version))
                        if (common.cpr_version(res.version_number, plus.runtime.version)) {
                            APPUpdate()
                        } else {
                            that.$refs.uToast.show({
                                title: '当前已是最新版本~',
                                type: 'default',
                                position: 'bottom'
                            })
                        }
                    }
                }).catch(function (err) {
                })
            }
        }
        
    } else {
        uni.redirectTo({
            url: '/pages/login/wxlogin'
        })
    }
}
 
common.cpr_version = function(a, b) {
    var _a = common.toNum(a),
        _b = common.toNum(b);
    if (_a == _b) return false
    if (_a < _b) return false
    if (_a > _b) return true
}
 
common.toNum = function(a) {
    var a = a.toString();
    //也可以这样写 var c=a.split(/\./);
    var c = a.split('.');
    var num_place = ["", "0", "00", "000", "0000"],
        r = num_place.reverse();
    for (var i = 0; i < c.length; i++) {
        var len = c[i].length;
        c[i] = r[len] + c[i];
    }
    var res = c.join('');
    return res;
}
 
common.shareApp = function() {
    
    // #ifdef APP-PLUS
    var userinfo = common.getCacheSync('userInfo');
    var appInfo = common.getCacheSync('appInfo');
    var txtdata=appInfo.invite_url + "?code="+userinfo.invitation_code
    /* if (plus.os.name == 'Android') {
        txtdata = appInfo.appName + '的下载链接为:' + appInfo.appAndroidDownUrl +
            '\n邀请码:' + userinfo.invitation_code
    } else {
        txtdata = appInfo.appName + '的下载链接为:' + appInfo.appIosDownUrl + '\n邀请码:' +
            userinfo.invitation_code
    } */
    uni.setClipboardData({
        data: txtdata,
        success: res => {
            uni.showToast({
                title: '下载链接已复制~快去分享给好友吧!',
                icon: 'none'
            })
            uni.setStorageSync('clipboard', txtdata);
        }
    });
    // #endif
}
 
 
 
 
export default common