fileBottomPop.ts 5.9 KB

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