123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- const app = getApp()
- Page({
- data: {
- frameStyle: { useTop: true, name: '系统', leftArrow: false, useBar: false },
- },
- toCommon: function (e) {
- const { route } = e.currentTarget.dataset;
- if (route) wx.navigateTo({ url: `/pages/${route}` });
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) { },
- // 监听用户是否登录
- watchLogin: async function () {
- // 监听用户是否登录,
- wx.getStorage({
- key: 'user',
- success: async res => {
- if (res.data) wx.redirectTo({ url: '/pages/school/index' })
- },
- fail: async res => {
- wx.login({
- success: async (arr) => {
- if (app.globalData?.wxInfo?.openid) { await this.toLogin(app.globalData?.wxInfo?.openid); return; }
- const { code: js_code } = arr;
- const aee = await app.$get('/wechat/api/login/app', { js_code: js_code, config: 'newCourtApp' });
- if (aee.errcode === 0 && aee.data?.openid) {
- const openid = aee.data.openid;
- app.globalData.wxInfo = { openid };
- await this.toLogin(openid);
- } else {
- wx.showToast({ title: `${aee.errmsg}`, icon: 'fail', duration: 2000 });
- wx.redirectTo({ url: '/pages/register/index' });
- }
- },
- });
- }
- })
- },
- async toLogin(openid) {
- const res = await app.$post('/newCourt/api/user/wxAppLogin', { openid });
- if (app.$checkRes(res)) {
- const { data } = res;
- // 没有用户,去注册
- if (!data) wx.redirectTo({ url: '/pages/register/index' });
- // 有用户,存起来,跳转
- else { wx.setStorageSync('user', data); wx.redirectTo({ url: '/pages/school/index' }); }
- }
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- const that = this;
- // 监听用户是否登录
- that.watchLogin();
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- }
- })
|