fix(admin): 管理控制台界面使用element plus
This commit is contained in:
1 parent
6c47d0639c
commit
cdc8610ec1
45 files changed
+6258
-4639
No files matched your search
@@ -1,18 +1,31 @@
|
||||
/**
|
||||
* features/admin/modules/linked-services/LinkedServicesPage.vue
|
||||
* 关联服务管理独立页面:表格列表 + 新增/编辑弹窗。
|
||||
* 依赖:useLinkedServicesAdmin、LinkedServiceFormModal、DeleteConfirmDialog。
|
||||
* 逻辑:路由 /admin/linked-services;启用项自动出现在 Chat/工作台侧栏底部。
|
||||
* 用途:关联服务列表。一张卡片里放标题、新增按钮和表格。
|
||||
* 依赖:AdminListPage、useLinkedServicesAdmin、useElementProvider、element-plus、关联服务表单对话框。
|
||||
* 逻辑:路由 /admin/linked-services。启用项会出现在对话和工作台侧栏。删除用 Element 确认框。
|
||||
*/
|
||||
<script setup lang="ts">
|
||||
import { onMounted } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { Edit, Plus, Trash2 } from 'lucide-vue-next';
|
||||
import DeleteConfirmDialog from '@/shared/components/DeleteConfirmDialog.vue';
|
||||
import { Plus } from '@element-plus/icons-vue';
|
||||
import {
|
||||
ElButton,
|
||||
ElConfigProvider,
|
||||
ElSwitch,
|
||||
ElTable,
|
||||
ElTableColumn,
|
||||
} from 'element-plus';
|
||||
import 'element-plus/dist/index.css';
|
||||
import 'element-plus/theme-chalk/dark/css-vars.css';
|
||||
import '@/features/admin/styles/element-trial.css';
|
||||
import AdminListPage from '@/features/admin/components/AdminListPage.vue';
|
||||
import { useElementProvider } from '@/features/admin/composables/useElementProvider';
|
||||
import type { AdminLinkedServiceRow } from '@/features/admin/types/linked-service.types';
|
||||
import LinkedServiceFormModal from './components/LinkedServiceFormModal.vue';
|
||||
import { useLinkedServicesAdmin } from './composables/useLinkedServicesAdmin';
|
||||
|
||||
const { t } = useI18n();
|
||||
const { elementLocale } = useElementProvider();
|
||||
|
||||
const {
|
||||
services,
|
||||
@@ -20,8 +33,6 @@ const {
|
||||
isLoading,
|
||||
isSaving,
|
||||
showFormModal,
|
||||
showDeleteConfirmDialog,
|
||||
deleteConfirmMessage,
|
||||
loadAll,
|
||||
openCreateModal,
|
||||
openEditModal,
|
||||
@@ -29,93 +40,68 @@ const {
|
||||
saveService,
|
||||
toggleEnabled,
|
||||
deleteServiceItem,
|
||||
closeDeleteConfirm,
|
||||
confirmDelete,
|
||||
} = useLinkedServicesAdmin();
|
||||
|
||||
/**
|
||||
* 打开编辑对话框。表格行类型较宽,这里收成关联服务行。
|
||||
* @param row - 当前表格行
|
||||
*/
|
||||
function editService(row: AdminLinkedServiceRow): void {
|
||||
openEditModal(row);
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
void loadAll();
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section class="admin-table-section animate-fade-in-up">
|
||||
<div v-if="isLoading" class="flex items-center justify-center py-20">
|
||||
<div class="animate-spin rounded-full h-10 w-10 border-b-2 border-brand-600" />
|
||||
</div>
|
||||
<ElConfigProvider :locale="elementLocale">
|
||||
<AdminListPage :loading="isLoading">
|
||||
<template #title>
|
||||
<h2 class="section-title">{{ t('admin.linkedServices.title') }}</h2>
|
||||
<p class="section-desc mt-1">{{ t('admin.linkedServices.subtitle') }}</p>
|
||||
</template>
|
||||
<template #actions>
|
||||
<ElButton type="primary" :icon="Plus" @click="openCreateModal">
|
||||
{{ t('admin.linkedServices.add') }}
|
||||
</ElButton>
|
||||
</template>
|
||||
|
||||
<template v-else>
|
||||
<div class="admin-table-header admin-table-header--stacked">
|
||||
<div>
|
||||
<h2 class="section-title">{{ t('admin.linkedServices.title') }}</h2>
|
||||
<p class="section-desc mt-1">{{ t('admin.linkedServices.subtitle') }}</p>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
class="flex items-center gap-2 px-4 py-2 bg-brand-600 text-white rounded-xl hover:bg-brand-700 transition-all shadow-lg shadow-brand-200 active:scale-95 text-sm font-medium"
|
||||
@click="openCreateModal"
|
||||
>
|
||||
<Plus class="w-4 h-4" />
|
||||
<span>{{ t('admin.linkedServices.add') }}</span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="admin-table-wrap">
|
||||
<table class="admin-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="px-6 py-4 text-left text-xs">{{ t('admin.linkedServices.headers.name') }}</th>
|
||||
<th class="px-6 py-4 text-left text-xs">{{ t('admin.linkedServices.headers.url') }}</th>
|
||||
<th class="px-6 py-4 text-left text-xs w-28">{{ t('admin.linkedServices.headers.status') }}</th>
|
||||
<th class="px-6 py-4 text-left text-xs w-24">{{ t('admin.linkedServices.headers.sortOrder') }}</th>
|
||||
<th class="px-6 py-4 text-right text-xs w-40">{{ t('admin.linkedServices.headers.actions') }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-if="services.length === 0">
|
||||
<td colspan="5" class="px-6 admin-table-empty">{{ t('admin.linkedServices.empty') }}</td>
|
||||
</tr>
|
||||
<tr v-for="row in services" :key="row.id">
|
||||
<td class="px-6 py-4 text-sm font-medium text-primary">{{ row.name }}</td>
|
||||
<td class="px-6 py-4 text-sm text-secondary font-mono break-all">{{ row.url }}</td>
|
||||
<td class="px-6 py-4">
|
||||
<button
|
||||
type="button"
|
||||
class="inline-flex items-center rounded-full px-2.5 py-1 text-xs font-medium transition-colors"
|
||||
:class="row.is_enabled
|
||||
? 'bg-emerald-50 text-emerald-700 hover:bg-emerald-100'
|
||||
: 'bg-surface-soft text-muted hover:bg-surface'"
|
||||
@click="toggleEnabled(row)"
|
||||
>
|
||||
{{ row.is_enabled ? t('admin.linkedServices.status.enabled') : t('admin.linkedServices.status.disabled') }}
|
||||
</button>
|
||||
</td>
|
||||
<td class="px-6 py-4 text-sm text-secondary">{{ row.sort_order }}</td>
|
||||
<td class="px-6 py-4 text-right">
|
||||
<div class="inline-flex items-center gap-1">
|
||||
<button
|
||||
type="button"
|
||||
class="p-2 rounded-lg text-muted hover:bg-surface-soft hover:text-secondary"
|
||||
:title="t('admin.edit')"
|
||||
@click="openEditModal(row)"
|
||||
>
|
||||
<Edit class="w-4 h-4" />
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="p-2 rounded-lg text-muted hover:bg-red-50 hover:text-red-600"
|
||||
:title="t('admin.delete')"
|
||||
@click="deleteServiceItem(row.id)"
|
||||
>
|
||||
<Trash2 class="w-4 h-4" />
|
||||
</button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</template>
|
||||
<ElTable
|
||||
class="hx-admin-table"
|
||||
:data="services"
|
||||
row-key="id"
|
||||
:empty-text="t('admin.linkedServices.empty')"
|
||||
>
|
||||
<ElTableColumn prop="name" :label="t('admin.linkedServices.headers.name')" min-width="160" />
|
||||
<ElTableColumn prop="url" :label="t('admin.linkedServices.headers.url')" min-width="240">
|
||||
<template #default="{ row }">
|
||||
<span class="linked-service-url">{{ row.url }}</span>
|
||||
</template>
|
||||
</ElTableColumn>
|
||||
<ElTableColumn :label="t('admin.linkedServices.headers.status')" width="120">
|
||||
<template #default="{ row }">
|
||||
<ElSwitch
|
||||
:model-value="row.is_enabled"
|
||||
:title="row.is_enabled ? t('admin.linkedServices.status.enabled') : t('admin.linkedServices.status.disabled')"
|
||||
@change="toggleEnabled(row as AdminLinkedServiceRow)"
|
||||
/>
|
||||
</template>
|
||||
</ElTableColumn>
|
||||
<ElTableColumn prop="sort_order" :label="t('admin.linkedServices.headers.sortOrder')" width="100" />
|
||||
<ElTableColumn :label="t('admin.linkedServices.headers.actions')" width="140" align="right">
|
||||
<template #default="{ row }">
|
||||
<ElButton link type="primary" @click="editService(row as AdminLinkedServiceRow)">
|
||||
{{ t('admin.edit') }}
|
||||
</ElButton>
|
||||
<ElButton link type="danger" @click="deleteServiceItem((row as AdminLinkedServiceRow).id)">
|
||||
{{ t('admin.delete') }}
|
||||
</ElButton>
|
||||
</template>
|
||||
</ElTableColumn>
|
||||
</ElTable>
|
||||
</AdminListPage>
|
||||
|
||||
<LinkedServiceFormModal
|
||||
:visible="showFormModal"
|
||||
@@ -124,12 +110,11 @@ onMounted(() => {
|
||||
@close="closeFormModal"
|
||||
@save="saveService"
|
||||
/>
|
||||
|
||||
<DeleteConfirmDialog
|
||||
v-model="showDeleteConfirmDialog"
|
||||
:message="deleteConfirmMessage"
|
||||
@cancel="closeDeleteConfirm"
|
||||
@confirm="confirmDelete"
|
||||
/>
|
||||
</section>
|
||||
</ElConfigProvider>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.linked-service-url {
|
||||
word-break: break-all;
|
||||
}
|
||||
</style>
|
||||
Reference in new issue
Block a user