|
|
@@ -264,16 +264,22 @@ const recommendTemplates = ref([])
|
|
|
|
|
|
const templateIcons = ['📊', '🏢', '📅', '💼', '📋', '📈', '🎯', '📝']
|
|
|
|
|
|
-onMounted(async () => {
|
|
|
+// 刷新统计数据
|
|
|
+async function refreshStats() {
|
|
|
try {
|
|
|
- // 获取统计数据
|
|
|
const statsData = await templateApi.getStats()
|
|
|
stats.reportCount = statsData.reportCount || 0
|
|
|
stats.templateCount = statsData.templateCount || 0
|
|
|
stats.variableCount = statsData.variableCount || 0
|
|
|
stats.sourceFileCount = statsData.sourceFileCount || 0
|
|
|
-
|
|
|
- // 获取模板列表
|
|
|
+ } catch (error) {
|
|
|
+ console.error('获取统计数据失败:', error)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+// 刷新推荐模板列表
|
|
|
+async function refreshRecommendTemplates() {
|
|
|
+ try {
|
|
|
await templateStore.fetchTemplates()
|
|
|
// 取前3个模板作为推荐(按使用次数排序)
|
|
|
const sortedTemplates = [...templateStore.templates].sort((a, b) => (b.useCount || 0) - (a.useCount || 0))
|
|
|
@@ -286,8 +292,12 @@ onMounted(async () => {
|
|
|
isHot: (t.useCount || 0) >= 100 // 使用次数>=100标记为热门
|
|
|
}))
|
|
|
} catch (error) {
|
|
|
- console.error('获取数据失败:', error)
|
|
|
+ console.error('获取模板列表失败:', error)
|
|
|
}
|
|
|
+}
|
|
|
+
|
|
|
+onMounted(async () => {
|
|
|
+ await Promise.all([refreshStats(), refreshRecommendTemplates()])
|
|
|
})
|
|
|
|
|
|
function handleAiSubmit() {
|
|
|
@@ -316,11 +326,10 @@ async function handleDeleteTemplate(tpl) {
|
|
|
)
|
|
|
|
|
|
await templateStore.deleteTemplate(tpl.id)
|
|
|
- // 从推荐列表中移除
|
|
|
- recommendTemplates.value = recommendTemplates.value.filter(t => t.id !== tpl.id)
|
|
|
- // 更新统计
|
|
|
- stats.templateCount = Math.max(0, stats.templateCount - 1)
|
|
|
ElMessage.success('删除成功')
|
|
|
+ // 刷新统计和模板列表
|
|
|
+ refreshStats()
|
|
|
+ refreshRecommendTemplates()
|
|
|
} catch (error) {
|
|
|
if (error !== 'cancel') {
|
|
|
console.error('删除模板失败:', error)
|
|
|
@@ -345,6 +354,9 @@ async function handleCreateTemplate() {
|
|
|
// 重置表单
|
|
|
Object.assign(newTemplate, { name: '', description: '' })
|
|
|
ElMessage.success('模板创建成功')
|
|
|
+ // 刷新统计和列表
|
|
|
+ refreshStats()
|
|
|
+ refreshRecommendTemplates()
|
|
|
router.push(`/editor/${template.id}`)
|
|
|
} catch (error) {
|
|
|
ElMessage.error('创建失败: ' + error.message)
|
|
|
@@ -426,8 +438,9 @@ async function handleUploadTemplate() {
|
|
|
ElMessage.warning('模板创建成功,但解析启动失败,请稍后手动触发')
|
|
|
}
|
|
|
|
|
|
- // 刷新模板列表
|
|
|
- await templateStore.fetchTemplates()
|
|
|
+ // 刷新统计和模板列表
|
|
|
+ refreshStats()
|
|
|
+ refreshRecommendTemplates()
|
|
|
// 不自动跳转编辑页面,等解析完成后用户自行进入
|
|
|
} catch (error) {
|
|
|
ElMessage.error('创建失败: ' + error.message)
|