You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

216 lines
6.5 KiB

var WXAPI = require('./utils/server.js');
2 years ago
var util = require('./utils/util.js');
App({
d: {
appId: "", // 小程序appid
appKey: "", // 小程序密钥
purchase: 0, //设置购物车刷新
indexchase: false, //设置首页刷新
frontColor: '#ffffff',
one: false,
bf_color: '#FF6347',
h_color: '#FF63477',
order: {},
ceshiUrl: util.getUrl(),
2 years ago
titlee: '',
bgcolor: '',
},
onLaunch: function (options) {
//调用API从本地缓存中获取数据
var logs = wx.getStorageSync('logs') || []
logs.unshift(Date.now())
wx.setStorageSync('logs', logs);
// wx.login({
// success: function (res) {
// console.log(res.code)
// }
// });
//计算导航栏高度
const { statusBarHeight, platform } = wx.getSystemInfoSync()
const { top, height } = wx.getMenuButtonBoundingClientRect()
// 状态栏高度
wx.setStorageSync('statusBarHeight', statusBarHeight)
// 胶囊按钮高度 一般是32 如果获取不到就使用32
wx.setStorageSync('menuBtnHeight', height ? height : 32)
// 判断胶囊按钮信息是否成功获取
if (top && top !== 0 && height && height !== 0) {
//获取成功进行计算
const navBarHeight = (top - statusBarHeight) * 2 + height
// 导航栏高度
wx.setStorageSync('navBarHeight', navBarHeight)
} else {
//获取失败使用默认的高度
wx.setStorageSync(
'navBarHeight', platform === 'android' ? 48 : 40
)
}
2 years ago
},
//控制授权登入
2 years ago
// isLogin: function (page) {
// if (this.globalData.userInfo.openid == '' || !this.globalData.userInfo.openid) {
2 years ago
2 years ago
// if (page) {
// return true
// } else {
// wx.navigateTo({
// // url: 'pages/login/login'
// })
// }
// } else {
// console.log(this.globalData.userInfo)
// }
// },
2 years ago
onShow: function (options) {
var referee_openid = options.query.userid ? options.query.userid : '';
this.globalData.referee_openid = referee_openid;
},
onPullDownRefresh: function () {
wx.showNavigationBarLoading() //在标题栏中显示加载
wx.hideNavigationBarLoading() //完成停止加载
wx.stopPullDownRefresh() //停止下拉刷新
},
getUserInfo: function (cb, stype, uesr, callback) {
var that = this;
if (this.d.one) {
this.d.one = false;
that.getUserInfo(cb, stype);
} else {
this.d.one = true;
//调用登录接口 已更新登入接口
wx.login({
success: function (res) {
var code = res.code;
that.globalData.code = res.code;
that.getUserSessionKey(code, cb, uesr, callback);
}
});
}
//添加控制在同一秒执行同一个方法两次
},
getHomeData: function () {
var that = this;
wx.login({
success: function (res) {
that.globalData.code = res.code;
var userinfo = wx.getStorageSync('userInfo');
if (userinfo.nickName) {
that.globalData.userInfo = userinfo;
}
}
});
},
// 获取用户会话密钥
getUserSessionKey: function (code, cb, stype, callback) {
var that = this;
WXAPI.appIndex({
code: code,
nickName: stype.nickName,
avatarUrl: stype.avatarUrl,
gender: stype.gender,
referee_openid: this.globalData.userInfo.referee_openid || ''
}).then(res => {
2 years ago
if (res.code == 200) {
var data = res;
2 years ago
if (data.status == 0) {
wx.showToast({
title: res.err,
2 years ago
duration: 2000
});
return false;
}
that.d.ceshiUrl = that.d.ceshiUrl + '&token=' + data.access_token; // 线上密钥
that.d.localhost = that.d.localhost + '&token=' + data.access_token; // 本地密钥
that.globalData.userInfo['plug_ins'] = data.plug_ins; // 插件状态
that.globalData.userInfo['coupon'] = data.coupon; // 优惠券状态
that.globalData.userInfo['wallet'] = data.wallet; // 钱包状态
that.globalData.userInfo['sign'] = data.sign; // 签到状态
that.globalData.userInfo['sign_status'] = data.sign_status; // 是否签名
that.globalData.userInfo['sign_image'] = data.sign_image; // 签到图片
that.globalData.userInfo['user_id'] = data.user_id; // user_id
that.globalData.userInfo['nickName'] = data.nickName;
that.globalData.userInfo['avatarUrl'] = data.avatarUrl; //头像
that.globalData.userInfo['session_key'] = data.user.session_key;
that.globalData.userInfo['openid'] = data.user.openid;
that.globalData.userInfo['nickName'] = data.user.nickName;
that.globalData.userInfo['gender'] = data.user.gender;
that.globalData.userInfo['company'] = data.user.company;
that.globalData.userInfo['bgcolor'] = data.user.bgcolor;
2 years ago
//修改缓存写入
wx.setStorageSync('userInfo', that.globalData.userInfo);
callback()
}
else {
2 years ago
that.showToast(res.message);
}
2 years ago
});
},
getOrBindTelPhone: function (returnUrl) {
var user = this.globalData.userInfo;
if (!user.tel) {
wx.navigateTo({
url: 'pages/binding/binding'
});
}
},
globalData: {
userInfo: {},
2 years ago
isLogin: false,
accessId: wx.getStorageSync('accessId'),
2 years ago
},
redirect: function (url, param) {
wx.navigateTo({
url: '/pages/' + url + '?' + param
})
},
showModal: function (that) {
var animation = wx.createAnimation({
duration: 200
})
animation.opacity(0).rotateX(-100).step();
that.setData({
animationData: animation.export()
})
setTimeout(function () {
animation.opacity(1).rotateX(0).step();
that.setData({
animationData: animation
});
}.bind(that), 200)
},
showToast: function (that, title) {
var toast = {};
toast.toastTitle = title;
that.setData({
toast: toast
})
var animation = wx.createAnimation({
duration: 100
})
animation.opacity(0).rotateY(-100).step();
toast.toastStatus = true;
toast.toastAnimationData = animation.export()
that.setData({
toast: toast
})
setTimeout(function () {
animation.opacity(1).rotateY(0).step();
toast.toastAnimationData = animation
that.setData({
toast: toast
});
}.bind(that), 100)
// 定时器关闭
setTimeout(function () {
toast.toastStatus = false
that.setData({
toast: toast
});
}.bind(that), 2000);
}
});