//app.js const util = require("util/util.js") App({ onLaunch: function() { // 初始化配置 this.autoUpgrade() wx.getSystemInfo({ success: e => { this.globalData.StatusBar = e.statusBarHeight; let capsule = wx.getMenuButtonBoundingClientRect(); if (capsule) { this.globalData.Custom = capsule; this.globalData.CustomBar = capsule.bottom + capsule.top - e.statusBarHeight; } else { this.globalData.CustomBar = e.statusBarHeight + 50; } this.globalData.CustomRate = e.screenHeight / e.screenWidth; } }) }, autoUpgrade: function(){ if (wx.canIUse('getUpdateManager')) { const updateManager = wx.getUpdateManager() updateManager.onCheckForUpdate(function (res) { // 请求完新版本信息的回调 if (res.hasUpdate) { console.log('res.hasUpdate====') updateManager.onUpdateReady(function () { wx.showModal({ title: '更新提示', content: '新版本已经准备好,是否重启应用?', success: function (res) { console.log('success====', res) if (res.confirm) { updateManager.applyUpdate() } } }) }) updateManager.onUpdateFailed(function () { // 新的版本下载失败 wx.showModal({ title: '已经有新版本了哟~', content: '新版本已经上线啦~,请您删除当前小程序,重新搜索打开哟~' }) }) } }) } }, // 微信登入 doLogin: function( cb ){ let that = this wx.login({ success: res => { if (res.code) { let param = { code: res.code }; //发起网络请求 util.http("base/wxLogin", param, (errCode, data) => { if( errCode == 0){ let {user, token} = data user.token = token; wx.setStorageSync('@yunyuanqu', user); }else{ util.showMsg( data ) } cb&&cb(errCode, data ); }); } else { console.log('登录失败!' + res.errMsg) } } }) }, checkLogin:function( cb ){ var info = wx.getStorageSync('@yunyuanqu')||{}; let isLogin = !!info.token; this.globalData.userInfo = info; if (!isLogin){ this.doLogin( cb ) }else{ cb&&cb( ) } }, getSysInfo: function (cb) { wx.getSystemInfo({ success: function (res) { console.log(res) typeof cb == "function" && cb(res); } }) }, addForm( e ){ let { formId } = e.detail; if (!formId || formId == "the formId is a mock one" ){ return; } util.http("Form/addForm", {formId}, (err, res) => { console.log( "addForm", err, res); }); }, goHome() { wx.navigateTo({ url: '/pages/index/index', }) }, getLocation: function (cb) { var that = this; wx.getLocation({ type: 'wgs84', success: function (res) { console.log(res) typeof cb == "function" && cb(res); } }) }, checkPermission( cb ){ wx.getSetting({ success: function (res) { if (!res.authSetting['scope.userLocation']) { //申请授权 wx.authorize({ scope: 'scope.userLocation', success() { console.log("authorize success") cb&&cb() }, fail(){ console.log("authorize fail") } }) }else{ cb&&cb() } }, fail: function(res){ console.log("fail", res) } }) }, setGbInfo:function( info ){ this.globalData.info = info; }, getGbInfo: function(){ if( !this.globalData.info ){ let data = wx.getStorageSync( "@data")||{}; let {thumb, image, wiki} = data; this.globalData.info = {thumb,image, wiki}; } return this.globalData.info; }, getGbVote(){ return this.globalData.voteInfo; }, setGbVote( voteInfo ){ this.globalData.voteInfo = voteInfo; }, getLocation(){ return this.globalData.location; }, setLocaltion( location ){ this.globalData.location = location; }, getUserInfo( ){ return this.globalData.userInfo }, setUserInfo( userInfo ){ userInfo = Object.assign(this.globalData.userInfo, userInfo ) wx.setStorageSync('@flogin', userInfo); this.globalData.userInfo = userInfo; }, globalData: { userInfo: {}, location: {}, info: null, voteInfo: null, wiki:[], Custom:0, CustomBar:0, CustomRate:0, StatusBar:0 } })