| | |
| | | } |
| | | |
| | | const imgReg = /\.(png|jpeg|jpg|webp|gif)$/i; |
| | | const videoReg = /\.(mp4|avi|mkv|wmv|flv|webm|m4v|3gp|mpeg|mpg|ts|vob|ogv|f4v)$/i; |
| | | |
| | | function getFileType(path: string) { |
| | | if (imgReg.test(path)) { |
| | | return 'image'; |
| | | } |
| | | if (videoReg.test(path)) { |
| | | return 'video'; |
| | | } |
| | | return ''; |
| | | } |
| | | |
| | | /** |
| | | * 把api返回的路径转换为upload的路径 |
| | |
| | | path: urlOmitDomain(path), |
| | | url: setOSSLink(path), |
| | | status: 'success', |
| | | type: imgReg.test(path) ? 'image' : '', |
| | | type: getFileType(path), |
| | | uid: _.uniqueId(), |
| | | } as FileItem; |
| | | } |
| | |
| | | return fileName; |
| | | }); |
| | | } |
| | | |
| | | export function openDocument(url: string) { |
| | | Taro.downloadFile({ |
| | | url: url, |
| | | success: function (res) { |
| | | var filePath = res.tempFilePath; |
| | | Taro.openDocument({ |
| | | filePath: filePath, |
| | | }); |
| | | }, |
| | | }); |
| | | } |