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.

235 lines
5.0 KiB

// pages/lookup/lookimg/img.js
import {
http,
matchType
} from '../../../utils/util'
Page({
/**
* 页面的初始数据
*/
data: {
data: {},
cdn: getApp().globalData.cdn,
shou: true
},
//用户点击右上角分享朋友圈
onShareTimeline() {
return {
title: this.data.data.title,
query: 'value=' + JSON.stringify(this.data.data),
imageUrl: this.data.data.fileUrl ? this.data.cdn + this.data.data.fileUrl : this.data.cdn + this.data.data.teachRefeFileUrl
}
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
wx.setNavigationBarTitle({
title: '文件查看',
})
wx.setNavigationBarColor({
// frontColor: '#ffffff',
// backgroundColor: '#000000',
animation: {
duration: 400,
timingFunc: 'easeIn'
}
})
// wx.setBackgroundColor({
// backgroundColor: '#000000',
// })
wx.showShareMenu({
withShareTicket: true,
menus: ['shareAppMessage', 'shareTimeline']
})
// 获取当前场景值 以适应单页面模式
// 1154 为单页面模式的场景值
var pathData = wx.getLaunchOptionsSync()
if (pathData.scene == 1154) {
console.log(options)
var value = JSON.parse(options.value)
this.setData({
data: JSON.parse(options.value),
shou: false
})
} else {
let that = this
wx.getStorage({
key: 'file',
success(res) {
let a = matchType(res.data.fileUrl)
that.setData({
data: res.data,
'data.filetype': a
})
},
fail: {}
})
}
},
downloadfile(e) {
wx.showLoading({
title: '正在下载',
mask: true
})
console.log(e)
var url = this.data.data.fileUrl;
//下载文件,生成临时地址
wx.downloadFile({
url: this.data.cdn + url,
success(res) {
console.log(res)
//保存到本地
wx.getFileSystemManager().saveFile({
tempFilePath: res.tempFilePath,
success: function (res) {
console.log(res)
console.log('保存到本地', res)
},
fail: function (err) {
wx.showToast({
title: '保存失败',
duration: 2000,
mask: true,
});
console.log('保存失败:', err)
},
complete(res) {
wx.hideLoading();
console.log(res)
}
});
}
})
},
seefile(e) {
wx.showLoading({
title: '正在加载',
mask: true
})
var url = this.data.data.fileUrl;
//下载文件,生成临时地址
wx.downloadFile({
url: this.data.cdn + url,
success(res) {
console.log(res)
wx.openDocument({
filePath: res.tempFilePath,
showMenu: true,
success(re) {
wx.showToast({
title: '加载成功',
duration: 2000,
mask: true,
});
},
fail(re) {
wx.showToast({
title: '加载失败',
duration: 2000,
mask: true,
});
},
complete(re) {
wx.hideLoading();
}
})
}
})
},
add() {
http("/userReference/add", "post", {
referenceId: this.data.data.id
}).then(re => {
wx.showToast({
title: re.data,
icon: 'none',
duration: 2000
}).then(res => {
if (re.code === 200) {
this.setData({
'data.isCollected': 1
})
}
})
})
},
del() {
http("/userReference/del", "post", {
referenceId: this.data.data.id
}).then(re => {
wx.showToast({
title: re.data,
icon: 'none',
duration: 2000
}).then(res => {
if (re.code === 200) {
this.setData({
'data.isCollected': 0
})
}
})
})
},
to(e) {
console.log(e)
if (e.currentTarget.dataset.type === '1') {
wx.navigateTo({
url: '/pages/lookup/labelsearch/brand/brandsearch?id=' + e.currentTarget.dataset.mes.id + '&name=' + e.currentTarget.dataset.mes.name,
})
} else if (e.currentTarget.dataset.type === '2') {
wx.navigateTo({
url: '/pages/lookup/labelsearch/tag/tagsearch?id=' + e.currentTarget.dataset.mes.id + '&name=' + e.currentTarget.dataset.mes.title,
})
}
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})