index.vue 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <template>
  2. <div class="bg-white p-20px">
  3. <!-- TODO @fan:style 建议换成 unocss -->
  4. <!-- TODO @fan:Search 可以换成 Icon 组件么? -->
  5. <el-input
  6. v-model="queryParams.prompt"
  7. class="!w-full !mb-20px"
  8. size="large"
  9. placeholder="请输入要搜索的内容"
  10. :suffix-icon="Search"
  11. @keyup.enter="handleQuery"
  12. />
  13. <div class="grid grid-cols-[repeat(auto-fill,minmax(200px,1fr))] gap-10px bg-white shadow-[0_0_10px_rgba(0,0,0,0.1)]">
  14. <!-- TODO @fan:这个图片的风格,要不和 ImageCard.vue 界面一致?(只有卡片,没有操作);因为看着更有相框的感觉~~~ -->
  15. <div v-for="item in list" :key="item.id" class="relative overflow-hidden bg-gray-100 cursor-pointer transition-transform duration-300 hover:scale-105">
  16. <img :src="item.picUrl" class="w-full h-auto block transition-transform duration-300 hover:scale-110" />
  17. </div>
  18. </div>
  19. <!-- TODO @fan:缺少翻页 -->
  20. <!-- 分页 -->
  21. <Pagination
  22. :total="total"
  23. v-model:page="queryParams.pageNo"
  24. v-model:limit="queryParams.pageSize"
  25. @pagination="getList"
  26. />
  27. </div>
  28. </template>
  29. <script setup lang="ts">
  30. import { ImageApi, ImageVO } from '@/api/ai/image'
  31. import { Search } from '@element-plus/icons-vue'
  32. // TODO @fan:加个 loading 加载中的状态
  33. const loading = ref(true) // 列表的加载中
  34. const list = ref<ImageVO[]>([]) // 列表的数据
  35. const total = ref(0) // 列表的总页数
  36. const queryParams = reactive({
  37. pageNo: 1,
  38. pageSize: 10,
  39. publicStatus: true,
  40. prompt: undefined
  41. })
  42. /** 查询列表 */
  43. const getList = async () => {
  44. loading.value = true
  45. try {
  46. const data = await ImageApi.getImagePageMy(queryParams)
  47. list.value = data.list
  48. total.value = data.total
  49. } finally {
  50. loading.value = false
  51. }
  52. }
  53. /** 搜索按钮操作 */
  54. const handleQuery = () => {
  55. queryParams.pageNo = 1
  56. getList()
  57. }
  58. /** 初始化 */
  59. onMounted(async () => {
  60. await getList()
  61. })
  62. </script>