破坏性重构。框架对外只暴露一个 `sources` glob 入口,消费侧任何 .vue 都按文件路径后缀匹配同后缀覆盖: - shrimp/components/<name>.vue 同后缀覆盖框架内置(login/layout/topbar/ShrimpTable/...) - shrimp/components/fields/Field<X>.vue 注册类型 <x>(首字母小写) - shrimp/module/<key>.vue 业务模块 变更: - 删除 customFields / moduleSources / overrideField / registerField 旧入口 - 删除 fieldOverrides Map,字段表纯靠 glob 扫描注册 - 框架内 .vue 对可覆盖 peer 改用 defineAsyncComponent(resolveVue(...)) (login → ShrimpLangSwitch / layout → sideM/navMenu/topbar/userbar/logo / ShrimpTable → ShrimpEditDrawer/ShrimpFilterDrawer/...) - views/ 全部并入 components/,App.vue 上提到 src/ 根 - LangSwitch → ShrimpLangSwitch,PowerTree → ShrimpPowerTree - module/FieldRelativeTime.vue → components/fields/FieldRelativeTime.vue - module/user.vue 改用 #column-updatedAt slot 替代旧的 overrideField 字段类型约定从 'field' + Name 改为 lowercase-first(FieldString → 'string'), 内置和消费侧统一。
103 lines
3.1 KiB
Vue
103 lines
3.1 KiB
Vue
<template>
|
|
<div class="adminui-topbar">
|
|
<div class="left-panel">
|
|
<el-button v-if="canBack" :icon="ArrowLeft" link size="large" class="back-btn" @click="handleBack">{{ $t('base.back') }}</el-button>
|
|
<el-breadcrumb separator-icon="el-icon-arrow-right">
|
|
<template v-for="(item, index) in breadcrumb" :key="index">
|
|
<el-breadcrumb-item v-if="item.to && index < breadcrumb.length - 1" :to="item.to">
|
|
{{ vueAdmin.t(item.label) }}
|
|
</el-breadcrumb-item>
|
|
<el-breadcrumb-item v-else>{{ vueAdmin.t(item.label) }}</el-breadcrumb-item>
|
|
</template>
|
|
</el-breadcrumb>
|
|
</div>
|
|
<div class="center-panel"></div>
|
|
<div class="right-panel">
|
|
<slot></slot>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
|
|
<script lang="ts" setup>
|
|
import { vueAdmin } from "../VueAdmin";
|
|
import { computed } from "vue";
|
|
import { ArrowLeft } from "@element-plus/icons-vue";
|
|
import type { RouteLocationRaw } from "vue-router";
|
|
|
|
interface BreadcrumbItem {
|
|
key: string;
|
|
label: any;
|
|
to?: RouteLocationRaw;
|
|
}
|
|
|
|
// 把 ?id + ?pids 复原成 root→immediate-parent 的 id 数组
|
|
function getAncestorIds(): string[] {
|
|
const route = vueAdmin.router.currentRoute.value;
|
|
const pids = ((route.query.pids as string) || '').split(',').filter(Boolean);
|
|
const id = route.query.id as string | undefined;
|
|
return id ? [...pids, id] : pids;
|
|
}
|
|
|
|
const breadcrumb = computed<BreadcrumbItem[]>(() => {
|
|
const route = vueAdmin.router.currentRoute.value;
|
|
const raw = vueAdmin.getBreadcrumb(route.path);
|
|
const ancestors = getAncestorIds();
|
|
|
|
return raw.map(item => {
|
|
if (!item.path) return { key: item.key, label: item.label };
|
|
// path 段数 - 1 = 模块链深度 (0=顶层, >=1=子模块)
|
|
const depth = item.path.split('/').filter(Boolean).length - 1;
|
|
if (depth <= 0) return { key: item.key, label: item.label, to: item.path };
|
|
// 该 depth 的页面需要 ?id = ancestors[depth-1], pids = ancestors[0..depth-2]
|
|
const id = ancestors[depth - 1];
|
|
if (!id) return { key: item.key, label: item.label, to: item.path };
|
|
const newPids = ancestors.slice(0, depth - 1);
|
|
const query: Record<string, string> = { id };
|
|
if (newPids.length > 0) query.pids = newPids.join(',');
|
|
return { key: item.key, label: item.label, to: { path: item.path, query } };
|
|
});
|
|
});
|
|
|
|
// 倒数第二个可点的 item 即"上一级"
|
|
const backTarget = computed<RouteLocationRaw | undefined>(() => {
|
|
const list = breadcrumb.value;
|
|
for (let i = list.length - 2; i >= 0; i--) {
|
|
if (list[i].to) return list[i].to;
|
|
}
|
|
return undefined;
|
|
});
|
|
const canBack = computed(() => !!backTarget.value);
|
|
|
|
function handleBack() {
|
|
// 优先用浏览器历史(保留来时的完整 query);无历史则按 breadcrumb 计算的目标 push
|
|
if (window.history.length > 1) {
|
|
vueAdmin.router.back();
|
|
} else if (backTarget.value) {
|
|
vueAdmin.router.push(backTarget.value);
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<style scoped>
|
|
.left-panel {
|
|
display: flex;
|
|
align-items: center;
|
|
}
|
|
|
|
.back-btn {
|
|
margin-left: 10px;
|
|
margin-right: 16px;
|
|
}
|
|
|
|
.el-breadcrumb {
|
|
margin-left: 8px;
|
|
}
|
|
|
|
/* 小屏: 只保留最后一段(当前页);返回按钮和菜单覆盖上层导航 */
|
|
@media (max-width: 768px) {
|
|
.el-breadcrumb :deep(.el-breadcrumb__item):not(:last-child) {
|
|
display: none;
|
|
}
|
|
}
|
|
</style>
|