You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

73 lines
1.6 KiB

const app = getApp();
Component({
properties: {
course_id: {
type: Number
},
id: {
type: Number
},
refresh:{
type:Boolean,
observer:function(v){
if(v){
this.onLoad();
this.setData({ refresh: false });
}
}
}
},
data: {
imgDir: global.config.imgDir,
files:[],
loading:true
},
attached(){
console.log("attachment",this.data);
this.onLoad();
},
methods: {
pull_files: function () {
wx.showLoading({
title: '加载中',
})
app.callApi({ name: "files", data: { course_id: this.data.course_id }, complete: () => { wx.hideLoading(); this.setData({ loading: false }) } })
.then(res => {
console.log("pull_files");
console.log(res);
this.setData({ files: res.data.files });
})
.catch(console.error);
},
previewFile: function ({ currentTarget: { dataset:{url=""} } }) {
let ext = url.split(".").slice(-1)[0].toLowerCase();
if(["bmp","jpg","png","gif"].indexOf(ext)!=-1){
wx.previewImage({
urls: [url]
});
return;
}
wx.showLoading({
title: '下载中',
})
wx.downloadFile({
url: global.config.eduUrl + url,
success: (res) => {
wx.openDocument({
filePath: res.tempFilePath,
fail: app.showError
});
},
fail: app.showError,
complete: wx.hideLoading
})
},
onLoad: function (options) {
this.pull_files();
},
}
})