From 3fbd27c72ca85028eb842be9e747c907e240023c Mon Sep 17 00:00:00 2001 From: zm2000 <18386612143@163.com> Date: Tue, 21 Apr 2026 18:23:36 +0800 Subject: [PATCH] fix: optimize receiving UI and stabilize COS image upload --- components/inputAndSelect/inputAndSelect.vue | 25 +- components/uploadImgCos/uploadImgCos.vue | 406 +++++++++++++++--- pages/work/product/edit.vue | 90 +++- .../receiving/components/info-container.vue | 1 + pages/work/storage/receiving/receiving.vue | 2 +- .../storage/receiving/receivingCreate.vue | 2 +- .../work/storage/receiving/receivingList.vue | 117 +++-- 7 files changed, 535 insertions(+), 108 deletions(-) diff --git a/components/inputAndSelect/inputAndSelect.vue b/components/inputAndSelect/inputAndSelect.vue index eb3b1c7..21582b9 100644 --- a/components/inputAndSelect/inputAndSelect.vue +++ b/components/inputAndSelect/inputAndSelect.vue @@ -11,13 +11,12 @@ - - + > @@ -84,6 +83,10 @@ allowCreate: { type: Boolean, default: false + }, + searchBorder: { + type: String, + default: 'surround' } }, computed: { @@ -237,6 +240,18 @@ background-color: #f5f7fa; border-radius: 10rpx; padding: 0 20rpx; + min-height: 84rpx; + display: flex; + align-items: center; + + ::v-deep .u-input { + height: 76rpx; + } + + ::v-deep .u-input__content { + height: 76rpx; + align-items: center; + } } .quick-filter { diff --git a/components/uploadImgCos/uploadImgCos.vue b/components/uploadImgCos/uploadImgCos.vue index 2100c5e..987e8b7 100644 --- a/components/uploadImgCos/uploadImgCos.vue +++ b/components/uploadImgCos/uploadImgCos.vue @@ -44,7 +44,9 @@ export default { return { internalFileList: [], // 记录正在上传的文件,用于避免重复上传 - uploadingFiles: new Set() + uploadingFiles: new Set(), + // 记录最近一次getCOSUploadConfig请求使用的id(ReferenceFile必须使用该值) + lastUploadConfigRequestId: null }; }, computed: { @@ -98,6 +100,150 @@ export default { return filePath.split(/[\\/]/).pop(); }, + /** + * 解析本地可上传文件路径(相册/拍照兼容) + */ + resolveLocalFilePath(file) { + const candidates = [file?.path, file?.tempFilePath, file?.url, file?.thumb].filter(Boolean); + if (!candidates.length) { + return ''; + } + + const rawPath = String(candidates[0]); + try { + return decodeURIComponent(rawPath); + } catch (e) { + return rawPath; + } + }, + + /** + * 提取扩展名(不含.) + */ + extractExtension(value) { + if (!value || typeof value !== 'string') return ''; + const cleanValue = value.split('?')[0].split('#')[0]; + const baseName = cleanValue.split(/[\\/]/).pop() || ''; + const match = baseName.match(/\.([a-z0-9]+)$/i); + return match ? match[1].toLowerCase() : ''; + }, + + /** + * 解析图片扩展名(优先文件路径/文件名) + */ + resolveImageExtension(file, filePath = '') { + const fromPath = this.extractExtension(filePath || file?.url || file?.path || ''); + if (['png', 'jpg', 'jpeg', 'webp', 'gif'].includes(fromPath)) { + return fromPath === 'jpeg' ? 'jpg' : fromPath; + } + + const fromName = this.extractExtension(file?.name || ''); + if (['png', 'jpg', 'jpeg', 'webp', 'gif'].includes(fromName)) { + return fromName === 'jpeg' ? 'jpg' : fromName; + } + + const rawType = String(file?.type || '').toLowerCase(); + if (rawType.includes('png')) return 'png'; + if (rawType.includes('jpeg') || rawType.includes('jpg')) return 'jpg'; + if (rawType.includes('webp')) return 'webp'; + if (rawType.includes('gif')) return 'gif'; + + return 'jpg'; + }, + + /** + * 提取上传配置返回的fileId + */ + resolveUploadConfigFileId(configData) { + if (!configData || typeof configData !== 'object') { + return ''; + } + + return configData.fileId || configData.file_id || configData?.fileInfo?.fileId || configData?.fileInfo?.file_id || ''; + }, + + /** + * 解析上传地址(兼容不同后端字段) + */ + resolveUploadUrl(configData) { + if (!configData || typeof configData !== 'object') { + return ''; + } + + return configData.uploadUrl || + configData.upload_url || + configData.fileUrl || + configData.file_url || + configData.url || + configData.postUrl || + configData.post_url || + configData?.fileInfo?.uploadUrl || + configData?.fileInfo?.upload_url || + configData?.fileInfo?.fileUrl || + configData?.fileInfo?.file_url || + ''; + }, + + /** + * 归一化上传配置 + */ + normalizeUploadConfig(rawUploadConfig, fallbackFileInfo) { + const primary = rawUploadConfig?.data && typeof rawUploadConfig.data === 'object' + ? rawUploadConfig.data + : rawUploadConfig; + const nested = primary?.data && typeof primary.data === 'object' ? primary.data : null; + const source = nested || primary || {}; + + const uploadUrl = this.resolveUploadUrl(source) || this.resolveUploadUrl(primary) || this.resolveUploadUrl(rawUploadConfig); + const formData = source.data || source.formData || source.fields || source.params || {}; + const fileInfo = source.fileInfo || primary?.fileInfo || fallbackFileInfo || {}; + const fileId = this.resolveUploadConfigFileId(source) || this.resolveUploadConfigFileId(primary) || this.resolveUploadConfigFileId(rawUploadConfig); + const method = String(source.method || source.httpMethod || source.uploadMethod || source?.fileInfo?.method || '').toUpperCase(); + const fileFieldName = source.fileFieldName || source.fieldName || source.fileField || source?.fileInfo?.fileFieldName || 'file'; + const header = source.header || source.headers || source?.fileInfo?.header || source?.fileInfo?.headers || {}; + + return { + uploadUrl, + data: formData, + fileInfo, + fileId, + method: method || '', + fileFieldName, + header + }; + }, + + /** + * 规范化图片MIME类型 + */ + resolveImageMimeType(file) { + const extension = this.resolveImageExtension(file); + if (extension === 'png') return 'image/png'; + if (extension === 'webp') return 'image/webp'; + if (extension === 'gif') return 'image/gif'; + return 'image/jpeg'; + }, + + /** + * 确保文件名包含后缀 + */ + ensureFileNameWithExtension(fileName, fileType, filePath = '') { + let normalizedName = String(fileName || '').trim(); + if (!normalizedName) { + normalizedName = `image_${Date.now()}`; + } + + const cleanName = normalizedName.split('?')[0].split('#')[0]; + const expectedExt = `.${this.resolveImageExtension({ type: fileType, name: cleanName }, filePath)}`; + const hasExt = /\.[a-z0-9]+$/i.test(cleanName); + + if (!hasExt) { + return `${cleanName}${expectedExt}`; + } + + return cleanName.replace(/\.[a-z0-9]+$/i, expectedExt); + }, + /** * 获取文件MD5 */ @@ -112,6 +258,60 @@ export default { }); }, + /** + * 读取文件为ArrayBuffer(用于预签名PUT原始上传) + */ + readFileAsArrayBuffer(filePath) { + return new Promise((resolve, reject) => { + if (!uni.getFileSystemManager) { + reject(new Error('当前环境不支持文件系统读取')); + return; + } + + const fileSystemManager = uni.getFileSystemManager(); + fileSystemManager.readFile({ + filePath, + encoding: 'binary', + success: (res) => { + resolve(res.data); + }, + fail: (error) => { + reject(new Error(`读取文件失败: ${error?.errMsg || JSON.stringify(error)}`)); + } + }); + }); + }, + + /** + * 预签名PUT原始二进制上传 + */ + async uploadByRawPut(filePath, config) { + const fileBinary = await this.readFileAsArrayBuffer(filePath); + const requestHeader = { + 'Content-Type': config?.fileInfo?.fileType || 'application/octet-stream', + ...(config?.header || {}) + }; + + return new Promise((resolve, reject) => { + uni.request({ + url: config.uploadUrl, + method: 'PUT', + header: requestHeader, + data: fileBinary, + success: (res) => { + if (res.statusCode === 200 || res.statusCode === 201 || res.statusCode === 204) { + resolve(); + return; + } + reject(new Error(`COS原始PUT上传失败,状态码: ${res.statusCode}, 响应: ${typeof res.data === 'string' ? res.data : JSON.stringify(res.data)}`)); + }, + fail: (error) => { + reject(new Error(`COS原始PUT请求失败: ${error?.errMsg || JSON.stringify(error)}`)); + } + }); + }); + }, + /** @@ -158,7 +358,11 @@ export default { async processFileUpload(file, fileIndex) { try { // 检查是否已经在上传 - const fileKey = `${file.url}_${file.size}`; + const localFilePath = this.resolveLocalFilePath(file); + if (!localFilePath) { + throw new Error('未获取到可上传的本地文件路径'); + } + const fileKey = `${localFilePath}_${file.size}`; if (this.uploadingFiles.has(fileKey)) { return; } @@ -166,8 +370,11 @@ export default { this.uploadingFiles.add(fileKey); // 1. 获取文件MD5 - const fileInfo = await this.getFileMd5(file.url); - const fileName = this.extractFileName(file.url) || file.name; + const fileInfo = await this.getFileMd5(localFilePath); + const fileType = this.resolveImageMimeType(file); + const rawFileName = this.extractFileName(localFilePath) || file.name; + const fileName = this.ensureFileNameWithExtension(rawFileName, fileType, localFilePath); + const requestBusinessId = this.business_id; // 2. 更新状态为上传中 this.fileList[fileIndex] = { @@ -178,23 +385,39 @@ export default { }; // 3. 获取COS上传配置 + const getCosUploadConfigPayload = { + fileName, + fileSize: fileInfo.size, + fileType, + id: requestBusinessId, + md5: fileInfo.digest, + type: this.business_type, + }; + console.log('[API] index.getCOSUploadConfig request:', getCosUploadConfigPayload); const uploadConfig = await this.$http('common.getCOSUploadConfig', { - data: { - fileName, - fileSize: fileInfo.size, - fileType: file.type, - id: this.business_id, - md5: fileInfo.digest, - type: this.business_type, - } + data: getCosUploadConfigPayload }); - - const configData = uploadConfig.data; - if (!configData) { + console.log('[API] index.getCOSUploadConfig response:', uploadConfig); + + const fallbackFileInfo = { + fileName, + fileSize: fileInfo.size, + fileType, + md5: fileInfo.digest + }; + const configData = this.normalizeUploadConfig(uploadConfig, fallbackFileInfo); + console.log('[API] normalized COS config:', configData); + if (!configData || !configData.uploadUrl) { + console.error('[API] getCOSUploadConfig invalid response:', uploadConfig); throw new Error("获取上传配置失败"); } + const uploadConfigFileId = configData.fileId; + if (!uploadConfigFileId) { + console.warn('[API] index.getCOSUploadConfig response missing fileId, will fallback to index.uploadSuccessNotify fileId'); + } + this.lastUploadConfigRequestId = requestBusinessId; // 4. 执行COS上传(这里不会返回响应数据) - await this.uploadToCOS(file.url, configData, fileIndex); + await this.uploadToCOS(localFilePath, configData, fileIndex); // 5. 通知后端上传完成 @@ -202,13 +425,18 @@ export default { // 6. 更新状态为成功 if (notifyResult.data?.data) { - const { fileUrl, fileId } = notifyResult.data.data; + const { fileUrl, fileId: notifyFileId, file_id: notifyFileIdAlt } = notifyResult.data.data; + const finalFileId = uploadConfigFileId || notifyFileId || notifyFileIdAlt || ''; + if (!finalFileId) { + throw new Error('上传成功但未获取到fileId'); + } this.fileList[fileIndex] = { ...this.fileList[fileIndex], status: "success", message: "", url: fileUrl, - id: fileId, + id: finalFileId, + uploadConfigRequestId: requestBusinessId, successUrl: fileUrl // 保存成功后的URL }; @@ -223,6 +451,7 @@ export default { } catch (error) { console.error("上传流程失败:", error); + console.error('[API] index.getCOSUploadConfig/reference flow error:', error); this.fileList[fileIndex] = { ...this.fileList[fileIndex], status: "error", @@ -230,7 +459,8 @@ export default { }; } finally { // 清理上传记录 - const fileKey = `${file.url}_${file.size}`; + const localFilePath = this.resolveLocalFilePath(file); + const fileKey = `${localFilePath}_${file.size}`; this.uploadingFiles.delete(fileKey); } }, @@ -240,42 +470,91 @@ export default { */ uploadToCOS(filePath, config, fileIndex) { return new Promise((resolve, reject) => { - // COS上传不会返回数据,所以这里只是发起请求 - const uploadTask = uni.uploadFile({ - url: config.uploadUrl, // 应该从config中获取 - filePath: filePath, - name: 'file', - formData: config.data, - // COS上传成功不会有响应体,只会有状态码 - success: (res) => { - // 注意:COS返回的HTTP状态码成功通常是204或200,但没有响应体 - if (res.statusCode === 200 || res.statusCode === 204) { - resolve(); - } else { - reject(new Error(`COS上传失败,状态码: ${res.statusCode}`)); - } - }, - fail: (error) => { - reject(new Error("COS上传请求失败")); - } + if (!config?.uploadUrl) { + reject(new Error('COS上传地址为空(uploadUrl)')); + return; + } + const normalizedUploadUrl = String(config.uploadUrl || '').trim(); + const hasFormData = !!(config?.data && Object.keys(config.data).length); + const preferredMethod = config?.method || (hasFormData ? 'POST' : 'PUT'); + const fallbackMethod = preferredMethod === 'POST' ? 'PUT' : 'POST'; + const shouldTryRawPut = !hasFormData && preferredMethod === 'PUT'; + + console.log('[API] COS upload request:', { + uploadUrl: normalizedUploadUrl, + filePath, + method: preferredMethod, + fallbackMethod, + fileFieldName: config?.fileFieldName || 'file', + header: config?.header || {}, + formData: config?.data || {}, + fileName: config?.fileInfo?.fileName, + fileType: config?.fileInfo?.fileType }); - - // 可以监听上传进度 - uploadTask.onProgressUpdate = (res) => { - this.fileList[fileIndex] = { - ...this.fileList[fileIndex], - progress: res.progress, - message: `上传中 ${res.progress}%` - }; - - // 触发进度事件 - this.$emit('upload-progress', { - index: fileIndex, - progress: res.progress, - totalBytesSent: res.totalBytesSent, - totalBytesExpectedToSend: res.totalBytesExpectedToSend + + const tryUpload = (method) => new Promise((uploadResolve, uploadReject) => { + const uploadTask = uni.uploadFile({ + url: normalizedUploadUrl, + filePath: filePath, + name: config?.fileFieldName || 'file', + formData: config?.data || {}, + header: config?.header || {}, + method, + success: (res) => { + if (res.statusCode === 200 || res.statusCode === 201 || res.statusCode === 204) { + uploadResolve(); + } else { + uploadReject(new Error(`COS上传失败,状态码: ${res.statusCode}, 响应: ${typeof res.data === 'string' ? res.data : JSON.stringify(res.data)}`)); + } + }, + fail: (error) => { + uploadReject(new Error(`COS上传请求失败: ${error?.errMsg || JSON.stringify(error) || 'unknown error'}`)); + } }); + + uploadTask.onProgressUpdate((res) => { + this.fileList[fileIndex] = { + ...this.fileList[fileIndex], + progress: res.progress, + message: `上传中 ${res.progress}%` + }; + + this.$emit('upload-progress', { + index: fileIndex, + progress: res.progress, + totalBytesSent: res.totalBytesSent, + totalBytesExpectedToSend: res.totalBytesExpectedToSend + }); + }); + }); + + const runUploadFileFallback = () => { + tryUpload(preferredMethod) + .then(resolve) + .catch((firstError) => { + console.error('[API] COS upload fail detail:', firstError); + console.warn(`[API] COS upload retry with method: ${fallbackMethod}`); + tryUpload(fallbackMethod) + .then(resolve) + .catch((secondError) => { + console.error('[API] COS upload retry fail detail:', secondError); + reject(secondError); + }); + }); }; + + if (shouldTryRawPut) { + console.log('[API] COS raw PUT upload attempt'); + this.uploadByRawPut(filePath, config) + .then(resolve) + .catch((rawError) => { + console.error('[API] COS raw PUT upload fail detail:', rawError); + runUploadFileFallback(); + }); + return; + } + + runUploadFileFallback(); }); }, @@ -307,18 +586,25 @@ export default { async referenceFiles() { console.log("this.fileList",this.fileList); try { + const referenceId = this.lastUploadConfigRequestId || this.business_id; + // 获取所有成功的文件(包括之前已经关联的) const validFiles = this.fileList .filter(item => item.status === "success" && item.id) .map(item => ({ file_id: item.id })); if (validFiles.length === 0) { - // 如果没有成功文件,也要通知后端清空关联 - const response = await this.$http('common.ReferenceFile', { - id: this.business_id, + const referencePayload = { + id: referenceId, type: this.business_type, images: [] + }; + console.log('[API] index.ReferenceFile request:', referencePayload); + // 如果没有成功文件,也要通知后端清空关联 + const response = await this.$http('common.ReferenceFile', { + ...referencePayload }); + console.log('[API] index.ReferenceFile response:', response); // 更新外部绑定 this.$emit('change', this.fileList); @@ -326,11 +612,16 @@ export default { return response; } - const response = await this.$http('common.ReferenceFile', { - id: this.business_id, + const referencePayload = { + id: referenceId, type: this.business_type, images: validFiles + }; + console.log('[API] index.ReferenceFile request:', referencePayload); + const response = await this.$http('common.ReferenceFile', { + ...referencePayload }); + console.log('[API] index.ReferenceFile response:', response); // 更新外部绑定 this.$emit('change', this.fileList); @@ -339,6 +630,7 @@ export default { return response; } catch (error) { console.error("关联文件失败:", error); + console.error('[API] index.ReferenceFile error:', error); throw error; } }, diff --git a/pages/work/product/edit.vue b/pages/work/product/edit.vue index cc8e832..470c931 100644 --- a/pages/work/product/edit.vue +++ b/pages/work/product/edit.vue @@ -46,6 +46,19 @@ + + + + 支持jpg/png格式,单张不超过10MB + 请先保存一次商品后再上传图片 + + @@ -63,6 +76,7 @@ :show="showProhibitedPicker" :value="formData.prohibited_type_id" :itemFontSize="32" + searchBorder="none" :allowCreate="true" @change="handleProhibitedTypeChange" @create="handleProhibitedTypeCreate" @@ -75,6 +89,7 @@ :show="showStockUnitPicker" :value="formData.stock_unit_value" :itemFontSize="32" + searchBorder="none" :allowCreate="true" @change="handleStockUnitChange" @create="handleStockUnitCreate" @@ -103,6 +118,7 @@ export default { prohibited_type_name: '', gross_weight: '', net_weight: '', + images: [], stock_unit_value: '', stock_unit: '', tag_price: '', @@ -110,6 +126,11 @@ export default { } }; }, + computed: { + productImageBusinessId() { + return this.resolveWarehouseStockId(this.rawItem || {}) || 0; + } + }, onLoad(options) { this.cacheKey = (options && options.cacheKey) || ''; this.loadProhibitedTypes(); @@ -134,6 +155,7 @@ export default { this.formData.prohibited_type_name = String((cached.prohibited && cached.prohibited.type_name) || ''); this.formData.gross_weight = this.normalizeInputValue(cached.gross_weight); this.formData.net_weight = this.normalizeInputValue(cached.net_weight); + this.formData.images = this.normalizeImageListForUpload(cached); this.formData.stock_unit = String(cached.stock_unit || ''); this.formData.stock_unit_value = String(cached.stock_unit || ''); this.formData.tag_price = this.normalizeInputValue(cached.tag_price); @@ -181,10 +203,10 @@ export default { } const candidates = [ - item.id, item.stock_id, item.warehouse_stock_id, - item.storage_id + item.storage_id, + item.id ]; for (let i = 0; i < candidates.length; i++) { @@ -419,6 +441,56 @@ export default { } return String(value); }, + normalizeImageListForUpload(item) { + if (!item || typeof item !== 'object') { + return []; + } + + if (Array.isArray(item.images) && item.images.length > 0) { + return item.images + .map(image => { + if (!image) return null; + if (typeof image === 'string') { + return { url: image, status: 'success' }; + } + if (typeof image === 'object') { + const imageUrl = image.url || image.path || image.fileUrl || image.image_url; + if (!imageUrl) return null; + return { + ...image, + url: imageUrl, + status: image.status || 'success' + }; + } + return null; + }) + .filter(Boolean); + } + + const singleImage = item.image || item.image_url || item.img || item.pic || item.photo || item.cover || item.cover_url; + if (singleImage) { + return [{ url: String(singleImage), status: 'success' }]; + } + + return []; + }, + extractImageUrls(list) { + if (!Array.isArray(list)) { + return []; + } + + return list + .map(image => { + if (!image) return ''; + if (typeof image === 'string') return image; + if (typeof image === 'object') return image.url || image.path || image.successUrl || image.fileUrl || ''; + return ''; + }) + .filter(Boolean); + }, + handleImagesChange(nextImages) { + this.formData.images = Array.isArray(nextImages) ? [...nextImages] : []; + }, handleCancel() { uni.navigateBack({ delta: 1 @@ -501,6 +573,7 @@ export default { prohibited_type_name: String(this.formData.prohibited_type_name || '').trim(), gross_weight: grossWeight, net_weight: String(this.formData.net_weight || '').trim(), + images: this.extractImageUrls(this.formData.images), stock_unit: stockUnit, tag_price: String(this.formData.tag_price || '').trim(), retail_price: String(this.formData.retail_price || '').trim() @@ -548,6 +621,8 @@ export default { }, gross_weight: grossWeight, net_weight: String(this.formData.net_weight || '').trim(), + images: this.extractImageUrls(this.formData.images), + image: this.extractImageUrls(this.formData.images)[0] || '', stock_unit: stockUnit, tag_price: String(this.formData.tag_price || '').trim(), retail_price: String(this.formData.retail_price || '').trim() @@ -667,6 +742,17 @@ export default { color: #c0c4cc; } +.product-image-upload-wrap { + width: 100%; +} + +.product-image-tip { + display: block; + margin-top: 12rpx; + font-size: 24rpx; + color: #909399; +} + .safe-padding-bottom { height: 170rpx; } diff --git a/pages/work/storage/receiving/components/info-container.vue b/pages/work/storage/receiving/components/info-container.vue index f7405d7..1188d99 100644 --- a/pages/work/storage/receiving/components/info-container.vue +++ b/pages/work/storage/receiving/components/info-container.vue @@ -106,6 +106,7 @@ :list="storeList" :show="showStorePicker" :value="pendingStoreId" + searchBorder="none" @change="handleStoreChange" @close="showStorePicker = false" > diff --git a/pages/work/storage/receiving/receiving.vue b/pages/work/storage/receiving/receiving.vue index e950d0f..1ab5c4e 100644 --- a/pages/work/storage/receiving/receiving.vue +++ b/pages/work/storage/receiving/receiving.vue @@ -165,7 +165,7 @@ + searchBorder="none" @change="handleStoreChange" @close="showStore=false"> diff --git a/pages/work/storage/receiving/receivingCreate.vue b/pages/work/storage/receiving/receivingCreate.vue index 0b1323f..e12a9ba 100644 --- a/pages/work/storage/receiving/receivingCreate.vue +++ b/pages/work/storage/receiving/receivingCreate.vue @@ -95,7 +95,7 @@ + searchBorder="none" @change="handleStoreChange" @close="showStorePicker=false"> diff --git a/pages/work/storage/receiving/receivingList.vue b/pages/work/storage/receiving/receivingList.vue index 72c6028..9480924 100644 --- a/pages/work/storage/receiving/receivingList.vue +++ b/pages/work/storage/receiving/receivingList.vue @@ -3,9 +3,9 @@ :scroll-with-animation="scrollWithAnimation" @scroll="handleScroll"> - + - {{ receivingInfo.receiving_number }} @@ -17,7 +17,7 @@ - + 货主: {{ receivingInfo.store_name }} @@ -224,6 +224,7 @@ receivingInfo: {}, details: [], infoExpanded: true, + disableInfoTransition: false, scrollTopValue: 0, currentScrollTop: 0, scrollWithAnimation: true, @@ -267,12 +268,7 @@ }, showHeaderMask() { - if (!this.fixedHeader) { - return false - } - - const maskHeight = Number(this.fixedMaskHeight) - return Number.isFinite(maskHeight) ? maskHeight > 0 : !!this.fixedMaskHeight + return false }, infoHeaderStyle() { @@ -280,7 +276,16 @@ return {} } - const topValue = typeof this.fixedTop === 'number' ? `${this.fixedTop}px` : this.fixedTop + let topValue = this.fixedTop + if (typeof this.fixedTop === 'number' && typeof this.fixedMaskHeight === 'number') { + topValue = Math.max(this.fixedTop - this.fixedMaskHeight, 0) + topValue = `${topValue}px` + } else if (this.fixedMaskHeight) { + topValue = `calc(${this.fixedTop} - ${this.fixedMaskHeight})` + } else if (typeof this.fixedTop === 'number') { + topValue = `${this.fixedTop}px` + } + return { top: topValue } @@ -419,28 +424,27 @@ } if (!nextExpanded) { + if (this.currentScrollTop > 0) { + this.disableInfoTransition = true + this.infoExpanded = false + this.$nextTick(() => { + setTimeout(() => { + this.disableInfoTransition = false + }, 0) + }) + return + } + this.infoExpanded = false return } - if (this.currentScrollTop > 2) { - this.scrollWithAnimation = true - this.scrollTopValue = Math.ceil(this.currentScrollTop) - this.$nextTick(() => { - this.scrollTopValue = 0 - }) - - this.expandTimer = setTimeout(() => { - this.currentScrollTop = 0 - this.infoExpanded = true - this.expandTimer = null - }, 260) - return - } - if (this.currentScrollTop > 0) { this.scrollWithAnimation = false - this.scrollTopValue = 0 + this.scrollTopValue = Math.ceil(this.currentScrollTop) + this.$nextTick(() => { + this.scrollTopValue = 0 + }) this.expandTimer = setTimeout(() => { this.currentScrollTop = 0 this.infoExpanded = true @@ -448,7 +452,7 @@ this.scrollWithAnimation = true }) this.expandTimer = null - }, 20) + }, 30) return } @@ -493,28 +497,43 @@ background-color: #fff; margin: 20rpx; border-radius: 12rpx; - padding: 30rpx; + overflow: hidden; box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.05); + &.fixed.collapsed { + background-color: transparent; + box-shadow: none; + } + + &.no-transition, + &.no-transition .info-header, + &.no-transition .info-content { + transition: none !important; + } + .info-header { display: flex; justify-content: space-between; align-items: center; background-color: #fff; - margin-bottom: 30rpx; - padding-bottom: 20rpx; - border-bottom: 1rpx solid #f0f0f0; + padding: 20rpx 30rpx; + margin-bottom: 0; + border-bottom: none; + min-height: 96rpx; + transition: border-bottom-color 0.3s cubic-bezier(0.22, 1, 0.36, 1), box-shadow 0.3s cubic-bezier(0.22, 1, 0.36, 1), background-color 0.3s cubic-bezier(0.22, 1, 0.36, 1); &.fixed { position: fixed; - left: 40rpx; - right: 40rpx; + left: 20rpx; + right: 20rpx; z-index: 200; margin-bottom: 0; - padding: 18rpx 30rpx; - min-height: 76rpx; + padding: 20rpx 30rpx; + min-height: 96rpx; + box-sizing: border-box; border-radius: 12rpx; - box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.08); + box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.05); + border: none; } &.collapsed { @@ -565,8 +584,8 @@ .info-header-top-mask { position: fixed; - left: 40rpx; - right: 40rpx; + left: 20rpx; + right: 20rpx; z-index: 199; background-color: #fff; pointer-events: none; @@ -583,16 +602,30 @@ } .info-header-placeholder { - height: 76rpx; - margin-bottom: 24rpx; + height: 96rpx; + margin-bottom: 0; + background-color: #fff; &.collapsed { - height: 76rpx; + height: 96rpx; margin-bottom: 0; + background-color: transparent; } } .info-content { + padding: 0 30rpx 30rpx; + overflow: hidden; + max-height: 2200rpx; + opacity: 1; + transition: max-height 0.3s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.3s cubic-bezier(0.22, 1, 0.36, 1), padding 0.3s cubic-bezier(0.22, 1, 0.36, 1); + + &.collapsed { + max-height: 0; + opacity: 0; + padding-bottom: 0; + } + .info-item { display: flex; margin-bottom: 20rpx; @@ -626,7 +659,7 @@ .stats-card { display: flex; background-color: #fff; - margin: 20rpx; + margin: 20rpx 0; border-radius: 12rpx; padding: 30rpx 0;