123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199 |
- //app.js
- import md5 from 'utils/md5.js';
- App({
- globalData: {
- isFullSucreen: false, // 当前设备是否为 FullSucreen
- key: '12345678901234567890abcdefghijkl',
- openid: null,
- userInfo: null,
- usertype: 1,
- nickName: null,
- userphone: null,
- introducer: '',
- xu_content_date: '',
- xu_content_type: '',
- payurl: 'https://test.yueguanjia.com/jielin-web/pay/third/prepay/approve',
- url: 'https://api.zhumi.tech/mili_admin'
- // url: 'https://www.e-jinying.com/jy-ty-1'//正式
- },
- onLaunch: function() {
- this.checkFullSucreen();
- var logs = wx.getStorageSync('logs') || [];
- logs.unshift(Date.now());
- wx.setStorageSync('logs', logs);
- // 获取今日日期
- let date = new Date();
- let year = date.getFullYear().toString().padStart(2, '0');
- let month = (date.getMonth() + 1).toString().padStart(2, '0');
- let day = date.getDate().toString().padStart(2, '0');
- let time = year + "-" + month + "-" + day;
- wx.setStorageSync('todayDate', time);
- wx.getSystemInfo({
- success: res => {
- //导航高度
- this.globalData.navHeight = res.statusBarHeight + 46;
- },
- fail(err) {
- console.log(err);
- }
- })
- },
- timeOut: function() {
- wx.showToast({
- title: '网络开小差啦,请稍后尝试......',
- icon: 'none',
- duration: 1500
- })
- },
- //检查是否仍有登陆session
- checkSession: function(data) {
- const _this = this;
- return new Promise(function(resolve, reject) {
- wx.checkSession({
- success(res) {
- //session_key 未过期,并且在本生命周期一直有效
- _this.setUserInfo().then(() => {
- resolve()
- });
- },
- fail(res) {
- wx.setStorageSync('resofOpenid', {});
- wx.setStorageSync('PHONE', '');
- // session_key 已经失效,需要重新执行登录流程
- //重新登录
- let Url = '/pages/login/login'
- if (data) {
- Url = '/pages/login/login?fromwhere=' + data.fromwhere
- }
- wx.navigateTo({
- url: Url
- })
- }
- })
- })
- },
- //检查是否授权
- ifAuthorization: function() {
- var phone = wx.getStorageSync('PHONE');
- if (phone) {
- this.globalData.userphone = phone;
- } else {
- wx.navigateTo({
- url: '/pages/getphone/getphone'
- })
- }
- },
- //给用户信息赋值
- setUserInfo: function() {
- const _this = this;
- return new Promise((resolve, reject) => {
- var resofOpenid = wx.getStorageSync('resofOpenid');
- _this.globalData.openid = resofOpenid.openid;
- if(resofOpenid.phone){
- _this.globalData.userphone = resofOpenid.phone;
- wx.setStorageSync('PHONE', resofOpenid.phone);
- }
- // if (resofOpenid.type == 2) {
- wx.getSetting({
- success: resofGetSetting => {
- if (resofGetSetting.authSetting['scope.userInfo']) { //同意
- wx.getUserInfo({ //获取用户信息,不包括手机号
- success: res => {
- _this.globalData.userInfo = res.userInfo;
- _this.globalData.usertype = 2;
- wx.request({
- url: _this.globalData.url + '/updateWXUser',
- method: 'post',
- header: {
- "Content-Type": "application/x-www-form-urlencoded",
- "Accept": "application/json"
- },
- data: {
- xu_openid: resofOpenid.openid,
- xu_isauthorize: 1,
- xu_name: res.userInfo.nickName,
- xu_avatarUrl: res.userInfo.avatarUrl,
- xu_city: res.userInfo.city,
- xu_gender: res.userInfo.gender,
- xu_country: res.userInfo.country,
- xu_language: res.userInfo.language,
- xu_province: res.userInfo.province,
- xu_sessionkey: resofOpenid.session_key
- },
- success: function(res) {
- resolve();
- },
- fail: function(error) {
- app.timeOut()
- reject(error,2333333333333333); //请求失败
- },
- })
- // })
- return true;
- },
- fail(err) {
- app.timeOut();
- }
- })
- } else {
- app.globalData.usertype = 1;
- app.globalData.nickName = resofOpenid.nickName;
- app.globalData.userphone = resofOpenid.phone;
- return false;
- }
- },
- fail(err) {
- app.timeOut()
- }
- })
- // } else {
- // _this.globalData.usertype = 1;
- // _this.globalData.nickName = resofOpenid.nickName;
- // return false;
- // }
- })
- },
- gopage: function(target) {
- var pages = getCurrentPages()
- var back = 0;
- if (pages.length >= 10) {
- wx.redirectTo({
- url: target
- });
- } else {
- for (var i = 0; i < pages.length; i++) {
- pages[i].route == target
- if (pages[i].route == target.substr(1, target.length)) {
- back = i + 1
- break;
- }
- }
- }
- if (back == 0) {
- wx.navigateTo({
- url: target
- });
- } else {
- wx.navigateBack({
- delta: pages.length - back
- });
- }
- },
- checkFullSucreen: function() {
- // const self = this;
- let result = false;
- wx.getSystemInfo({
- success: function(res) {
- const rate = res.windowHeight / res.windowWidth;
- let limit = res.windowHeight == res.screenHeight ? 1.8 : 1.65; // 临界判断值
- if (rate > limit) {
- result = true;
- }
- wx.setStorageSync('isFullscreen', result)
- }
- })
- return result;
- }
- })
|