//app.js var JMessage = require('./libs/jmessage-wxapplet-sdk-1.4.2.min.js') App({ onLaunch: function () { // 展示本地存储能力 let _this = this; let logs = wx.getStorageSync('logs') || [] const updateManager = wx.getUpdateManager() updateManager.onCheckForUpdate(function (res) { // 请求完新版本信息的回调 if (res.hasUpdate) { updateManager.onUpdateReady(function () { wx.showModal({ title: '更新提示', content: '新版本已经准备好,是否重启应用?', success(res) { if (res.confirm) { // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启 updateManager.applyUpdate() } } }) }) }; }) logs.unshift(Date.now()); wx.setStorageSync('logs', logs); wx.login({ success: loginCode => { wx.setStorageSync('key', { 'code': loginCode.code }); wx.request({ url: _this.globalData.prodUrl + 'web-sso/get_open_id', data: { code: loginCode.code }, success: function (data) { _this.globalData.requestStatus = true; wx.setStorageSync('key', { 'openid': data.data.data.openid, 'ydw_token': data.data.ydw_token, 'persionid': data.data.persion.kid}); wx.setStorageSync('persion', { 'persion': data.data.persion }); // 去支付提醒 _this.payRemind(); if(data.data.is_first) { _this.globalData.is_first = true; }; if(data.data.red_pack_msg.length>0) { _this.globalData.red_pack_msg = data.data.red_pack_msg.length } } }) // 发送 res.code 到后台换取 openId, sessionKey, unionId } }) //获取openID // _this.getLogs(_this); // 获取用户信息 // wx.getSetting({ // success: res => { // if (res.authSetting['scope.userInfo']) { // // 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框 // wx.getUserInfo({ // success: res => { // // 可以将 res 发送给后台解码出 unionId // this.globalData.userInfo = res.userInfo // console.log(this.globalData.userInfo) // // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回 // // 所以此处加入 callback 以防止这种情况 // if (this.userInfoReadyCallback) { // this.userInfoReadyCallback(res) // } // } // }) // } // } // }); }, globalData: { userInfo: null, requestStatus: false, prodUrl: 'https://www.eqbidding.com/', is_first: false, awardsConfig: {}, red_pack_msg:0 }, getLogs: function (obj) { return new Promise((resolve, reject) => { let _this = obj; wx.login({ success: loginCode => { wx.setStorageSync('key', { 'code': loginCode.code }); wx.request({ url: _this.globalData.prodUrl + 'web-sso/get_open_id', data: { code: loginCode.code }, success: function (data) { _this.globalData.requestStatus = true; wx.setStorageSync('key', { 'openid': data.data.data.openid, 'ydw_token': data.data.ydw_token }); wx.setStorageSync('persion', { 'persion': data.data.persion }); resolve(); if (data.data.is_first) { _this.globalData.is_first = true; }; if (data.data.red_pack_msg.length > 0) { _this.globalData.red_pack_msg = data.data.red_pack_msg.length }; }, fail: reject }) } }) }) }, payRemind : function () { let _this = this; wx.request({ url: _this.globalData.prodUrl + 'web-pm/wx/pm/wait_pay_money', header: { 'ydw-token': wx.getStorageSync('key').ydw_token }, success: function (data) { if (data.data.status!=500){ if (data.data.data.length > 0) { wx.showModal({ title: '温馨提示', content: '您有' + data.data.data.length + '件商品未付款', confirmText: '去支付', showCancel: false, success(res) { if (res.confirm) { wx.navigateTo({ url: '/pages/mine/wxml/beingphotographed/beingphotographed' }) } } }) } } }, }); }, update: function (userinfo) { var _this = this; wx.request({ url: _this.globalData.prodUrl + 'web-pm/wx/pm/update_userinfo', data: { userinfo }, header: { 'ydw-token': wx.getStorageSync('key').ydw_token }, method: 'GET', dataType: 'json', responseType: 'text', success: function (data) { wx.setStorageSync('persion', { 'persion': data.data.persion }); _this.globalData.userInfo = true }, fail: function (res) { } }) }, smalltoBIG(n){ var fraction = ['角', '分']; var digit = ['零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖']; var unit = [['元', '万', '亿'], ['', '拾', '佰', '仟']]; var head = n < 0 ? '欠' : ''; n = Math.abs(n); var s = ''; for(var i = 0; i 0; i++) { var p = ''; for (var j = 0; j < unit[1].length && n > 0; j++) { p = digit[n % 10] + unit[1][j] + p; n = Math.floor(n / 10); } s = p.replace(/(零.)*零$/, '').replace(/^$/, '零') + unit[0][i] + s; } return head + s.replace(/(零.)*零元/, '元').replace(/(零.)+/g, '零').replace(/^整$/, '零元整'); } })