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": [
|
"pages": [
|
||||||
|
{
|
||||||
|
"path": "pages/gameplay/gameplay",
|
||||||
|
"style": {
|
||||||
|
"navigationBarTitleText": "玩法选择"
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"path": "pages/index/index",
|
"path": "pages/index/index",
|
||||||
"style": {
|
"style": {
|
||||||
@@ -19,12 +25,6 @@
|
|||||||
"navigationStyle": "custom"
|
"navigationStyle": "custom"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"path": "pages/gameplay/gameplay",
|
|
||||||
"style": {
|
|
||||||
"navigationBarTitleText": "玩法选择"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"path": "pages/random/random",
|
"path": "pages/random/random",
|
||||||
"style": {
|
"style": {
|
||||||
|
|||||||
@@ -13,7 +13,12 @@
|
|||||||
</view>
|
</view>
|
||||||
|
|
||||||
<view class="record-section">
|
<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 v-for="(record, index) in recordList" :key="index" class="record-item" @click="handleRecordClick(record)">
|
||||||
<view class="record-header">
|
<view class="record-header">
|
||||||
<view class="record-category">{{ record.category }}</view>
|
<view class="record-category">{{ record.category }}</view>
|
||||||
@@ -105,7 +110,8 @@ export default {
|
|||||||
isFirstLoad: true,
|
isFirstLoad: true,
|
||||||
showDetail: false,
|
showDetail: false,
|
||||||
detailQuestion: null,
|
detailQuestion: null,
|
||||||
detailLoading: false
|
detailLoading: false,
|
||||||
|
isNotLoggedIn: false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -168,6 +174,7 @@ export default {
|
|||||||
if (!isLoadMore) {
|
if (!isLoadMore) {
|
||||||
this.currentPage = 1
|
this.currentPage = 1
|
||||||
this.hasMore = true
|
this.hasMore = true
|
||||||
|
this.isNotLoggedIn = false
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.hasMore) return
|
if (!this.hasMore) return
|
||||||
@@ -198,6 +205,10 @@ export default {
|
|||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('获取答题记录失败:', error)
|
console.error('获取答题记录失败:', error)
|
||||||
|
// 检查是否是401错误
|
||||||
|
if (error.message && error.message.includes('401')) {
|
||||||
|
this.isNotLoggedIn = true
|
||||||
|
}
|
||||||
} finally {
|
} finally {
|
||||||
this.isLoading = false
|
this.isLoading = false
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,6 +67,7 @@ export default {
|
|||||||
success: (res) => {
|
success: (res) => {
|
||||||
if (res.confirm) {
|
if (res.confirm) {
|
||||||
storage.removeToken()
|
storage.removeToken()
|
||||||
|
storage.removeRefreshToken()
|
||||||
storage.removeUserInfo()
|
storage.removeUserInfo()
|
||||||
storage.removeQuestion()
|
storage.removeQuestion()
|
||||||
storage.clearAnsweredQuestions()
|
storage.clearAnsweredQuestions()
|
||||||
|
|||||||
68
utils/api.js
68
utils/api.js
@@ -22,6 +22,7 @@ const request = (options) => {
|
|||||||
console.log('Data:', options.data)
|
console.log('Data:', options.data)
|
||||||
|
|
||||||
const token = storage.getToken()
|
const token = storage.getToken()
|
||||||
|
const { noAuthModal = false } = options
|
||||||
|
|
||||||
uni.request({
|
uni.request({
|
||||||
url: fullUrl,
|
url: fullUrl,
|
||||||
@@ -106,16 +107,24 @@ const request = (options) => {
|
|||||||
storage.removeRefreshToken()
|
storage.removeRefreshToken()
|
||||||
storage.removeUserInfo()
|
storage.removeUserInfo()
|
||||||
|
|
||||||
uni.showModal({
|
if (!noAuthModal) {
|
||||||
title: '登录过期',
|
uni.showModal({
|
||||||
content: '请重新登录',
|
title: '登录过期',
|
||||||
showCancel: false,
|
content: '请重新登录',
|
||||||
success: () => {
|
showCancel: false,
|
||||||
uni.reLaunch({
|
success: () => {
|
||||||
url: '/pages/login/login'
|
uni.reLaunch({
|
||||||
})
|
url: '/pages/login/login'
|
||||||
}
|
})
|
||||||
})
|
}
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
// 不弹出窗口,直接返回错误
|
||||||
|
const error = new Error('401 Unauthorized')
|
||||||
|
error.statusCode = 401
|
||||||
|
reject(error)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
reject(refreshError)
|
reject(refreshError)
|
||||||
}
|
}
|
||||||
@@ -126,22 +135,26 @@ const request = (options) => {
|
|||||||
console.error('=== 业务错误 ===')
|
console.error('=== 业务错误 ===')
|
||||||
console.error('Code:', data.code)
|
console.error('Code:', data.code)
|
||||||
console.error('Message:', data.message)
|
console.error('Message:', data.message)
|
||||||
uni.showModal({
|
if (!noAuthModal) {
|
||||||
title: '请求失败',
|
uni.showModal({
|
||||||
content: data.message || '服务器返回错误',
|
title: '请求失败',
|
||||||
showCancel: false
|
content: data.message || '服务器返回错误',
|
||||||
})
|
showCancel: false
|
||||||
|
})
|
||||||
|
}
|
||||||
reject(data)
|
reject(data)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
console.error('=== HTTP错误 ===')
|
console.error('=== HTTP错误 ===')
|
||||||
console.error('StatusCode:', statusCode)
|
console.error('StatusCode:', statusCode)
|
||||||
console.error('Response:', data)
|
console.error('Response:', data)
|
||||||
uni.showModal({
|
if (!noAuthModal) {
|
||||||
title: '网络错误',
|
uni.showModal({
|
||||||
content: `状态码: ${statusCode}`,
|
title: '网络错误',
|
||||||
showCancel: false
|
content: `状态码: ${statusCode}`,
|
||||||
})
|
showCancel: false
|
||||||
|
})
|
||||||
|
}
|
||||||
reject(res)
|
reject(res)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -161,11 +174,13 @@ const request = (options) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uni.showModal({
|
if (!noAuthModal) {
|
||||||
title: '错误',
|
uni.showModal({
|
||||||
content: errorMsg,
|
title: '错误',
|
||||||
showCancel: false
|
content: errorMsg,
|
||||||
})
|
showCancel: false
|
||||||
|
})
|
||||||
|
}
|
||||||
reject(err)
|
reject(err)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -216,7 +231,8 @@ const api = {
|
|||||||
data: {
|
data: {
|
||||||
page,
|
page,
|
||||||
page_size: pageSize
|
page_size: pageSize
|
||||||
}
|
},
|
||||||
|
noAuthModal: true
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user