mirror of
https://github.com/setube/ogame-vue-ts.git
synced 2026-05-12 07:55:11 +08:00
feat: 重构战报弹窗与模拟器视图,优化UI与逻辑
重构BattleReportDialog和BattleSimulatorView相关静态资源,替换旧版JS/CSS文件,提升界面一致性和交互体验。新增和优化空状态、滚动区域等通用UI组件,移除部分冗余composable,完善多语言内容。引入导弹逻辑,补充版本检测工具,提升整体代码结构和可维护性。
This commit is contained in:
@@ -342,6 +342,7 @@ export const simulateBattle = (
|
||||
} else if (defenderUnits.length === 0) {
|
||||
winner = 'attacker'
|
||||
} else {
|
||||
// OGame原版规则:6回合后双方都有剩余单位时判定为平局
|
||||
winner = 'draw'
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
|
||||
/**
|
||||
* 格式化数字为英文单位(K, M, B, T, Q)
|
||||
* @param num 数字
|
||||
|
||||
57
src/utils/versionCheck.ts
Normal file
57
src/utils/versionCheck.ts
Normal file
@@ -0,0 +1,57 @@
|
||||
import pkg from '../../package.json'
|
||||
|
||||
export interface VersionInfo {
|
||||
version: string
|
||||
releaseNotes: string
|
||||
downloadUrl: string
|
||||
}
|
||||
|
||||
// 检查GitHub最新版本
|
||||
export const checkLatestVersion = async (lastCheckTime: number, updateCheckTime: (time: number) => void): Promise<VersionInfo | null> => {
|
||||
const now = Date.now()
|
||||
const fiveMinutes = 5 * 60 * 1000 // 5分钟
|
||||
|
||||
// 如果距离上次检查不到5分钟,跳过
|
||||
if (now - lastCheckTime < fiveMinutes) {
|
||||
return null
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch(`https://api.github.com/repos/${pkg.author.name}/${pkg.name}/releases/latest`)
|
||||
|
||||
if (!response.ok) {
|
||||
console.error('Failed to fetch latest version:', response.status)
|
||||
// 更新检查时间,避免频繁请求失败的API
|
||||
updateCheckTime(now)
|
||||
throw new Error(`Failed to fetch version: ${response.status}`)
|
||||
}
|
||||
|
||||
const data = await response.json()
|
||||
const githubVersion = data.tag_name?.replace(/^v/, '') // 移除开头的 'v' (如 v1.2.0 -> 1.2.0)
|
||||
|
||||
// 更新最后检查时间
|
||||
updateCheckTime(now)
|
||||
|
||||
// 比较版本号
|
||||
if (githubVersion && githubVersion !== pkg.version) {
|
||||
return {
|
||||
version: githubVersion,
|
||||
releaseNotes: data.body || '',
|
||||
downloadUrl: `https://github.com/${pkg.author.name}/${pkg.name}/releases/latest`
|
||||
}
|
||||
}
|
||||
return null
|
||||
} catch (error) {
|
||||
console.error('Error checking version:', error)
|
||||
// 更新检查时间,避免频繁请求失败的API
|
||||
updateCheckTime(now)
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
// 检查是否可以进行版本检查(距离上次检查是否超过5分钟)
|
||||
export const canCheckVersion = (lastCheckTime: number): boolean => {
|
||||
const now = Date.now()
|
||||
const fiveMinutes = 5 * 60 * 1000 // 5分钟
|
||||
return now - lastCheckTime >= fiveMinutes
|
||||
}
|
||||
Reference in New Issue
Block a user