feat: element plus UI组件库

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
sophieandCursor committed 2026-10-14 20:25:35 +08:00
1 parent 041bb73b9a
commit 5f6fbcd76f
30 files changed
+3621 -1327

No files matched your search

@@ -1,14 +1,16 @@
<script setup lang="ts">
/**
* features/kb/components/KbGroupDrawer.vue
* 知识库分组新建/编辑抽屉表单。
* 依赖:Vue I18n、lucide-vue-next、父级 KbAdminPanel 传入的表单状态。
* 逻辑:只负责抽屉展示、表单双向同步和提交/关闭事件;接口调用与列表刷新由父组件处理。
* 知识库分组新建/编辑弹窗。
* 依赖:Element Plus 对话框与表单、Vue I18n、父级 KbAdminPanel 传入的表单状态。
* 逻辑:只负责弹窗展示、表单双向同步和提交/关闭事件;接口调用与列表刷新由父组件处理。
* 字段只有名称和描述,用随内容增高的对话框,避免整屏抽屉留下大块空白。
*/
import { computed } from 'vue';
import { useI18n } from 'vue-i18n';
import { FolderPlus, X } from 'lucide-vue-next';
import { FolderAdd } from '@element-plus/icons-vue';
import { ElButton, ElDialog, ElForm, ElFormItem, ElInput } from 'element-plus';
export interface KbGroupFormValue {
name: string;
@@ -37,7 +39,11 @@ const submitText = computed(() => {
return props.mode === 'edit' ? t('kbAdmin.form.saveChanges') : t('kbAdmin.form.create');
});
/** 更新指定表单字段,并将完整表单值同步回父组件。 */
/**
* 更新指定表单字段,并将完整表单值同步回父组件。
* @param field - 要改的字段,只能是名称或描述
* @param value - 输入框当前文本
*/
const updateField = (field: keyof KbGroupFormValue, value: string) => {
emit('update:form', {
...props.form,
@@ -47,81 +53,53 @@ const updateField = (field: keyof KbGroupFormValue, value: string) => {
</script>
<template>
<Teleport to="body">
<Transition name="kb-admin-drawer">
<div v-if="open" class="fixed inset-0 z-[100] bg-overlay backdrop-blur-sm" @click.self="emit('close')">
<aside class="ml-auto flex h-full w-full max-w-[440px] flex-col border-l border-default bg-surface shadow-elevated">
<header class="flex items-start justify-between gap-4 border-b border-default px-6 py-5">
<div class="min-w-0">
<h3 class="text-lg font-semibold text-primary">{{ formTitle }}</h3>
<p class="section-desc mt-1">{{ formDescription }}</p>
</div>
<button type="button" class="btn-icon-ds shrink-0" @click="emit('close')" :title="t('common.close')">
<X class="h-5 w-5" />
</button>
</header>
<div class="flex-1 space-y-5 overflow-y-auto px-6 py-5">
<div>
<label class="label-field mb-2 block">{{ t('kbAdmin.form.groupName') }}</label>
<input
:value="form.name"
class="input-field"
:placeholder="t('kbAdmin.form.groupNamePlaceholder')"
@input="updateField('name', ($event.target as HTMLInputElement).value)"
/>
</div>
<div>
<label class="label-field mb-2 block">{{ t('kbAdmin.form.groupDesc') }}</label>
<textarea
:value="form.description"
rows="8"
class="input-field"
:placeholder="t('kbAdmin.form.groupDescPlaceholder')"
@input="updateField('description', ($event.target as HTMLTextAreaElement).value)"
/>
</div>
</div>
<footer class="flex justify-end gap-2 border-t border-default px-6 py-4">
<button type="button" class="btn-secondary inline-flex items-center gap-1.5 px-4 py-2 text-sm" @click="emit('close')">
<X class="h-4 w-4 shrink-0" />
{{ t('common.cancel') }}
</button>
<button
type="button"
class="btn-primary inline-flex items-center gap-1.5 px-5 py-2 text-sm disabled:cursor-not-allowed disabled:opacity-60"
:disabled="submitting"
@click="emit('submit')"
>
<FolderPlus v-if="!submitting" class="h-4 w-4 shrink-0" />
{{ submitText }}
</button>
</footer>
</aside>
<ElDialog
:model-value="open"
width="480px"
align-center
append-to-body
:close-on-click-modal="!submitting"
:close-on-press-escape="!submitting"
:show-close="!submitting"
@close="emit('close')"
>
<template #header>
<div>
<h3 class="text-lg font-semibold text-primary">{{ formTitle }}</h3>
<p class="mt-1 text-sm text-muted">{{ formDescription }}</p>
</div>
</Transition>
</Teleport>
</template>
<ElForm class="kb-group-form" label-position="top" @submit.prevent="emit('submit')">
<ElFormItem :label="t('kbAdmin.form.groupName')">
<ElInput
:model-value="form.name"
:placeholder="t('kbAdmin.form.groupNamePlaceholder')"
@update:model-value="updateField('name', String($event))"
/>
</ElFormItem>
<ElFormItem :label="t('kbAdmin.form.groupDesc')">
<ElInput
:model-value="form.description"
type="textarea"
:rows="4"
:placeholder="t('kbAdmin.form.groupDescPlaceholder')"
@update:model-value="updateField('description', String($event))"
/>
</ElFormItem>
</ElForm>
<template #footer>
<ElButton :disabled="submitting" @click="emit('close')">{{ t('common.cancel') }}</ElButton>
<ElButton type="primary" :icon="FolderAdd" :loading="submitting" @click="emit('submit')">
{{ submitText }}
</ElButton>
</template>
</ElDialog>
</template>
<style scoped>
.kb-admin-drawer-enter-active,
.kb-admin-drawer-leave-active {
transition: opacity 0.18s ease;
}
.kb-admin-drawer-enter-active aside,
.kb-admin-drawer-leave-active aside {
transition: transform 0.18s ease;
}
.kb-admin-drawer-enter-from,
.kb-admin-drawer-leave-to {
opacity: 0;
}
.kb-admin-drawer-enter-from aside,
.kb-admin-drawer-leave-to aside {
transform: translateX(100%);
.kb-group-form :deep(.el-form-item:last-child) {
margin-bottom: 0;
}
</style>