From 9ab4955166b7b1370fc2a49b152353241ca9e64a Mon Sep 17 00:00:00 2001 From: jiangping <jp@doumee.com> Date: 星期一, 16 十月 2023 09:22:23 +0800 Subject: [PATCH] 小程序 --- minipro_standard/uni_modules/uview-ui/components/u-upload/utils.js | 151 -------------------------------------------------- 1 files changed, 0 insertions(+), 151 deletions(-) diff --git a/minipro_standard/uni_modules/uview-ui/components/u-upload/utils.js b/minipro_standard/uni_modules/uview-ui/components/u-upload/utils.js index 5c58f95..e69de29 100644 --- a/minipro_standard/uni_modules/uview-ui/components/u-upload/utils.js +++ b/minipro_standard/uni_modules/uview-ui/components/u-upload/utils.js @@ -1,151 +0,0 @@ -function pickExclude(obj, keys) { - // 鏌愪簺鎯呭喌涓嬶紝type鍙兘浼氫负 - if (!['[object Object]', '[object File]'].includes(Object.prototype.toString.call(obj))) { - return {} - } - return Object.keys(obj).reduce((prev, key) => { - if (!keys.includes(key)) { - prev[key] = obj[key] - } - return prev - }, {}) -} - -function formatImage(res) { - return res.tempFiles.map((item) => ({ - ...pickExclude(item, ['path']), - type: 'image', - url: item.path, - thumb: item.path, - size: item.size, - // #ifdef H5 - name: item.name - // #endif - })) -} - -function formatVideo(res) { - return [ - { - ...pickExclude(res, ['tempFilePath', 'thumbTempFilePath', 'errMsg']), - type: 'video', - url: res.tempFilePath, - thumb: res.thumbTempFilePath, - size: res.size, - // #ifdef H5 - name: res.name - // #endif - } - ] -} - -function formatMedia(res) { - return res.tempFiles.map((item) => ({ - ...pickExclude(item, ['fileType', 'thumbTempFilePath', 'tempFilePath']), - type: res.type, - url: item.tempFilePath, - thumb: res.type === 'video' ? item.thumbTempFilePath : item.tempFilePath, - size: item.size - })) -} - -function formatFile(res) { - return res.tempFiles.map((item) => ({ - ...pickExclude(item, ['path']), - url: item.path, - size:item.size, - // #ifdef H5 - name: item.name, - type: item.type - // #endif - })) -} -export function chooseFile({ - accept, - multiple, - capture, - compressed, - maxDuration, - sizeType, - camera, - maxCount -}) { - return new Promise((resolve, reject) => { - switch (accept) { - case 'image': - uni.chooseImage({ - count: multiple ? Math.min(maxCount, 9) : 1, - sourceType: capture, - sizeType, - success: (res) => resolve(formatImage(res)), - fail: reject - }) - break - // #ifdef MP-WEIXIN - // 鍙湁寰俊灏忕▼搴忔墠鏀寔chooseMedia鎺ュ彛 - case 'media': - wx.chooseMedia({ - count: multiple ? Math.min(maxCount, 9) : 1, - sourceType: capture, - maxDuration, - sizeType, - camera, - success: (res) => resolve(formatMedia(res)), - fail: reject - }) - break - // #endif - case 'video': - uni.chooseVideo({ - sourceType: capture, - compressed, - maxDuration, - camera, - success: (res) => resolve(formatVideo(res)), - fail: reject - }) - break - // #ifdef MP-WEIXIN || H5 - // 鍙湁寰俊灏忕▼搴忔墠鏀寔chooseMessageFile鎺ュ彛 - case 'file': - // #ifdef MP-WEIXIN - wx.chooseMessageFile({ - count: multiple ? maxCount : 1, - type: accept, - success: (res) => resolve(formatFile(res)), - fail: reject - }) - // #endif - // #ifdef H5 - // 闇�瑕乭x2.9.9浠ヤ笂鎵嶆敮鎸乽ni.chooseFile - uni.chooseFile({ - count: multiple ? maxCount : 1, - type: accept, - success: (res) => resolve(formatFile(res)), - fail: reject - }) - // #endif - break - // #endif - default: - // 姝や负淇濆簳閫夐」锛屽湪accept涓嶄负涓婇潰浠绘剰涓�椤圭殑鏃跺�欓�夊彇鍏ㄩ儴鏂囦欢 - // #ifdef MP-WEIXIN - wx.chooseMessageFile({ - count: multiple ? maxCount : 1, - type: 'all', - success: (res) => resolve(formatFile(res)), - fail: reject - }) - // #endif - // #ifdef H5 - // 闇�瑕乭x2.9.9浠ヤ笂鎵嶆敮鎸乽ni.chooseFile - uni.chooseFile({ - count: multiple ? maxCount : 1, - type: 'all', - success: (res) => resolve(formatFile(res)), - fail: reject - }) - // #endif - } - }) -} -- Gitblit v1.9.3