fix: 修复问题

This commit is contained in:
2026-01-18 02:15:08 +08:00
parent aa81a1aebc
commit 961e4bcc77
15 changed files with 1652 additions and 1103 deletions

View File

@@ -1,31 +1,116 @@
import { ref } from 'vue'
import { defineStore } from 'pinia'
import localforage from 'localforage'
import { UserPromptApi } from '@/api/userPrompt'
export const usePromptStore = defineStore('prompt', () => {
// 存储当前选中的提示词
const currentPrompt = ref('')
// 存储提示词相关的视频信息
const currentVideoInfo = ref(null)
// 存储提示词列表
const promptList = ref([])
const promptListLoading = ref(false)
const promptListError = ref(null)
// 设置提示词
function setPrompt(prompt, videoInfo = null) {
currentPrompt.value = prompt
currentVideoInfo.value = videoInfo
}
// 清空提示词
function clearPrompt() {
currentPrompt.value = ''
currentVideoInfo.value = null
}
// 加载提示词列表
async function loadPromptList(userId) {
if (!userId) {
console.warn('用户未登录,无法加载提示词')
return
}
// 如果已有数据且不在加载中,直接返回缓存数据
if (promptList.value.length > 0 && !promptListLoading.value) {
return promptList.value
}
promptListLoading.value = true
promptListError.value = null
try {
const response = await UserPromptApi.getUserPromptPage({
pageNo: 1,
pageSize: 100,
status: undefined
})
if (response?.data?.list) {
promptList.value = response.data.list
} else {
promptList.value = []
}
return promptList.value
} catch (error) {
console.error('加载提示词列表失败:', error)
promptListError.value = error
throw error
} finally {
promptListLoading.value = false
}
}
// 添加提示词到列表
function addPromptToList(prompt) {
const existingIndex = promptList.value.findIndex(p => p.id === prompt.id)
if (existingIndex >= 0) {
// 更新已存在的提示词
promptList.value[existingIndex] = prompt
} else {
// 添加新提示词
promptList.value.unshift(prompt)
}
}
// 从列表中删除提示词
function removePromptFromList(promptId) {
const index = promptList.value.findIndex(p => p.id === promptId)
if (index >= 0) {
promptList.value.splice(index, 1)
}
}
// 更新提示词
function updatePromptInList(updatedPrompt) {
const index = promptList.value.findIndex(p => p.id === updatedPrompt.id)
if (index >= 0) {
promptList.value[index] = updatedPrompt
}
}
// 刷新提示词列表
async function refreshPromptList(userId) {
promptList.value = [] // 清空缓存,强制重新加载
return await loadPromptList(userId)
}
return {
currentPrompt,
currentVideoInfo,
promptList,
promptListLoading,
promptListError,
setPrompt,
clearPrompt
clearPrompt,
loadPromptList,
addPromptToList,
removePromptFromList,
updatePromptInList,
refreshPromptList
}
}, {
persist: {
@@ -35,6 +120,6 @@ export const usePromptStore = defineStore('prompt', () => {
setItem: (key, value) => localforage.setItem(key, value),
removeItem: (key) => localforage.removeItem(key)
},
paths: ['currentPrompt', 'currentVideoInfo']
paths: ['currentPrompt', 'currentVideoInfo', 'promptList']
}
})