feat 首页不登陆

This commit is contained in:
2026-01-26 10:26:06 +08:00
parent bbf8e6776d
commit a53bbc3319
5 changed files with 66 additions and 34 deletions

View File

@@ -0,0 +1,4 @@
1. 本项目是用Uni APP构建的
2. 务必保证代码可维护性,做好模块划分
3. 不要过度理解需求,尽量保持需求的简单性
4. 保持最小修改,不要大刀阔斧的改动代码

View File

@@ -1,5 +1,11 @@
{
"pages": [
{
"path": "pages/gameplay/gameplay",
"style": {
"navigationBarTitleText": "玩法选择"
}
},
{
"path": "pages/index/index",
"style": {
@@ -19,12 +25,6 @@
"navigationStyle": "custom"
}
},
{
"path": "pages/gameplay/gameplay",
"style": {
"navigationBarTitleText": "玩法选择"
}
},
{
"path": "pages/random/random",
"style": {

View File

@@ -13,7 +13,12 @@
</view>
<view class="record-section">
<view v-if="recordList.length > 0" class="record-list">
<view v-if="isNotLoggedIn" class="empty-record">
<text class="empty-icon">🔐</text>
<text class="empty-text">需要登录</text>
<text class="empty-hint">登录后才会记录答题记录</text>
</view>
<view v-else-if="recordList.length > 0" class="record-list">
<view v-for="(record, index) in recordList" :key="index" class="record-item" @click="handleRecordClick(record)">
<view class="record-header">
<view class="record-category">{{ record.category }}</view>
@@ -105,7 +110,8 @@ export default {
isFirstLoad: true,
showDetail: false,
detailQuestion: null,
detailLoading: false
detailLoading: false,
isNotLoggedIn: false
}
},
@@ -168,6 +174,7 @@ export default {
if (!isLoadMore) {
this.currentPage = 1
this.hasMore = true
this.isNotLoggedIn = false
}
if (!this.hasMore) return
@@ -198,6 +205,10 @@ export default {
}
} catch (error) {
console.error('获取答题记录失败:', error)
// 检查是否是401错误
if (error.message && error.message.includes('401')) {
this.isNotLoggedIn = true
}
} finally {
this.isLoading = false
}

View File

@@ -67,6 +67,7 @@ export default {
success: (res) => {
if (res.confirm) {
storage.removeToken()
storage.removeRefreshToken()
storage.removeUserInfo()
storage.removeQuestion()
storage.clearAnsweredQuestions()

View File

@@ -22,6 +22,7 @@ const request = (options) => {
console.log('Data:', options.data)
const token = storage.getToken()
const { noAuthModal = false } = options
uni.request({
url: fullUrl,
@@ -106,16 +107,24 @@ const request = (options) => {
storage.removeRefreshToken()
storage.removeUserInfo()
uni.showModal({
title: '登录过期',
content: '请重新登录',
showCancel: false,
success: () => {
uni.reLaunch({
url: '/pages/login/login'
})
}
})
if (!noAuthModal) {
uni.showModal({
title: '登录过期',
content: '请重新登录',
showCancel: false,
success: () => {
uni.reLaunch({
url: '/pages/login/login'
})
}
})
} else {
// 不弹出窗口,直接返回错误
const error = new Error('401 Unauthorized')
error.statusCode = 401
reject(error)
return
}
reject(refreshError)
}
@@ -126,22 +135,26 @@ const request = (options) => {
console.error('=== 业务错误 ===')
console.error('Code:', data.code)
console.error('Message:', data.message)
uni.showModal({
title: '请求失败',
content: data.message || '服务器返回错误',
showCancel: false
})
if (!noAuthModal) {
uni.showModal({
title: '请求失败',
content: data.message || '服务器返回错误',
showCancel: false
})
}
reject(data)
}
} else {
console.error('=== HTTP错误 ===')
console.error('StatusCode:', statusCode)
console.error('Response:', data)
uni.showModal({
title: '网络错误',
content: `状态码: ${statusCode}`,
showCancel: false
})
if (!noAuthModal) {
uni.showModal({
title: '网络错误',
content: `状态码: ${statusCode}`,
showCancel: false
})
}
reject(res)
}
},
@@ -161,11 +174,13 @@ const request = (options) => {
}
}
uni.showModal({
title: '错误',
content: errorMsg,
showCancel: false
})
if (!noAuthModal) {
uni.showModal({
title: '错误',
content: errorMsg,
showCancel: false
})
}
reject(err)
}
})
@@ -216,7 +231,8 @@ const api = {
data: {
page,
page_size: pageSize
}
},
noAuthModal: true
})
},