// packageA/pages/refuelingCharging/RefuelingChargingDetail/RefuelingChargingDetail.ts Page({ /** * 页面的初始数据 */ data: { item: {} as any, attachmentUrlList: [] }, // 查看文件 checkFile(event: any) { let url = event.currentTarget.dataset.url; let type = url.split('.')[url.split('.').length - 1]; if (type == 'jpg' || type == 'jpeg' || type == 'png') { wx.previewImage({ current: url, // 当前显示图片的http链接 urls: [url] // 需要预览的图片http链接列表 }); } else { wx.showLoading({ title: '数据加载中' }); wx.downloadFile({ // 示例 url,并非真实存在 url: url, success: function (res) { const filePath = res.tempFilePath; wx.openDocument({ filePath: filePath, showMenu: true, success: function (res) { wx.hideLoading(); }, fail: function () { wx.hideLoading(); } }); }, fail: function () { wx.hideLoading(); } }); } }, /** * 生命周期函数--监听页面加载 */ onLoad() { // 接收传参 const eventChannel = this.getOpenerEventChannel(); eventChannel && eventChannel.on && eventChannel.on('eventName', (data: any) => { let attachmentUrlList = [] as any; if (data.attachmentUrl) { attachmentUrlList = data.attachmentUrl.split(',').map((item: any) => { return { url: item, name: item.split('/')[item.split('/').length - 1] }; }); } this.setData({ item: data, attachmentUrlList: attachmentUrlList }); }); }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() {}, /** * 生命周期函数--监听页面显示 */ onShow() {}, /** * 生命周期函数--监听页面隐藏 */ onHide() {}, /** * 生命周期函数--监听页面卸载 */ onUnload() {}, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() {}, /** * 页面上拉触底事件的处理函数 */ onReachBottom() {}, /** * 用户点击右上角分享 */ onShareAppMessage() {} });