index.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <template>
  2. <view class="file-info-container">
  3. <view class="u-page">
  4. <u-list
  5. @scrolltolower="scrolltolower"
  6. >
  7. <u-list-item
  8. v-for="(item, index) in indexList"
  9. :key="index"
  10. >
  11. <view class="file-info-item" @click="onItemClick(item)">
  12. <view class="file-info-item-img">
  13. <image :src="getImageUrl(ICON_CFG.file_icon)" mode="aspectFill" />
  14. </view>
  15. <view class="file-info-item-content">
  16. <view class="file-info-item-title">{{ item.title }}</view>
  17. <view class="file-info-item-date">{{ item.date }}</view>
  18. </view>
  19. </view>
  20. </u-list-item>
  21. </u-list>
  22. <u-loadmore :status="loadStatus" />
  23. </view>
  24. </view>
  25. </template>
  26. <script>
  27. import { fetchFileList } from '@/common/api';
  28. import { ICON_CFG } from '@/common/EnumConst';
  29. import { getImageUrl, viewFileFn } from '@/util';
  30. let page = 1;
  31. export default {
  32. name: 'content',
  33. props: {},
  34. data() {
  35. return {
  36. ICON_CFG,
  37. indexList: [],
  38. loadStatus: 'loadmore', // loadmore,loading,nomore
  39. };
  40. },
  41. created() {
  42. },
  43. onLoad() {
  44. this.loadmore();
  45. },
  46. methods: {
  47. getImageUrl,
  48. onItemClick(item) {
  49. viewFileFn(getImageUrl(item.uri), item.title, `.${item.fileExt}`);
  50. },
  51. scrolltolower() {
  52. if (page > 1 && this.loadStatus === 'nomore') {
  53. return;
  54. }
  55. this.loadmore();
  56. },
  57. loadmore() {
  58. this.loadStatus = 'loading';
  59. fetchFileList({
  60. pageNum: page,
  61. pageSize: 10,
  62. fileType: 2,
  63. }).then(res => {
  64. page += 1;
  65. if (res.rows.length > 0) {
  66. this.indexList = this.indexList.concat(res.rows.map(item => {
  67. return {
  68. id: item.id,
  69. title: item.fileName,
  70. date: item.createTime,
  71. ...item,
  72. };
  73. }));
  74. }
  75. if (res.rows.length < 10) {
  76. this.loadStatus = 'nomore';
  77. }
  78. });
  79. },
  80. },
  81. };
  82. </script>
  83. <style lang="scss" src="./index.scss" />;