Files
prompt-optimizer/packages/ui/src/composables/useModals.ts
T
linshen f89fbb76eb feat(template): 增强模板管理器以支持内置模板语言切换
- 新增内置模板语言服务,支持中英文切换
- 更新模板管理器以根据当前语言加载相应的内置模板
- 实现语言切换功能,允许用户动态更改模板语言
- 增强错误处理,确保在语言切换和模板加载过程中稳定性
- 更新相关测试用例以验证新功能的正确性
2025-06-08 21:58:32 +08:00

61 lines
1.5 KiB
TypeScript

import { ref } from 'vue'
import { useToast } from './useToast'
import { useI18n } from 'vue-i18n'
export function useModals(
templateManager: any,
optimizeModelSelect: any,
testModelSelect: any,
loadModels: () => Promise<void>,
initTemplateSelection: () => Promise<void>
) {
const toast = useToast()
const { t } = useI18n()
// 弹窗状态
const showConfig = ref(false)
const showHistory = ref(false)
const showTemplates = ref(false)
const currentType = ref('optimize')
// 打开提示词管理器
const openTemplateManager = (type = 'optimize') => {
currentType.value = type
showTemplates.value = true
}
// 加载提示词模板
const loadTemplates = async () => {
try {
await templateManager.ensureInitialized()
await initTemplateSelection()
} catch (error) {
console.error(t('toast.error.loadTemplatesFailed'), error)
toast.error(t('toast.error.loadTemplatesFailed'))
}
}
// 关闭提示词管理器
const handleTemplateManagerClose = async () => {
await loadTemplates()
showTemplates.value = false
}
// 关闭模型管理器
const handleModelManagerClose = async () => {
await loadModels()
optimizeModelSelect.value?.refresh()
testModelSelect.value?.refresh()
showConfig.value = false
}
return {
showConfig,
showHistory,
showTemplates,
currentType,
openTemplateManager,
handleTemplateManagerClose,
handleModelManagerClose
}
}