KnowledgePanel.vue 5.88 KB
<template>
  <div class="knowledge-panel">
    <div class="settings-content-header">
      <h1>{{ $t("settings.knowledge.title") }}</h1>
      <p>{{ $t("settings.knowledge.desc") }}</p>
    </div>
    <div class="section section-storage">
      <div class="section-title">
        {{ $t("settings.knowledge.storageTitle") }}
      </div>
      <div class="storage-cards">
        <div class="storage-card">
          <div class="card-label">{{ $t("settings.knowledge.used") }}</div>
          <div class="card-value">
            {{ usedSpace }} <span class="unit">GB</span>
          </div>
        </div>
        <div class="storage-card">
          <div class="card-label">{{ $t("settings.knowledge.total") }}</div>
          <div class="card-value">
            {{ totalSpace }} <span class="unit">GB</span>
          </div>
        </div>
        <div class="storage-card">
          <div class="card-label">{{ $t("settings.knowledge.docCount") }}</div>
          <div class="card-value">{{ docCount }}</div>
        </div>
      </div>
      <div class="storage-progress">
        <div class="progress-bar">
          <div
            class="progress-inner"
            :style="{ width: progressPercent + '%' }"
          ></div>
        </div>
        <div class="progress-tip">
          {{ $t("settings.knowledge.storageTip") }}
        </div>
      </div>
    </div>
    <div class="divider"></div>
    <div class="section section-process">
      <div class="section-title">
        {{ $t("settings.knowledge.processTitle") }}
      </div>
      <div class="form-group process-row">
        <label class="switch">
          <input type="checkbox" v-model="autoIndex" />
          <span class="slider"></span>
        </label>
        <span class="process-label">
          {{ $t("settings.knowledge.autoIndex") }}
        </span>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, computed, onMounted } from "vue";
import { useI18n } from "vue-i18n";

const { t: _t } = useI18n();

const usedSpace = ref(0);
const totalSpace = ref(0);
const docCount = ref(0);
const autoIndex = ref(true);

const progressPercent = computed(() => {
  if (!totalSpace.value) return 0;
  return Math.min((usedSpace.value / totalSpace.value) * 100, 100).toFixed(2);
});

const fetchStorageStats = async () => {
  // TODO: 实际API调用
  // const res = await api.get('/api/storage/stats');
  // usedSpace.value = res.data.usedSpace;
  // totalSpace.value = res.data.totalSpace;
  // docCount.value = res.data.docCount;

  // Mock数据
  usedSpace.value = 1.2;
  totalSpace.value = 10;
  docCount.value = 127;
};

onMounted(() => {
  fetchStorageStats();
});
</script>

<style scoped lang="scss">
.knowledge-panel {
  color: var(--color-text);
  background: var(--color-bg);
  max-width: 700px;
  margin-left: 0;
  margin-right: auto;
  padding: 0 0 40px 0;
}

.settings-content-header {
  margin-top: 24px;
  margin-bottom: 48px;
  text-align: left;

  h1 {
    font-size: 32px;
    font-weight: 800;
    color: var(--color-text);
    margin-bottom: 10px;
    letter-spacing: 1px;
  }

  p {
    font-size: 16px;
    color: var(--color-secondary);
    font-weight: 400;
  }
}

.section {
  width: 100%;
  margin-bottom: 56px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}

.section-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--color-text);
  margin-bottom: 18px;
  text-align: left;
  letter-spacing: 1px;
}

.storage-cards {
  display: flex;
  gap: 24px;
  margin-bottom: 18px;
}

.storage-card {
  background: var(--color-card);
  border-radius: 12px;
  padding: 24px 32px 18px 32px;
  min-width: 160px;
  text-align: center;
  box-shadow: 0 2px 8px rgba(51, 153, 255, 0.04);
  border: 1px solid var(--color-border);
}

.card-label {
  font-size: 15px;
  color: var(--color-secondary);
  margin-bottom: 12px;
  font-weight: 500;
}

.card-value {
  font-size: 32px;
  font-weight: 800;
  color: var(--color-text);
  letter-spacing: -1px;

  .unit {
    font-size: 18px;
    font-weight: 600;
    color: var(--color-secondary);
    margin-left: 4px;
  }
}

.storage-progress {
  width: 100%;
  margin-top: 8px;
}

.progress-bar {
  width: 100%;
  height: 10px;
  background: var(--color-card);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.04);
  border: 1px solid var(--color-border);
}

.progress-inner {
  height: 100%;
  background: linear-gradient(90deg, #3399ff 0%, #66b3ff 100%);
  border-radius: 12px 0 0 12px;
  transition: width 0.5s;
}

.progress-tip {
  font-size: 13px;
  color: var(--color-secondary);
  margin-top: 12px;
}

.divider {
  width: calc(100% + 48px);
  height: 1px;
  background: var(--color-border);
  margin: 48px 0 56px -48px;
  opacity: 0.7;
}

.process-row {
  display: flex;
  align-items: center;
  gap: 16px;
}

.switch {
  position: relative;
  display: inline-block;
  width: 48px;
  height: 26px;

  input {
    opacity: 0;
    width: 0;
    height: 0;

    &:checked + .slider {
      background-color: #3399ff;

      &:before {
        transform: translateX(22px);
      }
    }

    &:focus + .slider {
      box-shadow: 0 0 1px #3399ff;
    }
  }
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--color-border);
  transition: 0.3s;
  border-radius: 26px;

  &:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 4px;
    bottom: 4px;
    background-color: white;
    transition: 0.3s;
    border-radius: 50%;
  }
}

.process-label {
  font-size: 15px;
  color: var(--color-text);
  font-weight: 500;
}

@media (max-width: 1024px) {
  .knowledge-panel {
    max-width: 100%;
    padding: 0 4px 20px 4px;
  }

  .storage-cards {
    flex-wrap: wrap;
    gap: 12px;
  }

  .storage-card {
    flex: 1;
    min-width: 120px;
    padding: 16px 20px 12px 20px;
  }

  .card-value {
    font-size: 24px;

    .unit {
      font-size: 14px;
    }
  }
}
</style>