123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150 |
- var http = require("/utils/config.js");
- App({
- onLaunch: function () {
- // 登录
- console.log(http)
- var that = this;
- wx.getSystemInfo({
- success: res => {
- 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 >= 736) {
- that.globalData.screenHeight = 'xSeries'
- }
- }
- })
- 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'],
- localUrl: http.url,
- screenHeight: '',
- login: false
- },
- request(api, params, method) {
- var that = this;
- if (true) {
- return new Promise((resolve, reject) => {
- wx.request({
- url: this.globalData.localUrl + api,
- data: params,
- header: {
- 'content-type': 'application/x-www-form-urlencoded',
- 'Authorization': 'bearer'+ ' ' + wx.getStorageSync('token'),
- },
- method: method,
- success: (res) => {
- resolve(res)
- // console.log(res)
- if (res.statusCode == 450) {
- return;
- }
- if (res.data.statusCode != 200) {
- if (res.data.message == '订单不存在或订单已结算') {
- wx.redirectTo({
- 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 == '订单不存在或订单已结算') {
- wx.redirectTo({
- 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) {
- wx.removeStorageSync('token')
- // wx.removeStorageSync('token_time')
- wx.showToast({
- title: '登陆过期请重新登陆~',
- icon: 'none',
- mask: true,
- success:function(){
- wx.redirectTo({
- url: '../login/login',
- })
- }
- })
- }
- },
- fail: (err) => {
- wx.showToast({
- title: err,
- icon: 'none',
- mask: true
- });
- reject("请求失败")
- }
- })
- })
- }
- },
- })
|