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

修改上传时的命名逻辑

Huanyi 2 месяцев назад
Родитель
Сommit
c2ae7dda18
6 измененных файлов с 117 добавлено и 59 удалено
  1. 2 0
      .env.development
  2. 2 0
      .env.production
  3. 19 0
      apis/scan.js
  4. 4 4
      package.json
  5. 88 52
      pages/scan/folderSelect/index.vue
  6. 2 3
      utils/request.js

+ 2 - 0
.env.development

@@ -0,0 +1,2 @@
+# API 基础路径
+VITE_API_BASE_URL=http://192.168.1.118:8080

+ 2 - 0
.env.production

@@ -0,0 +1,2 @@
+# API 基础路径
+VITE_API_BASE_URL=https://api.example.com

+ 19 - 0
apis/scan.js

@@ -124,3 +124,22 @@ export const uploadNew = (data) => {
     data
   })
 }
+
+/**
+ * 上传扫描文件到指定项目和中心
+ * @param {Object} data - 上传数据
+ * @param {Number} data.projectId - 项目ID
+ * @param {Number} data.country - 国家ID(0表示NA)
+ * @param {Number} data.center - 中心ID(0表示NA)
+ * @param {String} data.name - 完整文件名
+ * @param {String} data.effectiveDate - 生效日期(格式:YYYYMMDD)
+ * @param {Array<String>} data.files - 文件列表(base64格式)
+ * @returns {Promise}
+ */
+export const uploadScanFile = (data) => {
+  return request({
+    url: '/applet/scan/upload',
+    method: 'POST',
+    data
+  })
+}

+ 4 - 4
package.json

@@ -5,10 +5,10 @@
   "main": "main.js",
   "type": "module",
   "scripts": {
-    "dev:mp-weixin": "uni -p mp-weixin",
-    "build:mp-weixin": "uni build -p mp-weixin",
-    "dev:h5": "uni",
-    "build:h5": "uni build"
+    "dev:mp-weixin": "uni -p mp-weixin --mode development",
+    "build:mp-weixin": "uni build -p mp-weixin --mode production",
+    "dev:h5": "uni --mode development",
+    "build:h5": "uni build --mode production"
   },
   "dependencies": {
     "@dcloudio/uni-app": "^3.0.0-alpha-4020220360004",

+ 88 - 52
pages/scan/folderSelect/index.vue

@@ -43,69 +43,52 @@
           </picker>
         </view>
         
-        <!-- 名称输入 -->
+        <!-- 名称和生效日期合并 -->
         <view class="form-item highlight-item">
           <view class="form-label required">名称:</view>
           <view class="input-wrapper highlight">
             <input
-              v-model="fileName"
+              v-model="documentName"
               type="text"
-              placeholder="请输入名"
+              placeholder="请输入具体文档名"
               class="input-field"
             />
           </view>
-        </view>
-        
-        <!-- 生效日期选择 -->
-        <view class="form-item">
-          <view class="form-label">生效日期:</view>
-          <picker 
-            mode="date" 
-            :value="effectiveDate"
-            @change="handleDateChange"
-          >
-            <view class="picker-display">
-              <text class="picker-text" :class="{ placeholder: !effectiveDate }">
-                {{ effectiveDate || '请选择生效日期' }}
-              </text>
-              <text class="picker-arrow">›</text>
-            </view>
-          </picker>
+          <view class="date-picker-wrapper">
+            <picker 
+              mode="date" 
+              :value="effectiveDate"
+              @change="handleDateChange"
+            >
+              <view class="picker-display">
+                <text class="picker-text" :class="{ placeholder: !effectiveDate }">
+                  {{ effectiveDate || '请输入生效日期' }}
+                </text>
+                <text class="picker-arrow">›</text>
+              </view>
+            </picker>
+          </view>
+          <view class="final-name-preview">
+            <text class="preview-label">完整名称预览:</text>
+            <text class="preview-text">{{ getFinalName() }}</text>
+          </view>
         </view>
         
         <!-- 提交按钮 -->
         <button 
           class="confirm-btn" 
-          :disabled="selectedCountryIndex < 0 || selectedCenterIndex < 0 || !fileName.trim()"
+          :disabled="selectedCountryIndex < 0 || selectedCenterIndex < 0 || !documentName.trim()"
           @click="handleSubmit"
         >
           提交
         </button>
-        
-        <!-- 调试信息 -->
-        <view class="debug-section">
-          <view class="debug-title">调试信息:</view>
-          <view class="debug-item">国家数量: {{ countryList.length }}</view>
-          <view class="debug-item">中心数量: {{ centerList.length }}</view>
-          <view class="debug-item">选中国家: {{ selectedCountryIndex === -1 ? '未选择' : countryList[selectedCountryIndex]?.name }}</view>
-          <view class="debug-item">选中中心: {{ selectedCenterIndex === -1 ? '未选择' : centerList[selectedCenterIndex]?.name }}</view>
-        </view>
-        
-        <!-- 原始数据展示 -->
-        <view class="raw-data-section">
-          <view class="raw-data-title" @click="showRawData = !showRawData">
-            原始数据 {{ showRawData ? '▼' : '▶' }}
-          </view>
-          <view v-if="showRawData" class="json-display">{{ JSON.stringify(rawData, null, 2) }}</view>
-        </view>
-      </view>
+		</view>
     </view>
   </view>
 </template>
 
 <script>
-import { getFolderList } from '@/apis/scan'
-import request from '@/utils/request.js'
+import { getFolderList, uploadScanFile } from '@/apis/scan'
 
 export default {
   data() {
@@ -128,8 +111,8 @@ export default {
       centerList: [],
       selectedCenterIndex: 0, // 默认选中第一个(NA)
       
-      // 名称输入
-      fileName: '',
+      // 文档名称输入
+      documentName: '',
       
       // 生效日期
       effectiveDate: ''
@@ -341,6 +324,28 @@ export default {
       console.log('选择的生效日期:', this.effectiveDate)
     },
     
+    // 格式化日期为 YYYYMMDD 格式
+    formatDate(dateStr) {
+      if (!dateStr) return ''
+      // 将 2026-01-21 转换为 20260121
+      return dateStr.replace(/-/g, '')
+    },
+    
+    // 获取名称前缀(项目名-中心ID)
+    getNamePrefix() {
+      const center = this.centerList[this.selectedCenterIndex]
+      const centerId = center && center.id !== 'NA' ? center.id : 'NA'
+      return `${this.projectName}-${centerId}-`
+    },
+    
+    // 获取最终完整名称
+    getFinalName() {
+      const prefix = this.getNamePrefix()
+      const docName = this.documentName.trim() || '[请输入具体文档名]'
+      const date = this.formatDate(this.effectiveDate) || '[请输入生效日期]'
+      return `${prefix}${docName}-${date}`
+    },
+    
     // 获取所有不属于任何国家的中心
     getIndependentCenters() {
       // 收集所有国家下的中心ID
@@ -407,9 +412,17 @@ export default {
         return
       }
       
-      if (!this.fileName.trim()) {
+      if (!this.documentName.trim()) {
         uni.showToast({
-          title: '请输入名称',
+          title: '请输入具体文档名',
+          icon: 'none'
+        })
+        return
+      }
+      
+      if (!this.effectiveDate) {
+        uni.showToast({
+          title: '请输入生效日期',
           icon: 'none'
         })
         return
@@ -436,12 +449,13 @@ export default {
         })
         
         // 构建请求参数
+        const finalName = this.getFinalName()
         const params = {
           projectId: this.projectId,
           country: selectedCountry.id === 'NA' ? 0 : selectedCountry.id,
           center: selectedCenter.id === 'NA' ? 0 : selectedCenter.id,
-          name: this.fileName.trim(),
-          effectiveDate: this.effectiveDate || '',
+          name: finalName,
+          effectiveDate: this.formatDate(this.effectiveDate),
           files: fileBase64List
         }
         
@@ -449,11 +463,7 @@ export default {
         console.log('params:', params)
         
         // 调用上传接口
-        const response = await request({
-          url: '/applet/scan/upload',
-          method: 'POST',
-          data: params
-        })
+        const response = await uploadScanFile(params)
         
         console.log('========== 上传响应 ==========')
         console.log('response:', response)
@@ -601,6 +611,32 @@ export default {
       margin-bottom: 16rpx;
     }
     
+    .date-picker-wrapper {
+      margin-top: 16rpx;
+    }
+    
+    .final-name-preview {
+      margin-top: 16rpx;
+      padding: 20rpx 24rpx;
+      background: #f5f5f5;
+      border-radius: 12rpx;
+      border: 2rpx dashed #cccccc;
+      
+      .preview-label {
+        font-size: 24rpx;
+        color: #666666;
+        display: block;
+        margin-bottom: 8rpx;
+      }
+      
+      .preview-text {
+        font-size: 26rpx;
+        color: #333333;
+        font-weight: 500;
+        word-break: break-all;
+      }
+    }
+    
     .input-wrapper {
       background: #ffffff;
       border: 2rpx solid #e0e0e0;

+ 2 - 3
utils/request.js

@@ -6,9 +6,8 @@ import { t } from './i18n.js'
 // 固定的 clientid
 const CLIENT_ID = '2f847927afb2b3ebeefc870c13d623f2'
 
-// 基础 URL(根据实际情况修改)
-// const BASE_URL = 'https://www.production.com/api'
-const BASE_URL = 'http://192.168.1.118:8080'
+// 基础 URL(从环境变量读取)
+const BASE_URL = import.meta.env.VITE_API_BASE_URL
 
 /**
  * 获取当前语言环境