feat 首页不登陆
This commit is contained in:
4
.trae/rules/project_rules.md
Normal file
4
.trae/rules/project_rules.md
Normal file
@@ -0,0 +1,4 @@
|
||||
1. 本项目是用Uni APP构建的
|
||||
2. 务必保证代码可维护性,做好模块划分
|
||||
3. 不要过度理解需求,尽量保持需求的简单性
|
||||
4. 保持最小修改,不要大刀阔斧的改动代码
|
||||
12
pages.json
12
pages.json
@@ -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": {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -67,6 +67,7 @@ export default {
|
||||
success: (res) => {
|
||||
if (res.confirm) {
|
||||
storage.removeToken()
|
||||
storage.removeRefreshToken()
|
||||
storage.removeUserInfo()
|
||||
storage.removeQuestion()
|
||||
storage.clearAnsweredQuestions()
|
||||
|
||||
18
utils/api.js
18
utils/api.js
@@ -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,6 +107,7 @@ const request = (options) => {
|
||||
storage.removeRefreshToken()
|
||||
storage.removeUserInfo()
|
||||
|
||||
if (!noAuthModal) {
|
||||
uni.showModal({
|
||||
title: '登录过期',
|
||||
content: '请重新登录',
|
||||
@@ -116,6 +118,13 @@ const request = (options) => {
|
||||
})
|
||||
}
|
||||
})
|
||||
} 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)
|
||||
if (!noAuthModal) {
|
||||
uni.showModal({
|
||||
title: '请求失败',
|
||||
content: data.message || '服务器返回错误',
|
||||
showCancel: false
|
||||
})
|
||||
}
|
||||
reject(data)
|
||||
}
|
||||
} else {
|
||||
console.error('=== HTTP错误 ===')
|
||||
console.error('StatusCode:', statusCode)
|
||||
console.error('Response:', data)
|
||||
if (!noAuthModal) {
|
||||
uni.showModal({
|
||||
title: '网络错误',
|
||||
content: `状态码: ${statusCode}`,
|
||||
showCancel: false
|
||||
})
|
||||
}
|
||||
reject(res)
|
||||
}
|
||||
},
|
||||
@@ -161,11 +174,13 @@ const request = (options) => {
|
||||
}
|
||||
}
|
||||
|
||||
if (!noAuthModal) {
|
||||
uni.showModal({
|
||||
title: '错误',
|
||||
content: errorMsg,
|
||||
showCancel: false
|
||||
})
|
||||
}
|
||||
reject(err)
|
||||
}
|
||||
})
|
||||
@@ -216,7 +231,8 @@ const api = {
|
||||
data: {
|
||||
page,
|
||||
page_size: pageSize
|
||||
}
|
||||
},
|
||||
noAuthModal: true
|
||||
})
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user