|
|
@@ -5,13 +5,13 @@ Page({
|
|
|
* 页面的初始数据
|
|
|
*/
|
|
|
data: {
|
|
|
-
|
|
|
+ pageNum: 0,
|
|
|
},
|
|
|
/**
|
|
|
* 生命周期函数--监听页面加载
|
|
|
*/
|
|
|
onLoad(options) {
|
|
|
- console.log(options)
|
|
|
+ // console.log(options)
|
|
|
const url = decodeURIComponent(options.url || '')
|
|
|
if (url) {
|
|
|
this.downloadFileH5(url)
|
|
|
@@ -24,24 +24,40 @@ Page({
|
|
|
title: '文件下载中...',
|
|
|
mask: true
|
|
|
})
|
|
|
+ let type = url.split('.');
|
|
|
+ type = type[type.length - 1];
|
|
|
+ // return
|
|
|
wx.downloadFile({
|
|
|
url: url,
|
|
|
success: (ret) => {
|
|
|
console.log(ret)
|
|
|
if (ret.statusCode == 200) {
|
|
|
- //下载完文件
|
|
|
- wx.getFileSystemManager().saveFile({
|
|
|
- tempFilePath: ret.tempFilePath,
|
|
|
- complete: (err) => {
|
|
|
- wx.hideLoading();
|
|
|
- wx.showToast({
|
|
|
- title: err.errMsg == 'saveFile:ok' ? '下载成功' : '下载失败',
|
|
|
- })
|
|
|
- setTimeout(() => {
|
|
|
- wx.navigateBack();
|
|
|
- }, 500);
|
|
|
- }
|
|
|
- })
|
|
|
+ if ((["png", "jpeg", "jpg"].includes(type))) {
|
|
|
+ wx.saveImageToPhotosAlbum({
|
|
|
+ filePath: ret.tempFilePath,
|
|
|
+ complete: (err) => {
|
|
|
+ // console.log(err)
|
|
|
+ wx.hideLoading();
|
|
|
+ wx.showToast({
|
|
|
+ title: err.errMsg == 'saveImageToPhotosAlbum:ok' ? '下载成功' : '下载失败',
|
|
|
+ })
|
|
|
+ setTimeout(() => {
|
|
|
+ wx.navigateBack();
|
|
|
+ }, 500);
|
|
|
+ }
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ wx.openDocument({
|
|
|
+ filePath: ret.tempFilePath,
|
|
|
+ showMenu: true,
|
|
|
+ success: function (res) {
|
|
|
+ console.log('打开文档成功')
|
|
|
+ },
|
|
|
+ complete: (err)=>{
|
|
|
+ console.log(err)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
} else {
|
|
|
wx.hideLoading();
|
|
|
wx.showToast({
|
|
|
@@ -72,7 +88,13 @@ Page({
|
|
|
* 生命周期函数--监听页面显示
|
|
|
*/
|
|
|
onShow() {
|
|
|
-
|
|
|
+ if(this.data.pageNum){
|
|
|
+ wx.navigateBack();
|
|
|
+ return
|
|
|
+ }
|
|
|
+ this.setData({
|
|
|
+ pageNum: 1,
|
|
|
+ })
|
|
|
},
|
|
|
|
|
|
/**
|