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

1.修复有时候上传动态图片闪退问题(由于测试无法复现,只能分析可能是多选图导致内存溢出) 2.隐藏锁屏页 试用已结束 字样

蒋开心 2 недель назад
Родитель
Сommit
a95d970116

+ 2 - 2
common/config/runtime-manifest.js

@@ -12,8 +12,8 @@ const ENDPOINTS = Object.freeze(
 )
 
 const IDENTITY = Object.freeze({
-	releaseLabel: '1.1.39',
-	numericBuild: '1139',
+	releaseLabel: '1.1.40',
+	numericBuild: '1140',
 	// 排查"看不到直播"期间临时开启,正式发布请改回 false
 	traceVerbose: false,
 	geoServiceKey: '',

+ 62 - 5
features/dynamics/publish-gateway.js

@@ -46,6 +46,56 @@ function parseUploadResponse(raw) {
 	return ''
 }
 
+/**
+ * 上传前解码并压缩图片,降低 App 端大图 / HEIC 导致的内存闪退。
+ * 
+ * @param {string} src
+ * @returns {Promise<string>} 可用于 uploadFile 的本地路径
+ */
+export function prepareImageForUpload(src) {
+	return new Promise((resolve) => {
+		const fallback = () => resolve(src || '')
+		if (!src) {
+			fallback()
+			return
+		}
+		const compress = (path, width = 0, height = 0) => {
+			if (typeof uni.compressImage !== 'function') {
+				resolve(path)
+				return
+			}
+			const opts = {
+				src: path,
+				quality: 60,
+				success: (res) => resolve((res && res.tempFilePath) || path),
+				fail: () => resolve(path)
+			}
+			const w = Number(width) || 0
+			const h = Number(height) || 0
+			if (w > 1280 || h > 1280) {
+				if (w >= h) opts.compressedWidth = 1280
+				else opts.compressedHeight = 1280
+			}
+			try {
+				uni.compressImage(opts)
+			} catch (_) {
+				resolve(path)
+			}
+		}
+		uni.getImageInfo({
+			src,
+			success: (info) => {
+				const path = (info && info.path) || src
+				compress(path, info && info.width, info && info.height)
+			},
+			fail: () => {
+				// 解码失败时仍尝试压缩原路径(部分机型 getImageInfo 对 HEIC 不稳定)
+				compress(src)
+			}
+		})
+	})
+}
+
 /**
  * 获取图片上传配置(wanlshop/common/uploadData)
  */
@@ -61,24 +111,31 @@ export async function fetchUploadConfig() {
  */
 export function uploadImageFile(filePath, config) {
 	return new Promise((resolve, reject) => {
-		const uploadurl = resolveUploadUrl(config.uploadurl)
+		const uploadurl = resolveUploadUrl(config && config.uploadurl)
 		if (!uploadurl) {
 			reject(new Error('上传地址无效'))
 			return
 		}
-		const formData = config.storage === 'local' ? {} : (config.multipart || {})
-		uni.uploadFile({
+		if (!filePath) {
+			reject(new Error('图片文件无效'))
+			return
+		}
+		const opts = {
 			url: uploadurl,
 			filePath,
 			name: 'file',
-			formData,
 			success: (res) => {
 				const url = parseUploadResponse(res.data)
 				if (url) resolve(url)
 				else reject(new Error('上传失败'))
 			},
 			fail: (err) => reject(err || new Error('上传失败'))
-		})
+		}
+		// local 不传 formData;非 local 才带 multipart(与参考工程一致)
+		if (config && config.storage !== 'local' && config.multipart) {
+			opts.formData = config.multipart
+		}
+		uni.uploadFile(opts)
 	})
 }
 

+ 4 - 3
manifest.json

@@ -2,8 +2,8 @@
     "name" : "88live",
     "appid" : "__UNI__3F63D9A",
     "description" : "",
-    "versionName" : "1.1.39",
-    "versionCode" : 1039,
+    "versionName" : "1.1.40",
+    "versionCode" : 1140,
     "transformPx" : false,
     /* 5+App特有相关 */
     "app-plus" : {
@@ -161,5 +161,6 @@
     "uniStatistics" : {
         "enable" : false
     },
-    "vueVersion" : "2"
+    "vueVersion" : "2",
+    "locale" : "en"
 }

+ 23 - 4
pages/dynamics/publish.vue

@@ -231,6 +231,7 @@
 import {
 	fetchUploadConfig,
 	uploadImageFile,
+	prepareImageForUpload,
 	uploadVideoFile,
 	fetchVideoLabels,
 	publishGrassPost,
@@ -470,6 +471,8 @@ export default {
 					chooseImageWithPermission(this, 'album', {
 						count: remain,
 						sizeType: ['compressed'],
+						// 部分端支持,压低相册原图质量
+						crop: { quality: 60 },
 						success: (res) => {
 							const paths = res.tempFilePaths || []
 							if (paths.length) this.uploadPaths(paths)
@@ -480,6 +483,7 @@ export default {
 					chooseImageWithPermission(this, 'camera', {
 						count: 1,
 						sizeType: ['compressed'],
+						crop: { quality: 60 },
 						success: (res) => {
 							const paths = res.tempFilePaths || []
 							if (paths.length) this.uploadPaths(paths)
@@ -489,20 +493,35 @@ export default {
 			})
 		},
 		async uploadPaths(paths) {
+			const list = Array.isArray(paths) ? paths.filter(Boolean) : []
+			if (!list.length) return
 			this.uploading = true
 			uni.showLoading({ title: this.copy.publishUploading, mask: true })
+			let failCount = 0
 			try {
 				const config = await fetchUploadConfig()
-				for (let i = 0; i < paths.length; i++) {
+				for (let i = 0; i < list.length; i++) {
 					if (this.images.length >= this.maxImages) break
-					const url = await uploadImageFile(paths[i], config)
-					this.images.push(url)
+					try {
+						// 先解码再压缩,再上传,避免 HEIC / 超大图直接 upload 闪退
+						const ready = await prepareImageForUpload(list[i])
+						const url = await uploadImageFile(ready, config)
+						if (url) this.images.push(url)
+						else failCount += 1
+					} catch (_) {
+						failCount += 1
+					}
+				}
+				if (failCount > 0) {
+					this.$appKit && this.$appKit.msg(this.copy.publishUploadFailed)
 				}
 			} catch (err) {
 				this.$appKit && this.$appKit.msg((err && err.message) || this.copy.publishUploadFailed)
 			} finally {
 				this.uploading = false
-				uni.hideLoading()
+				try {
+					uni.hideLoading()
+				} catch (_) {}
 			}
 		},
 		removeImage(index) {

+ 0 - 1
pages/live/watch.nvue

@@ -313,7 +313,6 @@
 			<view class="stage-paywall-mask" :style="paywallMaskStyle" />
 			<view class="stage-paywall-body" :style="fullFrameStyle">
 				<image class="stage-paywall-lock-img" src="/static/imgs/icon/ic_lock.png" mode="aspectFit" />
-				<text class="stage-paywall-title">{{ copy.trialEnd }}</text>
 				<!-- 仅父级 @tap,避免 iOS 上 click+tap / 子节点冒泡连弹两次 -->
 				<view class="stage-paywall-btn" @tap="openLivePayPopup">
 					<image