|
@@ -2,4 +2,43 @@ export const getImageUrl = (uri) => {
|
|
|
return `${process.env.UNI_FILE_PREFIX}${uri}`;
|
|
|
};
|
|
|
|
|
|
-
|
|
|
+export const viewFileFn = (fileUrl, fileName, fileSuffix) => { // 文件url 文件名 文件后缀
|
|
|
+ uni.showLoading({
|
|
|
+ title: '加载中…',
|
|
|
+ mask: true,
|
|
|
+ });
|
|
|
+ let downloadTask = uni.downloadFile({
|
|
|
+ url: fileUrl,
|
|
|
+ success: function (res) {
|
|
|
+ console.log('downloadFile 成功', res);
|
|
|
+ var tempFilePath = res.tempFilePath; // 下载成功后的临时文件路径
|
|
|
+ var newFilePath = `${wx.env.USER_DATA_PATH}/${fileName}${fileSuffix}`; // 新的文件路径,USER_DATA_PATH 是小程序的本地文件存储目录
|
|
|
+ uni.saveFile({
|
|
|
+ tempFilePath: tempFilePath,
|
|
|
+ filePath: newFilePath,
|
|
|
+ success: function (res) {
|
|
|
+ console.log('saveFile 成功', res.savedFilePath);
|
|
|
+ uni.openDocument({
|
|
|
+ filePath: res.savedFilePath, // 打开新的文件路径
|
|
|
+ showMenu: false,
|
|
|
+ success: function (res) {
|
|
|
+ console.log('openDocument 成功', res);
|
|
|
+ },
|
|
|
+ fail: function (err) {
|
|
|
+ console.log('openDocument 失败', err);
|
|
|
+ },
|
|
|
+ });
|
|
|
+ uni.hideLoading();
|
|
|
+ },
|
|
|
+ fail: function (err) {
|
|
|
+ console.log('saveFile 失败', err);
|
|
|
+ uni.hideLoading();
|
|
|
+ },
|
|
|
+ });
|
|
|
+ },
|
|
|
+ fail: function (res) {
|
|
|
+ console.log('downloadFile 失败', res);
|
|
|
+ uni.hideLoading();
|
|
|
+ },
|
|
|
+ });
|
|
|
+};
|