TemplateDetail.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. <template>
  2. <div class="template-detail-page">
  3. <div class="page-header">
  4. <div class="header-left">
  5. <el-button :icon="ArrowLeft" @click="router.back()">返回</el-button>
  6. <h1>{{ template?.name || '模板详情' }}</h1>
  7. <el-tag :type="getStatusType(template?.status)">
  8. {{ getStatusLabel(template?.status) }}
  9. </el-tag>
  10. </div>
  11. <div class="header-right">
  12. <el-button @click="router.push(`/editor/${templateId}`)">编辑模板</el-button>
  13. <el-button type="primary" @click="useTemplate">使用模板</el-button>
  14. </div>
  15. </div>
  16. <el-row :gutter="20">
  17. <el-col :span="16">
  18. <!-- 基本信息 -->
  19. <div class="card section">
  20. <h3>基本信息</h3>
  21. <el-descriptions :column="2" border>
  22. <el-descriptions-item label="模板名称">{{ template?.name }}</el-descriptions-item>
  23. <el-descriptions-item label="状态">{{ getStatusLabel(template?.status) }}</el-descriptions-item>
  24. <el-descriptions-item label="使用次数">{{ template?.useCount || 0 }} 次</el-descriptions-item>
  25. <el-descriptions-item label="是否公开">{{ template?.isPublic ? '是' : '否' }}</el-descriptions-item>
  26. <el-descriptions-item label="创建时间" :span="2">{{ template?.createTime }}</el-descriptions-item>
  27. <el-descriptions-item label="描述" :span="2">{{ template?.description || '暂无描述' }}</el-descriptions-item>
  28. </el-descriptions>
  29. </div>
  30. <!-- 变量列表 -->
  31. <div class="card section">
  32. <div class="section-header">
  33. <h3>变量列表 ({{ variables.length }})</h3>
  34. </div>
  35. <el-table :data="variables" stripe>
  36. <el-table-column prop="displayName" label="显示名称" width="150" />
  37. <el-table-column prop="name" label="变量名" width="150" />
  38. <el-table-column prop="category" label="类别" width="120">
  39. <template #default="{ row }">
  40. <el-tag :color="getCategoryColor(row.category)" effect="dark" size="small">
  41. {{ getCategoryLabel(row.category) }}
  42. </el-tag>
  43. </template>
  44. </el-table-column>
  45. <el-table-column prop="sourceType" label="来源类型" width="120">
  46. <template #default="{ row }">
  47. {{ getSourceTypeLabel(row.sourceType) }}
  48. </template>
  49. </el-table-column>
  50. <el-table-column prop="exampleValue" label="示例值" />
  51. </el-table>
  52. </div>
  53. </el-col>
  54. <el-col :span="8">
  55. <!-- 来源文件定义 -->
  56. <div class="card section">
  57. <h3>来源文件定义 ({{ sourceFiles.length }})</h3>
  58. <div class="source-file-list">
  59. <div v-for="sf in sourceFiles" :key="sf.id" class="source-file-item">
  60. <span class="sf-icon">📄</span>
  61. <div class="sf-info">
  62. <div class="sf-name">{{ sf.alias }}</div>
  63. <div class="sf-desc">{{ sf.description || '暂无描述' }}</div>
  64. </div>
  65. <el-tag size="small" :type="sf.required ? 'danger' : 'info'">
  66. {{ sf.required ? '必需' : '可选' }}
  67. </el-tag>
  68. </div>
  69. </div>
  70. </div>
  71. <!-- 统计信息 -->
  72. <div class="card section">
  73. <h3>统计信息</h3>
  74. <div class="stat-item">
  75. <span class="stat-label">变量总数</span>
  76. <span class="stat-value">{{ variables.length }}</span>
  77. </div>
  78. <div class="stat-item">
  79. <span class="stat-label">来源文件</span>
  80. <span class="stat-value">{{ sourceFiles.length }}</span>
  81. </div>
  82. <div class="stat-item">
  83. <span class="stat-label">生成次数</span>
  84. <span class="stat-value">{{ template?.useCount || 0 }}</span>
  85. </div>
  86. </div>
  87. </el-col>
  88. </el-row>
  89. </div>
  90. </template>
  91. <script setup>
  92. import { ref, onMounted } from 'vue'
  93. import { useRouter, useRoute } from 'vue-router'
  94. import { ArrowLeft } from '@element-plus/icons-vue'
  95. import { ElMessage } from 'element-plus'
  96. import { templateApi, sourceFileApi, variableApi } from '@/api'
  97. const router = useRouter()
  98. const route = useRoute()
  99. const templateId = route.params.id
  100. const loading = ref(false)
  101. // 从 API 获取数据
  102. const template = ref(null)
  103. const sourceFiles = ref([])
  104. const variables = ref([])
  105. onMounted(async () => {
  106. await fetchTemplateDetail()
  107. })
  108. async function fetchTemplateDetail() {
  109. loading.value = true
  110. try {
  111. // 并行获取模板详情、来源文件和变量
  112. const [templateData, sourceFilesData, variablesData] = await Promise.all([
  113. templateApi.getById(templateId),
  114. sourceFileApi.list(templateId),
  115. variableApi.list(templateId)
  116. ])
  117. template.value = templateData
  118. sourceFiles.value = sourceFilesData || []
  119. variables.value = variablesData || []
  120. } catch (error) {
  121. console.error('获取模板详情失败:', error)
  122. ElMessage.error('获取模板详情失败')
  123. } finally {
  124. loading.value = false
  125. }
  126. }
  127. function getStatusType(status) {
  128. const map = { draft: 'info', published: 'success', archived: 'warning' }
  129. return map[status] || 'info'
  130. }
  131. function getStatusLabel(status) {
  132. const map = { draft: '草稿', published: '已发布', archived: '已归档' }
  133. return map[status] || status
  134. }
  135. function getCategoryColor(category) {
  136. const map = {
  137. entity: '#1890ff',
  138. concept: '#722ed1',
  139. data: '#52c41a',
  140. location: '#faad14',
  141. asset: '#eb2f96'
  142. }
  143. return map[category] || '#8c8c8c'
  144. }
  145. function getCategoryLabel(category) {
  146. const map = {
  147. entity: '核心实体',
  148. concept: '概念/技术',
  149. data: '数据/指标',
  150. location: '地点/组织',
  151. asset: '资源模板'
  152. }
  153. return map[category] || '其他'
  154. }
  155. function getSourceTypeLabel(type) {
  156. const map = {
  157. document: '文档提取',
  158. manual: '手动输入',
  159. reference: '引用变量',
  160. fixed: '固定值'
  161. }
  162. return map[type] || type
  163. }
  164. function useTemplate() {
  165. router.push(`/generations?templateId=${templateId}`)
  166. ElMessage.info('请上传来源文件后开始生成')
  167. }
  168. </script>
  169. <style lang="scss" scoped>
  170. .template-detail-page {
  171. max-width: 1200px;
  172. margin: 0 auto;
  173. }
  174. .page-header {
  175. display: flex;
  176. align-items: center;
  177. justify-content: space-between;
  178. margin-bottom: 20px;
  179. .header-left {
  180. display: flex;
  181. align-items: center;
  182. gap: 12px;
  183. h1 {
  184. font-size: 20px;
  185. margin: 0;
  186. }
  187. }
  188. .header-right {
  189. display: flex;
  190. gap: 8px;
  191. }
  192. }
  193. .section {
  194. padding: 20px;
  195. margin-bottom: 20px;
  196. h3 {
  197. font-size: 15px;
  198. margin-bottom: 16px;
  199. padding-bottom: 10px;
  200. border-bottom: 1px solid var(--border);
  201. }
  202. .section-header {
  203. display: flex;
  204. justify-content: space-between;
  205. align-items: center;
  206. margin-bottom: 16px;
  207. padding-bottom: 10px;
  208. border-bottom: 1px solid var(--border);
  209. h3 {
  210. margin: 0;
  211. border: none;
  212. padding: 0;
  213. }
  214. }
  215. }
  216. .source-file-list {
  217. .source-file-item {
  218. display: flex;
  219. align-items: center;
  220. gap: 12px;
  221. padding: 12px;
  222. background: var(--bg);
  223. border-radius: 8px;
  224. margin-bottom: 8px;
  225. .sf-icon {
  226. font-size: 24px;
  227. }
  228. .sf-info {
  229. flex: 1;
  230. .sf-name {
  231. font-weight: 600;
  232. margin-bottom: 2px;
  233. }
  234. .sf-desc {
  235. font-size: 12px;
  236. color: var(--text-3);
  237. }
  238. }
  239. }
  240. }
  241. .stat-item {
  242. display: flex;
  243. justify-content: space-between;
  244. padding: 10px 0;
  245. border-bottom: 1px solid var(--border);
  246. &:last-child {
  247. border-bottom: none;
  248. }
  249. .stat-label {
  250. color: var(--text-2);
  251. }
  252. .stat-value {
  253. font-weight: 600;
  254. }
  255. }
  256. </style>