Commit 40ae2164 authored by Facius's avatar Facius

资料文件页面加访问缓存

parent a190be72
...@@ -64,6 +64,7 @@ export default { ...@@ -64,6 +64,7 @@ export default {
mixWater: "", // 缓存水印拍照图片 mixWater: "", // 缓存水印拍照图片
}, },
}, },
fileList: {} // 文件地址缓存 {url最后一段: tmpPath}
}, },
onLaunch: async function () { onLaunch: async function () {
// 应用初始化(全局只触发一次) // 应用初始化(全局只触发一次)
......
...@@ -88,7 +88,6 @@ const install = (Vue, vm) => { ...@@ -88,7 +88,6 @@ const install = (Vue, vm) => {
*/ */
// 响应拦截,判断状态码是否通过 // 响应拦截,判断状态码是否通过
Vue.prototype.$u.http.interceptor.response = (res) => { Vue.prototype.$u.http.interceptor.response = (res) => {
console.log(res)
let result = res.data || res; let result = res.data || res;
let msg = getMsg(res) let msg = getMsg(res)
//返回__token__,设置 //返回__token__,设置
...@@ -102,7 +101,7 @@ const install = (Vue, vm) => { ...@@ -102,7 +101,7 @@ const install = (Vue, vm) => {
// return result; // return result;
case 200: case 200:
return { return {
data:result.data == null ? result : result.data, // result.data的值为0, false, ''的时候也要算有值 data:result.data == null ? result : result.data, // result.data的值为0, false, ''的时候也要算有值;;null的情况下后台返回的是单层及{header: ', data: 数据, message:'', code: ''}
code:code, code:code,
message:msg message:msg
}; };
......
...@@ -68,7 +68,8 @@ ...@@ -68,7 +68,8 @@
'2': {} // 选中的品牌 '2': {} // 选中的品牌
}, },
loading: false, // 文件列表加载中 loading: false, // 文件列表加载中
orderFile: false // 是否是订单详情进来 orderFile: false, // 是否是订单详情进来
fileList: {}, // 文件地址缓存 {url最后一段: tmpPath}
}; };
}, },
computed: { computed: {
...@@ -120,7 +121,7 @@ ...@@ -120,7 +121,7 @@
} else { // 获取所有文件资料 } else { // 获取所有文件资料
this.loadFileLabel('1') this.loadFileLabel('1')
} }
this.fileList = getApp().globalData.fileList || {} // 文件地址缓存 {url最后一段: tmpPath}
}, },
onShow() { onShow() {
// 从标签列表页面返回,获取选中的标签 // 从标签列表页面返回,获取选中的标签
...@@ -156,46 +157,95 @@ ...@@ -156,46 +157,95 @@
} }
this.$u.route({url: 'pages/order/document-tag' + '?partnerCompanyId=' + partnerCompanyId + '&selectedId=' + this.selected[key].id}) this.$u.route({url: 'pages/order/document-tag' + '?partnerCompanyId=' + partnerCompanyId + '&selectedId=' + this.selected[key].id})
}, },
// 分享 // 点击了分享
handleShare(item) { handleShare(item) {
// 分享资料事件 // 分享资料事件
getApp().track('share_document', { getApp().track('share_document', {
id: this.vuex_user.id, id: this.vuex_user.id,
url: item.url url: item.url
}); });
uni.showLoading({ let block = (filePath) => {
title: '加载中' wx.shareFileMessage({
filePath: filePath,
success() {},
fail: console.error,
}) })
// callback 写法 }
wx.downloadFile({ let filePath = this.fileList[(item.url || '').split('/').pop()]
url: item.url, // 下载url if (filePath) { // 有下载记录
success(res) { wx.shareFileMessage({ // 如果用checkFile检查文件是否存在后再分享,shareFileMess报错:shareFileMessage:fail can only be invoked by user TAP gesture.
uni.hideLoading() filePath: filePath,
// 下载完成后转发 success() {},
fail: (error) => {
console.log(error)
if (error.errMsg.indexOf('internal') != -1) { // 文件不存在重新下载
this.downloadFile(item.url, (result)=> {
wx.shareFileMessage({ wx.shareFileMessage({
filePath: res.tempFilePath, filePath: result.tempFilePath,
success() {}, success() {},
fail: console.error, fail: console.error,
}) })
})
}
}, },
})
} else { // 无下载记录
this.downloadFile(item.url, (res)=> { // 下载
wx.shareFileMessage({
filePath: res.tempFilePath,
success() {},
fail: console.error, fail: console.error,
}) })
})
}
}, },
// 查看 // 点击了查看
handlePreview(item) { handlePreview(item) {
// 查看资料事件 // 查看资料事件
getApp().track('preview_document', { getApp().track('preview_document', {
id: this.vuex_user.id, id: this.vuex_user.id,
url: item.url url: item.url
}); });
let filePath = this.fileList[(item.url || '').split('/').pop()]
if (filePath) { // 有下载记录
this.checkFile(filePath, (res)=> { // 文件是否还存在
if (res.size && res.size > 0) { // 存在,预览文件
this.previewFile(filePath)
} else { // 文件已经不存在, 下载
this.downloadFile(item.url, (result)=> {
this.previewFile(result.tempFilePath)
})
}
})
} else { // 无下载记录
this.downloadFile(item.url, (res)=> { // 下载
this.previewFile(res.tempFilePath)
})
}
},
// 缓存文件是否存在
checkFile(filePath, complete) {
uni.getFileInfo({
filePath: filePath,
complete: complete
})
},
// 下载文件
downloadFile(url, block) {
uni.showLoading({ uni.showLoading({
title: '加载中' title: '加载中'
}) })
uni.downloadFile({ uni.downloadFile({
url: item.url, url: url,
success: function(res) { success: (res)=> {
uni.hideLoading() uni.hideLoading()
var filePath = res.tempFilePath; this.fileList[url.split('/').pop()] = res.tempFilePath
block(res)
}
});
},
// 预览文件
previewFile(filePath) {
if (/\.(gif|jpg|jpeg|png|GIF|JPG|PNG)$/.test(filePath)) { // 查看图片 if (/\.(gif|jpg|jpeg|png|GIF|JPG|PNG)$/.test(filePath)) { // 查看图片
wx.previewImage({ wx.previewImage({
current: filePath, // 当前显示图片的http链接 current: filePath, // 当前显示图片的http链接
...@@ -209,8 +259,14 @@ ...@@ -209,8 +259,14 @@
} }
}); });
} }
} },
}); // 分享文件
shareFile(filePath) {
wx.shareFileMessage({
filePath: filePath,
success() {},
fail: console.error,
})
}, },
// 获取合作商或品牌列表 // 获取合作商或品牌列表
async loadFileLabel(type, partnerCompanyId) { async loadFileLabel(type, partnerCompanyId) {
...@@ -245,7 +301,6 @@ ...@@ -245,7 +301,6 @@
}) })
this.loading = false this.loading = false
if (res && res.code == 200) { if (res && res.code == 200) {
console.log(res.data)
this.list = res.data || [] this.list = res.data || []
// this.list = [...res.data,...res.data,...res.data,...res.data,...res.data,...res.data,...res.data] // 测试模拟多条数据 // this.list = [...res.data,...res.data,...res.data,...res.data,...res.data,...res.data,...res.data] // 测试模拟多条数据
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment