gaoluyang
2 天以前 b64a0deae5b5d33f9e20671a68936b27f0b9b00b
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
<script setup lang="ts">
import type { AiImageApi } from '#/api/ai/image';
 
import { onMounted, reactive, ref } from 'vue';
 
import { Page } from '@vben/common-ui';
 
import { useDebounceFn } from '@vueuse/core';
import { Image, Input, Pagination } from 'ant-design-vue';
 
import { getImagePageMy } from '#/api/ai/image';
 
const loading = ref(true); // 列表的加载中
const list = ref<AiImageApi.Image[]>([]); // 列表的数据
const total = ref(0); // 列表的总页数
const queryParams = reactive({
  pageNo: 1,
  pageSize: 10,
  publicStatus: true,
  prompt: undefined,
});
 
/** 查询列表 */
async function getList() {
  loading.value = true;
  try {
    const data = await getImagePageMy(queryParams);
    list.value = data.list;
    total.value = data.total;
  } finally {
    loading.value = false;
  }
}
 
const debounceGetList = useDebounceFn(getList, 80);
 
/** 搜索按钮操作 */
function handleQuery() {
  queryParams.pageNo = 1;
  getList();
}
 
/** 初始化 */
onMounted(async () => {
  await getList();
});
</script>
<template>
  <Page auto-content-height>
    <div class="bg-card p-5">
      <Input.Search
        v-model="queryParams.prompt"
        class="mb-5 w-full"
        size="large"
        placeholder="请输入要搜索的内容"
        @keyup.enter="handleQuery"
      />
      <div
        class="grid grid-cols-[repeat(auto-fill,minmax(200px,1fr))] gap-2.5 bg-card shadow-sm"
      >
        <div
          v-for="item in list"
          :key="item.id"
          class="relative cursor-pointer overflow-hidden bg-card transition-transform duration-300 hover:scale-105"
        >
          <Image
            :src="item.picUrl"
            class="block h-auto w-full transition-transform duration-300 hover:scale-110"
          />
        </div>
      </div>
      <!-- 分页 -->
      <Pagination
        :total="total"
        :show-total="(total) => `共 ${total} 条`"
        show-quick-jumper
        show-size-changer
        v-model:current="queryParams.pageNo"
        v-model:page-size="queryParams.pageSize"
        @change="debounceGetList"
        @show-size-change="debounceGetList"
        class="mt-5"
      />
    </div>
  </Page>
</template>