fileBottomPop.ts 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. // component/fileBottomPop/fileBottomPop.ts
  2. import { TimeUtil } from '../../utils/TimeUtil'
  3. import { httpUtil } from '../../utils/restful'
  4. Component({
  5. /**
  6. * 组件的属性列表
  7. */
  8. properties: {
  9. },
  10. /**
  11. * 组件的初始数据
  12. */
  13. data: {
  14. pageHeight: 0,
  15. pageWidth: 0,
  16. windowType: -1,
  17. hideModal: true,
  18. itemData: null,
  19. fileName: '',
  20. uploadTime: '',
  21. expireTime: '',
  22. iconUrl: ''
  23. },
  24. lifetimes: {
  25. attached: function () {
  26. // 在组件实例被从页面节点树添加时执行
  27. this.setData({
  28. pageHeight: wx.getSystemInfoSync().windowHeight,
  29. pageWidth: wx.getSystemInfoSync().windowWidth
  30. })
  31. },
  32. detached: function () {
  33. // 在组件实例被从页面节点树移除时执行
  34. },
  35. },
  36. /**
  37. * 组件的方法列表
  38. */
  39. methods: {
  40. // 显示遮罩层 windowType==是文件夹 windowType==1是文件
  41. showModal: function (showItem: any, windowType: any) {
  42. var that = this;
  43. let icon = ''
  44. if (showItem.type == 0) {
  45. //图片
  46. icon = '../../image/document/document_img.png'
  47. } else if (showItem.type == 1) {
  48. //不知道是不是视频
  49. icon = '../../image/document/document_video.png'
  50. } else {
  51. icon = '../../image/teacher/file_icon.png'
  52. }
  53. that.setData({
  54. hideModal: false,
  55. itemData: showItem,
  56. fileName: showItem.title,
  57. uploadTime: TimeUtil.dateFormat(parseInt(showItem.uploadTime), "yyyy-MM-dd HH:mm"),
  58. expireTime: TimeUtil.dateFormat(parseInt(showItem.expireTime), "yyyy-MM-dd HH:mm"),
  59. iconUrl: icon,
  60. windowType: windowType
  61. })
  62. },
  63. // 隐藏遮罩层
  64. hideModal: function () {
  65. var that = this;
  66. that.setData({
  67. hideModal: true
  68. })
  69. },
  70. none: function () {
  71. return true;
  72. },
  73. renameFile: function () {
  74. let rename = '';
  75. let that = this;
  76. wx.showModal({
  77. title: '重命名',
  78. editable: true,
  79. success: function (res) {
  80. if (res.confirm) {
  81. rename = res.content
  82. console.log('点击确认回调:', res.content)
  83. let puturl = ''
  84. console.log("重命名方法")
  85. if (that.data.windowType == 0) {
  86. //文件夹重命名
  87. puturl = httpUtil.interfaces.createLess
  88. } else if (that.data.windowType == 1) {
  89. puturl = httpUtil.interfaces.getDocumentFile
  90. //文件重命名
  91. }
  92. let params = {
  93. id: that.data.itemData.id,
  94. lessId: that.data.itemData.lessId,
  95. title: rename
  96. }
  97. httpUtil.wxPut(puturl, params).then((res:any) => {
  98. that.setData({
  99. fileName: res.data.data.title
  100. })
  101. that.triggerEvent("fileDel")
  102. }).catch((res) => {
  103. console.log("重命名失败:", res)
  104. })
  105. } else {
  106. console.log('点击取消回调')
  107. }
  108. }
  109. })
  110. },
  111. downloadFile: function () {
  112. console.log("下载方法")
  113. if (this.data.windowType == 0) {
  114. //文件夹下载
  115. } else if (this.data.windowType == 1) {
  116. //文件下载
  117. httpUtil.wxDownLoadFile(this.data.itemData.url, function (res: any) {
  118. console.log("下载没??===", res.progress)
  119. })
  120. }
  121. },
  122. deleteFile: function () {
  123. if (this.data.windowType == 0) {
  124. //删除文件夹
  125. console.log("删除文件夹")
  126. let params = {
  127. id: this.data.itemData.id
  128. }
  129. httpUtil.wxDel(httpUtil.interfaces.createLess, params).then((res) => {
  130. this.delVoer()
  131. }).catch((res) => {
  132. console.log("删除失败:", res)
  133. })
  134. } else if (this.data.windowType == 1) {
  135. console.log("删除单独文件")
  136. let params = {
  137. id: this.data.itemData.id,
  138. lessonId: this.data.itemData.lessonId
  139. }
  140. httpUtil.wxDel(httpUtil.interfaces.getDocumentFile, params).then((res) => {
  141. this.delVoer()
  142. }).catch((res) => {
  143. console.log("删除失败:", res)
  144. })
  145. }
  146. },
  147. delVoer() {
  148. this.hideModal()
  149. this.triggerEvent("fileDel")
  150. }
  151. }
  152. })