|
@@ -142,141 +142,167 @@ Page({
|
|
|
|
|
|
// 下载
|
|
|
handleDownloadFile() {
|
|
|
- const url = this.data.itemtempFileURL;
|
|
|
- if (!url) {
|
|
|
+ const link = this.data.itemtempFileURL;
|
|
|
+ if (!link) {
|
|
|
wx.showToast({
|
|
|
- title: '文件链接不存在',
|
|
|
+ title: '下载链接为空',
|
|
|
icon: 'none'
|
|
|
});
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- wx.showLoading({
|
|
|
- title: '下载中...',
|
|
|
- mask: true
|
|
|
+ // 复制到剪贴板
|
|
|
+ wx.setClipboardData({
|
|
|
+ data: link,
|
|
|
+ success: () => {
|
|
|
+ wx.showModal({
|
|
|
+ title: '提示',
|
|
|
+ content: '下载链接已复制,请到浏览器粘贴并下载',
|
|
|
+ showCancel: false, // 不显示取消按钮
|
|
|
+ confirmText: '我知道了',
|
|
|
+ success(res) {
|
|
|
+ if (res.confirm) {
|
|
|
+ console.log('用户点击确定,弹框关闭');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
});
|
|
|
+ // const url = this.data.itemtempFileURL;
|
|
|
+ // if (!url) {
|
|
|
+ // wx.showToast({
|
|
|
+ // title: '文件链接不存在',
|
|
|
+ // icon: 'none'
|
|
|
+ // });
|
|
|
+ // return;
|
|
|
+ // }
|
|
|
|
|
|
- wx.downloadFile({
|
|
|
- url: url,
|
|
|
- success: (res) => {
|
|
|
- wx.hideLoading();
|
|
|
+ // wx.showLoading({
|
|
|
+ // title: '下载中...',
|
|
|
+ // mask: true
|
|
|
+ // });
|
|
|
|
|
|
- if (res.statusCode === 200) {
|
|
|
- const tempFilePath = res.tempFilePath;
|
|
|
- const fileExt = url.split('.').pop().toLowerCase();
|
|
|
- const that = this; // 保存页面上下文
|
|
|
- if (['pdf', 'ppt', 'pptx', 'doc', 'docx', 'xls', 'xlsx'].includes(fileExt)) {
|
|
|
- // 打开文档
|
|
|
- wx.openDocument({
|
|
|
- filePath: tempFilePath,
|
|
|
- showMenu: true,
|
|
|
- success() {
|
|
|
- console.log('打开文档成功');
|
|
|
- that.getaddlishi()
|
|
|
- },
|
|
|
- fail(err) {
|
|
|
- wx.showToast({
|
|
|
- title: '打开文档失败',
|
|
|
- icon: 'none'
|
|
|
- });
|
|
|
- console.error('文档打开失败', err);
|
|
|
- }
|
|
|
- });
|
|
|
+ // wx.downloadFile({
|
|
|
+ // url: url,
|
|
|
+ // success: (res) => {
|
|
|
+ // wx.hideLoading();
|
|
|
|
|
|
- } else if (['mp4', 'mov', 'avi'].includes(fileExt)) {
|
|
|
- // 视频:先检查权限再保存
|
|
|
- wx.getSetting({
|
|
|
- success: (res) => {
|
|
|
- if (!res.authSetting['scope.writePhotosAlbum']) {
|
|
|
- wx.authorize({
|
|
|
- scope: 'scope.writePhotosAlbum',
|
|
|
- success: () => {
|
|
|
- this.saveVideo(tempFilePath);
|
|
|
- },
|
|
|
- fail: () => {
|
|
|
- wx.showModal({
|
|
|
- title: '提示',
|
|
|
- content: '保存视频需要开启“保存到相册”权限,请前往设置开启。',
|
|
|
- showCancel: true,
|
|
|
- success(result) {
|
|
|
- if (result.confirm) {
|
|
|
- wx.openSetting();
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
- });
|
|
|
- } else {
|
|
|
- this.saveVideo(tempFilePath);
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
+ // if (res.statusCode === 200) {
|
|
|
+ // const tempFilePath = res.tempFilePath;
|
|
|
+ // const fileExt = url.split('.').pop().toLowerCase();
|
|
|
+ // const that = this; // 保存页面上下文
|
|
|
+ // if (['pdf', 'ppt', 'pptx', 'doc', 'docx', 'xls', 'xlsx'].includes(fileExt)) {
|
|
|
+ // // 打开文档
|
|
|
+ // wx.openDocument({
|
|
|
+ // filePath: tempFilePath,
|
|
|
+ // showMenu: true,
|
|
|
+ // success() {
|
|
|
+ // console.log('打开文档成功');
|
|
|
+ // that.getaddlishi()
|
|
|
+ // },
|
|
|
+ // fail(err) {
|
|
|
+ // wx.showToast({
|
|
|
+ // title: '打开文档失败',
|
|
|
+ // icon: 'none'
|
|
|
+ // });
|
|
|
+ // console.error('文档打开失败', err);
|
|
|
+ // }
|
|
|
+ // });
|
|
|
|
|
|
- } else if (['mp3', 'wav', 'aac'].includes(fileExt)) {
|
|
|
- // 音频保存到本地缓存
|
|
|
- wx.saveFile({
|
|
|
- tempFilePath,
|
|
|
- success(result) {
|
|
|
- wx.showToast({
|
|
|
- title: '音频已保存',
|
|
|
- icon: 'success'
|
|
|
- });
|
|
|
- that.getaddlishi()
|
|
|
- console.log('音频保存路径:', result.savedFilePath);
|
|
|
- },
|
|
|
- fail(err) {
|
|
|
- wx.showToast({
|
|
|
- title: '保存失败',
|
|
|
- icon: 'none'
|
|
|
- });
|
|
|
- console.error('音频保存失败:', err);
|
|
|
- }
|
|
|
- });
|
|
|
+ // } else if (['mp4', 'mov', 'avi'].includes(fileExt)) {
|
|
|
+ // // 视频:先检查权限再保存
|
|
|
+ // wx.getSetting({
|
|
|
+ // success: (res) => {
|
|
|
+ // if (!res.authSetting['scope.writePhotosAlbum']) {
|
|
|
+ // wx.authorize({
|
|
|
+ // scope: 'scope.writePhotosAlbum',
|
|
|
+ // success: () => {
|
|
|
+ // this.saveVideo(tempFilePath);
|
|
|
+ // },
|
|
|
+ // fail: () => {
|
|
|
+ // wx.showModal({
|
|
|
+ // title: '提示',
|
|
|
+ // content: '保存视频需要开启“保存到相册”权限,请前往设置开启。',
|
|
|
+ // showCancel: true,
|
|
|
+ // success(result) {
|
|
|
+ // if (result.confirm) {
|
|
|
+ // wx.openSetting();
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // });
|
|
|
+ // }
|
|
|
+ // });
|
|
|
+ // } else {
|
|
|
+ // this.saveVideo(tempFilePath);
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // });
|
|
|
|
|
|
- } else {
|
|
|
- wx.showToast({
|
|
|
- title: '暂不支持的文件类型',
|
|
|
- icon: 'none'
|
|
|
- });
|
|
|
- }
|
|
|
+ // } else if (['mp3', 'wav', 'aac'].includes(fileExt)) {
|
|
|
+ // // 音频保存到本地缓存
|
|
|
+ // wx.saveFile({
|
|
|
+ // tempFilePath,
|
|
|
+ // success(result) {
|
|
|
+ // wx.showToast({
|
|
|
+ // title: '音频已保存',
|
|
|
+ // icon: 'success'
|
|
|
+ // });
|
|
|
+ // that.getaddlishi()
|
|
|
+ // console.log('音频保存路径:', result.savedFilePath);
|
|
|
+ // },
|
|
|
+ // fail(err) {
|
|
|
+ // wx.showToast({
|
|
|
+ // title: '保存失败',
|
|
|
+ // icon: 'none'
|
|
|
+ // });
|
|
|
+ // console.error('音频保存失败:', err);
|
|
|
+ // }
|
|
|
+ // });
|
|
|
|
|
|
- } else {
|
|
|
- wx.showToast({
|
|
|
- title: '下载失败',
|
|
|
- icon: 'none'
|
|
|
- });
|
|
|
- }
|
|
|
- },
|
|
|
- fail: (err) => {
|
|
|
- wx.hideLoading();
|
|
|
- wx.showToast({
|
|
|
- title: '下载失败',
|
|
|
- icon: 'none'
|
|
|
- });
|
|
|
- console.error('下载出错:', err);
|
|
|
- }
|
|
|
- });
|
|
|
+ // } else {
|
|
|
+ // wx.showToast({
|
|
|
+ // title: '暂不支持的文件类型',
|
|
|
+ // icon: 'none'
|
|
|
+ // });
|
|
|
+ // }
|
|
|
+
|
|
|
+ // } else {
|
|
|
+ // wx.showToast({
|
|
|
+ // title: '下载失败',
|
|
|
+ // icon: 'none'
|
|
|
+ // });
|
|
|
+ // }
|
|
|
+ // },
|
|
|
+ // fail: (err) => {
|
|
|
+ // wx.hideLoading();
|
|
|
+ // wx.showToast({
|
|
|
+ // title: '下载失败',
|
|
|
+ // icon: 'none'
|
|
|
+ // });
|
|
|
+ // console.error('下载出错:', err);
|
|
|
+ // }
|
|
|
+ // });
|
|
|
},
|
|
|
- saveVideo(filePath) {
|
|
|
- const that = this; // 保存页面上下文
|
|
|
- wx.saveVideoToPhotosAlbum({
|
|
|
- filePath,
|
|
|
- success() {
|
|
|
- wx.showToast({
|
|
|
- title: '视频已保存',
|
|
|
- icon: 'success'
|
|
|
- });
|
|
|
- that.getaddlishi()
|
|
|
- },
|
|
|
- fail(err) {
|
|
|
- wx.showToast({
|
|
|
- title: '保存失败',
|
|
|
- icon: 'none'
|
|
|
- });
|
|
|
- console.error('视频保存失败:', err);
|
|
|
- }
|
|
|
- });
|
|
|
- },
|
|
|
+ // saveVideo(filePath) {
|
|
|
+ // const that = this; // 保存页面上下文
|
|
|
+ // wx.saveVideoToPhotosAlbum({
|
|
|
+ // filePath,
|
|
|
+ // success() {
|
|
|
+ // wx.showToast({
|
|
|
+ // title: '视频已保存',
|
|
|
+ // icon: 'success'
|
|
|
+ // });
|
|
|
+ // that.getaddlishi()
|
|
|
+ // },
|
|
|
+ // fail(err) {
|
|
|
+ // wx.showToast({
|
|
|
+ // title: '保存失败',
|
|
|
+ // icon: 'none'
|
|
|
+ // });
|
|
|
+ // console.error('视频保存失败:', err);
|
|
|
+ // }
|
|
|
+ // });
|
|
|
+ // },
|
|
|
|
|
|
// 新增下载历史
|
|
|
async getaddlishi() {
|