拉取代码

This commit is contained in:
qiaomu 2024-08-02 16:44:18 +08:00
commit 5147843266
3 changed files with 40 additions and 12 deletions

View File

@ -159,6 +159,11 @@ Page({
this.setData({ rechargeVisible: true }) this.setData({ rechargeVisible: true })
}, },
jumpToInvoice() { jumpToInvoice() {
const { user, } = this.data;
if (!user || !user.id) {
alertInfo("请先登录")
return
}
wx.navigateTo({ wx.navigateTo({
url: '/pages/invoiceList/index', url: '/pages/invoiceList/index',
}) })
@ -172,7 +177,6 @@ Page({
* 生命周期函数--监听页面显示 * 生命周期函数--监听页面显示
*/ */
onShow() { onShow() {
this.getAllList(); this.getAllList();
this.watchTenement(); this.watchTenement();
this.watchPark(); this.watchPark();
@ -251,6 +255,11 @@ Page({
// } // }
}, },
jumpToElectric() { jumpToElectric() {
const { user, } = this.data;
if (!user || !user.id) {
alertInfo("请先登录")
return
}
wx.navigateTo({ wx.navigateTo({
url: '/childPackage/pages/electricQuery/index', url: '/childPackage/pages/electricQuery/index',
}) })
@ -308,11 +317,21 @@ Page({
}) })
}, },
jumpToRecord() { jumpToRecord() {
const { user, } = this.data;
if (!user || !user.id) {
alertInfo("请先登录")
return
}
wx.navigateTo({ wx.navigateTo({
url: '/pages/rechargeRecord/index', url: '/pages/rechargeRecord/index',
}) })
}, },
jumpToOrder() { jumpToOrder() {
const { user, } = this.data;
if (!user || !user.id) {
alertInfo("请先登录")
return
}
// alertInfo("尚未完成") // alertInfo("尚未完成")
wx.navigateTo({ wx.navigateTo({
url: '/pages/billList/index', url: '/pages/billList/index',

View File

@ -1,6 +1,7 @@
import { getPrivaciList, login } from "../../service/user"; import { getPrivaciList, login } from "../../service/user";
import { alertError, alertInfo, alertSuccess, loadingFunc, wxLogin } from "../../utils/index"; import { alertError, alertInfo, alertSuccess, loadingFunc, wxLogin } from "../../utils/index";
import request from "../../utils/request"; import request from "../../utils/request";
import { getUserInfo } from "../../service/user"
import Dialog from '@vant/weapp/dialog/dialog'; import Dialog from '@vant/weapp/dialog/dialog';
const { OK } = request; const { OK } = request;
@ -20,12 +21,20 @@ Page({
/** /**
* 生命周期函数--监听页面加载 * 生命周期函数--监听页面加载
*/ */
onLoad() { async setUser() {
this.getPrivacy(); const result = await getUserInfo();
const user = wx.getStorageSync('user') if (result.code !== OK) {
if (!user || !user.id) {
return; 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) { // if (user.status === 0 || user.status === 2) {
// wx.redirectTo({ // wx.redirectTo({
// url: '/pages/waitApprove/index', // url: '/pages/waitApprove/index',

View File

@ -82,10 +82,10 @@ const parseResponse = function (response, url) {
alertError("服务异常") alertError("服务异常")
return return
} }
// const { statusCode } = response;
const { statusCode } = response; const { code } = response?.data || {};
console.log('url', url, 'response.status', statusCode, 'response.data', response.data) console.log('url', url,'code', code, 'response.data', response.data)
if (statusCode === 401) { if (code === 401) {
const currentUrl = getPageUrl() const currentUrl = getPageUrl()
if (!['pages/home/index', 'pages/login/index'].includes(currentUrl)) { if (!['pages/home/index', 'pages/login/index'].includes(currentUrl)) {
wx.redirectTo({ wx.redirectTo({
@ -95,17 +95,17 @@ const parseResponse = function (response, url) {
wx.clearStorageSync() wx.clearStorageSync()
return { code: 401, message: '未登录状态' } return { code: 401, message: '未登录状态' }
} }
if (statusCode === 403) { if (code === 403) {
return { code: 403, message: "非法访问" } return { code: 403, message: "非法访问" }
} }
if (statusCode === 404) { if (code === 404) {
wx.redirectTo({ wx.redirectTo({
url: '/pages/login/index', url: '/pages/login/index',
}) })
wx.clearStorageSync() wx.clearStorageSync()
return { code: 404, message: "服务故障" } return { code: 404, message: "服务故障" }
} }
if (500 <= statusCode && statusCode < 600) { if (500 <= code && code < 600) {
return { code: 500, message: "服务错误" } return { code: 500, message: "服务错误" }
} }
return response.data; return response.data;