// component/fileBottomPop/fileBottomPop.ts import { TimeUtil } from '../../utils/TimeUtil' import { httpUtil } from '../../utils/restful' Component({ /** * 组件的属性列表 */ properties: { itemIndex: { type: Number, value: 0 } }, /** * 组件的初始数据 */ data: { pageHeight: 0, pageWidth: 0, windowType: -1, hideModal: true, itemData: { id: '', lessonId: '', url: '', lessId: '' }, fileName: '', uploadTime: '', expireTime: '', iconUrl: '', }, lifetimes: { attached: function () { // 在组件实例被从页面节点树添加时执行 this.setData({ pageHeight: wx.getSystemInfoSync().windowHeight, pageWidth: wx.getSystemInfoSync().windowWidth }) console.log("itemIndex:", this.properties.itemIndex) }, detached: function () { // 在组件实例被从页面节点树移除时执行 }, }, /** * 组件的方法列表 */ methods: { // 显示遮罩层 windowType==是文件夹 windowType==1是文件 showModal: function (showItem: any, windowType: any) { var that = this; let icon = '' if (showItem.type == 0) { //图片 icon = '../../image/document/document_img.png' } else if (showItem.type == 1) { //不知道是不是视频 icon = '../../image/document/document_video.png' } else { icon = '../../image/teacher/file_icon.png' } that.setData({ hideModal: false, itemData: showItem, fileName: showItem.title, uploadTime: TimeUtil.dateFormat(parseInt(showItem.uploadTime), "yyyy-MM-dd HH:mm"), expireTime: TimeUtil.dateFormat(parseInt(showItem.expireTime), "yyyy-MM-dd HH:mm"), iconUrl: icon, windowType: windowType }) }, // 隐藏遮罩层 hideModal: function () { var that = this; this.triggerEvent("hideWindow") that.setData({ hideModal: true }) }, none: function () { return true; }, renameFile: function () { let rename = ''; let that = this; wx.showModal({ title: '重命名', editable: true, success: function (res) { if (res.confirm) { rename = res.content console.log('点击确认回调:', res.content) let puturl = '' console.log("重命名方法") if (that.data.windowType == 0) { //文件夹重命名 puturl = httpUtil.interfaces.createLess } else if (that.data.windowType == 1) { puturl = httpUtil.interfaces.getDocumentFile //文件重命名 } let params = { id: that.data.itemData.id, lessId: that.data.itemData.lessId, title: rename } httpUtil.wxPut(puturl, params).then((res: any) => { that.setData({ fileName: res.data.data.title }) that.triggerEvent("fileDel") }).catch((res) => { console.log("重命名失败:", res) }) } else { console.log('点击取消回调') } } }) }, downloadFile: function () { console.log("下载方法") let that = this; if (that.data.windowType == 0) { //文件夹下载 wx.navigateTo({ url: '../../../pages/document/document?lessId=' + that.data.itemData.id + '&downLoadAll=true' }) } else if (that.data.windowType == 1) { //文件下载 httpUtil.wxDownLoadFile(that.data.itemData.url, function (res: any) { // console.log("下载没===", res) that.triggerEvent("downLoading", { progress: res.progress }) }).then((res) => { // console.log("下载成功:", res) that.triggerEvent("downLoadComplete", { data: res }) }).catch((res) => { // console.log("下载失败") that.triggerEvent("downLoadError", { data: res }) }) } }, deleteFile: function () { if (this.data.windowType == 0) { //删除文件夹 console.log("删除文件夹") let params = { id: this.data.itemData.id } httpUtil.wxDel(httpUtil.interfaces.createLess, params).then(() => { this.delVoer() }).catch((res) => { console.log("删除失败:", res) }) } else if (this.data.windowType == 1) { console.log("删除单独文件") let params = { id: this.data.itemData.id, lessonId: this.data.itemData.lessonId } httpUtil.wxDel(httpUtil.interfaces.getDocumentFile, params).then(() => { this.delVoer() }).catch((res) => { console.log("删除失败:", res) }) } }, delVoer() { this.hideModal() this.triggerEvent("fileDel") } } })