chenkun 1 ماه پیش
والد
کامیت
e2c80199b3
2فایلهای تغییر یافته به همراه77 افزوده شده و 61 حذف شده
  1. 3 2
      src/api/document.ts
  2. 74 59
      src/views/documents/Index.vue

+ 3 - 2
src/api/document.ts

@@ -17,9 +17,10 @@ export interface DocumentItem {
   whether_to_enter: number
   conversion_status: number
   conversion_progress: number
-  converted_file_name?: string
-  converted_file_url?: string
+  md_url?: string
   json_url?: string
+  md_display_name?: string
+  json_display_name?: string
   conversion_error?: string
   error_message?: string // 兼容旧代码
   created_by?: string

+ 74 - 59
src/views/documents/Index.vue

@@ -121,25 +121,30 @@
           </template>
         </el-table-column>
 
-        <el-table-column label="转换进度" min-width="180">
+        <el-table-column label="转换状态" min-width="180">
           <template #default="scope">
             <div class="conversion-cell">
-              <el-progress 
-                :percentage="scope.row.conversion_progress || 0" 
-                :stroke-width="12" 
-                :text-inside="true"
-                :status="getProgressStatus(scope.row)"
-              />
-              <div class="converted-file-name" v-if="scope.row.converted_file_name">
-                <el-link type="primary" :underline="false" @click="handleDownloadConverted(scope.row)">
-                  <el-icon><Link /></el-icon> 下载转换后文件
-                </el-link>
-              </div>
-              <div class="converted-file-name" v-if="scope.row.json_url">
-                <el-link type="success" :underline="false" @click="handleDownloadJson(scope.row)">
-                  <el-icon><Link /></el-icon> 下载转换后 JSON
-                </el-link>
-              </div>
+              <el-tag 
+                :type="getConversionStatusTag(scope.row)"
+                size="small"
+                effect="light"
+                class="status-tag"
+              >
+                {{ getConversionStatusText(scope.row) }}
+              </el-tag>
+              
+              <div class="converted-file-links" v-if="scope.row.conversion_status === 2">
+                 <div class="converted-file-name" v-if="scope.row.md_url">
+                   <el-link type="primary" :underline="false" @click="handleDownloadConverted(scope.row)">
+                     <el-icon><Link /></el-icon> {{ scope.row.md_display_name || '下载 Markdown' }}
+                   </el-link>
+                 </div>
+                 <div class="converted-file-name" v-if="scope.row.json_url">
+                   <el-link type="success" :underline="false" @click="handleDownloadJson(scope.row)">
+                     <el-icon><Link /></el-icon> {{ scope.row.json_display_name || '下载 JSON' }}
+                   </el-link>
+                 </div>
+               </div>
             </div>
           </template>
         </el-table-column>
@@ -155,13 +160,7 @@
           </template>
         </el-table-column>
 
-        <el-table-column prop="validity" label="效力" width="80" align="center">
-          <template #default="scope">
-            <el-tag size="small" :type="getValidityTagType(scope.row.validity)">
-              {{ scope.row.validity || '现行' }}
-            </el-tag>
-          </template>
-        </el-table-column>
+
 
         <el-table-column label="操作" width="260" fixed="right" align="center">
           <template #default="scope">
@@ -534,19 +533,7 @@ const formatDate = (date: string, formatStr: string = 'YYYY-MM-DD HH:mm:ss') =>
   return date ? dayjs(date).format(formatStr) : '-'
 }
 
-const getValidityTagType = (validity: string | null) => {
-  if (!validity) return 'info'
-  switch (validity) {
-    case '现行':
-      return 'success'
-    case '已废止':
-      return 'danger'
-    case '被替代':
-      return 'warning'
-    default:
-      return 'info'
-  }
-}
+
 
 const getFileExtension = (row: DocumentItem) => {
   // 1. 优先使用数据库存储的后缀
@@ -744,10 +731,22 @@ const isEntered = (val: any) => {
   return val === 1 || val === true
 }
 
-const getProgressStatus = (row: DocumentItem) => {
-  if (row.conversion_status === 3) return 'exception'
-  if (row.conversion_progress === 100) return 'success'
-  return ''
+const getConversionStatusTag = (row: DocumentItem) => {
+  switch (row.conversion_status) {
+    case 1: return 'warning'   // 转换中
+    case 2: return 'success'   // 成功
+    case 3: return 'danger'    // 失败
+    default: return 'info'     // 未转换 (0)
+  }
+}
+
+const getConversionStatusText = (row: DocumentItem) => {
+  switch (row.conversion_status) {
+    case 1: return '转换中'
+    case 2: return '转换成功'
+    case 3: return '转换失败'
+    default: return '未转换'
+  }
 }
 
 const fetchDocuments = async () => {
@@ -985,11 +984,9 @@ const handleDownload = (row: DocumentItem) => {
 }
 
 const handleDownloadConverted = (row: DocumentItem) => {
-  if (row.converted_file_name) {
-    // 提取后缀,默认为 md
-    const ext = row.converted_file_name.split('.').pop() || 'md'
-    const filename = `${row.title}_转换后.${ext}`
-    downloadFile(row.converted_file_name, filename)
+  if (row.md_url) {
+    const filename = row.md_display_name || `${row.title}.md`
+    downloadFile(row.md_url, filename)
   } else {
     ElMessage.warning('该文档暂无转换后的文件')
   }
@@ -997,7 +994,7 @@ const handleDownloadConverted = (row: DocumentItem) => {
 
 const handleDownloadJson = (row: DocumentItem) => {
   if (row.json_url) {
-    const filename = `${row.title}_转换后.json`
+    const filename = row.json_display_name || `${row.title}.json`
     downloadFile(row.json_url, filename)
   } else {
     ElMessage.warning('该文档暂无转换后的 JSON 文件')
@@ -1006,9 +1003,8 @@ const handleDownloadJson = (row: DocumentItem) => {
 
 const handleConvert = async (row: DocumentItem) => {
   try {
-    // 乐观更新:重置进度
+    // 乐观更新:设置状态为转换中
     row.conversion_status = 1
-    row.conversion_progress = 0
     row.conversion_error = null
     
     const res = await documentApi.convert(row.id)
@@ -1215,22 +1211,41 @@ onUnmounted(() => {
   color: #909399;
 }
 
-.converted-file-name {
-  font-size: 11px;
-  color: #409eff;
-  white-space: nowrap;
-  overflow: hidden;
-  text-overflow: ellipsis;
-  margin-top: 2px;
+.conversion-cell {
   display: flex;
-  align-items: center;
+  flex-direction: column;
+  align-items: flex-start;
   gap: 4px;
+  padding: 2px 0;
 }
 
-.conversion-cell {
+.status-tag {
+  font-weight: 500;
+  margin-bottom: 2px;
+}
+
+.converted-file-links {
   display: flex;
   flex-direction: column;
-  gap: 4px;
+  gap: 0px;
+  width: 100%;
+}
+
+.converted-file-name {
+  font-size: 12px;
+  line-height: 1.2;
+  white-space: nowrap;
+  overflow: hidden;
+  text-overflow: ellipsis;
+}
+
+.converted-file-name :deep(.el-link) {
+  font-size: 12px;
+  justify-content: flex-start;
+}
+
+.converted-file-name :deep(.el-link .el-icon) {
+  margin-right: 4px;
 }
 
 .file-name-mini {