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) { console.log(info) 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; console.log(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