<script setup lang="ts">
import { onMounted, ref, reactive, computed, watch } from 'vue'
import { Pixihttp } from '../systems/http.ts'

const checked_type = ref('1')
const model_id = ref('')

// 使用 reactive 创建响应式数组
const stable_diffusion_xls = reactive<Array<any>>([])
const fluxs = reactive<Array<any>>([])

// 分页状态
const currentPage = ref(1)
const itemsPerPage = 50

// 监听 checked_type 变化，重置 currentPage
watch(checked_type, () => {
  currentPage.value = 1
})

// 计算总页数
const totalPages = computed(() => {
  const totalItems =
    checked_type.value === '1' ? stable_diffusion_xls.length : fluxs.length
  return Math.ceil(totalItems / itemsPerPage)
})

// 计算当前页显示的模型
const paginatedModels = computed(() => {
  const models = checked_type.value === '1' ? stable_diffusion_xls : fluxs
  const start = (currentPage.value - 1) * itemsPerPage
  const end = start + itemsPerPage
  return models.slice(start, end)
})

onMounted(async () => {
  try {
    const httpdata = await Pixihttp.get_model_list()
    for (let entry of httpdata.data) {
      if (entry.model_category === 'stable_diffusion_xl') {
        stable_diffusion_xls.push(entry)
      } else if (entry.model_category === 'flux') {
        fluxs.push(entry)
      }
    }

    // 按 api_calls 降序排序 stable_diffusion_xls
    stable_diffusion_xls.sort((a, b) => b.api_calls - a.api_calls)

    // 按 api_calls 降序排序 fluxs
    fluxs.sort((a, b) => b.api_calls - a.api_calls)

    console.log('Stable Diffusion XL Models:', stable_diffusion_xls)
    console.log('Flux Models:', fluxs)
  } catch (error) {
    console.error('Failed to fetch model list:', error)
  }
})
</script>

<template>
  <div class="root">
    <van-row justify="center">
      <van-col :span="20">
        <div class="main-container">
          <!-- 标题部分 -->
          <van-row class="header" justify="center">
            <van-col>
              <h1 class="title">模型测试</h1>
            </van-col>
          </van-row>

          <!-- 模型类型选择 -->
          <van-row class="section" justify="center">
            <van-col :span="12">
              <div class="model-type">
                <van-radio-group v-model="checked_type" direction="horizontal">
                  <van-radio name="1">SD-XL</van-radio>
                  <van-radio name="2">FLUX</van-radio>
                </van-radio-group>
              </div>
            </van-col>
          </van-row>

          <!-- 模型ID输入 -->
          <van-row class="section" justify="center">
            <van-col :span="12">
              <div class="model-id">
                <van-cell-group inset>
                  <van-field
                    v-model="model_id"
                    label="模型ID："
                    left-icon="smile-o"
                    right-icon="warning-o"
                    placeholder="输入模型ID"
                    clearable
                  />
                </van-cell-group>
              </div>
            </van-col>
          </van-row>

          <!-- 模型列表和代码输入区域 -->
          <van-row class="section align-stretch" justify="center">
            <!-- 模型列表 -->
            <van-col :span="12" class="flex-item">
              <div class="model-list">
                <v-list lines="one" density="compact" max-height="300">
                  <v-list-item
                    v-for="item in paginatedModels"
                    :key="item.model_id"
                    :title="item.model_name + ' 调用次数： ' + item.api_calls"
                    :subtitle="'模型ID: ' + item.model_id"
                  ></v-list-item>
                </v-list>
                <v-pagination
                  v-model="currentPage"
                  :length="totalPages"
                  class="pagination"
                ></v-pagination>
              </div>
            </van-col>

            <!-- 代码输入 -->
            <van-col :span="12" class="flex-item">
              <div class="code_input">
                <v-container>
                  <v-textarea
                    row-height="15"
                    bg-color="amber-lighten-4"
                    color="orange orange-darken-4"
                    label="代码输入"
                    rows="10"
                    placeholder="在此输入代码..."
                    auto-grow
                  ></v-textarea>
                </v-container>
                <v-btn block>开始绘图</v-btn>
              </div>
            </van-col>
          </van-row>
        </div>
      </van-col>
    </van-row>
  </div>
</template>

<style scoped>
.root {
  background-color: #f5f5f5;
  padding: 20px 0;
  min-height: 100vh;
}

.main-container {
  background-color: #ffffff;
  padding: 30px;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.header {
  margin-bottom: 30px;
}

.title {
  font-size: 24px;
  font-weight: 600;
  text-align: center;
  color: #333333;
}

.section {
  margin-bottom: 25px;
}

.align-stretch {
  display: flex;
  align-items: stretch;
}

.flex-item {
  display: flex;
}

.model-type {
  display: flex;
  justify-content: center;
}

.model-id .van-field__control {
  padding-left: 10px;
}

.model-list,
.code_input {
  background-color: #fafafa;
  padding: 15px;
  border-radius: 6px;
  border: 1px solid #eaeaea;
  flex: 1;
  display: flex;
  flex-direction: column;
}

.v-list-item {
  padding: 10px 15px;
  border-bottom: 1px solid #eaeaea;
  flex: none;
}

.v-list-item:last-child {
  border-bottom: none;
}

.v-list-item__title {
  font-weight: 500;
  color: #555555;
}

.v-list-item__subtitle {
  color: #888888;
  font-size: 14px;
}

.pagination {
  display: flex;
  justify-content: center;
  margin-top: 20px;
  flex-shrink: 0;
}

.code_input v-container {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.v-textarea {
  flex: 1;
  resize: none;
}
</style>
帮我在底部增加一个画廊，用于显示一系列图片，你先假设有100张图片，你帮我把这些图片按10张图一页这样分页展示，修改我的代码