|
@@ -1,91 +1,92 @@
|
|
|
const app = getApp();
|
|
|
Page({
|
|
|
- data: {
|
|
|
- frameStyle: { useTop: true, name: '系统', leftArrow: false, useBar: false },
|
|
|
- },
|
|
|
- /**
|
|
|
- * 生命周期函数--监听页面加载
|
|
|
- */
|
|
|
- onLoad: function (options) {
|
|
|
- const that = this;
|
|
|
+ data: {
|
|
|
+ frameStyle: { useTop: false, name: '系统', leftArrow: false, useBar: false },
|
|
|
+ fileUrl: app.globalData.fileUrl,
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * 生命周期函数--监听页面加载
|
|
|
+ */
|
|
|
+ onLoad: function (options) {
|
|
|
+ const that = this;
|
|
|
+ // 监听用户是否登录
|
|
|
+ that.watchLogin();
|
|
|
+ },
|
|
|
// 监听用户是否登录
|
|
|
- that.watchLogin();
|
|
|
- },
|
|
|
- // 监听用户是否登录
|
|
|
- watchLogin: async function () {
|
|
|
- // 监听用户是否登录,
|
|
|
- wx.getStorage({
|
|
|
- key: 'user',
|
|
|
- success: async (res) => {
|
|
|
- if (res.data) wx.redirectTo({ url: '/pages/home/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: `${res.errMsg}`, icon: 'fail', duration: 2000 });
|
|
|
- wx.redirectTo({ url: '/pages/login/index' });
|
|
|
- }
|
|
|
- },
|
|
|
+ watchLogin: async function () {
|
|
|
+ // 监听用户是否登录,
|
|
|
+ wx.getStorage({
|
|
|
+ key: 'user',
|
|
|
+ success: async (res) => {
|
|
|
+ if (res.data) wx.redirectTo({ url: '/pages/home/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: `${res.errMsg}`, icon: 'fail', duration: 2000 });
|
|
|
+ wx.redirectTo({ url: '/pages/login/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/home/index' });
|
|
|
- }
|
|
|
- }
|
|
|
- },
|
|
|
- /**
|
|
|
- * 生命周期函数--监听页面初次渲染完成
|
|
|
- */
|
|
|
- onReady: function () {},
|
|
|
+ },
|
|
|
+ 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/home/index' });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * 生命周期函数--监听页面初次渲染完成
|
|
|
+ */
|
|
|
+ onReady: function () { },
|
|
|
|
|
|
- /**
|
|
|
- * 生命周期函数--监听页面显示
|
|
|
- */
|
|
|
- onShow: function () {},
|
|
|
+ /**
|
|
|
+ * 生命周期函数--监听页面显示
|
|
|
+ */
|
|
|
+ onShow: function () { },
|
|
|
|
|
|
- /**
|
|
|
- * 生命周期函数--监听页面隐藏
|
|
|
- */
|
|
|
- onHide: function () {},
|
|
|
+ /**
|
|
|
+ * 生命周期函数--监听页面隐藏
|
|
|
+ */
|
|
|
+ onHide: function () { },
|
|
|
|
|
|
- /**
|
|
|
- * 生命周期函数--监听页面卸载
|
|
|
- */
|
|
|
- onUnload: function () {},
|
|
|
+ /**
|
|
|
+ * 生命周期函数--监听页面卸载
|
|
|
+ */
|
|
|
+ onUnload: function () { },
|
|
|
|
|
|
- /**
|
|
|
- * 页面相关事件处理函数--监听用户下拉动作
|
|
|
- */
|
|
|
- onPullDownRefresh: function () {},
|
|
|
+ /**
|
|
|
+ * 页面相关事件处理函数--监听用户下拉动作
|
|
|
+ */
|
|
|
+ onPullDownRefresh: function () { },
|
|
|
|
|
|
- /**
|
|
|
- * 页面上拉触底事件的处理函数
|
|
|
- */
|
|
|
- onReachBottom: function () {},
|
|
|
+ /**
|
|
|
+ * 页面上拉触底事件的处理函数
|
|
|
+ */
|
|
|
+ onReachBottom: function () { },
|
|
|
|
|
|
- /**
|
|
|
- * 用户点击右上角分享
|
|
|
- */
|
|
|
- onShareAppMessage: function () {},
|
|
|
+ /**
|
|
|
+ * 用户点击右上角分享
|
|
|
+ */
|
|
|
+ onShareAppMessage: function () { },
|
|
|
});
|