TestControlCenter.vue 3.45 KB
<template>
  <div class="panel">
    <div class="panel-head">
      <div class="title-group">
        <div class="title">测试案例</div>
        <div class="subtitle">选择数据集并点击案例快速测试</div>
      </div>
      <el-select
        v-model="selectedDatasetKey"
        size="small"
        class="dataset-select"
        :loading="catalog.datasetLoading"
        placeholder="选择数据集"
        @change="onDatasetChange"
      >
        <el-option v-for="d in catalog.datasets" :key="d.key" :label="d.label" :value="d.key" />
      </el-select>
    </div>

    <div class="list">
      <div
        v-for="(c, idx) in visibleCases"
        :key="idx"
        class="item"
        tabindex="0"
        @click="emitSend(c.message)"
        @keydown.enter.prevent="emitSend(c.message)"
      >
        <div class="item-text">{{ c.message }}</div>
        <div class="item-meta">
          <span class="pill">{{ c.expected_intent }}</span>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { computed, ref, watchEffect } from "vue";
import { useCatalogStore } from "../../stores/catalog";

const emit = defineEmits<{ (e: "send", text: string): void }>();
const catalog = useCatalogStore();

const selectedDatasetKey = ref("");
const visibleCases = computed(() => catalog.cases.slice(0, 28));

watchEffect(() => {
  if (catalog.datasets.length === 0 && !catalog.datasetLoading) {
    catalog.refreshDatasets();
  }
  if (!selectedDatasetKey.value && catalog.datasetKey) {
    selectedDatasetKey.value = catalog.datasetKey;
  }
});

async function onDatasetChange(key: string): Promise<void> {
  await catalog.switchDataset(key);
}

function emitSend(text: string): void {
  const value = text.trim();
  if (!value) return;
  emit("send", value);
}
</script>

<style scoped>
.panel {
  display: flex;
  flex-direction: column;
  background: transparent;
}
.panel-head {
  padding: 4px 0 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  border-bottom: 1px solid #f1f5f9;
  margin-bottom: 16px;
}
.title-group {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.title {
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-weight: 800;
  font-size: 15px;
  color: #0f172a;
}
.subtitle {
  font-size: 11px;
  color: #64748b;
  font-weight: 500;
}
.dataset-select {
  width: 100%;
}
.dataset-select :deep(.el-input__wrapper) {
  border-radius: 8px;
  border: 1px solid #e2e8f0;
  box-shadow: none !important;
  height: 32px;
}
.dataset-select :deep(.el-input__wrapper):hover,
.dataset-select :deep(.el-input__wrapper.is-focus) {
  border-color: #818cf8;
}
.list {
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.item {
  border-radius: 10px;
  padding: 12px;
  background: #ffffff;
  border: 1px solid #e2e8f0;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.02);
}
.item:hover,
.item:focus {
  outline: none;
  border-color: #c7d2fe;
  background: #faf5ff;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.08);
}
.item:active {
  transform: translateY(0);
}
.item-text {
  font-size: 13px;
  line-height: 1.45;
  font-weight: 500;
  color: #1e293b;
  word-break: break-word;
}
.item-meta {
  margin-top: 8px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.pill {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 6px;
  font-weight: 600;
  color: #4f46e5;
  background: #eeebff;
  border: 1px solid #e0dbff;
}
</style>