zhangwencui
5 天以前 b39e0358272ba224a7659fa2ed262c00e790ff0b
src/pages/equipmentManagement/upkeep/maintain.vue
@@ -41,7 +41,7 @@
                 clearable />
      </u-form-item>
      <u-form-item label="保养状态"
                   prop="status"
                   prop="maintenancestatusText"
                   required
                   border-bottom>
        <u-input v-model="maintenancestatusText"
@@ -96,7 +96,7 @@
                      style="margin-right: 5px;"></u-icon>
              {{ uploading ? '上传中...' : '拍照' }}
            </u-button>
            <u-button type="success"
            <!-- <u-button type="success"
                      @click="chooseMedia('video')"
                      :loading="uploading"
                      :disabled="uploadFiles.length >= uploadConfig.limit"
@@ -107,7 +107,7 @@
                         color="#fff"
                         style="margin-right: 5px;"></uni-icons>
              {{ uploading ? '上传中...' : '拍视频' }}
            </u-button>
            </u-button> -->
          </view>
          <!-- 上传进度 -->
          <view v-if="uploading"
@@ -123,8 +123,9 @@
                  :key="index"
                  class="file-item">
              <view class="file-preview-container">
                <!-- {{formatFileUrl(file.url)}} -->
                <image v-if="file.type === 'image' || isImageFile(file)"
                       :src="file.url || file.tempFilePath || file.path || file.downloadUrl"
                       :src="formatFileUrl(file.url || file.tempFilePath || file.path || file.downloadUrl)"
                       class="file-preview"
                       mode="aspectFill" />
                <view v-else-if="file.type === 'video'"
@@ -153,7 +154,7 @@
          </view>
          <view v-if="uploadFiles.length === 0"
                class="empty-state">
            <text>请选择要上传的保养图片或视频</text>
            <text>请选择要上传的保养图片</text>
          </view>
        </view>
      </u-form-item>
@@ -591,7 +592,6 @@
      await fetchSparePartOptions(pageId);
    }
    // 页面显示时初始化表单
    initForm();
  });
  const sparePartOptions = ref([]);
  const fetchSparePartOptions = deviceLedgerId => {
@@ -634,26 +634,26 @@
  };
  // 格式化文件URL
  const formatFileUrl = url => {
    if (!url) return "";
  // const formatFileUrl = url => {
  //   if (!url) return "";
    // 如果已经是完整的URL(http或https开头),直接返回
    if (url.startsWith("http://") || url.startsWith("https://")) {
      return url;
    }
  //   // 如果已经是完整的URL(http或https开头),直接返回
  //   if (url.startsWith("http://") || url.startsWith("https://")) {
  //     return url;
  //   }
    // 如果是本地路径(如 D:\\ruoyi\\prod\\uploads...),需要转换为网络URL
    // 从路径中提取uploads后面的部分
    const uploadsIndex = url.indexOf("uploads");
    if (uploadsIndex !== -1) {
      const relativePath = url.substring(uploadsIndex);
      // 使用baseUrl + /profile/ + 相对路径
      return `http://192.168.1.35:8888/profile/${relativePath}`;
    }
  //   // 如果是本地路径(如 D:\\ruoyi\\prod\\uploads...),需要转换为网络URL
  //   // 从路径中提取uploads后面的部分
  //   const uploadsIndex = url.indexOf("uploads");
  //   if (uploadsIndex !== -1) {
  //     const relativePath = url.substring(uploadsIndex);
  //     // 使用baseUrl + /profile/ + 相对路径
  //     return `http://192.168.1.35:8888/profile/${relativePath}`;
  //   }
    // 其他情况,尝试直接拼接
    return `http://192.168.1.35:8888/profile/${url}`;
  };
  //   // 其他情况,尝试直接拼接
  //   return `http://192.168.1.35:8888/profile/${url}`;
  // };
  // 格式化文件大小
  const formatFileSize = size => {
@@ -920,6 +920,18 @@
        uploadProgress.value = res.progress;
      });
    }
  }; // 格式化文件URL
  const formatFileUrl = url => {
    if (!url) return "";
    if (url.startsWith("http://") || url.startsWith("https://")) {
      return url;
    }
    // const uploadsIndex = url.indexOf("uploads");
    // if (uploadsIndex !== -1) {
    //   const relativePath = url.substring(uploadsIndex);
    //   return `${config.fileUrl}/${relativePath}`;
    // }
    return `${config.fileUrl}/${url}`;
  };
  // 上传成功处理