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