¶Ô±ÈÐÂÎļþ |
| | |
| | | /** |
| | | * è·åæä»¶åååç¼ |
| | | * @param {String} name |
| | | */ |
| | | export const get_file_ext = (name) => { |
| | | const last_len = name.lastIndexOf('.') |
| | | const len = name.length |
| | | return { |
| | | name: name.substring(0, last_len), |
| | | ext: name.substring(last_len + 1, len) |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * è·åæ©å±å |
| | | * @param {Array} fileExtname |
| | | */ |
| | | export const get_extname = (fileExtname) => { |
| | | if (!Array.isArray(fileExtname)) { |
| | | let extname = fileExtname.replace(/(\[|\])/g, '') |
| | | return extname.split(',') |
| | | } else { |
| | | return fileExtname |
| | | } |
| | | return [] |
| | | } |
| | | |
| | | /** |
| | | * è·åæä»¶åæ£æµæ¯å¦å¯é |
| | | */ |
| | | export const get_files_and_is_max = (res, _extname) => { |
| | | let filePaths = [] |
| | | let files = [] |
| | | if(!_extname || _extname.length === 0){ |
| | | return { |
| | | filePaths, |
| | | files |
| | | } |
| | | } |
| | | res.tempFiles.forEach(v => { |
| | | let fileFullName = get_file_ext(v.name) |
| | | const extname = fileFullName.ext.toLowerCase() |
| | | if (_extname.indexOf(extname) !== -1) { |
| | | files.push(v) |
| | | filePaths.push(v.path) |
| | | } |
| | | }) |
| | | if (files.length !== res.tempFiles.length) { |
| | | uni.showToast({ |
| | | title: `å½åéæ©äº${res.tempFiles.length}个æä»¶ ï¼${res.tempFiles.length - files.length} 个æä»¶æ ¼å¼ä¸æ£ç¡®`, |
| | | icon: 'none', |
| | | duration: 5000 |
| | | }) |
| | | } |
| | | |
| | | return { |
| | | filePaths, |
| | | files |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * è·åå¾çä¿¡æ¯ |
| | | * @param {Object} filepath |
| | | */ |
| | | export const get_file_info = (filepath) => { |
| | | return new Promise((resolve, reject) => { |
| | | uni.getImageInfo({ |
| | | src: filepath, |
| | | success(res) { |
| | | resolve(res) |
| | | }, |
| | | fail(err) { |
| | | reject(err) |
| | | } |
| | | }) |
| | | }) |
| | | } |
| | | /** |
| | | * è·åå°è£
æ°æ® |
| | | */ |
| | | export const get_file_data = async (files, type = 'image') => { |
| | | // æç»éè¦ä¸ä¼ æ°æ®åºçæ°æ® |
| | | let fileFullName = get_file_ext(files.name) |
| | | const extname = fileFullName.ext.toLowerCase() |
| | | let filedata = { |
| | | name: files.name, |
| | | uuid: files.uuid, |
| | | extname: extname || '', |
| | | cloudPath: files.cloudPath, |
| | | fileType: files.fileType, |
| | | url: files.path || files.path, |
| | | size: files.size, //å使¯åè |
| | | image: {}, |
| | | path: files.path, |
| | | video: {} |
| | | } |
| | | if (type === 'image') { |
| | | const imageinfo = await get_file_info(files.path) |
| | | delete filedata.video |
| | | filedata.image.width = imageinfo.width |
| | | filedata.image.height = imageinfo.height |
| | | filedata.image.location = imageinfo.path |
| | | } else { |
| | | delete filedata.image |
| | | } |
| | | return filedata |
| | | } |