document.ts 2.5 KB

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