zhengyiming
12 小时以前 d7c8a3a9e1fc5c8e596a17cdadb7079d20e52297
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<!--
 * @Author: 秦少卫
 * @Date: 2024-06-11 16:34:23
 * @LastEditors: 秦少卫
 * @LastEditTime: 2024-06-12 15:41:52
 * @Description: 分页组件
-->
 
<template>
  <!-- 列表 -->
  <div class="page-list-box" style="height: calc(100vh - 100px)" :id="props.DOMId">
    <Scroll
      :key="props.DOMId"
      v-if="showScroll"
      :on-reach-bottom="nextPage"
      :height="scrollHeight"
      :distance-to-edge="[-1, -1]"
    >
      <div class="img-box" v-if="pageData.length">
        <!-- 列表 -->
        <div class="img-item" v-for="info in pageData" :key="info.id">
          <Tooltip :content="info.name" placement="top">
            <Image
              lazy
              :src="info.src"
              @click="(e) => emit('click', { info, e })"
              @dragend="(e) => emit('dragend', { info, e })"
              fit="contain"
              width="100%"
              height="100%"
              :alt="info.name"
            />
          </Tooltip>
        </div>
      </div>
      <Spin size="large" fix :show="pageLoading"></Spin>
      <Divider plain v-if="isDownBottom">{{ pageData.length ? '已经到底了' : '暂无内容' }}</Divider>
    </Scroll>
  </div>
</template>
 
<script name="ImportJson" setup>
import usePageList from '@/hooks/usePageList';
 
const emit = defineEmits(['back', 'click', 'dragend']);
 
const props = defineProps({
  pageListApi: {
    type: Function,
  },
  filters: {
    type: Object,
  },
  DOMId: {
    type: String,
    default: '',
  },
  formatData: {
    type: Function,
  },
});
 
const sort = [];
 
// 通用分页
const {
  pageData,
  showScroll,
  scrollHeight,
  isDownBottom,
  pageLoading,
  startPage,
  startGetList,
  nextPage,
} = usePageList({
  el: '#' + props.DOMId,
  apiClient: props.pageListApi,
  filters: props.filters,
  sort,
  fields: [],
  formatData: props.formatData,
});
 
onMounted(async () => {
  startPage();
});
 
defineExpose({
  startGetList,
  startPage,
});
</script>
<style scoped lang="less">
.page-list-box {
  margin-top: 10px;
}
:deep(.ivu-scroll-container) {
  div.ivu-scroll-loader:first-child {
    height: 0;
  }
}
:deep(.ivu-divider-horizontal) {
  &.ivu-divider-with-text-center {
    margin-bottom: 0;
  }
}
:deep(.ivu-tooltip-rel) {
  display: block;
  position: relative;
  width: 100%;
  height: 100%;
}
 
:deep(.ivu-tooltip) {
  display: block;
  height: 100%;
  width: 100%;
}
 
.img-box {
  display: grid;
  display: grid;
  grid-template-columns: repeat(3, 90px);
  grid-auto-rows: 90px;
  grid-row-gap: 10px;
  justify-content: space-between;
  padding: 8px;
  background: #f1f2f4;
  border-radius: 10px;
  margin-bottom: 10px;
  .img-item {
    border-radius: 5px;
    padding: 5px;
    cursor: pointer;
    &:hover {
      background: #bababa;
    }
  }
}
</style>