From 6e85904598d152ac81ee8d19cb452d0a31564343 Mon Sep 17 00:00:00 2001 From: qiaomu <3520484422@qq.com> Date: Thu, 1 Aug 2024 20:17:28 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E9=A6=96=E9=A1=B5=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.json | 2 +- pages/home/index.js | 21 ++++++++++++++++++++- pages/login/index.js | 23 ++++++++++++++++------- utils/request.js | 13 +++++++------ 4 files changed, 44 insertions(+), 15 deletions(-) diff --git a/app.json b/app.json index 8958dc7..7d87324 100644 --- a/app.json +++ b/app.json @@ -1,7 +1,7 @@ { "pages": [ - "pages/login/index", "pages/home/index", + "pages/login/index", "pages/billList/index", "pages/rechargeRecord/index", "pages/invoiceList/index", diff --git a/pages/home/index.js b/pages/home/index.js index 2f41b43..f67c92f 100644 --- a/pages/home/index.js +++ b/pages/home/index.js @@ -159,6 +159,11 @@ Page({ this.setData({ rechargeVisible: true }) }, jumpToInvoice() { + const { user, } = this.data; + if (!user || !user.id) { + alertInfo("请先登录") + return + } wx.navigateTo({ url: '/pages/invoiceList/index', }) @@ -172,7 +177,6 @@ Page({ * 生命周期函数--监听页面显示 */ onShow() { - this.getAllList(); this.watchTenement(); this.watchPark(); @@ -251,6 +255,11 @@ Page({ // } }, jumpToElectric() { + const { user, } = this.data; + if (!user || !user.id) { + alertInfo("请先登录") + return + } wx.navigateTo({ url: '/childPackage/pages/electricQuery/index', }) @@ -308,11 +317,21 @@ Page({ }) }, jumpToRecord() { + const { user, } = this.data; + if (!user || !user.id) { + alertInfo("请先登录") + return + } wx.navigateTo({ url: '/pages/rechargeRecord/index', }) }, jumpToOrder() { + const { user, } = this.data; + if (!user || !user.id) { + alertInfo("请先登录") + return + } // alertInfo("尚未完成") wx.navigateTo({ url: '/pages/billList/index', diff --git a/pages/login/index.js b/pages/login/index.js index 5b9bd06..b0c1dcb 100644 --- a/pages/login/index.js +++ b/pages/login/index.js @@ -1,6 +1,7 @@ import { getPrivaciList, login } from "../../service/user"; import { alertError, alertInfo, alertSuccess, loadingFunc, wxLogin } from "../../utils/index"; import request from "../../utils/request"; +import { getUserInfo } from "../../service/user" import Dialog from '@vant/weapp/dialog/dialog'; const { OK } = request; @@ -20,21 +21,29 @@ Page({ /** * 生命周期函数--监听页面加载 */ - onLoad() { - this.getPrivacy(); - const user = wx.getStorageSync('user') - if (!user || !user.id) { + async setUser() { + const result = await getUserInfo(); + if (result.code !== OK) { return; } + + this.setData({ user: result.data }) + wx.setStorageSync('user', result.data) + // const user = wx.getStorageSync('user') + // this.setData({ user: user }) + }, + onLoad() { + this.getPrivacy(); + this.setUser(); // if (user.status === 0 || user.status === 2) { // wx.redirectTo({ // url: '/pages/waitApprove/index', // }) // return // } - wx.switchTab({ - url: '/pages/home/index', - }) + // wx.switchTab({ + // url: '/pages/home/index', + // }) }, async getPrivacy() { diff --git a/utils/request.js b/utils/request.js index 13ce795..ff4d5fb 100644 --- a/utils/request.js +++ b/utils/request.js @@ -82,26 +82,27 @@ const parseResponse = function (response, url) { alertError("服务异常") return } - const { statusCode } = response; - console.log('url', url, 'response.status', statusCode, 'response.data', response.data) - if (statusCode === 401) { + // const { statusCode } = response; + const { code } = response?.data || {}; + console.log('url', url,'code', code, 'response.data', response.data) + if (code === 401) { wx.redirectTo({ url: '/pages/login/index', }) wx.clearStorageSync() return { code: 401, message: '未登录状态' } } - if (statusCode === 403) { + if (code === 403) { return { code: 403, message: "非法访问" } } - if (statusCode === 404) { + if (code === 404) { wx.redirectTo({ url: '/pages/login/index', }) wx.clearStorageSync() return { code: 404, message: "服务故障" } } - if (500 <= statusCode && statusCode < 600) { + if (500 <= code && code < 600) { return { code: 500, message: "服务错误" } } return response.data;