v1.2.33: 修复未登录时News页面崩溃问题
This commit is contained in:
parent
bfa92b307b
commit
2878a0ca35
|
|
@ -1,14 +1,25 @@
|
|||
import React, { useState, useEffect } from 'react'
|
||||
// 本地获取用户手机号
|
||||
|
||||
// 本地获取用户手机号 - 添加异常处理
|
||||
const getUserPhone = () => {
|
||||
try {
|
||||
const user = JSON.parse(localStorage.getItem('user') || '{}')
|
||||
console.log('getUserPhone user:', user)
|
||||
// Try multiple possible field names
|
||||
const userStr = localStorage.getItem('user')
|
||||
if (!userStr) return ''
|
||||
const user = JSON.parse(userStr)
|
||||
return user.phone || user.phoneNumber || user.mobile || user.tel || ''
|
||||
} catch { return '' }
|
||||
}
|
||||
|
||||
// 本地获取用户ID - 添加异常处理
|
||||
const getStoredUserId = () => {
|
||||
try {
|
||||
const userStr = localStorage.getItem('user')
|
||||
if (!userStr) return null
|
||||
const user = JSON.parse(userStr)
|
||||
return user.id || user.user_id || user.f99_90_id || null
|
||||
} catch { return null }
|
||||
}
|
||||
|
||||
// 资讯页面 - 展示寻配号和行情信息(所有人可见)
|
||||
export default function News() {
|
||||
const [activeTab, setActiveTab] = useState(localStorage.getItem('news_activeTab') || 'seek')
|
||||
|
|
@ -205,13 +216,7 @@ export default function News() {
|
|||
}
|
||||
|
||||
// 获取当前用户ID
|
||||
const getUserId = () => {
|
||||
try {
|
||||
const user = JSON.parse(localStorage.getItem('user') || '{}')
|
||||
return user.id || user.user_id || user.f99_90_id || null
|
||||
} catch { return null }
|
||||
}
|
||||
const currentUserId = getUserId()
|
||||
const currentUserId = getStoredUserId()
|
||||
|
||||
// 获取我的寻号列表
|
||||
const [mySeekList, setMySeekList] = useState([])
|
||||
|
|
|
|||
Loading…
Reference in New Issue