优化前端认证与类型管理

This commit is contained in:
yml
2026-05-25 01:59:59 +08:00
parent eafa6f96b2
commit 2cfd3d9422
28 changed files with 435 additions and 280 deletions
+3 -1
View File
@@ -64,7 +64,9 @@ export function readPublishDraft(draftKey: string) {
}
export function writePublishDraft(draftKey: string, draft: PublishDraft) {
localStorage.setItem(draftKey, JSON.stringify(draft))
const nextValue = JSON.stringify(draft)
if (localStorage.getItem(draftKey) === nextValue) return
localStorage.setItem(draftKey, nextValue)
}
export function removePublishDraft(draftKey: string) {
+32 -1
View File
@@ -25,6 +25,8 @@ import {
import type { PublishForm } from '@/types/publish'
import { commonOnlineTimes, dailyLossOptions, formatNumber, roundRatio } from '@/utils/pricing'
const draftSaveDelay = 400
interface UsePublishFormOptions {
draftKey: string
submitSuccessPath: string
@@ -51,6 +53,7 @@ export function usePublishForm(options: UsePublishFormOptions) {
const screenshotFiles = reactive<Record<string, string>>({})
const screenshotPreviews = reactive<Record<string, string>>({})
const selectedSkins = ref<string[]>([])
let draftSaveTimer: number | undefined
const pricing = usePricingCalculator({
form,
@@ -124,8 +127,34 @@ export function usePublishForm(options: UsePublishFormOptions) {
}
function saveDraft(saveOptions: { force?: boolean } = {}) {
if (suppressDraftSave.value) return
if (suppressDraftSave.value) {
clearDraftSaveTimer()
return
}
if (!saveOptions.force && !draftReady.value) return
if (!saveOptions.force) {
scheduleDraftSave()
return
}
clearDraftSaveTimer()
writeDraft()
}
function scheduleDraftSave() {
clearDraftSaveTimer()
draftSaveTimer = window.setTimeout(() => {
draftSaveTimer = undefined
writeDraft()
}, draftSaveDelay)
}
function clearDraftSaveTimer() {
if (draftSaveTimer === undefined) return
window.clearTimeout(draftSaveTimer)
draftSaveTimer = undefined
}
function writeDraft() {
writePublishDraft(
options.draftKey,
buildPublishDraft({
@@ -178,6 +207,7 @@ export function usePublishForm(options: UsePublishFormOptions) {
return
}
suppressDraftSave.value = true
clearDraftSaveTimer()
resetDraftState()
removePublishDraft(options.draftKey)
options.notifySuccess('已重置')
@@ -349,6 +379,7 @@ export function usePublishForm(options: UsePublishFormOptions) {
})
removePublishDraft(options.draftKey)
suppressDraftSave.value = true
clearDraftSaveTimer()
options.notifySuccess(
listing.status === 'published' && listing.review_status === 'approved'
? '发布成功,已上架'