feat: 功能优化

This commit is contained in:
2026-03-15 15:36:29 +08:00
parent 29e11056dc
commit 4ab1efbc12
63 changed files with 4175 additions and 170 deletions

View File

@@ -128,7 +128,7 @@ const props = defineProps({
// 展示模式tags标签或 select下拉选择
displayMode: {
type: String,
default: 'select' // 默认为select模式因为用户反馈标签模式不好看
default: 'select'
},
// 展示数量(仅标签模式有效)
displayCount: {
@@ -140,7 +140,7 @@ const props = defineProps({
type: Boolean,
default: true
},
// 本地存储键名前缀,用于保存和恢复选择
// 本地存储键名前缀
storageKey: {
type: String,
default: 'prompt_selector'
@@ -150,7 +150,7 @@ const props = defineProps({
// Emits
const emit = defineEmits(['update:modelValue', 'change'])
// Stores
// Stores - 单一数据源
const userStore = useUserStore()
const promptStore = usePromptStore()
@@ -159,7 +159,7 @@ const showAllPromptsModal = ref(false)
const promptSearchKeyword = ref('')
const selectedPromptId = ref(props.modelValue)
// 使用 store 中的数据
// ===== 单一数据源:从 Store 获取 =====
const allPrompts = computed(() => promptStore.promptList)
const loading = computed(() => promptStore.promptListLoading)
@@ -197,28 +197,31 @@ watch(() => props.modelValue, (newValue) => {
selectedPromptId.value = newValue
})
// 加载用户提示词
// 加载用户提示词(通过 Store
async function loadUserPrompts() {
// 检查用户是否登录
if (!userStore.userId) {
console.warn('用户未登录,无法加载提示词')
return
}
try {
// 使用 store 加载数据
const prompts = await promptStore.loadPromptList(userStore.userId)
// 使用 store 加载(自建 + 收藏的智能体)
await promptStore.loadPromptList()
// 如果有选中ID但当前选中的提示词不在列表中,清空选择
if (selectedPromptId.value && !prompts.find(p => p.id === selectedPromptId.value)) {
selectedPromptId.value = null
}
// 如果没有选中ID且有提示词默认选中第一个
else if (!selectedPromptId.value && prompts.length > 0) {
selectedPromptId.value = prompts[0].id
// 如果有选中ID验证是否在列表中
if (selectedPromptId.value) {
const exists = allPrompts.value.find(p => p.id === selectedPromptId.value)
if (!exists) {
selectedPromptId.value = null
}
}
// 尝试从本地存储恢复选中状态
// 如果没有选中且有提示词,默认选中第一个
if (!selectedPromptId.value && allPrompts.value.length > 0) {
selectedPromptId.value = allPrompts.value[0].id
}
// 恢复本地存储的选择
await restoreSelectedPromptId()
} catch (error) {
console.error('加载提示词失败:', error)
@@ -272,10 +275,10 @@ function handleSelectChange(value) {
}
}
// 刷新用户提示词
// 刷新用户提示词(强制重新加载)
async function refreshUserPrompts() {
try {
await promptStore.refreshPromptList(userStore.userId)
await promptStore.refreshPromptList()
await restoreSelectedPromptId()
} catch (error) {
console.error('刷新提示词失败:', error)