aqyj/pages/data/detail.js

162 lines
3.4 KiB
JavaScript

// pages/suggest/detail.js
var util = require('../../utils/util.js')
Page({
openfj: function (e) {
var that = this
let fileurl = that.data.url
wx.showLoading({
title: '正在下载...',
})
wx.downloadFile({
url: fileurl,
success(res) {
wx.showLoading({
title: '成功,正在打开...',
})
const filePath = res.tempFilePath
console.log(filePath)
var filetype
if (fileurl.indexOf(".docx") != -1) {
filetype = 'docx'
}
else if (fileurl.indexOf(".doc") != -1) {
filetype = 'doc'
}
else if (fileurl.indexOf(".xlsx") != -1) {
filetype = 'xlsx'
}
else if (fileurl.indexOf(".xls") != -1) {
filetype = 'xls'
}
else if (fileurl.indexOf(".pptx") != -1) {
filetype = 'pptx'
}
else if (fileurl.indexOf(".ppt") != -1) {
filetype = 'ppt'
}
else if (fileurl.indexOf(".pdf") != -1) {
filetype = 'pdf'
}else{
wx.hideLoading()
return
}
wx.openDocument({
filePath,
fileType: filetype,
success(res) {
wx.hideLoading()
console.log('打开文档成功')
}, fail: function (e) {
console.log(e)
}
})
that.hasRead()
}
})
},
hasRead:function(){
wx.request({
url: this.data.serverUrl + 'edu/api?a=downfile&id=' + this.data.id,
header: {
'content-type': 'application/json', // 默认值
'Cookie': getApp().globalData.sessionId,
},
data: {
},
success: res => {
}
});
},
/**
* 页面的初始数据
*/
data: {
serverUrl: getApp().globalData.serverUrl,
isDocument:false
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
this.getFiledetail(options.id);
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
},
getFiledetail: function (id) {
wx.showLoading({
title: '加载中',
}),
wx.request({
url: this.data.serverUrl + 'edu/api?a=detail&id=' + id,
header: {
'content-type': 'application/json', // 默认值
'Cookie': getApp().globalData.sessionId,
},
data: {
},
success: res => {
wx.hideLoading();
console.log(res.data);
if (res.statusCode === 200) {
var filedetail = res.data
filedetail.url = this.data.serverUrl + filedetail.url
this.setData(filedetail)
if([2,3,4,5].indexOf(filedetail.type)!=-1){
this.setData({
isDocument:true
})
}
}
}
});
},
})