184 lines
4.0 KiB
JavaScript
184 lines
4.0 KiB
JavaScript
// pages/details/details.js
|
|
|
|
|
|
const request = require('../../utils/request')
|
|
const ui = require('../../utils/ui')
|
|
const wxParse = require("../../wxParse/wxParse.js");
|
|
|
|
Page({
|
|
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
|
|
navTitle: "详情",
|
|
date: "",
|
|
title: "",
|
|
content: "",
|
|
aid: 0,
|
|
isDow: false,
|
|
ext_download_link: ""
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
onLoad(options) {
|
|
let that = this;
|
|
if (!options.aid) {
|
|
wx.navigateBack()
|
|
this.triggerEvent('onBack')
|
|
}
|
|
that.setData({
|
|
aid: options.aid
|
|
})
|
|
that.GetDetailsInfo()
|
|
console.log(options);
|
|
//
|
|
},
|
|
|
|
initContent() {
|
|
let that = this;
|
|
console.log(that.data.content);
|
|
if (that.data.content.length > 0) {
|
|
wxParse.wxParse('content', 'html', that.data.content, that, 0);
|
|
}
|
|
},
|
|
|
|
|
|
GetDetailsInfo() {
|
|
let that = this;
|
|
request.request({
|
|
method: "GET",
|
|
// https://app.19year.cn/api.php/doc/details?id=51
|
|
url: "/api.php/doc/details?id=" + that.data.aid
|
|
}).then(res => {
|
|
if (res.data.code === 1) {
|
|
|
|
that.setData({
|
|
title: res.data.data.title,
|
|
date: res.data.data.date,
|
|
content: res.data.data.content,
|
|
ext_download_link: res.data.data.ext_download_link,
|
|
})
|
|
if (res.data.data.ext_download_link.length > 0) {
|
|
that.setData({
|
|
isDow: true
|
|
})
|
|
}
|
|
that.initContent()
|
|
}
|
|
}).catch(err => {
|
|
console.log('ERROR')
|
|
});
|
|
},
|
|
|
|
|
|
downloadFileOpen() {
|
|
let that = this;
|
|
let link = that.data.ext_download_link
|
|
wx.setClipboardData({
|
|
data: link,
|
|
success: function (res) {
|
|
wx.getClipboardData({
|
|
success: function (res) {
|
|
wx.showToast({
|
|
title: '复制成功'
|
|
})
|
|
}
|
|
})
|
|
}
|
|
})
|
|
|
|
|
|
|
|
|
|
//复制到剪切板
|
|
// wx.setClipboardData({
|
|
// data: link,
|
|
// success(res) {
|
|
// console.log('copy success');
|
|
// //获取剪切板的纸
|
|
// // wx.getClipboardData({
|
|
// // success(res) {
|
|
// // console.log(res) // data
|
|
// // that.copyContent = res.data
|
|
// // }
|
|
// // })
|
|
// }
|
|
// })
|
|
|
|
|
|
|
|
// wx.showLoading({
|
|
// title: '下载中',
|
|
// })
|
|
//下载文件
|
|
// wx.downloadFile({
|
|
// url: link,
|
|
// success (res) {
|
|
// if (res.statusCode === 200) {
|
|
// const filePath = res.tempFilePath
|
|
// wx.openDocument({
|
|
// filePath: filePath,
|
|
// showMenu:true, //关键点
|
|
// success: function (res) {
|
|
// console.log('打开文档成功')
|
|
// }
|
|
// })
|
|
// }
|
|
// }
|
|
// })
|
|
},
|
|
|
|
|
|
/**
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
*/
|
|
onReady() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面显示
|
|
*/
|
|
onShow() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面隐藏
|
|
*/
|
|
onHide() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面卸载
|
|
*/
|
|
onUnload() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
*/
|
|
onPullDownRefresh() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 页面上拉触底事件的处理函数
|
|
*/
|
|
onReachBottom() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 用户点击右上角分享
|
|
*/
|
|
onShareAppMessage() {
|
|
|
|
}
|
|
}) |