fileBottomPop.ts 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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: { id: '', lessonId: '', url: '', lessId: '' },
  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. this.triggerEvent("hideWindow")
  72. that.setData({
  73. hideModal: true
  74. })
  75. },
  76. none: function () {
  77. return true;
  78. },
  79. renameFile: function () {
  80. let rename = '';
  81. let that = this;
  82. wx.showModal({
  83. title: '重命名',
  84. editable: true,
  85. success: function (res) {
  86. if (res.confirm) {
  87. rename = res.content
  88. console.log('点击确认回调:', res.content)
  89. let puturl = ''
  90. console.log("重命名方法")
  91. if (that.data.windowType == 0) {
  92. //文件夹重命名
  93. puturl = httpUtil.interfaces.createLess
  94. } else if (that.data.windowType == 1) {
  95. puturl = httpUtil.interfaces.getDocumentFile
  96. //文件重命名
  97. }
  98. let params = {
  99. id: that.data.itemData.id,
  100. lessId: that.data.itemData.lessId,
  101. title: rename
  102. }
  103. httpUtil.wxPut(puturl, params).then((res: any) => {
  104. that.setData({
  105. fileName: res.data.data.title
  106. })
  107. that.triggerEvent("fileDel")
  108. }).catch((res) => {
  109. console.log("重命名失败:", res)
  110. })
  111. } else {
  112. console.log('点击取消回调')
  113. }
  114. }
  115. })
  116. },
  117. downloadFile: function () {
  118. console.log("下载方法")
  119. let that = this;
  120. if (that.data.windowType == 0) {
  121. //文件夹下载
  122. wx.navigateTo({
  123. url: '../../../pages/document/document?lessId=' + that.data.itemData.id + '&downLoadAll=true'
  124. })
  125. } else if (that.data.windowType == 1) {
  126. //文件下载
  127. httpUtil.wxDownLoadFile(that.data.itemData.url, function (res: any) {
  128. // console.log("下载没===", res)
  129. that.triggerEvent("downLoading", { progress: res.progress })
  130. }).then((res) => {
  131. // console.log("下载成功:", res)
  132. that.triggerEvent("downLoadComplete", { data: res })
  133. }).catch((res) => {
  134. // console.log("下载失败")
  135. that.triggerEvent("downLoadError", { data: res })
  136. })
  137. }
  138. },
  139. deleteFile: function () {
  140. if (this.data.windowType == 0) {
  141. //删除文件夹
  142. console.log("删除文件夹")
  143. let params = {
  144. id: this.data.itemData.id
  145. }
  146. httpUtil.wxDel(httpUtil.interfaces.createLess, params).then(() => {
  147. this.delVoer()
  148. }).catch((res) => {
  149. console.log("删除失败:", res)
  150. })
  151. } else if (this.data.windowType == 1) {
  152. console.log("删除单独文件")
  153. let params = {
  154. id: this.data.itemData.id,
  155. lessonId: this.data.itemData.lessonId
  156. }
  157. httpUtil.wxDel(httpUtil.interfaces.getDocumentFile, params).then(() => {
  158. this.delVoer()
  159. }).catch((res) => {
  160. console.log("删除失败:", res)
  161. })
  162. }
  163. },
  164. delVoer() {
  165. this.hideModal()
  166. this.triggerEvent("fileDel")
  167. }
  168. }
  169. })