Просмотр исходного кода

重新修改了文件上传逻辑

Huanyi 2 месяцев назад
Родитель
Сommit
9c57c4c06f

+ 5 - 6
apis/scan.js

@@ -65,8 +65,7 @@ export const uploadOnSubmit = (data) => {
 /**
  * 获取项目列表
  * @param {Object} params - 查询参数
- * @param {String} params.code - 项目编号(可选)
- * @param {String} params.name - 项目名称(可选)
+ * @param {String} params.content - 搜索内容(项目编号或名称)
  * @param {Number} params.pageNum - 页码
  * @param {Number} params.pageSize - 每页数量
  * @returns {Promise}
@@ -126,13 +125,13 @@ export const uploadNew = (data) => {
 }
 
 /**
- * 上传扫描文件到指定项目和中心
+ * 上传扫描文件到指定项目和文件夹
  * @param {Object} data - 上传数据
  * @param {Number} data.projectId - 项目ID
- * @param {Number} data.country - 国家ID(0表示NA
- * @param {Number} data.center - 中心ID(0表示NA)
+ * @param {Number} data.folder - 文件夹ID(中心ID或国家ID,如果都未选择则为0
+ * @param {String} data.specificName - 具体文档名
  * @param {String} data.name - 完整文件名
- * @param {String} data.effectiveDate - 生效日期(格式:YYYYMMDD)
+ * @param {String} data.effectiveDate - 生效日期(格式:YYYY-MM-DD HH:mm:ss
  * @param {Array<String>} data.files - 文件列表(base64格式)
  * @returns {Promise}
  */

+ 7 - 1
pages/home/index.vue

@@ -77,7 +77,7 @@
           >
             <image class="doc-thumbnail" :src="getFileIcon(doc.url)" mode="aspectFit" />
             <view class="doc-info">
-              <text class="doc-name">{{ doc.name }}</text>
+              <text class="doc-name">{{ formatDocName(doc.name) }}</text>
               <text class="doc-meta">{{ doc.createTime }}</text>
             </view>
           </view>
@@ -111,6 +111,7 @@ import { ref, onMounted } from 'vue'
 import { useI18n } from 'vue-i18n'
 import TabBar from '@/components/TabBar/index.vue'
 import { getCarouselList, getRecentDocuments } from '@/apis/setting'
+import { formatDocumentNameForDisplay } from '@/utils/documentName'
 
 const { t } = useI18n()
 
@@ -161,6 +162,11 @@ const getFileIcon = (url) => {
   return iconMap[extension] || '/static/icon/document.svg'
 }
 
+// 格式化文档名称用于显示
+const formatDocName = (name) => {
+  return formatDocumentNameForDisplay(name)
+}
+
 onMounted(() => {
   // 获取系统信息
   const windowInfo = uni.getWindowInfo()

+ 7 - 1
pages/my/taskDocuments/index.vue

@@ -63,7 +63,7 @@
           >
             <image class="doc-thumbnail" :src="getFileIcon(doc.url)" mode="aspectFit" />
             <view class="doc-info">
-              <text class="doc-name">{{ doc.name }}</text>
+              <text class="doc-name">{{ formatDocName(doc.name) }}</text>
               <view class="doc-meta">
                 <text class="meta-text">{{ t('taskDocuments.createTime') }}:{{ doc.createTime }}</text>
                 <text class="meta-text" v-if="doc.submitter">{{ t('taskDocuments.submitter') }}:{{ doc.submitter }}</text>
@@ -118,6 +118,7 @@
 import { ref, onMounted, computed } from 'vue'
 import { useI18n } from 'vue-i18n'
 import { getTaskDocuments, getRejection } from '@/apis/auth'
+import { formatDocumentNameForDisplay } from '@/utils/documentName'
 
 const { t } = useI18n()
 
@@ -198,6 +199,11 @@ const getFileIcon = (url) => {
   return iconMap[extension] || '/static/icon/document.svg'
 }
 
+// 格式化文档名称用于显示
+const formatDocName = (name) => {
+  return formatDocumentNameForDisplay(name)
+}
+
 onMounted(() => {
   // 获取系统信息
   const windowInfo = uni.getWindowInfo()

+ 65 - 12
pages/scan/folderSelect/index.vue

@@ -96,6 +96,7 @@ export default {
       statusBarHeight: 0,
       projectId: 0,
       projectName: '',
+      projectCode: '',
       rawData: null,
       loading: false,
       showRawData: false,
@@ -134,9 +135,11 @@ export default {
     
     this.projectId = parseInt(options.projectId) || 0
     this.projectName = decodeURIComponent(options.projectName || '')
+    this.projectCode = decodeURIComponent(options.projectCode || '')
     
     console.log('解析后的projectId:', this.projectId)
     console.log('解析后的projectName:', this.projectName)
+    console.log('解析后的projectCode:', this.projectCode)
   },
   onReady() {
     // 获取系统信息
@@ -324,26 +327,74 @@ export default {
       console.log('选择的生效日期:', this.effectiveDate)
     },
     
-    // 格式化日期为 YYYYMMDD 格式
+    // 格式化日期为 YYYYMMDD 格式(用于显示)
     formatDate(dateStr) {
       if (!dateStr) return ''
       // 将 2026-01-21 转换为 20260121
       return dateStr.replace(/-/g, '')
     },
     
-    // 获取名称前缀(项目名-中心ID)
-    getNamePrefix() {
+    // 格式化日期为 YYYY-MM-DD HH:mm:ss 格式(用于提交)
+    formatDateTimeForSubmit(dateStr) {
+      if (!dateStr) return ''
+      // 将 2026-01-21 转换为 2026-01-21 00:00:00
+      return `${dateStr} 00:00:00`
+    },
+    
+    // 获取文件夹ID(folder参数的逻辑)
+    getFolderId() {
+      const selectedCountry = this.countryList[this.selectedCountryIndex]
+      const selectedCenter = this.centerList[this.selectedCenterIndex]
+      
+      // 如果选择了中心(且不是NA),使用中心ID
+      if (selectedCenter && selectedCenter.id !== 'NA') {
+        return selectedCenter.id
+      }
+      
+      // 如果选择了国家(且不是NA),使用国家ID
+      if (selectedCountry && selectedCountry.id !== 'NA') {
+        return selectedCountry.id
+      }
+      
+      // 否则使用0
+      return 0
+    },
+    
+    // 获取完整名称(用于提交)
+    // 格式:{项目编号}-{国家名/NA}-{中心号/NA}-[具体文档名]-[生效日期]
+    getFullNameForSubmit() {
+      const projectCode = this.projectCode || 'NA'
+      
+      const country = this.countryList[this.selectedCountryIndex]
+      const countryName = country && country.id !== 'NA' ? country.name : 'NA'
+      
       const center = this.centerList[this.selectedCenterIndex]
       const centerId = center && center.id !== 'NA' ? center.id : 'NA'
-      return `${this.projectName}-${centerId}-`
+      
+      const docName = this.documentName.trim() || '[请输入具体文档名]'
+      const date = this.formatDate(this.effectiveDate) || '[请输入生效日期]'
+      
+      return `${projectCode}-${countryName}-${centerId}-${docName}-${date}`
     },
     
-    // 获取最终完整名称
+    // 获取显示名称(用于前端显示,NA时隐藏)
+    // 格式:{项目编号}-[国家名(如果不是NA)]-[中心号(如果不是NA)]-[具体文档名]-[生效日期]
     getFinalName() {
-      const prefix = this.getNamePrefix()
+      const projectCode = this.projectCode || 'NA'
+      
+      const country = this.countryList[this.selectedCountryIndex]
+      const countryName = country && country.id !== 'NA' ? country.name : ''
+      
+      const center = this.centerList[this.selectedCenterIndex]
+      const centerId = center && center.id !== 'NA' ? center.id : ''
+      
       const docName = this.documentName.trim() || '[请输入具体文档名]'
       const date = this.formatDate(this.effectiveDate) || '[请输入生效日期]'
-      return `${prefix}${docName}-${date}`
+      
+      // 构建名称数组,过滤掉空值
+      const nameParts = [projectCode, countryName, centerId, docName, date].filter(part => part !== '')
+      
+      return nameParts.join('-')
     },
     
     // 获取所有不属于任何国家的中心
@@ -449,13 +500,15 @@ export default {
         })
         
         // 构建请求参数
-        const finalName = this.getFinalName()
+        const fullName = this.getFullNameForSubmit()  // 完整名称用于提交
+        const folderId = this.getFolderId()
+        
         const params = {
           projectId: this.projectId,
-          country: selectedCountry.id === 'NA' ? 0 : selectedCountry.id,
-          center: selectedCenter.id === 'NA' ? 0 : selectedCenter.id,
-          name: finalName,
-          effectiveDate: this.formatDate(this.effectiveDate),
+          folder: folderId,
+          specificName: this.documentName.trim(),
+          name: fullName,
+          effectiveDate: this.formatDateTimeForSubmit(this.effectiveDate),
           files: fileBase64List
         }
         

+ 3 - 4
pages/scan/projectSelect/index.vue

@@ -161,10 +161,9 @@ const loadProjectList = async () => {
       pageSize: pageSize.value
     }
     
-    // 搜索关键词可以同时匹配项目名称和编号
+    // 搜索关键词使用 content 参数
     if (searchName.value && searchName.value.trim()) {
-      params.name = searchName.value.trim()
-      params.code = searchName.value.trim()
+      params.content = searchName.value.trim()
     }
     
     const response = await getProjectList(params)
@@ -220,7 +219,7 @@ const handleSelectProject = async (project) => {
   
   // 跳转到文件夹选择页面
   uni.navigateTo({
-    url: `/pages/scan/folderSelect/index?projectId=${project.id}&projectName=${encodeURIComponent(project.name)}`
+    url: `/pages/scan/folderSelect/index?projectId=${project.id}&projectName=${encodeURIComponent(project.name)}&projectCode=${encodeURIComponent(project.code)}`
   })
 }
 

+ 67 - 0
utils/documentName.js

@@ -0,0 +1,67 @@
+/**
+ * 文档名称处理工具
+ * 用于格式化文档名称的显示
+ */
+
+/**
+ * 格式化文档名称用于显示
+ * 规则:通过"-"拆分,消除其中的"NA",然后再用"-"合并
+ * 例如:
+ * - CHINESE01-NA-NA-张三文档计划-20260131 -> CHINESE01-张三文档计划-20260131
+ * - PRJ001-中国-NA-文档名-20260121 -> PRJ001-中国-文档名-20260121
+ * - PRJ001-中国-59-文档名-20260121 -> PRJ001-中国-59-文档名-20260121
+ * 
+ * @param {String} name - 原始文档名称
+ * @returns {String} 格式化后的文档名称
+ */
+export const formatDocumentNameForDisplay = (name) => {
+  if (!name) return ''
+  
+  // 按 - 分割名称
+  const parts = name.split('-')
+  
+  // 过滤掉值为 'NA' 的部分
+  const filteredParts = parts.filter(part => part !== 'NA')
+  
+  // 重新组合
+  return filteredParts.join('-')
+}
+
+/**
+ * 解析文档名称的各个部分
+ * @param {String} name - 文档名称
+ * @returns {Object} 包含各部分的对象
+ */
+export const parseDocumentName = (name) => {
+  if (!name) {
+    return {
+      projectCode: '',
+      country: '',
+      center: '',
+      specificName: '',
+      effectiveDate: ''
+    }
+  }
+  
+  const parts = name.split('-')
+  
+  // 标准格式:{项目编号}-{国家名}-{中心号}-{具体文档名}-{生效日期}
+  if (parts.length >= 5) {
+    return {
+      projectCode: parts[0] || '',
+      country: parts[1] || '',
+      center: parts[2] || '',
+      specificName: parts.slice(3, -1).join('-') || '', // 中间部分可能包含多个-
+      effectiveDate: parts[parts.length - 1] || ''
+    }
+  }
+  
+  // 非标准格式,返回原始名称
+  return {
+    projectCode: '',
+    country: '',
+    center: '',
+    specificName: name,
+    effectiveDate: ''
+  }
+}