优化一些功能
This commit is contained in:
@@ -8,6 +8,7 @@ import { useLogs } from '@/composables/useLogs'
|
||||
import { useActivity } from '@/composables/useActivity'
|
||||
import AppShell from '@/components/layout/AppShell.vue'
|
||||
import ToastContainer from '@/components/ToastContainer.vue'
|
||||
import { GetTime, GetVersion } from '@wails/go/app/App'
|
||||
|
||||
const { initTheme } = useTheme()
|
||||
const { loadProducts, restoreSelection: restoreProductSelection } = useProducts()
|
||||
@@ -25,11 +26,9 @@ let timeTimer: number | null = null
|
||||
let logTimer: number | null = null
|
||||
let resultTimer: number | null = null
|
||||
|
||||
const App = window.go.app.App
|
||||
|
||||
const updateTime = async () => {
|
||||
try {
|
||||
const d = await App.GetTime()
|
||||
const d = await GetTime()
|
||||
serverTime.value = d.serverTime || '--'
|
||||
} catch {}
|
||||
}
|
||||
@@ -68,7 +67,7 @@ onMounted(async () => {
|
||||
|
||||
// 获取版本号
|
||||
try {
|
||||
version.value = await App.GetVersion()
|
||||
version.value = await GetVersion()
|
||||
} catch {}
|
||||
|
||||
// 清空后端旧结果
|
||||
|
||||
@@ -2,12 +2,15 @@
|
||||
import { ref, computed } from 'vue'
|
||||
import { useProducts } from '@/composables/useProducts'
|
||||
import { useToast } from '@/composables/useToast'
|
||||
import {
|
||||
ExportAccountsWithProduct,
|
||||
OrganizeAccounts,
|
||||
VerifyAndExport
|
||||
} from '@wails/go/app/App'
|
||||
|
||||
const { selectedProductId, selectedProductName, selectedProduct } = useProducts()
|
||||
const { showToast } = useToast()
|
||||
|
||||
const App = window.go.app.App
|
||||
|
||||
// 状态
|
||||
const loading = ref(false)
|
||||
const verifyResult = ref<any>(null)
|
||||
@@ -42,14 +45,14 @@ const handleVerify = async () => {
|
||||
|
||||
loading.value = true
|
||||
try {
|
||||
const result = await App.VerifyAndExport(selectedProductId.value)
|
||||
const result = await VerifyAndExport(selectedProductId.value)
|
||||
verifyResult.value = result
|
||||
organizeResult.value = null
|
||||
|
||||
if (result.success) {
|
||||
showToast('复验完成', `已抢到: ${result.hitCount}, 未抢到: ${result.missCount}`, 'success')
|
||||
} else {
|
||||
showToast('复验失败', result.error, 'error')
|
||||
showToast('复验失败', '后端未返回成功状态', 'error')
|
||||
}
|
||||
} catch (e: any) {
|
||||
showToast('复验失败', e.message, 'error')
|
||||
@@ -66,7 +69,7 @@ const exportHitAccounts = async () => {
|
||||
}
|
||||
|
||||
try {
|
||||
const result = await App.ExportAccountsWithProduct(
|
||||
const result = await ExportAccountsWithProduct(
|
||||
verifyResult.value.hitAccounts,
|
||||
selectedProductId.value,
|
||||
selectedProductName.value || ''
|
||||
@@ -74,7 +77,7 @@ const exportHitAccounts = async () => {
|
||||
if (result.success) {
|
||||
showToast('导出成功', `已导出 ${result.count} 个账号到 ${result.filePath}`, 'success')
|
||||
} else {
|
||||
showToast('导出失败', result.error, 'error')
|
||||
showToast('导出失败', result.error || '', 'error')
|
||||
}
|
||||
} catch (e: any) {
|
||||
showToast('导出失败', e.message, 'error')
|
||||
@@ -91,14 +94,14 @@ const handleOrganize = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
const { start, end } = timeRangeMs.value
|
||||
const result = await App.OrganizeAccounts(selectedProductId.value, selectedProductName.value, start, end)
|
||||
const result = await OrganizeAccounts(selectedProductId.value, selectedProductName.value, start, end)
|
||||
organizeResult.value = result
|
||||
verifyResult.value = null
|
||||
|
||||
if (result.success) {
|
||||
showToast('整理完成', `已抢到: ${result.hitCount}, 未抢到: ${result.missCount}`, 'success')
|
||||
} else {
|
||||
showToast('整理失败', result.error, 'error')
|
||||
showToast('整理失败', result.error || '', 'error')
|
||||
}
|
||||
} catch (e: any) {
|
||||
showToast('整理失败', e.message, 'error')
|
||||
|
||||
@@ -7,11 +7,12 @@ const { settings, loadSettings, saveSettings } = useSettings()
|
||||
const visible = ref(false)
|
||||
const formData = ref({
|
||||
timeApiUrl: '',
|
||||
activity: '',
|
||||
traceEnabled: false,
|
||||
traceMaxBody: 0,
|
||||
logLevel: 'info',
|
||||
concurrency: 150,
|
||||
attempts: 1,
|
||||
attempts: 2,
|
||||
retryStages: [] as RetryStage[],
|
||||
seckillMode: 1
|
||||
})
|
||||
|
||||
@@ -1,5 +1,12 @@
|
||||
import { ref } from 'vue'
|
||||
import { useToast } from './useToast'
|
||||
import {
|
||||
GetAccounts,
|
||||
QueryScore,
|
||||
ReloadAccounts,
|
||||
VerifyAllExchange,
|
||||
VerifyExchange
|
||||
} from '@wails/go/app/App'
|
||||
|
||||
export interface Account {
|
||||
index: number
|
||||
@@ -13,8 +20,6 @@ export interface AccountStatus {
|
||||
message?: string
|
||||
}
|
||||
|
||||
const App = window.go.app.App
|
||||
|
||||
const accounts = ref<Account[]>([])
|
||||
const selectedIndices = ref<Set<number>>(new Set())
|
||||
const statusMap = ref<Record<string, AccountStatus | boolean>>({})
|
||||
@@ -24,7 +29,7 @@ export function useAccounts() {
|
||||
const { showToast } = useToast()
|
||||
|
||||
const loadAccounts = async () => {
|
||||
const data = await App.GetAccounts()
|
||||
const data = await GetAccounts()
|
||||
accounts.value = data || []
|
||||
|
||||
// 清理无效选择
|
||||
@@ -35,7 +40,7 @@ export function useAccounts() {
|
||||
}
|
||||
|
||||
const reloadAccounts = async () => {
|
||||
const data = await App.ReloadAccounts()
|
||||
const data = await ReloadAccounts()
|
||||
await loadAccounts()
|
||||
showToast('账号已刷新', `共 ${data.count} 个账号`, 'success')
|
||||
}
|
||||
@@ -81,7 +86,7 @@ export function useAccounts() {
|
||||
showToast('查询积分', '正在并发查询...', 'info')
|
||||
const tasks = accounts.value.map(async (a) => {
|
||||
try {
|
||||
const d = await App.QueryScore(a.name)
|
||||
const d = await QueryScore(a.name)
|
||||
const score = d.score ?? 'N/A'
|
||||
scoreMap.value[a.name] = String(score)
|
||||
localStorage.setItem('accScore_' + a.name, String(score))
|
||||
@@ -193,7 +198,7 @@ export function useVerifyExchange() {
|
||||
|
||||
const verifyAccount = async (accountName: string) => {
|
||||
try {
|
||||
const result = await App.VerifyExchange(accountName)
|
||||
const result = await VerifyExchange(accountName)
|
||||
verifyResults.value[accountName] = result
|
||||
return result
|
||||
} catch (e: any) {
|
||||
@@ -206,8 +211,8 @@ export function useVerifyExchange() {
|
||||
verifying.value = true
|
||||
try {
|
||||
// 使用后端批量查询接口,自带间隔
|
||||
const results = await App.VerifyAllExchange()
|
||||
verifyResults.value = results || {}
|
||||
const results = await VerifyAllExchange()
|
||||
verifyResults.value = results?.results || {}
|
||||
} catch (e: any) {
|
||||
console.error('批量复验失败:', e)
|
||||
} finally {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { ref } from 'vue'
|
||||
import { useToast } from './useToast'
|
||||
import { GetActivities, GetCurrentActivity, SwitchActivity } from '@wails/go/app/App'
|
||||
|
||||
// 活动项(与后端 types.ActivityInfo 对齐)
|
||||
export interface ActivityItem {
|
||||
@@ -12,8 +13,7 @@ const activities = ref<ActivityItem[]>([])
|
||||
const currentActivity = ref<ActivityItem | null>(null)
|
||||
const switching = ref(false)
|
||||
|
||||
// 与项目其他 composable 一致,直接走 Wails 运行时注入的 window.go.app.App
|
||||
const App = window.go.app.App
|
||||
// 统一走 Wails 自动生成绑定,后端签名变化时可由 TypeScript 暴露问题。
|
||||
|
||||
export function useActivity() {
|
||||
const { showToast } = useToast()
|
||||
@@ -21,10 +21,10 @@ export function useActivity() {
|
||||
// 拉取全部活动与当前生效活动
|
||||
const loadActivities = async () => {
|
||||
try {
|
||||
const list = await App.GetActivities()
|
||||
const list = await GetActivities()
|
||||
activities.value = list || []
|
||||
try {
|
||||
currentActivity.value = await App.GetCurrentActivity()
|
||||
currentActivity.value = await GetCurrentActivity()
|
||||
} catch {
|
||||
// 当前活动读取失败不阻塞列表展示
|
||||
}
|
||||
@@ -38,7 +38,7 @@ export function useActivity() {
|
||||
if (id === currentActivity.value?.id) return true
|
||||
switching.value = true
|
||||
try {
|
||||
const d: Record<string, any> = await App.SwitchActivity(id)
|
||||
const d: Record<string, any> = await SwitchActivity(id)
|
||||
if (d && d.success) {
|
||||
currentActivity.value = { id: d.activity, displayName: d.displayName }
|
||||
showToast('活动已切换', (d.displayName || id) + ',正在刷新商品...', 'success')
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { ref } from 'vue'
|
||||
import { useAccounts, type AccountStatus } from './useAccounts'
|
||||
import { ClearResults, GetLogs, GetResults } from '@wails/go/app/App'
|
||||
|
||||
export interface LogEntry {
|
||||
id: number
|
||||
@@ -20,8 +21,6 @@ export interface LogMessage {
|
||||
source: 'local' | 'server'
|
||||
}
|
||||
|
||||
const App = window.go.app.App
|
||||
|
||||
const logs = ref<LogMessage[]>([])
|
||||
const results = ref<Record<string, string>>({})
|
||||
const lastLogId = ref(0)
|
||||
@@ -91,7 +90,7 @@ export function useLogs() {
|
||||
|
||||
const fetchServerLogs = async () => {
|
||||
try {
|
||||
const d = await App.GetLogs(lastLogId.value)
|
||||
const d = await GetLogs(lastLogId.value)
|
||||
if (!d.success || !Array.isArray(d.logs) || d.logs.length === 0) return
|
||||
|
||||
d.logs.forEach((item: LogEntry) => {
|
||||
@@ -127,7 +126,7 @@ export function useLogs() {
|
||||
|
||||
const checkResults = async () => {
|
||||
try {
|
||||
const d = await App.GetResults()
|
||||
const d = await GetResults()
|
||||
const data = (d || {}) as Record<string, string>
|
||||
const json = JSON.stringify(d)
|
||||
|
||||
@@ -156,7 +155,7 @@ export function useLogs() {
|
||||
}
|
||||
|
||||
const clearResults = async () => {
|
||||
await App.ClearResults()
|
||||
await ClearResults()
|
||||
clearLocalResults()
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { ref, computed } from 'vue'
|
||||
import { useToast } from './useToast'
|
||||
import { LoadProducts } from '@wails/go/app/App'
|
||||
|
||||
export interface Product {
|
||||
commodityId: string
|
||||
@@ -25,8 +26,6 @@ export interface ProductPayload {
|
||||
stale: boolean
|
||||
}
|
||||
|
||||
const App = window.go.app.App
|
||||
|
||||
const products = ref<Product[]>([])
|
||||
const productInfo = ref<ProductPayload | null>(null)
|
||||
const selectedProductId = ref<string | null>(null)
|
||||
@@ -54,7 +53,7 @@ export function useProducts() {
|
||||
const loadProducts = async (showToastMsg = true) => {
|
||||
loading.value = true
|
||||
try {
|
||||
const data = await App.LoadProducts(true)
|
||||
const data = await LoadProducts(true)
|
||||
products.value = Array.isArray(data.products) ? data.products : []
|
||||
productInfo.value = data
|
||||
|
||||
|
||||
@@ -3,8 +3,7 @@ import { useToast } from './useToast'
|
||||
import { useAccounts } from './useAccounts'
|
||||
import { useProducts } from './useProducts'
|
||||
import { useLogs } from './useLogs'
|
||||
|
||||
const App = window.go.app.App
|
||||
import { CancelSchedule, SetSchedule, StartSeckill } from '@wails/go/app/App'
|
||||
|
||||
const scheduleActive = ref(false)
|
||||
const countdownSeconds = ref(0)
|
||||
@@ -33,7 +32,7 @@ export function useScheduler() {
|
||||
showToast('抢购中', `${Object.keys(ap).length} 个账号正在抢购`, 'info', 3000)
|
||||
|
||||
try {
|
||||
const d = await App.StartSeckill(ap)
|
||||
const d = await StartSeckill(ap)
|
||||
if (d?.success === false) {
|
||||
throw new Error(d.error || '提交失败')
|
||||
}
|
||||
@@ -75,12 +74,12 @@ export function useScheduler() {
|
||||
addLocalLog(`设置定时: ${fullTime}`, 'i')
|
||||
|
||||
try {
|
||||
const d = await App.SetSchedule({
|
||||
const d = await SetSchedule({
|
||||
accountProducts: ap,
|
||||
targetTime: fullTime
|
||||
})
|
||||
if (d?.success === false) {
|
||||
throw new Error(d.error || '定时设置失败')
|
||||
throw new Error('定时设置失败')
|
||||
}
|
||||
|
||||
scheduleActive.value = true
|
||||
@@ -106,7 +105,7 @@ export function useScheduler() {
|
||||
|
||||
const cancelSchedule = async () => {
|
||||
try {
|
||||
await App.CancelSchedule()
|
||||
await CancelSchedule()
|
||||
} catch {}
|
||||
|
||||
scheduleActive.value = false
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import { ref } from 'vue'
|
||||
import { useToast } from './useToast'
|
||||
import { GetSettings, SaveSettings } from '@wails/go/app/App'
|
||||
import { types } from '@wails/go/models'
|
||||
|
||||
export interface RetryStage {
|
||||
maxElapsed: number
|
||||
@@ -8,6 +10,7 @@ export interface RetryStage {
|
||||
|
||||
export interface Settings {
|
||||
timeApiUrl: string
|
||||
activity: string
|
||||
traceEnabled: boolean
|
||||
traceMaxBody: number
|
||||
logLevel: string
|
||||
@@ -17,8 +20,6 @@ export interface Settings {
|
||||
seckillMode: number // 0=标准, 1=激进
|
||||
}
|
||||
|
||||
const App = window.go.app.App
|
||||
|
||||
const defaultRetryStages: RetryStage[] = [
|
||||
{ maxElapsed: 4, interval: 120 },
|
||||
{ maxElapsed: 12, interval: 200 },
|
||||
@@ -28,11 +29,12 @@ const defaultRetryStages: RetryStage[] = [
|
||||
|
||||
const settings = ref<Settings>({
|
||||
timeApiUrl: '',
|
||||
activity: '',
|
||||
traceEnabled: false,
|
||||
traceMaxBody: 0,
|
||||
logLevel: 'info',
|
||||
concurrency: 150,
|
||||
attempts: 1,
|
||||
attempts: 2,
|
||||
retryStages: [...defaultRetryStages],
|
||||
seckillMode: 1
|
||||
})
|
||||
@@ -42,14 +44,15 @@ export function useSettings() {
|
||||
|
||||
const loadSettings = async () => {
|
||||
try {
|
||||
const cfg = await App.GetSettings()
|
||||
const cfg = await GetSettings()
|
||||
settings.value = {
|
||||
timeApiUrl: cfg.timeApiUrl || '',
|
||||
activity: cfg.activity || '',
|
||||
traceEnabled: !!cfg.traceEnabled,
|
||||
traceMaxBody: cfg.traceMaxBody || 0,
|
||||
logLevel: cfg.logLevel || 'info',
|
||||
concurrency: cfg.concurrency || 150,
|
||||
attempts: cfg.attempts || 1,
|
||||
attempts: cfg.attempts || 2,
|
||||
retryStages: cfg.retryStages && cfg.retryStages.length > 0
|
||||
? cfg.retryStages
|
||||
: [...defaultRetryStages],
|
||||
@@ -62,13 +65,13 @@ export function useSettings() {
|
||||
|
||||
const saveSettings = async (newSettings: Settings) => {
|
||||
try {
|
||||
const d = await App.SaveSettings(newSettings)
|
||||
const d = await SaveSettings(types.Config.createFrom(newSettings))
|
||||
if (d.success) {
|
||||
settings.value = { ...newSettings }
|
||||
showToast('设置已保存', '配置已生效', 'success')
|
||||
return true
|
||||
} else {
|
||||
showToast('保存失败', d.error || '', 'error')
|
||||
showToast('保存失败', '后端未返回成功状态', 'error')
|
||||
return false
|
||||
}
|
||||
} catch (e: any) {
|
||||
|
||||
Vendored
-16
@@ -5,19 +5,3 @@ declare module '*.vue' {
|
||||
const component: DefineComponent<{}, {}, any>
|
||||
export default component
|
||||
}
|
||||
|
||||
// 统一从 Wails 自动生成的强类型绑定派生 window.go.app.App 的类型声明,
|
||||
// 避免手写声明与后端契约漂移。后端方法签名变更后重新运行 `wails generate`
|
||||
// 会更新 wailsjs/go/app/App.d.ts,此处类型随之更新;若前端引用了已删除或
|
||||
// 已重命名的方法,TypeScript 编译(vue-tsc)会直接报错。
|
||||
import type * as GoApp from './wailsjs/go/app/App'
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
go: {
|
||||
app: {
|
||||
App: typeof GoApp
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user