From 0264677110e0bf49897e1b7af0551af3f406e193 Mon Sep 17 00:00:00 2001
From: spring <2396852758@qq.com>
Date: 星期四, 19 三月 2026 10:33:50 +0800
Subject: [PATCH] fix: 原料检上传附件按钮点击无响应
---
src/pages/qualityManagement/rawMaterial/files.vue | 130 ++++++++++++++++++++++++++++++++++++++-----
1 files changed, 114 insertions(+), 16 deletions(-)
diff --git a/src/pages/qualityManagement/rawMaterial/files.vue b/src/pages/qualityManagement/rawMaterial/files.vue
index 32842f4..8668373 100644
--- a/src/pages/qualityManagement/rawMaterial/files.vue
+++ b/src/pages/qualityManagement/rawMaterial/files.vue
@@ -18,7 +18,7 @@
</view>
<view class="upload-bar">
- <view class="btn-upload" @click="chooseFile">涓婁紶闄勪欢</view>
+ <view class="btn-upload" @tap="chooseFile">涓婁紶闄勪欢</view>
</view>
</view>
</template>
@@ -48,15 +48,46 @@
uni.showToast({ title: '缂哄皯妫�楠岃褰旾D', icon: 'none' })
return
}
- uni.chooseFile({
- count: 1,
- success: (res) => {
- const path = res?.tempFiles?.[0]?.path
- const name = res?.tempFiles?.[0]?.name
- if (!path) return
- uploadOne(path, name)
+ const pickByChooseFile = () => {
+ if (typeof uni.chooseFile !== 'function') return false
+ uni.chooseFile({
+ count: 1,
+ success: (res) => {
+ const file = res?.tempFiles?.[0]
+ const path = file?.path
+ const name = file?.name
+ if (!path) return
+ uploadOne(path, name)
+ },
+ fail: () => {
+ // chooseFile 鍦ㄩ儴鍒� App 鏈哄瀷/鍩哄骇鍙兘浼氬け璐ワ紝鍋氶檷绾�
+ pickByChooseImage()
+ }
+ })
+ return true
+ }
+
+ const pickByChooseImage = () => {
+ if (typeof uni.chooseImage !== 'function') {
+ uni.showToast({ title: '褰撳墠鐗堟湰涓嶆敮鎸侀�夋嫨鏂囦欢', icon: 'none' })
+ return
}
- })
+ uni.chooseImage({
+ count: 1,
+ success: (res) => {
+ const path = res?.tempFilePaths?.[0]
+ if (!path) return
+ uploadOne(path, '鍥剧墖闄勪欢')
+ },
+ fail: () => {
+ uni.showToast({ title: '閫夋嫨澶辫触', icon: 'none' })
+ }
+ })
+ }
+
+ // App/H5 缁熶竴璧� chooseFile锛屽け璐ユ椂闄嶇骇 chooseImage
+ const ok = pickByChooseFile()
+ if (!ok) pickByChooseImage()
}
const uploadOne = (filePath, originalName) => {
@@ -97,12 +128,69 @@
}
const previewFile = (f) => {
- const url = f?.url
+ const rawUrl = f?.url
+ if (!rawUrl) return
+
+ const url = normalizeUrl(rawUrl)
+ const name = f?.name || '闄勪欢'
if (!url) return
- // H5/APP 缁熶竴鐢ㄥ閮ㄦ墦寮�
- uni.navigateTo({
- url: `/pages/inspectionUpload/filePreview?url=${encodeURIComponent(url)}`
+
+ // 鍥剧墖浼樺厛鐢ㄥ師鐢熼瑙�
+ if (isImageUrl(url) || isImageName(name)) {
+ uni.previewImage({ urls: [url] })
+ return
+ }
+
+ // 闈炲浘鐗囷細涓嬭浇鍚庢墦寮�
+ const token = getToken()
+ uni.showLoading({ title: '鎵撳紑涓�...', mask: true })
+ uni.downloadFile({
+ url,
+ header: token ? { Authorization: 'Bearer ' + token } : undefined,
+ success: (res) => {
+ const filePath = res?.tempFilePath
+ if (!filePath) {
+ uni.hideLoading()
+ uni.showToast({ title: '鎵撳紑澶辫触', icon: 'none' })
+ return
+ }
+ uni.openDocument({
+ filePath,
+ showMenu: true,
+ success: () => {
+ uni.hideLoading()
+ },
+ fail: () => {
+ uni.hideLoading()
+ uni.showToast({ title: '鎵撳紑澶辫触', icon: 'none' })
+ }
+ })
+ },
+ fail: () => {
+ uni.hideLoading()
+ uni.showToast({ title: '涓嬭浇澶辫触', icon: 'none' })
+ }
})
+}
+
+const normalizeUrl = (u) => {
+ const s = String(u || '').trim()
+ if (!s) return ''
+ if (s.startsWith('http://') || s.startsWith('https://')) return s
+ if (s.startsWith('//')) return 'https:' + s
+ // 绯荤粺閲岄檮浠堕瑙�/涓嬭浇涓�鑸蛋 fileUrl
+ if (s.startsWith('/')) return `${config.fileUrl}${s}`
+ return `${config.fileUrl}/${s.replace(/^\//, '')}`
+}
+
+const isImageName = (name) => {
+ const n = String(name || '').toLowerCase()
+ return /\.(png|jpe?g|gif|bmp|webp|heic)$/.test(n)
+}
+
+const isImageUrl = (url) => {
+ const u = String(url || '').toLowerCase()
+ return /\.(png|jpe?g|gif|bmp|webp|heic)(\?|#|$)/.test(u)
}
const confirmDelete = (f) => {
@@ -148,12 +236,22 @@
.file-list { margin: 24rpx; background: #fff; border-radius: 16rpx; padding: 12rpx 24rpx; }
.file-item { padding: 20rpx 0; border-bottom: 1rpx solid #eee; display: flex; justify-content: space-between; align-items: center; gap: 16rpx; }
.file-item:last-child { border-bottom: 0; }
-.file-name { font-size: 28rpx; color: #333; }
-.file-actions { display: flex; gap: 20rpx; }
+.file-info { flex: 1; min-width: 0; }
+.file-name {
+ display: block;
+ width: 420rpx;
+ max-width: 100%;
+ font-size: 28rpx;
+ color: #333;
+ overflow: hidden;
+ text-overflow: ellipsis;
+ white-space: nowrap;
+}
+.file-actions { display: flex; gap: 20rpx; flex-shrink: 0; }
.btn-link { color: #2979ff; font-size: 26rpx; }
.btn-link.danger { color: #f56c6c; }
.empty { text-align: center; padding: 60rpx 0; color: #999; font-size: 28rpx; }
-.upload-bar { position: fixed; left: 0; right: 0; bottom: 0; padding: 16rpx 24rpx calc(16rpx + env(safe-area-inset-bottom)); background: #fff; box-shadow: 0 -4rpx 16rpx rgba(0,0,0,0.04); }
+.upload-bar { position: fixed; left: 0; right: 0; bottom: 0; padding: 16rpx 24rpx calc(16rpx + env(safe-area-inset-bottom)); background: #fff; box-shadow: 0 -4rpx 16rpx rgba(0,0,0,0.04); z-index: 20; }
.btn-upload { height: 88rpx; border-radius: 999rpx; background: #2979ff; color: #fff; font-size: 30rpx; display: flex; align-items: center; justify-content: center; }
</style>
--
Gitblit v1.9.3