获取用户自己的设备列表,获取用户数据,获取是否是代理人,通过是否登录判别是否发送请求

This commit is contained in:
WindowBird 2025-09-01 11:51:30 +08:00
parent a013e0bf9e
commit 49eeab90e2
3 changed files with 17 additions and 7 deletions

View File

@ -171,7 +171,13 @@ export default {
// //
async fetchDeviceList() { async fetchDeviceList() {
try { try {
const token = uni.getStorageSync('token')
if (!token) {
console.log('暂无登录,不请求设备列表')
return
}
const response = await getDeviceList() const response = await getDeviceList()
if (response.code === 200 && response.data && Array.isArray(response.data)) { if (response.code === 200 && response.data && Array.isArray(response.data)) {
// //
const devices = response.data.map(device => { const devices = response.data.map(device => {

View File

@ -174,6 +174,11 @@ export default {
async fetchUserData() { async fetchUserData() {
this.loading = true this.loading = true
try { try {
const token = uni.getStorageSync('token')
if (!token) {
console.log('暂无登录,不请求用户数据')
return
}
// //
const [userInfoRes, financialRes, statsRes] = await Promise.allSettled([ const [userInfoRes, financialRes, statsRes] = await Promise.allSettled([
this.fetchUserInfo(), this.fetchUserInfo(),
@ -235,6 +240,11 @@ export default {
async getIsAgent() { async getIsAgent() {
try { try {
const token = uni.getStorageSync('token')
if (!token) {
console.log('暂无登录,不请求是否是代理人')
return
}
const response = await isAgent() const response = await isAgent()
this.isAgent = response.data this.isAgent = response.data
} catch (error) { } catch (error) {

View File

@ -139,13 +139,7 @@ function handleResponseError(res, reject, options = {}) {
const errorMap = { const errorMap = {
401: { 401: {
title: '登录已过期,请重新登录', title: '登录已过期,请重新登录',
action: () => { action: () => {},
setTimeout(() => {
uni.reLaunch({
url: '/pages/login/login',
})
}, 1500)
},
}, },
403: { 403: {
title: '权限不足', title: '权限不足',