feat: element plus UI组件库
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
041bb73b9a
commit
5f6fbcd76f
30 files changed
+3621
-1327
No files matched your search
@@ -2,17 +2,34 @@
|
||||
/**
|
||||
* features/kb/components/DifySettingsDialog.vue
|
||||
* 用途:提供知识库 Dify 连接及默认同步参数的查看、编辑和保存界面。
|
||||
* 依赖:Vue 响应式 API、Vue I18n、kb.api 的 Dify 设置读写接口。
|
||||
* 逻辑:KbAdminPanel 控制弹窗开关;本组件加载或保存设置后通过事件把结果反馈给父组件。
|
||||
* 依赖:Vue 响应式 API、Element Plus、Vue I18n、kb.api 的 Dify 设置读写接口。
|
||||
* 逻辑:KbAdminPanel 控制弹窗开关;本组件加载或保存设置后通过事件把结果反馈给父组件。表单按连接、检索、分段三块排,密钥默认遮挡;开关行按左标题、开关、右标题、数字四列对齐。
|
||||
*/
|
||||
|
||||
import { reactive, ref, watch } from 'vue';
|
||||
import { reactive, ref, useId, watch } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import {
|
||||
ElButton,
|
||||
ElDialog,
|
||||
ElForm,
|
||||
ElFormItem,
|
||||
ElInput,
|
||||
ElInputNumber,
|
||||
ElLoading,
|
||||
ElOption,
|
||||
ElSelect,
|
||||
ElSwitch,
|
||||
} from 'element-plus';
|
||||
import { getKbDifySettings, updateKbDifySettings } from '../api/kb.api';
|
||||
|
||||
const props = defineProps<{ open: boolean }>();
|
||||
const emit = defineEmits<{ close: []; saved: [message: string]; error: [message: string] }>();
|
||||
const { t } = useI18n();
|
||||
const vLoading = ElLoading.directive;
|
||||
const rerankLabelId = useId();
|
||||
const topKLabelId = useId();
|
||||
const scoreSwitchLabelId = useId();
|
||||
const scoreValueLabelId = useId();
|
||||
|
||||
const loading = ref(false);
|
||||
const saving = ref(false);
|
||||
@@ -108,94 +125,243 @@ watch(() => props.open, (open) => {
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div v-if="open" class="dialog-overlay" @click="close">
|
||||
<div class="dialog-panel max-w-3xl max-h-[92vh] overflow-y-auto" @click.stop>
|
||||
<div class="px-5 sm:px-8 pt-5 sm:pt-7 pb-4 border-b border-subtle flex items-center justify-between gap-4">
|
||||
<div>
|
||||
<h3 class="section-title">{{ t('kbDifySettings.title') }}</h3>
|
||||
<p class="section-desc mt-1">{{ t('kbDifySettings.subtitle') }}</p>
|
||||
</div>
|
||||
<button type="button" class="btn-secondary btn-sm" @click="close">
|
||||
{{ t('common.close') }}
|
||||
</button>
|
||||
<ElDialog
|
||||
:model-value="open"
|
||||
width="680px"
|
||||
align-center
|
||||
append-to-body
|
||||
:close-on-click-modal="false"
|
||||
@update:model-value="(value) => { if (!value) close(); }"
|
||||
>
|
||||
<template #header="{ titleId, titleClass }">
|
||||
<div class="dify-settings-heading">
|
||||
<span :id="titleId" :class="titleClass">{{ t('kbDifySettings.title') }}</span>
|
||||
<p class="dify-settings-subtitle">{{ t('kbDifySettings.subtitle') }}</p>
|
||||
</div>
|
||||
</template>
|
||||
<div v-loading="loading" class="dify-settings-body">
|
||||
<ElForm v-if="!loading" class="dify-settings-form" label-position="top" :model="form">
|
||||
<section class="dify-settings-section">
|
||||
<p class="dify-settings-section-title">{{ t('kbDifySettings.sections.connection') }}</p>
|
||||
<div class="dify-settings-panel dify-settings-stack">
|
||||
<ElFormItem :label="t('kbDifySettings.fields.baseUrl')">
|
||||
<ElInput v-model="form.DIFY_API_BASE" placeholder="https://api.dify.ai/v1" />
|
||||
</ElFormItem>
|
||||
<ElFormItem :label="t('kbDifySettings.fields.apiKey')">
|
||||
<ElInput v-model="form.DIFY_API_KEY" type="password" show-password autocomplete="off" placeholder="app-..." />
|
||||
</ElFormItem>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<div v-if="loading" class="px-5 sm:px-8 py-16 text-center text-sm text-muted">{{ t('kbDifySettings.loading') }}</div>
|
||||
<div v-else class="px-5 sm:px-8 py-5 grid gap-4 md:grid-cols-2">
|
||||
<label class="space-y-1.5">
|
||||
<span class="label-field block">{{ t('kbDifySettings.fields.baseUrl') }}</span>
|
||||
<input v-model="form.DIFY_API_BASE" class="input-field text-sm" placeholder="https://api.dify.ai/v1" />
|
||||
</label>
|
||||
<label class="space-y-1.5">
|
||||
<span class="label-field block">{{ t('kbDifySettings.fields.apiKey') }}</span>
|
||||
<input v-model="form.DIFY_API_KEY" class="input-field text-sm" placeholder="app-..." />
|
||||
</label>
|
||||
<label class="space-y-1.5">
|
||||
<span class="label-field block">{{ t('kbDifySettings.fields.permission') }}</span>
|
||||
<select v-model="form.KB_DIFY_PERMISSION" class="input-field text-sm">
|
||||
<option value="only_me">{{ t('kbDifySettings.options.permission.onlyMe') }}</option>
|
||||
<option value="all_team_members">{{ t('kbDifySettings.options.permission.allTeamMembers') }}</option>
|
||||
</select>
|
||||
</label>
|
||||
<label class="space-y-1.5">
|
||||
<span class="label-field block">{{ t('kbDifySettings.fields.indexingTechnique') }}</span>
|
||||
<select v-model="form.KB_DIFY_INDEXING_TECHNIQUE" class="input-field text-sm">
|
||||
<option value="high_quality">{{ t('kbDifySettings.options.indexingTechnique.highQuality') }}</option>
|
||||
<option value="economy">{{ t('kbDifySettings.options.indexingTechnique.economy') }}</option>
|
||||
</select>
|
||||
</label>
|
||||
<label class="space-y-1.5">
|
||||
<span class="label-field block">{{ t('kbDifySettings.fields.searchMethod') }}</span>
|
||||
<select v-model="form.KB_DIFY_SEARCH_METHOD" class="input-field text-sm">
|
||||
<option value="semantic_search">{{ t('kbDifySettings.options.searchMethod.semanticSearch') }}</option>
|
||||
<option value="hybrid_search">{{ t('kbDifySettings.options.searchMethod.hybridSearch') }}</option>
|
||||
<option value="full_text_search">{{ t('kbDifySettings.options.searchMethod.fullTextSearch') }}</option>
|
||||
</select>
|
||||
</label>
|
||||
<label class="space-y-1.5">
|
||||
<span class="label-field block">{{ t('kbDifySettings.fields.documentForm') }}</span>
|
||||
<select v-model="form.KB_DIFY_DOC_FORM" class="input-field text-sm">
|
||||
<option value="text_model">{{ t('kbDifySettings.options.documentForm.textModel') }}</option>
|
||||
</select>
|
||||
</label>
|
||||
<label class="flex items-center gap-2 space-y-0">
|
||||
<input v-model="form.KB_DIFY_RERANKING_ENABLE" type="checkbox" class="h-4 w-4" />
|
||||
<span class="label-field">{{ t('kbDifySettings.fields.rerankingEnable') }}</span>
|
||||
</label>
|
||||
<label class="space-y-1.5">
|
||||
<span class="label-field block">{{ t('kbDifySettings.fields.topK') }}</span>
|
||||
<input v-model.number="form.KB_DIFY_TOP_K" type="number" min="1" max="10" step="1" class="input-field text-sm" />
|
||||
</label>
|
||||
<label class="flex items-center gap-2 space-y-0">
|
||||
<input v-model="form.KB_DIFY_SCORE_THRESHOLD_ENABLED" type="checkbox" class="h-4 w-4" />
|
||||
<span class="label-field">{{ t('kbDifySettings.fields.scoreThresholdEnabled') }}</span>
|
||||
</label>
|
||||
<label class="space-y-1.5">
|
||||
<span class="label-field block">{{ t('kbDifySettings.fields.scoreThreshold') }}</span>
|
||||
<input v-model.number="form.KB_DIFY_SCORE_THRESHOLD" type="number" min="0" max="1" step="0.01" class="input-field text-sm" :disabled="!form.KB_DIFY_SCORE_THRESHOLD_ENABLED" />
|
||||
</label>
|
||||
<label class="space-y-1.5">
|
||||
<span class="label-field block">{{ t('kbDifySettings.fields.segmentMaxTokens') }}</span>
|
||||
<input v-model.number="form.KB_DIFY_SEGMENT_MAX_TOKENS" type="number" min="1" step="1" class="input-field text-sm" />
|
||||
</label>
|
||||
<label class="space-y-1.5">
|
||||
<span class="label-field block">{{ t('kbDifySettings.fields.segmentMaxTokensExcel') }}</span>
|
||||
<input v-model.number="form.KB_DIFY_SEGMENT_MAX_TOKENS_EXCEL" type="number" min="1" step="1" class="input-field text-sm" />
|
||||
</label>
|
||||
<label class="space-y-1.5">
|
||||
<span class="label-field block">{{ t('kbDifySettings.fields.segmentChunkOverlap') }}</span>
|
||||
<input v-model.number="form.KB_DIFY_SEGMENT_CHUNK_OVERLAP" type="number" min="0" step="1" class="input-field text-sm" />
|
||||
</label>
|
||||
</div>
|
||||
<section class="dify-settings-section">
|
||||
<p class="dify-settings-section-title">{{ t('kbDifySettings.sections.retrieval') }}</p>
|
||||
<div class="dify-settings-panel">
|
||||
<div class="dify-settings-grid">
|
||||
<ElFormItem :label="t('kbDifySettings.fields.permission')">
|
||||
<ElSelect v-model="form.KB_DIFY_PERMISSION">
|
||||
<ElOption value="only_me" :label="t('kbDifySettings.options.permission.onlyMe')" />
|
||||
<ElOption value="all_team_members" :label="t('kbDifySettings.options.permission.allTeamMembers')" />
|
||||
</ElSelect>
|
||||
</ElFormItem>
|
||||
<ElFormItem :label="t('kbDifySettings.fields.indexingTechnique')">
|
||||
<ElSelect v-model="form.KB_DIFY_INDEXING_TECHNIQUE">
|
||||
<ElOption value="high_quality" :label="t('kbDifySettings.options.indexingTechnique.highQuality')" />
|
||||
<ElOption value="economy" :label="t('kbDifySettings.options.indexingTechnique.economy')" />
|
||||
</ElSelect>
|
||||
</ElFormItem>
|
||||
<ElFormItem :label="t('kbDifySettings.fields.searchMethod')">
|
||||
<ElSelect v-model="form.KB_DIFY_SEARCH_METHOD">
|
||||
<ElOption value="semantic_search" :label="t('kbDifySettings.options.searchMethod.semanticSearch')" />
|
||||
<ElOption value="hybrid_search" :label="t('kbDifySettings.options.searchMethod.hybridSearch')" />
|
||||
<ElOption value="full_text_search" :label="t('kbDifySettings.options.searchMethod.fullTextSearch')" />
|
||||
</ElSelect>
|
||||
</ElFormItem>
|
||||
<ElFormItem :label="t('kbDifySettings.fields.documentForm')">
|
||||
<ElSelect v-model="form.KB_DIFY_DOC_FORM">
|
||||
<ElOption value="text_model" :label="t('kbDifySettings.options.documentForm.textModel')" />
|
||||
</ElSelect>
|
||||
</ElFormItem>
|
||||
</div>
|
||||
|
||||
<div class="admin-modal-footer">
|
||||
<button type="button" class="btn-ghost" @click="close">
|
||||
{{ t('common.cancel') }}
|
||||
</button>
|
||||
<button type="button" class="btn-primary" :disabled="saving" @click="save">
|
||||
{{ saving ? t('kbDifySettings.saving') : t('kbDifySettings.save') }}
|
||||
</button>
|
||||
</div>
|
||||
<div class="dify-settings-switch-grid">
|
||||
<div class="dify-settings-switch-row">
|
||||
<span :id="rerankLabelId">{{ t('kbDifySettings.fields.rerankingEnable') }}</span>
|
||||
<ElSwitch v-model="form.KB_DIFY_RERANKING_ENABLE" :aria-labelledby="rerankLabelId" />
|
||||
<span :id="topKLabelId">{{ t('kbDifySettings.fields.topK') }}</span>
|
||||
<ElInputNumber
|
||||
v-model="form.KB_DIFY_TOP_K"
|
||||
:min="1"
|
||||
:max="10"
|
||||
:step="1"
|
||||
controls-position="right"
|
||||
:aria-labelledby="topKLabelId"
|
||||
/>
|
||||
</div>
|
||||
<div class="dify-settings-switch-row">
|
||||
<span :id="scoreSwitchLabelId">{{ t('kbDifySettings.fields.scoreThresholdEnabled') }}</span>
|
||||
<ElSwitch v-model="form.KB_DIFY_SCORE_THRESHOLD_ENABLED" :aria-labelledby="scoreSwitchLabelId" />
|
||||
<span :id="scoreValueLabelId">{{ t('kbDifySettings.fields.scoreThreshold') }}</span>
|
||||
<ElInputNumber
|
||||
v-model="form.KB_DIFY_SCORE_THRESHOLD"
|
||||
:min="0"
|
||||
:max="1"
|
||||
:step="0.01"
|
||||
:precision="2"
|
||||
controls-position="right"
|
||||
:disabled="!form.KB_DIFY_SCORE_THRESHOLD_ENABLED"
|
||||
:aria-labelledby="scoreValueLabelId"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="dify-settings-section">
|
||||
<p class="dify-settings-section-title">{{ t('kbDifySettings.sections.chunking') }}</p>
|
||||
<div class="dify-settings-panel dify-settings-segments">
|
||||
<ElFormItem :label="t('kbDifySettings.fields.segmentMaxTokens')">
|
||||
<ElInputNumber v-model="form.KB_DIFY_SEGMENT_MAX_TOKENS" :min="1" :step="1" controls-position="right" />
|
||||
<p class="dify-settings-hint">{{ t('kbDifySettings.hints.maxTokens') }}</p>
|
||||
</ElFormItem>
|
||||
<ElFormItem :label="t('kbDifySettings.fields.segmentMaxTokensExcel')">
|
||||
<ElInputNumber v-model="form.KB_DIFY_SEGMENT_MAX_TOKENS_EXCEL" :min="1" :step="1" controls-position="right" />
|
||||
<p class="dify-settings-hint">{{ t('kbDifySettings.hints.maxTokens') }}</p>
|
||||
</ElFormItem>
|
||||
<ElFormItem :label="t('kbDifySettings.fields.segmentChunkOverlap')">
|
||||
<ElInputNumber v-model="form.KB_DIFY_SEGMENT_CHUNK_OVERLAP" :min="0" :step="1" controls-position="right" />
|
||||
<p class="dify-settings-hint">{{ t('kbDifySettings.hints.tokens') }}</p>
|
||||
</ElFormItem>
|
||||
</div>
|
||||
</section>
|
||||
</ElForm>
|
||||
</div>
|
||||
</div>
|
||||
<template #footer>
|
||||
<ElButton @click="close">{{ t('common.cancel') }}</ElButton>
|
||||
<ElButton type="primary" :loading="saving" @click="save">{{ t('kbDifySettings.save') }}</ElButton>
|
||||
</template>
|
||||
</ElDialog>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.dify-settings-heading {
|
||||
padding-right: 24px;
|
||||
}
|
||||
|
||||
.dify-settings-subtitle {
|
||||
margin: 4px 0 0;
|
||||
color: var(--el-text-color-secondary);
|
||||
font-size: var(--el-font-size-extra-small);
|
||||
font-weight: 400;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.dify-settings-body {
|
||||
min-height: 8rem;
|
||||
}
|
||||
|
||||
.dify-settings-section + .dify-settings-section {
|
||||
margin-top: 16px;
|
||||
}
|
||||
|
||||
.dify-settings-section-title {
|
||||
margin: 0 0 8px;
|
||||
color: var(--el-text-color-primary);
|
||||
font-size: var(--el-font-size-base);
|
||||
font-weight: 600;
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
.dify-settings-panel {
|
||||
padding: 16px;
|
||||
border: 1px solid var(--el-border-color-lighter);
|
||||
border-radius: var(--el-border-radius-base);
|
||||
}
|
||||
|
||||
.dify-settings-stack,
|
||||
.dify-settings-grid,
|
||||
.dify-settings-segments {
|
||||
display: grid;
|
||||
gap: 12px 16px;
|
||||
}
|
||||
|
||||
.dify-settings-grid,
|
||||
.dify-settings-segments {
|
||||
grid-template-columns: 1fr 1fr;
|
||||
}
|
||||
|
||||
.dify-settings-segments {
|
||||
grid-template-columns: 1fr 1fr 1fr;
|
||||
}
|
||||
|
||||
.dify-settings-form :deep(.el-form-item) {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.dify-settings-form :deep(.el-form-item__label) {
|
||||
margin-bottom: 4px;
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
.dify-settings-form :deep(.el-select),
|
||||
.dify-settings-stack :deep(.el-input),
|
||||
.dify-settings-segments :deep(.el-input-number) {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.dify-settings-segments :deep(.el-form-item__content) {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: stretch;
|
||||
}
|
||||
|
||||
.dify-settings-hint {
|
||||
margin: 4px 0 0;
|
||||
color: var(--el-text-color-secondary);
|
||||
font-size: var(--el-font-size-extra-small);
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
.dify-settings-switch-grid {
|
||||
display: grid;
|
||||
grid-template-columns: minmax(0, 1fr) auto max-content 8.5rem;
|
||||
column-gap: 16px;
|
||||
}
|
||||
|
||||
.dify-settings-switch-row {
|
||||
display: grid;
|
||||
grid-template-columns: subgrid;
|
||||
grid-column: 1 / -1;
|
||||
align-items: center;
|
||||
margin-top: 12px;
|
||||
padding-top: 12px;
|
||||
border-top: 1px solid var(--el-border-color-lighter);
|
||||
color: var(--el-text-color-regular);
|
||||
font-size: var(--el-font-size-base);
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
.dify-settings-form :deep(.el-input-number .el-input__inner) {
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.dify-settings-switch-row :deep(.el-input-number) {
|
||||
width: 8.5rem;
|
||||
}
|
||||
|
||||
@media (max-width: 640px) {
|
||||
.dify-settings-grid,
|
||||
.dify-settings-segments {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
.dify-settings-switch-grid,
|
||||
.dify-settings-switch-row {
|
||||
grid-template-columns: 1fr;
|
||||
row-gap: 8px;
|
||||
}
|
||||
|
||||
.dify-settings-switch-row :deep(.el-input-number) {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
Reference in new issue
Block a user