修复海报草稿页面
This commit is contained in:
parent
2b54d078f2
commit
9f0d8c26b2
@ -295,7 +295,7 @@ onMounted(() => {
|
|||||||
|
|
||||||
function openDifyAdmin() {
|
function openDifyAdmin() {
|
||||||
// Dify 管理后台运行在 3000 端口
|
// Dify 管理后台运行在 3000 端口
|
||||||
window.open('http://localhost:3000', '_blank')
|
window.open('http://150.5.135.143:3000', '_blank')
|
||||||
showMobileMenu.value = false
|
showMobileMenu.value = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -10,6 +10,7 @@
|
|||||||
import { ref, computed, watch, onMounted } from 'vue'
|
import { ref, computed, watch, onMounted } from 'vue'
|
||||||
import { useRouter, useRoute } from 'vue-router'
|
import { useRouter, useRoute } from 'vue-router'
|
||||||
import api from '@/utils/api'
|
import api from '@/utils/api'
|
||||||
|
import { useAuth } from '@/composables/useAuth'
|
||||||
|
|
||||||
export interface PosterTheme {
|
export interface PosterTheme {
|
||||||
primary: string
|
primary: string
|
||||||
@ -172,6 +173,7 @@ function normalizeFormat(draft: PosterDraft) {
|
|||||||
export function usePosterWorkspace() {
|
export function usePosterWorkspace() {
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
|
const { user } = useAuth()
|
||||||
|
|
||||||
// ── 核心状态 ──────────────────────────────
|
// ── 核心状态 ──────────────────────────────
|
||||||
const recordId = ref<number | null>(null)
|
const recordId = ref<number | null>(null)
|
||||||
@ -180,9 +182,23 @@ export function usePosterWorkspace() {
|
|||||||
const restored = ref(false)
|
const restored = ref(false)
|
||||||
|
|
||||||
// ── 持久化 Key ────────────────────────────
|
// ── 持久化 Key ────────────────────────────
|
||||||
const STORAGE_KEY = computed(() =>
|
function getStorageKey(targetRecordId: number | null = recordId.value): string {
|
||||||
recordId.value ? `poster_ws_draft_${recordId.value}` : 'poster_ws_draft_new'
|
if (!user.value?.id) return ''
|
||||||
)
|
const userId = encodeURIComponent(user.value.id)
|
||||||
|
return `poster_ws_draft_${userId}_${targetRecordId ?? 'new'}`
|
||||||
|
}
|
||||||
|
|
||||||
|
const STORAGE_KEY = computed(() => getStorageKey())
|
||||||
|
|
||||||
|
// 旧版草稿键没有用户维度,无法安全判断归属,直接清理以避免跨账号恢复。
|
||||||
|
try {
|
||||||
|
for (let index = localStorage.length - 1; index >= 0; index--) {
|
||||||
|
const key = localStorage.key(index)
|
||||||
|
if (key && /^poster_ws_draft_(?:new|\d+)$/.test(key)) {
|
||||||
|
localStorage.removeItem(key)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch { /* ignore */ }
|
||||||
|
|
||||||
/** 需要持久化的字段(排除瞬态数据) */
|
/** 需要持久化的字段(排除瞬态数据) */
|
||||||
function getPersistableDraft(): Partial<PosterDraft> {
|
function getPersistableDraft(): Partial<PosterDraft> {
|
||||||
@ -231,7 +247,9 @@ export function usePosterWorkspace() {
|
|||||||
// ── 持久化到 localStorage ─────────────────
|
// ── 持久化到 localStorage ─────────────────
|
||||||
function persistDraft() {
|
function persistDraft() {
|
||||||
try {
|
try {
|
||||||
localStorage.setItem(STORAGE_KEY.value, JSON.stringify(getPersistableDraft()))
|
const key = STORAGE_KEY.value
|
||||||
|
if (!key) return
|
||||||
|
localStorage.setItem(key, JSON.stringify(getPersistableDraft()))
|
||||||
} catch { /* quota exceeded, ignore */ }
|
} catch { /* quota exceeded, ignore */ }
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -241,7 +259,9 @@ export function usePosterWorkspace() {
|
|||||||
// ── 从 localStorage 恢复 ─────────────────
|
// ── 从 localStorage 恢复 ─────────────────
|
||||||
function tryRestoreLocal(): boolean {
|
function tryRestoreLocal(): boolean {
|
||||||
try {
|
try {
|
||||||
const saved = localStorage.getItem(STORAGE_KEY.value)
|
const key = STORAGE_KEY.value
|
||||||
|
if (!key) return false
|
||||||
|
const saved = localStorage.getItem(key)
|
||||||
if (saved) {
|
if (saved) {
|
||||||
const parsed = JSON.parse(saved)
|
const parsed = JSON.parse(saved)
|
||||||
Object.assign(draft.value, parsed)
|
Object.assign(draft.value, parsed)
|
||||||
@ -389,6 +409,12 @@ export function usePosterWorkspace() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function setRecordId(id: number) {
|
function setRecordId(id: number) {
|
||||||
|
const previousKey = STORAGE_KEY.value
|
||||||
|
if (!recordId.value && previousKey) {
|
||||||
|
try {
|
||||||
|
localStorage.removeItem(previousKey)
|
||||||
|
} catch { /* ignore */ }
|
||||||
|
}
|
||||||
recordId.value = id
|
recordId.value = id
|
||||||
persistDraft()
|
persistDraft()
|
||||||
syncUrl()
|
syncUrl()
|
||||||
@ -398,7 +424,8 @@ export function usePosterWorkspace() {
|
|||||||
function reset() {
|
function reset() {
|
||||||
// 清理 localStorage
|
// 清理 localStorage
|
||||||
try {
|
try {
|
||||||
localStorage.removeItem(STORAGE_KEY.value)
|
const key = STORAGE_KEY.value
|
||||||
|
if (key) localStorage.removeItem(key)
|
||||||
} catch { /* ignore */ }
|
} catch { /* ignore */ }
|
||||||
|
|
||||||
recordId.value = null
|
recordId.value = null
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user