123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238 |
- App({
- onLaunch: function () {
- // 登录
- var that = this;
- wx.getSystemInfo({
- success: res => {
- console.log(res)
- var system = res.system.trim().split(/\s+/)[1];
- var intNumber = system.substring(0, system.indexOf("."));
- if (res.platform == 'ios' && intNumber < 13 || res.SDKVersion < '2.1.0') {
- console.log('低版本')
- that.globalData.compatible = true;
- wx.reLaunch({
- url: '/pages/compatible/index/index',
- })
- }
- that.globalData.platform = res.platform
- that.globalData.version = res.version
- console.log(res.safeArea.bottom)
- console.log('手机信息res' + res.model)
- if (res.model == 'iPhone X' || res.model == 'iPhone XR' || res.model == 'iPhone XS Max') {
- that.globalData.screenHeight = 'xSeries'
- } else if (res.safeArea.bottom >= 780) {
- that.globalData.screenHeight = 'xSeries'
- }
- }
- })
- if (wx.getStorageSync('midTimes') != '') {
- var time = wx.getStorageSync('midTimes');
- var timestamp = Date.parse(new Date()) / 1000;
- if (time <= timestamp) {
- console.log('midtimes过期')
- wx.setStorageSync('midTimes', '')
- }
- }
- if (wx.canIUse('getUpdateManager')) {
- const updateManager = wx.getUpdateManager()
- updateManager.onCheckForUpdate(function (res) {
- if (res.hasUpdate) {
- updateManager.onUpdateReady(function () {
- wx.showModal({
- title: '更新提示',
- content: '新版本已经准备好,是否重启应用?',
- success: function (res) {
- if (res.confirm) {
- updateManager.applyUpdate()
- }
- }
- })
- })
- updateManager.onUpdateFailed(function () {
- wx.showModal({
- title: '已经有新版本了哟~',
- content: '新版本已经上线啦~,请您删除当前小程序,重新搜索打开哟~'
- })
- })
- }
- })
- } else {
- wx.showModal({
- title: '提示',
- content: '当前微信版本过低,无法使用该功能,请升级到最新微信版本后重试。'
- })
- }
- },
- globalData: {
- statusBarHeight: wx.getSystemInfoSync()['statusBarHeight'],
- windowHeight: wx.getSystemInfoSync()['windowHeight'],
- imgUrl: 'http://resource.bike.hanyiyun.com/',
- screenHeight: '',
- login: false,
- platform: '',
- version: '',
- req: true,
- id: 0,
- times: 60,
- invalid: false,
- compatible: '',
- //闪现出行
- // title: '闪现出行', //全局修改此小程序名称
- // logoUrl: '/img/shanxianLg.png', //logo图片路径 网络图片/本地图片 dejin.png shanxianLg.png yuzhouLg.png dingding.png xuezi.png
- // appid: 'wxd47b0ef6600fbe24', //小程序的appid
- // merchant_id: 1, //商户ID
- // url: 'https://api.bike.saas.yufengjiayun.com/api', //叮叮出行
- // mapKey: 'C3YBZ-SLSKU-TYWVP-2NEUJ-JNDO3-KCFBH' //地图key值 德劲:PM2BZ-CS7L3-MPR35-3A5GW-HGW66-QLBXA ,闪现出行:C3YBZ-SLSKU-TYWVP-2NEUJ-JNDO3-KCFBH,禹州闪现出行 GTLBZ-F6BKO-5EDWH-SDHIX-K2ART-O2FRQ ,叮叮:IQYBZ-IKIW5-R6CII-QMV47-OAJJE-OAFBP ,学子:JQIBZ-RQTLX-7EL4B-T67UE-6PGKQ-FPFMD
- // 华智出行
- title: '华智出行', //全局修改此小程序名称
- logoUrl: '/img/huazhi.png', //logo图片路径 网络图片/本地图片 dejin.png shanxianLg.png yuzhouLg.png dingding.png xuezi.png
- appid: 'wxd60ff0c8471a5a0d', //小程序的appid
- merchant_id: 7, //商户ID
- url: 'https://api.bike.saas.yufengjiayun.com/api', //叮叮出行
- mapKey: 'C3YBZ-SLSKU-TYWVP-2NEUJ-JNDO3-KCFBH'
- // url : 'http://api.weikemu.dev.hanyiyun.com/api', //威科姆测试域名
- // url : 'https://api.xiaobaichuxing.hanyiyun.com/api', //小白出行域名sa
- // url: 'https://api.bike.hanyiyun.com/api', //闪现出行域名
- // url : 'https://api.weilai.hanyiyun.com/api', //太比特测试域名
- // url : 'https://api.weilaibike.com/api', //线上域名
- // url: 'https://api.bike.saas.yufengjiayun.com/api', //商户端域名
- // url:'http://dev.api.saas.yufengjiayun.com/api',//测试域名
- // url:'https://api.dev.saas.yufengjiayun.com/api',//支付宝测试域名
- },
- request(api, params, method, req1) {
- var that = this;
- if (req1 == false) return;
- if (req1) {
- that.globalData.req = false;
- }
- if (wx.getStorageSync('token') != '' || wx.getStorageSync('token') != undefined) {
- if (req1 == true || req1 == undefined) {
- return new Promise((resolve, reject) => {
- wx.request({
- url: this.globalData.url + api,
- data: params,
- header: {
- 'content-type': 'application/x-www-form-urlencoded',
- 'Cache-Control': 'no-cache',
- 'Authorization': wx.getStorageSync('token'),
- 'merchant-id': this.globalData.merchant_id
- },
- method: method,
- success: (res) => {
- resolve(res)
- // console.log(res)
- if (res.statusCode == 450) {
- return;
- }
- if (res.data.statusCode != 200) {
- if (res.data.message == '订单不存在或订单已结算') {
- if (this.globalData.compatible) {
- wx.reLaunch({
- url: '/pages/compatible/index/index',
- })
- } else {
- wx.reLaunch({
- url: '/pages/index/index',
- })
- }
- return false;
- } else if (res.data.message == '运动中不能关锁') {
- return false;
- }
- if (res.message != undefined) {
- wx.showToast({
- title: res.message,
- icon: 'none',
- duration: 3000,
- mask: true
- })
- } else if (res.data.message != undefined) {
- wx.showToast({
- title: res.data.message,
- icon: 'none',
- duration: 3000,
- mask: true
- })
- }
- } else if (res.statusCode != 200) {
- if (res.data.message == '订单不存在或订单已结算') {
- if (this.globalData.compatible) {
- wx.reLaunch({
- url: '/pages/compatible/index/index',
- })
- } else {
- wx.reLaunch({
- url: '/pages/index/index',
- })
- }
- return false;
- } else if (res.data.message == '运动中不能关锁') {
- return false;
- }
- if (res.message != undefined) {
- wx.showToast({
- title: res.message,
- icon: 'none',
- duration: 3000,
- mask: true
- })
- } else if (res.data.message != undefined) {
- wx.showToast({
- title: res.data.message,
- icon: 'none',
- duration: 3000,
- mask: true
- })
- }
- }
- if (res.statusCode == 401) {
- var timeout;
- wx.removeStorageSync('token')
- that.globalData.invalid = true
- console.log(that.globalData.login)
- if (that.globalData.login) {
- return false;
- }
- if (that.globalData.login == false) {
- that.globalData.login = true
- wx.showToast({
- title: '登陆过期请重新登陆~',
- icon: 'none',
- duration: 1000,
- mask: true,
- success: function () {
- wx.reLaunch({
- url: '/pages/authentication/authentication',
- })
- }
- })
- timeout = setTimeout(function () {
- that.globalData.login = false
- if (that.globalData.login == false) {
- clearTimeout(timeout)
- }
- }, 3000)
- }
- } else if (res.statusCode == 404) {
- wx.navigateTo({
- url: '/pages/undefind/undefind',
- })
- }
- },
- fail: (err) => {
- wx.showToast({
- title: err,
- icon: 'none',
- mask: true
- });
- reject("请求失败")
- },
- complete: () => {
- that.globalData.req = true
- }
- })
- })
- }
- }
- },
- })
|