123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- import touch from '/utils/touch.js' //新加
- App({
- onLaunch: function () {
- // 登录
- 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 >= 750) {
- that.globalData.screenHeight = 'xSeries'
- }
- res.lang = res.language.indexOf('zh') !== -1 ? 'zh' : 'en';
- that.systemInfo = res;
- }
- })
- if (wx.getStorageSync('token') == '' || wx.getStorageSync('token') == undefined) {
- wx.reLaunch({
- url: '../login/login',
- })
- }
- 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: '当前微信版本过低,无法使用该功能,请升级到最新微信版本后重试。'
- })
- }
- if (wx.getStorageSync('token')) {
- }
- },
- globalData: {
- statusBarHeight: wx.getSystemInfoSync()['statusBarHeight'],
- windowHeight: wx.getSystemInfoSync()['windowHeight'],
- screenHeight: '',
- login: false,
- swichChecked: false,
- userInfo: null,
- title: '闪现出行', //定义全局标题
- // url: 'https://bike.hanyiyun.com/app-api/', //闪现出行
- // url : 'https://xiaobaichuxing.hanyiyun.com/app-api/', //小白出行
- url: 'https://bike.saas.yufengjiayun.com/app-api/', //商户端
- // url:'http://admin.weikemu.dev.hanyiyun.com/app-api/',//临时域名
- // url:'http://121.37.153.251/app-api/',
- merchant_id: 0
- },
- systemInfo:{},
- touch: new touch(), //实例化这个touch对象
- request(api, params, method) {
- var that = this;
- // wx.getStorage({
- // key: 'token',
- // success: function (resp) {
- // console.log(resp)
- return new Promise((resolve, reject) => {
- wx.request({
- url: that.globalData.url + api,
- data: params,
- header: {
- 'content-type': 'application/x-www-form-urlencoded',
- 'Authorization': 'bearer' + ' ' + wx.getStorageSync('token'),
- 'merchant-id': that.globalData.merchant_id
- },
- method: method,
- success: (res) => {
- if (res.statusCode == 200 || res.statusCode == 201) {
- resolve(res)
- }
- // console.log(res)
- if (res.statusCode == 450) {
- return;
- }
- if (res.statusCode != 200 && res.statusCode!=201) {
- 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.showToast({
- title: '令牌过期或请求报错',
- icon: 'none',
- duration: '3000'
- })
- wx.showToast({
- title: '登陆过期请重新登陆~',
- icon: 'none',
- mask: true,
- success: function () {
- wx.reLaunch({
- url: '../login/login',
- })
- }
- })
- }
- },
- fail: (err) => {
- wx.showToast({
- title: '请求超时',
- icon: 'none',
- mask: true
- });
- reject("请求失败")
- }
- })
- })
- // },
- // fail: function (err) {
- // console.log(err)
- // wx.reLaunch({
- // url: '../login/login',
- // })
- // }
- // })
- },
- })
|