更新项目配置,添加 terser 作为压缩工具,修改 Vite 配置以支持生产环境构建,调整 API 基础地址为实际域名,并优化登录页面和游戏页面的状态管理逻辑。
This commit is contained in:
@@ -2,8 +2,8 @@
|
||||
|
||||
// 链接地址生成规则
|
||||
export const LINK_CONFIG = {
|
||||
// 基础域名
|
||||
BASE_URL: 'http://localhost:5173',
|
||||
// 基础域名 - 生产环境需要修改为实际域名
|
||||
BASE_URL: import.meta.env.VITE_BASE_URL || window.location.origin,
|
||||
|
||||
// 游戏页面路径
|
||||
GAME_PATH: '/play',
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import axios from 'axios'
|
||||
import { getAccessToken, getRefreshToken, getTokenType, setTokens, clearTokens } from '../utils/auth'
|
||||
import { showErrorMessage } from '@/utils/error'
|
||||
import router from '@/router'
|
||||
|
||||
const baseURL = import.meta.env?.VITE_API_BASE || '/'
|
||||
|
||||
@@ -24,6 +25,11 @@ function onRefreshed(newToken, tokenType) {
|
||||
pendingQueue = []
|
||||
}
|
||||
|
||||
function onRefreshFailed() {
|
||||
pendingQueue.forEach((cb) => cb(null, null))
|
||||
pendingQueue = []
|
||||
}
|
||||
|
||||
// 请求拦截:附加 Authorization
|
||||
http.interceptors.request.use(
|
||||
(config) => {
|
||||
@@ -89,17 +95,31 @@ http.interceptors.response.use(
|
||||
} catch (e) {
|
||||
isRefreshing = false
|
||||
clearTokens()
|
||||
onRefreshFailed()
|
||||
// 跳转到登录页面,保存当前路径用于登录后重定向
|
||||
const currentPath = router.currentRoute.value.fullPath
|
||||
if (currentPath !== '/login') {
|
||||
router.replace({
|
||||
name: 'Login',
|
||||
query: { redirect: currentPath }
|
||||
})
|
||||
}
|
||||
return Promise.reject(error)
|
||||
}
|
||||
}
|
||||
|
||||
// 返回一个新的 Promise,等待刷新完成后重试原请求
|
||||
return new Promise((resolve) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
subscribeTokenRefresh((newToken, tokenType) => {
|
||||
const retryConfig = { ...config }
|
||||
retryConfig.headers = retryConfig.headers || {}
|
||||
retryConfig.headers.Authorization = `${tokenType || 'Bearer'} ${newToken}`
|
||||
resolve(http.request(retryConfig))
|
||||
if (newToken) {
|
||||
const retryConfig = { ...config }
|
||||
retryConfig.headers = retryConfig.headers || {}
|
||||
retryConfig.headers.Authorization = `${tokenType || 'Bearer'} ${newToken}`
|
||||
resolve(http.request(retryConfig))
|
||||
} else {
|
||||
// token刷新失败,拒绝请求
|
||||
reject(error)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
@@ -27,13 +27,7 @@
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
|
||||
<el-alert
|
||||
v-if="notice"
|
||||
:title="notice"
|
||||
type="info"
|
||||
show-icon
|
||||
class="notice"
|
||||
/>
|
||||
|
||||
</el-card>
|
||||
</div>
|
||||
</template>
|
||||
@@ -49,7 +43,6 @@ import { showErrorMessage, showSuccessMessage } from '@/utils/error'
|
||||
const formRef = ref()
|
||||
const loading = ref(false)
|
||||
const remember = ref(false)
|
||||
const notice = ref('')
|
||||
|
||||
const form = ref({
|
||||
username: 'admin',
|
||||
@@ -73,9 +66,6 @@ onMounted(() => {
|
||||
if (remember.value && savedUser) {
|
||||
form.value.username = savedUser
|
||||
}
|
||||
notice.value = import.meta?.env?.VITE_API_BASE
|
||||
? `当前 API: ${import.meta.env.VITE_API_BASE}`
|
||||
: '未配置 VITE_API_BASE,默认使用 /'
|
||||
})
|
||||
|
||||
function onForget() {
|
||||
@@ -151,5 +141,4 @@ async function onSubmit() {
|
||||
margin: -4px 0 8px;
|
||||
}
|
||||
.submit { width: 100%; }
|
||||
.notice { margin-top: 8px; }
|
||||
</style>
|
||||
|
||||
@@ -107,20 +107,20 @@
|
||||
|
||||
<!-- 游戏截图展示区域 -->
|
||||
<div class="image-gallery">
|
||||
<div class="image-item">
|
||||
<img src="http://36.138.184.60:12345/f1/首次主页.png" alt="首次主页" class="game-image" />
|
||||
<div class="image-item" v-if="state.assets?.homepageUrl">
|
||||
<img :src="state.assets.homepageUrl" alt="首次主页" class="game-image" />
|
||||
<div class="image-label">首次主页</div>
|
||||
</div>
|
||||
<div class="image-item">
|
||||
<img src="http://36.138.184.60:12345/f1/首次赏金.png" alt="首次赏金" class="game-image" style="transform: rotate(-90deg);" />
|
||||
<div class="image-item" v-if="state.assets?.firstRewardUrl">
|
||||
<img :src="state.assets.firstRewardUrl" alt="首次赏金" class="game-image" style="transform: rotate(-90deg);" />
|
||||
<div class="image-label">首次赏金</div>
|
||||
</div>
|
||||
<div class="image-item">
|
||||
<img src="http://36.138.184.60:12345/f1/中途赏金.png" alt="中途赏金" class="game-image" />
|
||||
<div class="image-item" v-if="state.assets?.midRewardUrl">
|
||||
<img :src="state.assets.midRewardUrl" alt="中途赏金" class="game-image" />
|
||||
<div class="image-label">中途赏金</div>
|
||||
</div>
|
||||
<div class="image-item">
|
||||
<img src="http://36.138.184.60:12345/f1/结束赏金.png" alt="结束赏金" class="game-image" />
|
||||
<div class="image-item" v-if="state.assets?.endRewardUrl">
|
||||
<img :src="state.assets.endRewardUrl" alt="结束赏金" class="game-image" />
|
||||
<div class="image-label">结束赏金</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -286,7 +286,17 @@ export default {
|
||||
|
||||
// 更新状态
|
||||
state.status = 'LOGGED_IN'
|
||||
state.assets = gameData.assets
|
||||
|
||||
// 构建assets对象,包含图片URL
|
||||
state.assets = {
|
||||
homepageUrl: gameData.homepageUrl,
|
||||
firstRewardUrl: gameData.firstRewardUrl,
|
||||
midRewardUrl: gameData.midRewardUrl,
|
||||
endRewardUrl: gameData.endRewardUrl,
|
||||
qrCodeUrl: gameData.qrCodeUrl,
|
||||
// 保留原有的assets数据(如果存在)
|
||||
...(gameData.assets || {})
|
||||
}
|
||||
|
||||
// 更新区域信息
|
||||
if (gameData.region) {
|
||||
|
||||
Reference in New Issue
Block a user