Skip to content
TheChatArchiveThe Chat Archive
o1-mini-2024-09-12· OpenAIAi2 WildChat-4.8M (AI2)

<script setup lang="ts"> import { onMounted, ref, reactive, computed, watch } from 'vue'…

  1. User

    稍微美化一下页面,而不修改逻辑代码

  2. Assistant

    当然,我可以帮助你美化页面而不修改逻辑代码。下面是优化后的代码,主要通过增强布局和样式来提升用户界面的视觉效果:

    <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 () => {
      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)
        }
      }
      console.log(stable_diffusion_xls)
      console.log(fluxs)
    })
    </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" justify="center">
                <van-col :span="20">
                  <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"
                        :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-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;
    }
    
    /* 模型类型选择样式 */
    .model-type {
      display: flex;
      justify-content: center;
    }
    
    /* 模型ID输入样式 */
    .model-id .van-field__control {
      padding-left: 10px;
    }
    
    /* 模型列表样式 */
    .model-list {
      background-color: #fafafa;
      padding: 15px;
      border-radius: 6px;
      border: 1px solid #eaeaea;
    }
    
    /* 列表项样式 */
    .v-list-item {
      padding: 10px 15px;
      border-bottom: 1px solid #eaeaea;
    }
    
    .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;
    }
    </style>
    

    主要改进点:

    1. 整体布局调整:

      • 使用 van-row 的 justify="center" 属性使内容居中显示。
      • 将主内容包裹在一个宽度为 20 的 van-col 中,并添加内边距和背景色,使页面看起来更加整洁。
    2. 标题美化:

      • 增加了一个标题部分,使用更大的字体和加粗样式,使标题更加醒目。
    3. 统一间距:

      • 为各个部分(模型类型选择、模型ID输入、模型列表)添加了统一的下边距,增强分隔效果。
    4. 增加背景和阴影:

      • 主容器添加了白色背景、圆角和阴影效果,使内容区域更加突出。
      • 模型列表区域也添加了淡灰色背景和边框,使列表更具层次感。
    5. 优化表单和列表样式:

      • 为模型ID输入框添加了 clearable 属性,提升用户体验。
      • 优化了列表项的填充和边框,使每个项之间有清晰的分隔。
      • 调整了标题和副标题的字体颜色和大小,使信息层次分明。
    6. 分页样式优化:

      • 分页组件居中显示,并增加顶部边距,使其与列表有适当的分隔。
    7. 响应式设计考虑:

      • 使用 van-col 的 span 属性合理分配宽度,确保在不同屏幕尺寸下的良好展示效果。

    预览效果

    以下是改进后的界面效果预览:


    模型测试


    模型类型选择

    • SD-XL
    • FLUX

    模型ID

    • 输入框(带有清除按钮)

    模型列表

    • 列表项1
    • 列表项2
    • ...
    • 分页器

    通过上述改进,页面的视觉层次更加清晰,布局更加整洁,用户体验也得到了提升。如果你有特定的设计需求或风格偏好,可以进一步调整样式以满足你的需求。