//app.js let key = 'MUZBZ-5OF33-BVO3Y-YDTEZ-2GLLK-KVFTF', gdKey = 'bca18d221a666f2c70387e0c8e669f1e', apiPath = __wxConfig.envVersion == 'release' ? "https://www.jjyl.top/api/v1/" : "http://39.98.128.49:8086/api/v1/"; App({ onLaunch: function() { // 展示本地存储能力 var logs = wx.getStorageSync('logs') || [] logs.unshift(Date.now()) wx.setStorageSync('logs', logs) // 获取用户信息 wx.getSetting({ success: res => { if (res.authSetting['scope.userInfo']) { // 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框 wx.getUserInfo({ success: res => { // 可以将 res 发送给后台解码出 unionId this.globalData.userInfo = res.userInfo // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回 // 所以此处加入 callback 以防止这种情况 if (this.userInfoReadyCallback) { this.userInfoReadyCallback(res) } } }) } } }) // 检查更新 if (wx.getUpdateManager) { var updateManager_1 = wx.getUpdateManager(); updateManager_1.onCheckForUpdate(function(res) { console.log(res.hasUpdate); }); updateManager_1.onUpdateReady(function() { wx.showModal({ title: '更新提示', content: '新版本已经准备好,是否重启应用?', success: function(res) { if (res.confirm) { updateManager_1.applyUpdate(); } } }); }); updateManager_1.onUpdateFailed(function() { console.log('新版本下载失败'); }); } else {} }, globalData: { userInfo: null, apiPath: apiPath, header: "", token: "JJYLeyJhbGciOiJIUzUxMiJ9.eyJ1c2VyUmVnaW9uIjoiMTk4MiIsInVzZXJOYW1lIjoi6K-E5Lyw5ZGYIiwidHlwZSI6IjEiLCJ1c2VySUQiOjEwNiwidXNlclJlZ2lvblN0cmluZyI6Iuaxn-axieWMuizmrabmsYnluIIs5rmW5YyX55yBIiwibG9naW5Vc2VyTmFtZSI6Indoal9wZ3kiLCJ1c2VyTGV2ZWwiOiIzIiwiamdkbSI6IjQyMDEwMzAxMTAwMSIsImpneGgiOiIxIiwiZXhwIjoxNzEwNTI2NDQyLCJpYXQiOjE3MTA0ODMyNDIsImFnZW5jeVR5cGUiOiIyIiwib3JnUGFyZW50Q29kZSI6IjQyMDEwMyJ9.rcatN7nLZd2lNKY3R5t9wMPaWKT4XOEbh6aKcdwQbL-tHePpxqT7v6zrhFab_-isSX8DDHAJX0F6XEw75fcJtw", providerNo: "F000002", personNo: "R000016", serviceParty: 2, orderStatus: 2, loginType: "", apiType: "", disablePhoto: 0, //1是 0否,就是1 禁止使用相册 apiList: { fws: { login: "serviceProviderLogin", tongji: "" }, fwz: { login: "servicePersonLogin", tongji: "" } }, userId: '', // 当前登录用户id userName: '评估员', }, ajax: function(url, type, data, dataType, successcallback, errorcallbak, contentType) { var header = {}, token = this.globalData.token; if (token) { header["token"] = token; } // wx.showLoading(); wx.request({ url: apiPath + url, method: type || "get", data: data || {}, header: header, dataType: dataType || "JSON", success: function(res) { var data = JSON.parse(res.data); if (data.code == "200") { successcallback && successcallback(data.data); } else { errorcallbak && errorcallbak(data); } }, error: function(res) { errorcallbak && errorcallbak(res); }, complete: () => { // wx.hideLoading() } }) }, tips: function(tips, icon = 'none', duration = 2000) { wx.showToast({ title: tips, icon, duration, }) }, justpage: function(url) { wx.navigateTo({ url: url }) }, getOrderList: function(data, successcallback, errorcallbak) { if (data) { data.sourceTag = "small"; } this.ajax("serviceOrder/selectServiceOrders", "POST", data, null, successcallback, errorcallbak) }, getEventData: function(e) { return e.currentTarget.dataset; }, getDict: function(jgxh, success) { this.ajax("dict/detail", "GET", { zdbh: jgxh }, null, function(res) { success && success(res) }) }, chooseImage: function(type, callback) { const sourceType = this.globalData.disablePhoto && type == 1 ? ['camera'] : ['camera', 'album'] wx.chooseImage({ count: 1, sizeType: ['original', 'compressed'], sourceType: sourceType, success(res) { callback && callback(res.tempFilePaths) } }) }, chooseImage2: function(count, type, callback) { const sourceType = this.globalData.disablePhoto && type == 1 ? ['camera'] : ['camera', 'album'] wx.chooseImage({ count: count, sizeType: ['original', 'compressed'], sourceType: sourceType, success(res) { callback && callback(res.tempFilePaths) } }) }, chooseVideo: function(callback) { const sourceType = this.globalData.disablePhoto ? ['camera'] : ['camera', 'album'] wx.chooseVideo({ sourceType: ['camera', 'album'], success(res) { callback && callback(res) } }) }, uploadFile: function(filePath, uploadType, fileType, successcallback, errorcallbak) { this.ajax("serviceOrder/uploadFile2Small", "POST", { uploadFiles: filePath, fileJson: JSON.stringify({ uploadType: uploadType, fileType: fileType }) }, null, successcallback, errorcallbak) }, // 获取省市区 getAdmin(regionId) { let that = this return new Promise((resolve, reject) => { this.ajax("region/selectRegionByRegionId", 'GET', { regionId }, '', function(res) { resolve(res) }, err => { that.tips(err.msg); }) }) }, // 获取服务中心 getServiceCenterList(params) { let that = this return new Promise((resolve, reject) => { this.ajax("organization/queryByOrg", 'POST', params, '', res => { resolve(res) }, err => { that.tips(err.msg); }) }) }, // 获取验证码 getCode(mobile) { let that = this return new Promise((resolve, reject) => { this.ajax("volunteer/getMsgCode", 'POST', { mobile }, '', res => { resolve(res) }, err => { that.tips(err.msg); resolve(err) }) }) }, // 获取字典代码 getZddm() { let that = this return new Promise((resolve, reject) => { this.ajax("dict/detail/user", 'GET', null, '', function(res) { resolve(res) }, function(err) { that.tips(err.message); }) }); }, // 上传图片 uploadImageFile(url, filePath, name = 'file') { return new Promise((resolve, reject) => { wx.uploadFile({ url: `${apiPath}${url}`, header: { 'content-type': 'multipart/form-data' }, filePath, name, success(res) { resolve(res) }, fail(err) { reject(err) } }) }) }, })