// component/fileBottomPop/fileBottomPop.ts import { TimeUtil } from '../../utils/TimeUtil' import { httpUtil } from '../../utils/restful' Component({ /** * 组件的属性列表 */ properties: { }, /** * 组件的初始数据 */ data: { pageHeight: 0, pageWidth: 0, windowType: -1, hideModal: true, itemData: null, fileName: '', uploadTime: '', expireTime: '', iconUrl: '' }, lifetimes: { attached: function () { // 在组件实例被从页面节点树添加时执行 this.setData({ pageHeight: wx.getSystemInfoSync().windowHeight, pageWidth: wx.getSystemInfoSync().windowWidth }) }, 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; 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("下载方法") if (this.data.windowType == 0) { //文件夹下载 } else if (this.data.windowType == 1) { //文件下载 httpUtil.wxDownLoadFile(this.data.itemData.url, function (res: any) { console.log("下载没??===", res.progress) }) } }, deleteFile: function () { if (this.data.windowType == 0) { //删除文件夹 console.log("删除文件夹") let params = { id: this.data.itemData.id } httpUtil.wxDel(httpUtil.interfaces.createLess, params).then((res) => { 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((res) => { this.delVoer() }).catch((res) => { console.log("删除失败:", res) }) } }, delVoer() { this.hideModal() this.triggerEvent("fileDel") } } })