1 line
4.6 KiB
Plaintext
1 line
4.6 KiB
Plaintext
{"version":3,"file":"utils.js","sources":["../../../../../../src/sheep/components/s-uploader/utils.js"],"sourcesContent":["/**\r\n * 获取文件名和后缀\r\n * @param {String} name\r\n */\r\nexport const get_file_ext = (name) => {\r\n const last_len = name.lastIndexOf('.')\r\n const len = name.length\r\n return {\r\n name: name.substring(0, last_len),\r\n ext: name.substring(last_len + 1, len),\r\n }\r\n}\r\n\r\n/**\r\n * 获取扩展名\r\n * @param {Array} fileExtname\r\n */\r\nexport const get_extname = (fileExtname) => {\r\n if (!Array.isArray(fileExtname)) {\r\n const extname = fileExtname.replace(/(\\[|\\])/g, '')\r\n return extname.split(',')\r\n } else {\r\n return fileExtname\r\n }\r\n return []\r\n}\r\n\r\n/**\r\n * 获取文件和检测是否可选\r\n */\r\nexport const get_files_and_is_max = (res, _extname) => {\r\n const filePaths = []\r\n const files = []\r\n if (!_extname || _extname.length === 0) {\r\n return {\r\n filePaths,\r\n files,\r\n }\r\n }\r\n res.tempFiles.forEach((v) => {\r\n const fileFullName = get_file_ext(v.name)\r\n const extname = fileFullName.ext.toLowerCase()\r\n if (_extname.indexOf(extname) !== -1) {\r\n files.push(v)\r\n filePaths.push(v.path)\r\n }\r\n })\r\n if (files.length !== res.tempFiles.length) {\r\n uni.showToast({\r\n title: `当前选择了${res.tempFiles.length}个文件 ,${\r\n res.tempFiles.length - files.length\r\n } 个文件格式不正确`,\r\n icon: 'none',\r\n duration: 5000,\r\n })\r\n }\r\n\r\n return {\r\n filePaths,\r\n files,\r\n }\r\n}\r\n\r\n/**\r\n * 获取图片信息\r\n * @param {Object} filepath\r\n */\r\nexport const get_file_info = (filepath) => {\r\n return new Promise((resolve, reject) => {\r\n uni.getImageInfo({\r\n src: filepath,\r\n success(res) {\r\n resolve(res)\r\n },\r\n fail(err) {\r\n reject(err)\r\n },\r\n })\r\n })\r\n}\r\n/**\r\n * 获取封装数据\r\n */\r\nexport const get_file_data = async (files, type = 'image') => {\r\n // 最终需要上传数据库的数据\r\n const fileFullName = get_file_ext(files.name)\r\n const extname = fileFullName.ext.toLowerCase()\r\n const filedata = {\r\n name: files.name,\r\n uuid: files.uuid,\r\n extname: extname || '',\r\n cloudPath: files.cloudPath,\r\n fileType: files.fileType,\r\n url: files.path || files.path,\r\n size: files.size, // 单位是字节\r\n image: {},\r\n path: files.path,\r\n video: {},\r\n }\r\n if (type === 'image') {\r\n const imageinfo = await get_file_info(files.path)\r\n delete filedata.video\r\n filedata.image.width = imageinfo.width\r\n filedata.image.height = imageinfo.height\r\n filedata.image.location = imageinfo.path\r\n } else {\r\n delete filedata.image\r\n }\r\n return filedata\r\n}\r\n"],"names":["uni"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAIO,MAAM,eAAe,CAAC,SAAS;AACpC,QAAM,WAAW,KAAK,YAAY,GAAG;AACrC,QAAM,MAAM,KAAK;AACjB,SAAO;AAAA,IACL,MAAM,KAAK,UAAU,GAAG,QAAQ;AAAA,IAChC,KAAK,KAAK,UAAU,WAAW,GAAG,GAAG;AAAA,EACtC;AACH;AAMY,MAAC,cAAc,CAAC,gBAAgB;AAC1C,MAAI,CAAC,MAAM,QAAQ,WAAW,GAAG;AAC/B,UAAM,UAAU,YAAY,QAAQ,YAAY,EAAE;AAClD,WAAO,QAAQ,MAAM,GAAG;AAAA,EAC5B,OAAS;AACL,WAAO;AAAA,EACR;AAEH;AAKY,MAAC,uBAAuB,CAAC,KAAK,aAAa;AACrD,QAAM,YAAY,CAAE;AACpB,QAAM,QAAQ,CAAE;AAChB,MAAI,CAAC,YAAY,SAAS,WAAW,GAAG;AACtC,WAAO;AAAA,MACL;AAAA,MACA;AAAA,IACD;AAAA,EACF;AACD,MAAI,UAAU,QAAQ,CAAC,MAAM;AAC3B,UAAM,eAAe,aAAa,EAAE,IAAI;AACxC,UAAM,UAAU,aAAa,IAAI,YAAa;AAC9C,QAAI,SAAS,QAAQ,OAAO,MAAM,IAAI;AACpC,YAAM,KAAK,CAAC;A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