document.ts 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. // pages/document/document.ts
  2. import { httpUtil } from "../../utils/restful"
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. lessId: '',
  9. itemList: null,
  10. showItemIndex: 0,
  11. downloadAll: false
  12. },
  13. /**
  14. * 生命周期函数--监听页面加载
  15. */
  16. onLoad(options) {
  17. let bool = false;
  18. if (options.downLoadAll) {
  19. bool = true
  20. }
  21. this.setData({
  22. lessId: options.lessId,
  23. downloadAll: bool
  24. })
  25. this.getDocumentAll();
  26. console.log("this.data.itemList:", this.data.itemList)
  27. },
  28. showActionWindow: function (evnet: any) {
  29. console.log("event:", evnet.detail.item)
  30. this.setData({
  31. showItemIndex: evnet.detail.itemIndex
  32. })
  33. this.selectComponent("#popupwindow").showModal(evnet.detail.item, 1)
  34. },
  35. fileDel: function () {
  36. //文件删除了就重新请求刷新一下
  37. this.getDocumentAll();
  38. },
  39. getDocumentAll() {
  40. //根据ID查询文件库下所有文件
  41. let params = {
  42. lessId: this.data.lessId,
  43. userId: httpUtil.httpData.userId,
  44. pageNo: 1,
  45. pageSize: 100000,
  46. }
  47. httpUtil.wxGet(httpUtil.interfaces.getDocumentFile, params).then((res: any) => {
  48. console.log("获取所有文件成功:", res)
  49. this.setData({
  50. itemList: res.data.data.list
  51. })
  52. if (this.data.downloadAll) {
  53. //下载全部
  54. console.log("this.data.downloadAll:", this.data.downloadAll)
  55. this.data.itemList.forEach((item, index) => {
  56. this.selectComponent('#documentItem' + index).downLoadItem(1, item.type);
  57. });
  58. }
  59. }).catch((res) => {
  60. console.log("获取所有文件失败:", res)
  61. })
  62. },
  63. downLoading: function (progress: any) {
  64. this.selectComponent("#documentItem" + this.data.showItemIndex).setDownLoadProgress(progress)
  65. },
  66. downLoadComplete: function (data: any) {
  67. this.selectComponent("#documentItem" + this.data.showItemIndex).downLoadComplete(data)
  68. },
  69. downLoadError: function (data: any) {
  70. this.selectComponent("#documentItem" + this.data.showItemIndex).downLoadError(data)
  71. }
  72. })