由于配置结构、部分路由元信息、目录组织以及少量组件命名都做了调整,建议按“先让项目跑起来,再逐项清理”的方式迁移。
apps/core 作为你的新应用基础src/settings.tsmeta、组件引用和目录结构配置文件统一放在 apps/<app>/src/settings.ts 中。
为了方便从 v5.x 迁移,框架提供了兼容函数 setSettingsLegacy :
import { setSettingsLegacy } from '@fantastic-admin/settings'
export default setSettingsLegacy({
// v5.x 配置
})你可以先把 v5.x 的配置整体复制到 apps/<app>/src/settings.ts 中,通过 setSettingsLegacy() 让项目先正常运行。
项目运行后,浏览器开发者工具中会输出一份转换后的新配置。将它复制回来,替换为正式写法即可:
import { setSettings } from '@fantastic-admin/settings'
export default setSettings({
// 新配置
})下面这些映射已按 packages/settings/src/utils.ts 中 setSettingsLegacy() 的实现校验:
| v5.x | 新配置 |
|---|---|
app.enablePermission | app.account.auth |
app.loginExpiredMode | app.account.expiredMode |
app.routeBaseOn | app.routeBaseOn |
app.routeBaseOn = 'filesystem' | 自动转为 app.routeBaseOn = 'frontend' |
app.enableDynamicTitle | app.dynamicTitle |
app.enableWatermark | app.watermark |
app.enableFeedback | app.feedback |
app.enableErrorLog | app.errorLog |
app.enableCheckUpdates | app.checkUpdates |
app.enableMournMode | app.rip |
layout.enableMobileAdaptation | app.mobile |
layout.widthMode = 'center' | app.layout.center = true |
layout.widthModeScope | app.layout.centerScope |
home.enable / title / fullPath | app.home.enable / title / fullPath |
copyright.* | app.copyright.* |
app.themeSync | theme.sync |
app.lightTheme / darkTheme | theme.light / dark |
app.colorScheme | theme.colorScheme |
app.radius | theme.radius |
app.enableColorAmblyopiaMode | theme.colorAmblyopia |
menu.enableDark | menu.dark |
menu.subMenuUniqueOpened | menu.subMenuUniqueExpand |
menu.enableSubMenuCollapseButton | menu.subMenuCollapseButton |
tabbar.enable | topbar.tabbar |
toolbar.enable | topbar.toolbar |
tabbar.enableIcon | tabbar.icon |
tabbar.enableMemory | tabbar.memory |
toolbar.navSearch | toolbar.menuSearch.enable |
navSearch.enableHotkeys | toolbar.menuSearch.hotkeys |
mainPage.iframeCacheMax | page.iframeKeepAliveMax |
app.enableProgress | page.progress |
routeBaseOn: 'filesystem' 的说明 已移除文件路由系统,也就是说 routeBaseOn 不再支持 filesystem 选项。
现在的类型定义中,routeBaseOn 只保留:
frontendbackend因此如果你的 v5 项目里使用过:
app: {
routeBaseOn: 'filesystem',
}迁移时需要改为前端路由方案。兼容迁移函数 setSettingsLegacy() 会自动把它转换成:
app: {
routeBaseOn: 'frontend',
}这也意味着:原先依赖文件路由的组织方式,需要手动调整为当前的路由模块组织方式。
setSettingsLegacy() 不会把旧版 userPreferences 自动转换成新版 app.preferences 的细粒度配置。
也就是说,如果你的 v5 项目开启过用户偏好设置,迁移后需要你手动改写为:
export default setSettings({
app: {
preferences: {
theme: true,
menu: true,
topbar: true,
tabbar: true,
toolbar: true,
page: true,
},
},
})如果你需要做更细粒度的偏好设置控制,例如只开放某几个子项,建议继续阅读《用户偏好设置》。
配置项做了重新分层,顶层配置大致分为:
app:应用级配置theme:主题配置menu:导航菜单配置topbar:顶栏配置tabbar:标签栏配置toolbar:工具栏配置page:页面行为配置其中:
app 是应用级配置,不允许动态修改详细配置可继续阅读:
v5.x 及之前版本的偏好设置相对复杂,现在改为按配置树精细控制。
import { setSettings } from '@fantastic-admin/settings'
export default setSettings({
app: {
preferences: {
theme: true,
menu: {
style: false,
subMenuCollapseButton: true,
hotkeys: true,
},
},
},
})含义如下:
theme: true:允许用户自定义 theme 下的全部配置menu.style: false:不允许用户修改菜单风格menu.subMenuCollapseButton: true:允许用户修改次导航折叠按钮menu.hotkeys: true:允许用户修改该项相关偏好另外,偏好设置相关界面已合并到 layouts/components/AppSetting/index.vue 中,后续维护会更简单。
将部分和框架强相关、但不属于通用 UI 组件的内容,从原先的内建组件体系中迁出,统一放到 apps/<app>/src/components/ 目录下,并改为 App* 命名。
迁移时涉及到的组件调整包括:
FaAuth → AppAuthFaBackToTop → AppBackToTopFaCheckUpdates → AppCheckUpdatesFaCopyright → AppCopyrightFaNotAllowed → AppNotAllowedFaSystemInfo → AppSystemInfo其中通常只需要重点关注 FaAuth,因为它更可能被业务页面直接使用。
FaPinInput → FaInputOTPFaNotification 已移除如果你的旧项目里直接使用过 FaNotification,需要在迁移时手动删除或替换。
部分路由 meta 配置做了合并或重命名,下面这些写法已与 packages/types/types.ts 当前定义核对。
icon + activeIcon // 旧
meta: {
icon: 'i-twemoji:face-without-mouth',
activeIcon: 'i-twemoji:grinning-face-with-big-eyes',
}
// 新
meta: {
icon: ['i-twemoji:face-without-mouth', 'i-twemoji:grinning-face-with-big-eyes'],
}如果没有激活态图标,则仍然可以直接写字符串:
meta: {
icon: 'i-twemoji:face-without-mouth',
}badge + badgeVariant // 旧
meta: {
badge: 'PRO',
badgeVariant: 'destructive',
}
// 新
meta: {
badge: ['PRO', 'destructive'],
}如果不需要颜色方案:
meta: {
badge: 'PRO',
}cache + noCache // 旧
meta: {
cache: true,
noCache: 'xxx',
}
// 新
meta: {
keepAlive: true,
noKeepAlive: 'xxx',
}更多说明可阅读:页面保活
maximize + exitMaximize // 旧
meta: {
maximize: true,
exitMaximize: true,
}
// 新
meta: {
maximize: true,
}这里移除了 exitMaximize。离开该路由时会自动退出最大化。
如果你希望页面处于强制最大化状态,可以写成:
meta: {
maximize: [true, true],
}defaultOpened + alwaysOpened // 旧
meta: {
defaultOpened: true,
alwaysOpened: true,
}
// 新
meta: {
expand: [true, true],
}如果只需要默认展开:
meta: {
expand: true,
}permanent // 旧
meta: {
permanent: true,
}
// 新
meta: {
tabPermanent: true,
}新增了一些路由元信息,例如:
meta: {
layout: {
center: true,
centerScope: 'inner',
centerWidth: 1400,
},
localeAuth: ['zh-cn', 'zh-tw'],
}其中:
layout:可为单个路由开启居中布局localeAuth:可控制路由的区域权限更多字段说明可阅读:路由(导航菜单)
新增了 apps/<app>/src/store/modules/app/ 目录,用于存放和框架强相关的 store。
框架内置模块包括:
accountsettingsmenutabbarkeepAlivepreferencesfavoritesnotificationwatermarkrouteiframe迁移建议:
apps/<app>/src/store/modules/app/apps/<app>/src/store/modules/ 下按模块管理这样做的好处是,后续升级框架时更容易区分“框架代码”和“业务代码”。
更多说明可阅读:全局状态管理
下面这些目录变更可直接按当前目录结构处理:
原先 src/mock 目录下的文件已迁移到 apps/<app>/src/api/modules/,并使用 *.fake.ts 命名。
例如:
apps/example/src/api/modules/app.fake.ts更多说明可阅读:与服务端交互 / 假数据
除了上面的核心迁移点,还建议你逐项检查以下内容:
apps/<app>/src/layouts/components/Topbar/Toolbar/Notification/apps/<app>/src/locales/index.ts 中配置各语言的 directiontabbar.minMaxWidthapps/<app>/.env.* 模板和 环境变量文档plop迁移完成前,建议至少确认以下项目:
apps/<app>/src/settings.ts 已从 setSettingsLegacy() 切换到 setSettings()userPreferences,已手动改写为 app.preferencesFa* 非 UI 组件命名已改为 App*meta 中的旧字段已完成替换src/store/modules/app/src/api/modules/*.fake.tsdocs/guide/env.md 与 .env.* 模板完成核对如果你的 v5 项目改动较多,不建议一次性全面重构,推荐按下面方式逐步迁移:
setSettingsLegacy() 兼容旧配置app.preferences、路由 meta 和旧组件引用这样成本更低,也更容易定位问题。