index.vue 2.1 KB

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