mirror of
https://github.com/XiaoDaiGua-Ray/ray-template.git
synced 2026-11-17 16:13:36 +08:00
perf(build): improve admin startup and runtime import boundaries
Load sign-in assets in the initial graph and defer the workspace, demo features, and mock client until needed. Split feature dependencies and clear stale files from the default production output. Document feature entry points for runtime imports and record the browser and Harness results.
This commit is contained in:
parent
8f49a1f44b
commit
eba29fcfcf
@ -4,6 +4,7 @@ A Vue 3 + TSX admin template with an admin application, a documentation site, an
|
||||
|
||||
- To locate an implementation, choose a topic from the [task index](llms.txt) or `pnpm harness context <scope>`. Consult the [architecture map](docs/architecture.md) for changes that cross module boundaries.
|
||||
- Check `git status` first and preserve existing changes. Trace callers and existing data contracts before changing routing, persistence, requests, or shared components.
|
||||
- Prefer feature entry points for runtime imports. Follow the [runtime import boundaries](harness/README.md#runtime-import-boundaries) when adding exports or changing what loads at startup or on demand.
|
||||
- For complex tasks, the lead agent may choose to use subagents under the [delegation guidelines](harness/README.md#using-subagents-when-useful), when the host supports them and current permissions allow it. Delegation needs no separate approval. The lead agent owns integration and final verification.
|
||||
- Write agent guidance and internal engineering documentation in English. Preserve the intended languages of product copy and reader-facing documentation.
|
||||
- Follow the [comment style](docs/comment-style.md) when adding or editing comments. Maintain both Chinese and English product copy. For visible behavior changes, use [browser verification](harness/README.md#browser-verification) only for affected pages, actions, and dimensions.
|
||||
|
||||
@ -12,25 +12,24 @@ vi.mock('@/api/admin/client', () => ({
|
||||
apiUrl: (path: string) => `http://localhost/ray-template/api/${path}`,
|
||||
}))
|
||||
|
||||
beforeEach(() => {
|
||||
vi.resetModules()
|
||||
installGuard.mockClear()
|
||||
setupWorker.mockReset()
|
||||
})
|
||||
|
||||
afterEach(() => vi.restoreAllMocks())
|
||||
|
||||
it('restarts the same MSW client across repeated and concurrent recoveries', async () => {
|
||||
const worker = { start: vi.fn(async () => {}), stop: vi.fn() }
|
||||
it('starts on the first API request and shares repeated concurrent recoveries', async () => {
|
||||
const worker = { start: vi.fn(async () => {}), stop: vi.fn(async () => {}) }
|
||||
|
||||
setupWorker.mockReturnValue(worker)
|
||||
|
||||
const { enableApiMock } = await import('@/mocks/browser')
|
||||
const { registerApiMock } = await import('@/mocks/register')
|
||||
|
||||
await Promise.all([enableApiMock(), enableApiMock()])
|
||||
registerApiMock()
|
||||
registerApiMock()
|
||||
expect(installGuard).toHaveBeenCalledOnce()
|
||||
expect(worker.start).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
serviceWorker: {
|
||||
url: `${import.meta.env.BASE_URL}mockServiceWorker.js?v=${mswVersion}`,
|
||||
options: { scope: import.meta.env.BASE_URL },
|
||||
},
|
||||
}),
|
||||
)
|
||||
|
||||
const guard = installGuard.mock.calls[0]![0]
|
||||
const probe = vi
|
||||
@ -41,6 +40,20 @@ it('restarts the same MSW client across repeated and concurrent recoveries', asy
|
||||
|
||||
await guard('http://localhost/unrelated')
|
||||
expect(probe).not.toHaveBeenCalled()
|
||||
expect(setupWorker).not.toHaveBeenCalled()
|
||||
|
||||
await Promise.all([
|
||||
guard('http://localhost/ray-template/api/admin/auth/session'),
|
||||
guard('http://localhost/ray-template/api/admin/routes'),
|
||||
])
|
||||
expect(worker.start).toHaveBeenCalledExactlyOnceWith(
|
||||
expect.objectContaining({
|
||||
serviceWorker: {
|
||||
url: `${import.meta.env.BASE_URL}mockServiceWorker.js?v=${mswVersion}`,
|
||||
options: { scope: import.meta.env.BASE_URL },
|
||||
},
|
||||
}),
|
||||
)
|
||||
|
||||
for (let attempt = 0; attempt < 2; attempt++) {
|
||||
probe.mockResolvedValueOnce(new Response(null, { status: 404 }))
|
||||
@ -52,6 +65,33 @@ it('restarts the same MSW client across repeated and concurrent recoveries', asy
|
||||
|
||||
expect(worker.stop).toHaveBeenCalledTimes(2)
|
||||
expect(worker.start).toHaveBeenCalledTimes(3)
|
||||
expect(probe).toHaveBeenCalledTimes(4)
|
||||
expect(probe).toHaveBeenCalledTimes(5)
|
||||
expect(setupWorker).toHaveBeenCalledOnce()
|
||||
})
|
||||
|
||||
it('blocks API requests if startup fails and retries the same client', async () => {
|
||||
const worker = {
|
||||
start: vi.fn(async () => {}).mockRejectedValueOnce(new Error('offline')),
|
||||
stop: vi.fn(async () => {}),
|
||||
}
|
||||
|
||||
setupWorker.mockReturnValue(worker)
|
||||
const probe = vi
|
||||
.spyOn(globalThis, 'fetch')
|
||||
.mockResolvedValue(
|
||||
new Response(null, { headers: { 'x-ray-mock': 'active' } }),
|
||||
)
|
||||
const { registerApiMock } = await import('@/mocks/register')
|
||||
|
||||
registerApiMock()
|
||||
const guard = installGuard.mock.calls[0]![0]
|
||||
const url = 'http://localhost/ray-template/api/admin/auth/login'
|
||||
|
||||
await expect(guard(url)).rejects.toThrow('offline')
|
||||
expect(probe).not.toHaveBeenCalled()
|
||||
await expect(guard(url)).resolves.toBeUndefined()
|
||||
expect(probe).toHaveBeenCalledOnce()
|
||||
expect(worker.stop).toHaveBeenCalledOnce()
|
||||
expect(worker.start).toHaveBeenCalledTimes(2)
|
||||
expect(setupWorker).toHaveBeenCalledOnce()
|
||||
})
|
||||
|
||||
@ -16,7 +16,7 @@ vi.mock('../../apps/admin/src/router/config/source', () => ({
|
||||
resetRouteSource: vi.fn(),
|
||||
}))
|
||||
vi.mock('../../apps/admin/src/router/routes', () => ({
|
||||
constantRoutes: [
|
||||
getRootRoutes: () => [
|
||||
{ path: '/', name: 'RLayout', component: { render: () => null } },
|
||||
],
|
||||
getLayoutRoutes: () => [],
|
||||
@ -43,7 +43,7 @@ it('loads no business routes before login, then shares a retry and registers gua
|
||||
.mockResolvedValue(void 0)
|
||||
|
||||
try {
|
||||
await setupRouter(app, false)
|
||||
await setupRouter(app, false, { render: () => null })
|
||||
expect(load).not.toHaveBeenCalled()
|
||||
await expect(loadAccountRoutes()).rejects.toThrow(
|
||||
'route endpoint unavailable',
|
||||
|
||||
@ -2,6 +2,7 @@ import { setupI18n } from '../../apps/admin/src/locales'
|
||||
import { setupRouter } from '../../apps/admin/src/router'
|
||||
import { setupStore } from '../../apps/admin/src/store'
|
||||
import { piniaSigningStore } from '../../apps/admin/src/store/modules/signing'
|
||||
import Login from '../../apps/admin/src/views/login'
|
||||
import renderHook from '../utils/renderHook'
|
||||
|
||||
/**
|
||||
@ -17,14 +18,14 @@ const setupMiniApp = async (authenticated = false) => {
|
||||
const [_, app] = renderHook(() => {})
|
||||
|
||||
setupStore(app)
|
||||
await setupI18n(app)
|
||||
setupI18n(app)
|
||||
|
||||
if (authenticated)
|
||||
await app.runWithContext(() =>
|
||||
piniaSigningStore().signing({ name: 'admin', pwd: '123456' }),
|
||||
)
|
||||
|
||||
await setupRouter(app, authenticated)
|
||||
await setupRouter(app, authenticated, Login)
|
||||
|
||||
return {
|
||||
app,
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
import { apiMockEnabled } from '@/api/admin/client'
|
||||
import AppGlobalSpin from '@/app-components/app/AppGlobalSpin'
|
||||
import AppLockScreen from '@/app-components/app/AppLockScreen'
|
||||
import AppNaiveGlobalProvider from '@/app-components/provider/AppNaiveGlobalProvider'
|
||||
import AppStyleProvider from '@/app-components/provider/AppStyleProvider'
|
||||
import AppVersionProvider from '@/app-components/provider/AppVersionProvider'
|
||||
@ -18,10 +17,15 @@ import { provideUiServices } from '@ray-template/ui/services'
|
||||
import { createStorage } from '@ray-template/utils/storage'
|
||||
import { RouterView } from 'vue-router'
|
||||
|
||||
const AppLockScreen = defineAsyncComponent(
|
||||
() => import('@/app-components/app/AppLockScreen'),
|
||||
)
|
||||
|
||||
export default defineComponent({
|
||||
name: 'App',
|
||||
setup() {
|
||||
const { getAppTheme, getThemeStyle } = useSettingGetters()
|
||||
const { getAppTheme, getThemeStyle, getLockScreenSwitch } =
|
||||
useSettingGetters()
|
||||
const { t } = useI18n()
|
||||
|
||||
provideUiServices({
|
||||
@ -34,12 +38,19 @@ export default defineComponent({
|
||||
iconUrl: (name, prefix) =>
|
||||
`${iconSprites[name.split('/')[0] as IconPackage]}#${prefix}-${name}`,
|
||||
})
|
||||
|
||||
// 首次打开后保留弹窗实例,让关闭动画正常完成。
|
||||
const lockScreenRequested = computed<boolean>(
|
||||
(requested) => !!requested || getLockScreenSwitch.value,
|
||||
)
|
||||
|
||||
return { lockScreenRequested }
|
||||
},
|
||||
render() {
|
||||
return (
|
||||
<AppNaiveGlobalProvider>
|
||||
<AppVersionProvider />
|
||||
{apiMockEnabled && <AppLockScreen />}
|
||||
{apiMockEnabled && this.lockScreenRequested && <AppLockScreen />}
|
||||
<AppStyleProvider />
|
||||
<AppWatermarkProvider />
|
||||
<AppGlobalSpin>
|
||||
|
||||
@ -5,10 +5,10 @@ import {
|
||||
useLockRules,
|
||||
} from '@/app-components/app/AppLockScreen/shared'
|
||||
import { APP_CATCH_KEY } from '@/app-config'
|
||||
import { RForm, useForm } from '@/components'
|
||||
import { useI18n } from '@/hooks'
|
||||
import { useSettingActions } from '@/store'
|
||||
import { encrypt, setStorage } from '@/utils'
|
||||
import { RForm, useForm } from '@ray-template/ui/form'
|
||||
import { NButton, NFormItem, NInput } from 'naive-ui'
|
||||
import type { InputInst } from 'naive-ui'
|
||||
import { useTemplateRef } from 'vue'
|
||||
|
||||
@ -6,7 +6,6 @@ import {
|
||||
useLockRules,
|
||||
} from '@/app-components/app/AppLockScreen/shared'
|
||||
import { APP_CATCH_KEY } from '@/app-config'
|
||||
import { RForm, useForm } from '@/components'
|
||||
import { useDevice, useI18n } from '@/hooks'
|
||||
import {
|
||||
useSettingActions,
|
||||
@ -14,6 +13,7 @@ import {
|
||||
useSigningActions,
|
||||
} from '@/store'
|
||||
import { decrypt, getStorage, removeStorage } from '@/utils'
|
||||
import { RForm, useForm } from '@ray-template/ui/form'
|
||||
import { useEventListener } from '@vueuse/core'
|
||||
import dayjs from 'dayjs'
|
||||
import { NButton, NFlex, NFormItem, NInput } from 'naive-ui'
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { RModal } from '@/components'
|
||||
import { useI18n } from '@/hooks'
|
||||
import { useSettingActions, useSettingGetters } from '@/store'
|
||||
import { RModal } from '@ray-template/ui/modal'
|
||||
import LockScreen from './components/LockScreen'
|
||||
|
||||
const AppLockScreen = defineComponent({
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
import './index.scss'
|
||||
import { RAY_TEMPLATE_DOCS_URL } from '@/app-config'
|
||||
import { RIcon } from '@/components'
|
||||
import { useI18n } from '@/hooks'
|
||||
import type { IconName } from '@/icons'
|
||||
import { RIcon } from '@ray-template/ui/icon'
|
||||
import type { PropType } from 'vue'
|
||||
|
||||
interface ShareLinkOption {
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
import { APP_CATCH_KEY } from '@/app-config'
|
||||
import { RModal } from '@/components'
|
||||
import { useI18n } from '@/hooks'
|
||||
import { useSigningActions } from '@/store'
|
||||
import { getStorage, setStorage } from '@/utils'
|
||||
import { getStorage, setStorage } from '@/utils/cache'
|
||||
import { RModal } from '@ray-template/ui/modal'
|
||||
|
||||
export default defineComponent({
|
||||
name: 'AppVersionProvider',
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
import './styles/entry'
|
||||
import { apiMockEnabled } from '@/api/admin/client'
|
||||
import AppNaiveGlobalProvider from '@/app-components/provider/AppNaiveGlobalProvider'
|
||||
import AppStyleProvider from '@/app-components/provider/AppStyleProvider'
|
||||
import AppWatermarkProvider from '@/app-components/provider/AppWatermarkProvider'
|
||||
@ -7,8 +6,8 @@ import { APP_THEME } from '@/app-config'
|
||||
import { setupDayjs } from '@/dayjs'
|
||||
import { setupDirectives } from '@/directives'
|
||||
import { useI18n, useTheme } from '@/hooks'
|
||||
import Layout from '@/layout'
|
||||
import { setupI18n } from '@/locales'
|
||||
import { registerApiMock } from '@/mocks/register'
|
||||
import { router } from '@/router'
|
||||
import {
|
||||
getStaticAppRoutes,
|
||||
@ -119,17 +118,12 @@ const DocumentationExample = defineComponent({
|
||||
|
||||
async function mountExample() {
|
||||
useMemoryCache()
|
||||
|
||||
if (apiMockEnabled) {
|
||||
const { enableApiMock } = await import('./mocks/browser')
|
||||
|
||||
await enableApiMock()
|
||||
}
|
||||
registerApiMock()
|
||||
|
||||
const app = createApp(DocumentationExample)
|
||||
|
||||
app.use(createPinia())
|
||||
await setupI18n(app)
|
||||
setupI18n(app)
|
||||
setupDayjs()
|
||||
setupDirectives(app)
|
||||
|
||||
@ -141,8 +135,6 @@ async function mountExample() {
|
||||
if (params.get('theme') === 'dark') darkTheme()
|
||||
else lightTheme()
|
||||
|
||||
router.removeRoute('RLogin')
|
||||
router.removeRoute('RLayout')
|
||||
setAppRouteModules(examples)
|
||||
|
||||
const routes = [
|
||||
@ -151,7 +143,11 @@ async function mountExample() {
|
||||
] as unknown as RouteRecordRaw[]
|
||||
|
||||
if (withLayout) {
|
||||
router.addRoute({ path: '/', component: Layout, children: routes })
|
||||
router.addRoute({
|
||||
path: '/',
|
||||
component: () => import('@/layout'),
|
||||
children: routes,
|
||||
})
|
||||
} else {
|
||||
for (const route of routes) router.addRoute(route)
|
||||
}
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
import { resolveIconName } from '@/icons'
|
||||
import './index.scss'
|
||||
import { RIcon } from '@/components'
|
||||
import { useSettingGetters } from '@/store'
|
||||
import { isValueType, renderNode } from '@/utils'
|
||||
import { RIcon } from '@ray-template/ui/icon'
|
||||
import { NEllipsis, NTooltip } from 'naive-ui'
|
||||
|
||||
export default defineComponent({
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
import './index.scss'
|
||||
import { LAYOUT_SIDER_REF } from '@/app-config'
|
||||
import { RIcon } from '@/components'
|
||||
import { useDevice, useI18n } from '@/hooks'
|
||||
import { positionSelectedMenuItem } from '@/layout/utils/position-selected-menu-item'
|
||||
import {
|
||||
@ -11,6 +10,7 @@ import {
|
||||
useSettingGetters,
|
||||
} from '@/store'
|
||||
import type { AppMenuOption, NaiveMenuOptions } from '@/types'
|
||||
import { RIcon } from '@ray-template/ui/icon'
|
||||
import { NButton, NDrawer, NLayoutContent, NLayoutSider, NMenu } from 'naive-ui'
|
||||
import type { MenuInst } from 'naive-ui'
|
||||
import type { PropType } from 'vue'
|
||||
|
||||
@ -1,10 +1,11 @@
|
||||
import './index.scss'
|
||||
import { RIcon, RMoreDropdown } from '@/components'
|
||||
import { useI18n, useMaximize, useSiderBar, useSpinning } from '@/hooks'
|
||||
import { FORBIDDEN_ROUTE_PATH } from '@/router/constant'
|
||||
import { useMenuActions, useMenuGetters, useRuntimeGetters } from '@/store'
|
||||
import type { AppMenuOption, MenuTagOptions } from '@/types'
|
||||
import { ShellTab } from '@ray-template/admin-shell'
|
||||
import { RIcon } from '@ray-template/ui/icon'
|
||||
import { RMoreDropdown } from '@ray-template/ui/more-dropdown'
|
||||
import { usePreferredReducedMotion, useResizeObserver } from '@vueuse/core'
|
||||
import { NDropdown, NFlex, NLayoutHeader, NScrollbar } from 'naive-ui'
|
||||
import type { ScrollbarInst } from 'naive-ui'
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
import './index.scss'
|
||||
import { RIcon } from '@/components'
|
||||
import { useI18n } from '@/hooks'
|
||||
import { positionSelectedMenuItem } from '@/layout/utils/position-selected-menu-item'
|
||||
import {
|
||||
@ -9,6 +8,7 @@ import {
|
||||
useNavigationHistoryGetters,
|
||||
} from '@/store'
|
||||
import type { AppMenuOption } from '@/types'
|
||||
import { RIcon } from '@ray-template/ui/icon'
|
||||
import { useEventListener } from '@vueuse/core'
|
||||
import { NButton, NCard, NInput, NModal, NScrollbar } from 'naive-ui'
|
||||
import type { InputInst } from 'naive-ui'
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import './index.scss'
|
||||
import { RIcon } from '@/components'
|
||||
import type { MaybeArray } from '@/types'
|
||||
import { call, detectOperatingSystem } from '@/utils'
|
||||
import { RIcon } from '@ray-template/ui/icon'
|
||||
import { NButton, NFlex } from 'naive-ui'
|
||||
import type { PropType } from 'vue'
|
||||
|
||||
|
||||
@ -1,7 +1,8 @@
|
||||
import { RIcon, RSegment } from '@/components'
|
||||
import { useI18n } from '@/hooks'
|
||||
import { useSettingActions, useSettingGetters } from '@/store'
|
||||
import type { SettingState } from '@/store/modules/setting/types'
|
||||
import { RIcon } from '@ray-template/ui/icon'
|
||||
import { RSegment } from '@ray-template/ui/segment'
|
||||
|
||||
export default defineComponent({
|
||||
name: 'ThemeSegment',
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { RIcon } from '@/components'
|
||||
import { useTheme } from '@/hooks'
|
||||
import { useSettingGetters } from '@/store'
|
||||
import { RIcon } from '@ray-template/ui/icon'
|
||||
import { NFlex, NSwitch, NTooltip } from 'naive-ui'
|
||||
|
||||
export default defineComponent({
|
||||
|
||||
@ -1,11 +1,12 @@
|
||||
import './index.scss'
|
||||
import { RIcon, useModal } from '@/components'
|
||||
import { useI18n } from '@/hooks'
|
||||
import { useMenuActions, useSettingActions } from '@/store'
|
||||
import { getDefaultSettingConfig } from '@/store/modules/setting/constant'
|
||||
import { PREFERENCE_FILE_LIMIT } from '@/store/modules/setting/preference-file'
|
||||
import type { SettingState } from '@/store/modules/setting/types'
|
||||
import { downloadAnyFile } from '@/utils/files'
|
||||
import { RIcon } from '@ray-template/ui/icon'
|
||||
import { useModal } from '@ray-template/ui/modal'
|
||||
import { cloneDeep, forIn } from 'lodash-es'
|
||||
import {
|
||||
drawerProps,
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import type { IconName } from '@/icons'
|
||||
import type { PropType } from 'vue'
|
||||
import './index.scss'
|
||||
import { RIcon } from '@/components'
|
||||
import { RIcon } from '@ray-template/ui/icon'
|
||||
import { NTooltip, tooltipProps } from 'naive-ui'
|
||||
import type { TooltipProps } from 'naive-ui'
|
||||
|
||||
|
||||
@ -2,13 +2,13 @@ import { useRuntimeActions, useRuntimeGetters } from '@/store'
|
||||
import './index.scss'
|
||||
import AppAvatar from '@/app-components/app/AppAvatar'
|
||||
import { LOCAL_OPTIONS } from '@/app-config'
|
||||
import { RIcon } from '@/components'
|
||||
import { useDevice, useI18n } from '@/hooks'
|
||||
import {
|
||||
useSettingActions,
|
||||
useSettingGetters,
|
||||
useSigningGetters,
|
||||
} from '@/store'
|
||||
import { RIcon } from '@ray-template/ui/icon'
|
||||
import { NButton, NDropdown, NFlex, NLayoutHeader } from 'naive-ui'
|
||||
import { useFullscreen } from 'vue-hooks-plus'
|
||||
import {
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
import { apiMockEnabled } from '@/api/admin/client'
|
||||
import { RIcon } from '@/components'
|
||||
import { useI18n } from '@/hooks'
|
||||
import { router } from '@/router'
|
||||
import { ACCOUNT_PROFILE_PATH } from '@/router/constant'
|
||||
import { useSettingActions, useSigningActions } from '@/store'
|
||||
import { RIcon } from '@ray-template/ui/icon'
|
||||
import type { IconOptions, IconOptionsFC } from './type'
|
||||
|
||||
export const createAvatarOptions = (t: ReturnType<typeof useI18n>['t']) => [
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import AppRequestCancelerProvider from '@/app-components/provider/AppRequestCancelerProvider'
|
||||
import { RTransitionComponent } from '@/components'
|
||||
import { RTransitionComponent } from '@/components/RTransitionComponent'
|
||||
import { useRuntimeGetters, useSettingGetters } from '@/store'
|
||||
|
||||
export default defineComponent({
|
||||
|
||||
@ -1 +1 @@
|
||||
export { findMenuRoot, firstMenuLeaf } from '@ray-template/routing'
|
||||
export { findMenuRoot, firstMenuLeaf } from '@ray-template/routing/navigation'
|
||||
|
||||
@ -22,9 +22,9 @@ if (import.meta.hot) {
|
||||
*
|
||||
* @returns 尚未安装到应用的国际化实例
|
||||
*/
|
||||
const createI18nOptions = async () => {
|
||||
const createI18nOptions = () => {
|
||||
const locale = getAppDefaultLanguage()
|
||||
const messages = await getAppLocalMessages(LOCAL_OPTIONS)
|
||||
const messages = getAppLocalMessages(LOCAL_OPTIONS)
|
||||
|
||||
const i18nInstance = createI18n({
|
||||
legacy: false,
|
||||
@ -45,8 +45,8 @@ const createI18nOptions = async () => {
|
||||
* @description
|
||||
* 安装国际化插件,并更新共享的国际化实例。
|
||||
*/
|
||||
export const setupI18n = async (app: App<Element>) => {
|
||||
const i18nInstance = await createI18nOptions()
|
||||
export const setupI18n = (app: App<Element>) => {
|
||||
const i18nInstance = createI18nOptions()
|
||||
|
||||
app.use(i18nInstance)
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import type { I18nModules } from '@/locales/types'
|
||||
import { combineI18nMessages } from '@/locales/utils'
|
||||
import { combineI18nMessages } from '@/locales/utils/combine-i18n-messages'
|
||||
import table from '@ray-template/ui/table-pro/messages/en-US'
|
||||
|
||||
const modules: I18nModules = import.meta.glob('./en-US/**/*.json', {
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import type { I18nModules } from '@/locales/types'
|
||||
import { combineI18nMessages } from '@/locales/utils'
|
||||
import { combineI18nMessages } from '@/locales/utils/combine-i18n-messages'
|
||||
import table from '@ray-template/ui/table-pro/messages/zh-CN'
|
||||
|
||||
const modules: I18nModules = import.meta.glob('./zh-CN/**/*.json', {
|
||||
|
||||
@ -4,6 +4,11 @@ import type {
|
||||
AppLocalesModules,
|
||||
} from '@/locales/types'
|
||||
|
||||
const locales = import.meta.glob<AppLocalesModules['default']>('../lang/*.ts', {
|
||||
eager: true,
|
||||
import: 'default',
|
||||
})
|
||||
|
||||
/**
|
||||
*
|
||||
* @param localOptions 语言包下拉配置项
|
||||
@ -12,21 +17,18 @@ import type {
|
||||
* 获取当前应用的所有语言包。
|
||||
*
|
||||
* @example
|
||||
* const messages = await getAppLocalMessages(localOptions)
|
||||
* const messages = getAppLocalMessages(localOptions)
|
||||
*/
|
||||
export const getAppLocalMessages = async (
|
||||
export const getAppLocalMessages = (
|
||||
localOptions: AppLocalesDropdownMixedOption[],
|
||||
) => {
|
||||
const message = {} as AppCurrentAppMessages
|
||||
const entries = localOptions.map(({ key }) => {
|
||||
const locale = locales[`../lang/${key}.ts`]
|
||||
|
||||
for (const curr of localOptions) {
|
||||
const msg: AppLocalesModules = await import(`@/locales/lang/${curr.key}.ts`)
|
||||
const key = curr.key as keyof AppCurrentAppMessages
|
||||
if (!locale) throw new Error(`Unknown locale: ${key}`)
|
||||
|
||||
if (key) {
|
||||
message[key] = msg?.default?.message ?? {}
|
||||
}
|
||||
}
|
||||
return [key, locale.message] as const
|
||||
})
|
||||
|
||||
return message
|
||||
return Object.fromEntries(entries) as AppCurrentAppMessages
|
||||
}
|
||||
|
||||
@ -1,19 +1,21 @@
|
||||
import App from './App'
|
||||
import './styles/entry'
|
||||
import type { App as AppType } from 'vue'
|
||||
import { apiMockEnabled, bindAdminUnauthorized } from './api/admin/client'
|
||||
import { bindAdminUnauthorized } from './api/admin/client'
|
||||
import { installAutocompleteDefaults } from './app-components/provider/AppAutocompleteDefaults'
|
||||
import { GLOBAL_CLASS_NAMES } from './app-config'
|
||||
import { setupDayjs } from './dayjs'
|
||||
import { setupDirectives } from './directives'
|
||||
import { runAppDoctor } from './doctor'
|
||||
import { setupI18n } from './locales'
|
||||
import { registerApiMock } from './mocks/register'
|
||||
import { setupRouter } from './router'
|
||||
import { setupStore } from './store'
|
||||
import {
|
||||
adminSessionChangeKey,
|
||||
piniaSigningStore,
|
||||
} from './store/modules/signing'
|
||||
import Login from './views/login'
|
||||
|
||||
const bootSplash = () =>
|
||||
document.getElementById(GLOBAL_CLASS_NAMES.preLoadingAnimation)
|
||||
@ -33,18 +35,13 @@ const showBootError = (error: unknown) => {
|
||||
* 注册时应该注意每个插件的加载顺序。
|
||||
*/
|
||||
const setupPlugins = async (inst: AppType<Element>) => {
|
||||
if (apiMockEnabled) {
|
||||
const { enableApiMock } = await import('./mocks/browser')
|
||||
|
||||
await enableApiMock()
|
||||
}
|
||||
|
||||
registerApiMock()
|
||||
setupStore(inst)
|
||||
await setupI18n(inst)
|
||||
setupI18n(inst)
|
||||
const signing = inst.runWithContext(() => piniaSigningStore())
|
||||
|
||||
await signing.restoreSession()
|
||||
await setupRouter(inst, !!signing.signingCallback.id)
|
||||
await setupRouter(inst, !!signing.signingCallback.id, Login)
|
||||
const unbindUnauthorized = bindAdminUnauthorized(signing.expireSession)
|
||||
const syncSession = (event: StorageEvent) => {
|
||||
if (event.key === adminSessionChangeKey) location.reload()
|
||||
@ -118,7 +115,7 @@ const setupWujieTemplate = async () => {
|
||||
* # 示例
|
||||
* const setupTemplate = async () => {
|
||||
* const app = createApp(App)
|
||||
* await setupRouter(app)
|
||||
* await setupRouter(app, false, Login)
|
||||
* ...
|
||||
* }
|
||||
* setupTemplate()
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
import { apiMockEnabled, apiUrl } from '@/api/admin/client'
|
||||
import { installMockRequestGuard } from '@/axios/instance'
|
||||
import { apiUrl } from '@/api/admin/client'
|
||||
import { getStorageInstance } from '@/utils/cache-backend'
|
||||
import { setupWorker } from 'msw/browser'
|
||||
import { HttpNetworkFrame } from 'msw/experimental'
|
||||
@ -8,67 +7,70 @@ import { createMockConnection } from './connection'
|
||||
import { createAdminDatabase } from './database'
|
||||
import { createAdminHandlers } from './handlers'
|
||||
|
||||
let ready: Promise<unknown> | undefined
|
||||
function createMockClient() {
|
||||
const base = apiUrl('')
|
||||
const handlers = createAdminHandlers(
|
||||
createAdminDatabase(getStorageInstance('localStorage')),
|
||||
base,
|
||||
)
|
||||
const worker = setupWorker(...handlers)
|
||||
const start = () =>
|
||||
worker.start({
|
||||
serviceWorker: {
|
||||
// 版本变化时注册新脚本,避免启动阶段与旧版 worker 握手。
|
||||
url: `${import.meta.env.BASE_URL}mockServiceWorker.js?v=${mswVersion}`,
|
||||
options: { scope: import.meta.env.BASE_URL },
|
||||
},
|
||||
quiet: true,
|
||||
onUnhandledFrame: ({ frame }) => {
|
||||
if (!(frame instanceof HttpNetworkFrame)) return
|
||||
|
||||
export function enableApiMock() {
|
||||
if (!apiMockEnabled) return Promise.resolve()
|
||||
const { method, url } = frame.data.request
|
||||
|
||||
ready ??= (async () => {
|
||||
const base = apiUrl('')
|
||||
const handlers = createAdminHandlers(
|
||||
createAdminDatabase(getStorageInstance('localStorage')),
|
||||
base,
|
||||
)
|
||||
const worker = setupWorker(...handlers)
|
||||
const start = () =>
|
||||
worker.start({
|
||||
serviceWorker: {
|
||||
// 版本变化时注册新脚本,避免启动阶段与旧版 worker 握手。
|
||||
url: `${import.meta.env.BASE_URL}mockServiceWorker.js?v=${mswVersion}`,
|
||||
options: { scope: import.meta.env.BASE_URL },
|
||||
},
|
||||
quiet: true,
|
||||
onUnhandledFrame: ({ frame }) => {
|
||||
if (!(frame instanceof HttpNetworkFrame)) return
|
||||
if (!url.startsWith(base)) return
|
||||
|
||||
const { method, url } = frame.data.request
|
||||
console.error(
|
||||
`[MSW] No mock handler for ${method} ${new URL(url).pathname}`,
|
||||
)
|
||||
// MSW 3 的默认错误回调只记录日志,拒绝此帧才能阻止请求穿透。
|
||||
throw Response.error()
|
||||
},
|
||||
})
|
||||
|
||||
if (!url.startsWith(base)) return
|
||||
|
||||
console.error(
|
||||
`[MSW] No mock handler for ${method} ${new URL(url).pathname}`,
|
||||
)
|
||||
// MSW 3 的默认错误回调只记录日志,拒绝此帧才能阻止请求穿透。
|
||||
throw Response.error()
|
||||
},
|
||||
const ensureReady = createMockConnection(
|
||||
async () => {
|
||||
const response = await fetch(apiUrl('admin/mock-health'), {
|
||||
cache: 'no-store',
|
||||
credentials: 'omit',
|
||||
redirect: 'error',
|
||||
signal: AbortSignal.timeout(5000),
|
||||
})
|
||||
|
||||
await start()
|
||||
return response.ok && response.headers.get('x-ray-mock') === 'active'
|
||||
},
|
||||
async () => {
|
||||
// Chromium 可能回收后台 worker;在同一个客户端恢复拦截。
|
||||
await worker.stop()
|
||||
await start()
|
||||
},
|
||||
)
|
||||
let started: ReturnType<typeof start> | undefined
|
||||
|
||||
const ensureReady = createMockConnection(
|
||||
async () => {
|
||||
const response = await fetch(apiUrl('admin/mock-health'), {
|
||||
cache: 'no-store',
|
||||
credentials: 'omit',
|
||||
redirect: 'error',
|
||||
signal: AbortSignal.timeout(5000),
|
||||
})
|
||||
return async () => {
|
||||
started ??= start().catch(async (error) => {
|
||||
try {
|
||||
await worker.stop()
|
||||
} finally {
|
||||
started = void 0
|
||||
}
|
||||
|
||||
return response.ok && response.headers.get('x-ray-mock') === 'active'
|
||||
},
|
||||
async () => {
|
||||
// 重启同一个实例,保持监听器和拦截状态由同一个客户端管理。
|
||||
worker.stop()
|
||||
await start()
|
||||
},
|
||||
)
|
||||
|
||||
// Chromium 可能回收后台 worker;先探测并恢复,再发送业务请求,避免写请求意外穿透。
|
||||
installMockRequestGuard(async (url) => {
|
||||
if (new URL(url, document.baseURI).href.startsWith(base))
|
||||
await ensureReady()
|
||||
throw error
|
||||
})
|
||||
})()
|
||||
|
||||
return ready
|
||||
await started
|
||||
await ensureReady()
|
||||
}
|
||||
}
|
||||
|
||||
let connect: ReturnType<typeof createMockClient> | undefined
|
||||
|
||||
export const ensureApiMock = () => (connect ??= createMockClient())()
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
import { userListQuerySchema } from '@/api/admin/contracts'
|
||||
import { listPeople } from '@/demo-data/people'
|
||||
import {
|
||||
chartsQuerySchema,
|
||||
orderSearchInputSchema,
|
||||
@ -218,6 +217,7 @@ export function createAdminHandlers(database: AdminDatabase, apiBase: string) {
|
||||
|
||||
if (query.fail) throw new MockApiError(503, 'requestFailed')
|
||||
|
||||
const { listPeople } = await import('@/demo-data/people')
|
||||
const result = listPeople({
|
||||
...query,
|
||||
page: query.page ?? 1,
|
||||
|
||||
20
apps/admin/src/mocks/register.ts
Normal file
20
apps/admin/src/mocks/register.ts
Normal file
@ -0,0 +1,20 @@
|
||||
import { apiMockEnabled, apiUrl } from '@/api/admin/client'
|
||||
import { installMockRequestGuard } from '@/axios/instance'
|
||||
|
||||
let installed = false
|
||||
|
||||
export function registerApiMock() {
|
||||
if (!apiMockEnabled || installed) return
|
||||
|
||||
const base = apiUrl('')
|
||||
|
||||
installMockRequestGuard(async (url) => {
|
||||
if (!new URL(url, document.baseURI).href.startsWith(base)) return
|
||||
|
||||
// 业务请求必须等到 Mock 可用后才能发出。
|
||||
const { ensureApiMock } = await import('./browser')
|
||||
|
||||
await ensureApiMock()
|
||||
})
|
||||
installed = true
|
||||
}
|
||||
@ -58,17 +58,18 @@ const views = {
|
||||
name: 'ModalDemo',
|
||||
},
|
||||
'demo/multi/views/multi-menu-one': {
|
||||
load: () => import('@/views/demo/multi/views/multi-menu-one/index'),
|
||||
load: () =>
|
||||
import('@/views/demo/multi').then((views) => views.MultiMenuOne),
|
||||
name: 'MultiMenuOne',
|
||||
},
|
||||
'demo/multi/views/multi-menu-two/views/sub-menu-other': {
|
||||
load: () =>
|
||||
import('@/views/demo/multi/views/multi-menu-two/views/sub-menu-other/index'),
|
||||
import('@/views/demo/multi').then((views) => views.SubMenuOther),
|
||||
name: 'SubMenuOther',
|
||||
},
|
||||
'demo/multi/views/multi-menu-two/views/sub-menu/views/multi-menu-two-one': {
|
||||
load: () =>
|
||||
import('@/views/demo/multi/views/multi-menu-two/views/sub-menu/views/multi-menu-two-one/index'),
|
||||
import('@/views/demo/multi').then((views) => views.MultiMenuTwoOne),
|
||||
name: 'MultiMenuTwoOne',
|
||||
},
|
||||
'demo/precision': {
|
||||
@ -104,27 +105,33 @@ const views = {
|
||||
name: 'PreviewSVGIcons',
|
||||
},
|
||||
'demo/tables/auto-height': {
|
||||
load: () => import('@/views/demo/tables/auto-height'),
|
||||
load: () =>
|
||||
import('@/views/demo/tables').then((views) => views.TableDemoAutoHeight),
|
||||
name: 'TableDemoAutoHeight',
|
||||
},
|
||||
'demo/tables/basic': {
|
||||
load: () => import('@/views/demo/tables/basic'),
|
||||
load: () =>
|
||||
import('@/views/demo/tables').then((views) => views.TableDemoBasic),
|
||||
name: 'TableDemoBasic',
|
||||
},
|
||||
'demo/tables/columns': {
|
||||
load: () => import('@/views/demo/tables/columns'),
|
||||
load: () =>
|
||||
import('@/views/demo/tables').then((views) => views.TableDemoColumns),
|
||||
name: 'TableDemoColumns',
|
||||
},
|
||||
'demo/tables/controlled': {
|
||||
load: () => import('@/views/demo/tables/controlled'),
|
||||
load: () =>
|
||||
import('@/views/demo/tables').then((views) => views.TableDemoControlled),
|
||||
name: 'TableDemoControlled',
|
||||
},
|
||||
'demo/tables/custom': {
|
||||
load: () => import('@/views/demo/tables/custom'),
|
||||
load: () =>
|
||||
import('@/views/demo/tables').then((views) => views.TableDemoCustom),
|
||||
name: 'TableDemoCustom',
|
||||
},
|
||||
'demo/tables/hooks-output': {
|
||||
load: () => import('@/views/demo/tables/hooks-output'),
|
||||
load: () =>
|
||||
import('@/views/demo/tables').then((views) => views.TableDemoHooksOutput),
|
||||
name: 'TableDemoHooksOutput',
|
||||
},
|
||||
'demo/tables/hooks-query': {
|
||||
@ -132,11 +139,15 @@ const views = {
|
||||
name: 'TableDemoHooksQuery',
|
||||
},
|
||||
'demo/tables/hooks-selection': {
|
||||
load: () => import('@/views/demo/tables/hooks-selection'),
|
||||
load: () =>
|
||||
import('@/views/demo/tables').then(
|
||||
(views) => views.TableDemoHooksSelection,
|
||||
),
|
||||
name: 'TableDemoHooksSelection',
|
||||
},
|
||||
'demo/tables/printing': {
|
||||
load: () => import('@/views/demo/tables/printing'),
|
||||
load: () =>
|
||||
import('@/views/demo/tables').then((views) => views.TableDemoPrinting),
|
||||
name: 'TableDemoPrinting',
|
||||
},
|
||||
'demo/tables/remote': {
|
||||
|
||||
@ -1,18 +1,18 @@
|
||||
import type { App } from 'vue'
|
||||
import type { App, Component } from 'vue'
|
||||
import { createRouter, createWebHashHistory } from 'vue-router'
|
||||
import { getStaticAppRoutes, setAppRouteModules } from './app-route-modules'
|
||||
import { loadRouteConfig, resetRouteSource } from './config/source'
|
||||
import {
|
||||
constantRoutes,
|
||||
getAccountProfileRoute,
|
||||
getLayoutRoutes,
|
||||
getRootRoutes,
|
||||
getSystemRoutes,
|
||||
} from './routes'
|
||||
import { scrollViewToTop, vueRouterRegister } from './utils'
|
||||
|
||||
export const router = createRouter({
|
||||
history: createWebHashHistory(),
|
||||
routes: constantRoutes,
|
||||
routes: [],
|
||||
scrollBehavior: (to) => {
|
||||
scrollViewToTop(to)
|
||||
},
|
||||
@ -63,7 +63,15 @@ export function loadAccountRoutes() {
|
||||
|
||||
let registered = false
|
||||
|
||||
export async function setupRouter(app: App<Element>, authenticated: boolean) {
|
||||
export async function setupRouter(
|
||||
app: App<Element>,
|
||||
authenticated: boolean,
|
||||
login: Component,
|
||||
) {
|
||||
if (!router.hasRoute('RLayout')) {
|
||||
for (const route of getRootRoutes(login)) router.addRoute(route)
|
||||
}
|
||||
|
||||
if (authenticated) await loadAccountRoutes()
|
||||
else clearAccountRoutes()
|
||||
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import Layout from '@/layout'
|
||||
import type { Component } from 'vue'
|
||||
import type { RouteRecordRaw } from 'vue-router'
|
||||
import { appExpandRoutes } from './app-route-modules'
|
||||
import {
|
||||
@ -21,9 +21,9 @@ const legacyRedirects = [
|
||||
{ path: '/table-auto-height', redirect: '/tables/auto-height' },
|
||||
]
|
||||
|
||||
export const constantRoutes: RouteRecordRaw[] = [
|
||||
{ path: '/', name: 'RLogin', component: () => import('@/views/login') },
|
||||
{ path: '/', name: 'RLayout', component: Layout },
|
||||
export const getRootRoutes = (login: Component): RouteRecordRaw[] => [
|
||||
{ path: '/', name: 'RLogin', component: login },
|
||||
{ path: '/', name: 'RLayout', component: () => import('@/layout') },
|
||||
]
|
||||
|
||||
export function getLayoutRoutes(): RouteRecordRaw[] {
|
||||
@ -72,19 +72,22 @@ export const getSystemRoutes = (): RouteRecordRaw[] => [
|
||||
{
|
||||
path: FORBIDDEN_ROUTE_PATH,
|
||||
name: 'ErrorPage403',
|
||||
component: () => import('@/views/error/views/Error403'),
|
||||
component: () =>
|
||||
import('@/views/error/system-errors').then((views) => views.Error403),
|
||||
meta: { i18nKey: 'workspaceStates.forbidden.title', hidden: true },
|
||||
},
|
||||
{
|
||||
path: NOT_FOUND_PAGE_PATH,
|
||||
name: 'ErrorPage404',
|
||||
component: () => import('@/views/error/views/Error404'),
|
||||
component: () =>
|
||||
import('@/views/error/system-errors').then((views) => views.Error404),
|
||||
meta: { i18nKey: 'workspaceStates.notFound.title', hidden: true },
|
||||
},
|
||||
{
|
||||
path: SERVER_ERROR_ROUTE_PATH,
|
||||
name: 'ErrorPage500',
|
||||
component: () => import('@/views/error/views/Error500'),
|
||||
component: () =>
|
||||
import('@/views/error/system-errors').then((views) => views.Error500),
|
||||
meta: { i18nKey: 'workspaceStates.serverError.title', hidden: true },
|
||||
},
|
||||
{
|
||||
|
||||
@ -1 +1 @@
|
||||
export { expandRoutes } from '@ray-template/routing'
|
||||
export { expandRoutes } from '@ray-template/routing/expand-routes'
|
||||
|
||||
@ -1 +1 @@
|
||||
export { orderRoutes } from '@ray-template/routing'
|
||||
export { orderRoutes } from '@ray-template/routing/order-routes'
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
import { APP_CATCH_KEY } from '@/app-config'
|
||||
import { RIcon } from '@/components'
|
||||
import { useI18n } from '@/hooks'
|
||||
import { resolveIconName } from '@/icons'
|
||||
import type { AppMenuKey, AppMenuOption } from '@/types/modules/app'
|
||||
import { getStorage } from '@/utils/cache'
|
||||
import { isValueType } from '@/utils/core'
|
||||
import { RIcon } from '@ray-template/ui/icon'
|
||||
import { NTag } from 'naive-ui'
|
||||
import type { TagProps } from 'naive-ui'
|
||||
import { piniaSettingStore } from '../setting'
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
import { AES, enc } from 'crypto-js'
|
||||
import AES from 'crypto-js/aes'
|
||||
import CryptoJS from 'crypto-js/core'
|
||||
import { CRYPTO_KEY } from './constant'
|
||||
import type { CipherParams, WordArray } from './types'
|
||||
|
||||
@ -18,18 +19,20 @@ export const decrypt = (
|
||||
const parts =
|
||||
typeof data === 'string' ? /^([a-f0-9]{32}):(.+)$/i.exec(data) : null
|
||||
const iv =
|
||||
typeof data === 'string' ? parts && enc.Hex.parse(parts[1]) : data.iv
|
||||
typeof data === 'string'
|
||||
? parts && CryptoJS.enc.Hex.parse(parts[1])
|
||||
: data.iv
|
||||
|
||||
if (!iv) throw new Error('Missing AES initialization vector.')
|
||||
|
||||
const decrypted = AES.decrypt(parts?.[2] ?? data, key, { iv })
|
||||
|
||||
return JSON.parse(decrypted.toString(enc.Utf8))
|
||||
return JSON.parse(decrypted.toString(CryptoJS.enc.Utf8))
|
||||
}
|
||||
|
||||
const decrypted = AES.decrypt(data, key || CRYPTO_KEY)
|
||||
|
||||
return JSON.parse(decrypted.toString(enc.Utf8))
|
||||
return JSON.parse(decrypted.toString(CryptoJS.enc.Utf8))
|
||||
} catch (error) {
|
||||
console.error('[decrypt]: Invalid ciphertext or key.', error)
|
||||
}
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
import { AES, lib } from 'crypto-js'
|
||||
import AES from 'crypto-js/aes'
|
||||
import CryptoJS from 'crypto-js/core'
|
||||
import { CRYPTO_KEY } from './constant'
|
||||
import type { WordArray } from './types'
|
||||
|
||||
@ -21,7 +22,7 @@ export const encrypt = (data: unknown, key?: string | WordArray) => {
|
||||
throw new TypeError('[encrypt]: Value is not JSON serializable.')
|
||||
|
||||
if (typeof key === 'object') {
|
||||
const iv = lib.WordArray.random(16)
|
||||
const iv = CryptoJS.lib.WordArray.random(16)
|
||||
const ciphertext = AES.encrypt(json, key, { iv })
|
||||
|
||||
return `${iv.toString()}:${ciphertext.toString()}`
|
||||
|
||||
@ -10,9 +10,9 @@ import type { AccountProfile } from '@/api/admin/contracts'
|
||||
import AccountPasswordForm from '@/app-components/app/AccountPasswordForm'
|
||||
import AccountAvatar from '@/app-components/app/AppAvatar/AccountAvatar'
|
||||
import AppPageHeader from '@/app-components/app/AppPageHeader'
|
||||
import { RIcon } from '@/components'
|
||||
import { useI18n } from '@/hooks'
|
||||
import { useSigningActions, useSigningGetters } from '@/store'
|
||||
import { RIcon } from '@ray-template/ui/icon'
|
||||
import {
|
||||
NAlert,
|
||||
NButton,
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
import './index.scss'
|
||||
import AppPageHeader from '@/app-components/app/AppPageHeader'
|
||||
import AppShareLink from '@/app-components/app/AppShareLink'
|
||||
import { RIcon } from '@/components'
|
||||
import { useI18n } from '@/hooks'
|
||||
import { useMenuGetters } from '@/store'
|
||||
import type { AppMenuOption } from '@/types'
|
||||
import { RIcon } from '@ray-template/ui/icon'
|
||||
import { NCard, NDescriptions, NDescriptionsItem } from 'naive-ui'
|
||||
import { RouterLink } from 'vue-router'
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import { RBarcode } from '@/components'
|
||||
import { useI18n } from '@/hooks'
|
||||
import { RBarcode } from '@ray-template/ui/barcode'
|
||||
import { NCard, NFlex, NFormItem, NInput, NSelect, NSwitch } from 'naive-ui'
|
||||
import DemoPage from './components/DemoPage'
|
||||
import DemoResult from './components/DemoResult'
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { RAY_TEMPLATE_DOCS_URL } from '@/app-config'
|
||||
import { RIframe } from '@/components'
|
||||
import { useI18n } from '@/hooks'
|
||||
import { RIframe } from '@ray-template/ui/iframe'
|
||||
|
||||
export default defineComponent({
|
||||
name: 'RTemplateDoc',
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { RDraggableCard } from '@/components'
|
||||
import type { DefaultPosition } from '@/components'
|
||||
import { useI18n } from '@/hooks'
|
||||
import RDraggableCard from '@ray-template/ui/draggable-card'
|
||||
import type { DefaultPosition } from '@ray-template/ui/draggable-card'
|
||||
import { NButton, NCard, NFlex, NSelect, NSwitch, NTag } from 'naive-ui'
|
||||
import DemoPage from './components/DemoPage'
|
||||
|
||||
|
||||
@ -3,8 +3,8 @@ import DemoResult from '../components/DemoResult'
|
||||
import './index.scss'
|
||||
import { getDemoCharts } from '@/api/demo/data'
|
||||
import type { DemoCharts } from '@/api/demo/data'
|
||||
import { RChart, useChart } from '@/components'
|
||||
import { useI18n } from '@/hooks'
|
||||
import { RChart, useChart } from '@ray-template/ui/chart'
|
||||
import { NButton, NCard, NFlex, NSwitch } from 'naive-ui'
|
||||
|
||||
const Echart = defineComponent({
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import { RFlow, useFlow } from '@/components'
|
||||
import { useI18n } from '@/hooks'
|
||||
import { RFlow, useFlow } from '@ray-template/ui/flow'
|
||||
import { NButton, NCard, NFlex, NSwitch, NTag } from 'naive-ui'
|
||||
import DemoPage from './components/DemoPage'
|
||||
import DemoResult from './components/DemoResult'
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import { RForm, useForm } from '@/components'
|
||||
import { useI18n } from '@/hooks'
|
||||
import { RForm, useForm } from '@ray-template/ui/form'
|
||||
import {
|
||||
NButton,
|
||||
NCard,
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import './index.scss'
|
||||
import { RIcon } from '@/components'
|
||||
import { useI18n } from '@/hooks'
|
||||
import { RIcon } from '@ray-template/ui/icon'
|
||||
import { NButton, NCard } from 'naive-ui'
|
||||
import { exampleFocusKey } from './example-focus'
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import { RIframe } from '@/components'
|
||||
import { useI18n } from '@/hooks'
|
||||
import { RIframe } from '@ray-template/ui/iframe'
|
||||
import { NButton, NCard, NTag } from 'naive-ui'
|
||||
import DemoPage from '../components/DemoPage'
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import { RModal, useModal } from '@/components'
|
||||
import { useI18n } from '@/hooks'
|
||||
import { RModal, useModal } from '@ray-template/ui/modal'
|
||||
import { NButton, NCard, NFlex, NInputNumber, NTag } from 'naive-ui'
|
||||
import DemoPage from '../components/DemoPage'
|
||||
import DemoResult from '../components/DemoResult'
|
||||
|
||||
3
apps/admin/src/views/demo/multi/index.ts
Normal file
3
apps/admin/src/views/demo/multi/index.ts
Normal file
@ -0,0 +1,3 @@
|
||||
export { default as MultiMenuOne } from './views/multi-menu-one'
|
||||
export { default as MultiMenuTwoOne } from './views/multi-menu-two/views/sub-menu/views/multi-menu-two-one'
|
||||
export { default as SubMenuOther } from './views/multi-menu-two/views/sub-menu-other'
|
||||
@ -1,10 +1,10 @@
|
||||
import { getRouteDemoPeople } from '@/api/demo/data'
|
||||
import { RTablePro } from '@/components'
|
||||
import { useI18n } from '@/hooks'
|
||||
import type {
|
||||
RouteDemoPerson,
|
||||
RoutePeopleQuery,
|
||||
} from '@ray-template/api-contracts/demo'
|
||||
import { RTablePro } from '@ray-template/ui/table-pro'
|
||||
import { NButton, NFlex } from 'naive-ui'
|
||||
import type { DataTableColumns } from 'naive-ui'
|
||||
|
||||
|
||||
@ -1,7 +1,9 @@
|
||||
import { RIcon, RSegment } from '@/components'
|
||||
import type { RSegmentOptions, RSegmentWidth } from '@/components'
|
||||
import type { RSegmentWidth } from '@/components'
|
||||
import { useI18n } from '@/hooks'
|
||||
import type { ComponentSize } from '@/types'
|
||||
import { RIcon } from '@ray-template/ui/icon'
|
||||
import { RSegment } from '@ray-template/ui/segment'
|
||||
import type { RSegmentOptions } from '@ray-template/ui/segment'
|
||||
import { NCard, NFlex, NRadioButton, NRadioGroup } from 'naive-ui'
|
||||
import DemoPage from '../components/DemoPage'
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import './index.scss'
|
||||
import { RIcon } from '@/components'
|
||||
import { useI18n } from '@/hooks'
|
||||
import { iconNames, iconPackages } from '@/icons'
|
||||
import { RIcon } from '@ray-template/ui/icon'
|
||||
import {
|
||||
NCard,
|
||||
NEmpty,
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import { RTablePro } from '@/components'
|
||||
import { useI18n } from '@/hooks/template/useI18n'
|
||||
import { RTablePro } from '@ray-template/ui/table-pro'
|
||||
import { NCheckbox } from 'naive-ui'
|
||||
import { createPeopleColumns } from './people'
|
||||
import { usePeopleData } from './usePeopleData'
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import { RTablePro } from '@/components'
|
||||
import { useI18n } from '@/hooks/template/useI18n'
|
||||
import { RTablePro } from '@ray-template/ui/table-pro'
|
||||
import { createPeopleColumns } from './people'
|
||||
import { usePeopleData } from './usePeopleData'
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { RTablePro } from '@/components'
|
||||
import { useI18n } from '@/hooks/template/useI18n'
|
||||
import type { Person } from '@ray-template/api-contracts/demo'
|
||||
import { RTablePro } from '@ray-template/ui/table-pro'
|
||||
import { NCheckbox } from 'naive-ui'
|
||||
import type { DataTableColumns } from 'naive-ui'
|
||||
import { createPeopleColumns } from './people'
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import { RTablePro, useTablePro } from '@/components'
|
||||
import { useI18n } from '@/hooks/template/useI18n'
|
||||
import { RTablePro, useTablePro } from '@ray-template/ui/table-pro'
|
||||
import { NButton, NFlex, NInput } from 'naive-ui'
|
||||
import { createPeopleColumns } from './people'
|
||||
import { usePeopleData } from './usePeopleData'
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import { RTablePro, useTablePro } from '@/components'
|
||||
import { useI18n } from '@/hooks/template/useI18n'
|
||||
import { RTablePro, useTablePro } from '@ray-template/ui/table-pro'
|
||||
import { NButton, NFlex } from 'naive-ui'
|
||||
import DemoPage from '../components/DemoPage'
|
||||
import DemoResult from '../components/DemoResult'
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
import { apiMockEnabled } from '@/api/admin/client'
|
||||
import { getPersonList } from '@/api/demo/mock/person'
|
||||
import type { PersonListParams } from '@/api/demo/mock/person'
|
||||
import { RTablePro, useTablePro } from '@/components'
|
||||
import { useI18n } from '@/hooks/template/useI18n'
|
||||
import { RTablePro, useTablePro } from '@ray-template/ui/table-pro'
|
||||
import {
|
||||
NButton,
|
||||
NCard,
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { RTablePro, useTablePro } from '@/components'
|
||||
import { useI18n } from '@/hooks/template/useI18n'
|
||||
import type { Person } from '@ray-template/api-contracts/demo'
|
||||
import { RTablePro, useTablePro } from '@ray-template/ui/table-pro'
|
||||
import { NButton, NFlex } from 'naive-ui'
|
||||
import type { DataTableColumns } from 'naive-ui'
|
||||
import DemoPage from '../components/DemoPage'
|
||||
|
||||
8
apps/admin/src/views/demo/tables/index.ts
Normal file
8
apps/admin/src/views/demo/tables/index.ts
Normal file
@ -0,0 +1,8 @@
|
||||
export { default as TableDemoAutoHeight } from './auto-height'
|
||||
export { default as TableDemoBasic } from './basic'
|
||||
export { default as TableDemoColumns } from './columns'
|
||||
export { default as TableDemoControlled } from './controlled'
|
||||
export { default as TableDemoCustom } from './custom'
|
||||
export { default as TableDemoHooksOutput } from './hooks-output'
|
||||
export { default as TableDemoHooksSelection } from './hooks-selection'
|
||||
export { default as TableDemoPrinting } from './printing'
|
||||
@ -1,7 +1,7 @@
|
||||
import './printing.scss'
|
||||
import { RTablePro } from '@/components'
|
||||
import type { TableProInst } from '@/components'
|
||||
import { useI18n } from '@/hooks/template/useI18n'
|
||||
import { RTablePro } from '@ray-template/ui/table-pro'
|
||||
import type { TableProInst } from '@ray-template/ui/table-pro'
|
||||
import { NButton } from 'naive-ui'
|
||||
import { useTemplateRef } from 'vue'
|
||||
import { createPeopleColumns } from './people'
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
import { getPersonList } from '@/api/demo/mock/person'
|
||||
import type { PersonListParams } from '@/api/demo/mock/person'
|
||||
import { RTablePro } from '@/components'
|
||||
import type { TableProInst } from '@/components'
|
||||
import { useI18n } from '@/hooks/template/useI18n'
|
||||
import { RTablePro } from '@ray-template/ui/table-pro'
|
||||
import type { TableProInst } from '@ray-template/ui/table-pro'
|
||||
import { NButton, NTag } from 'naive-ui'
|
||||
import type { DataTableSortState } from 'naive-ui'
|
||||
import { createPeopleColumns } from './people'
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
import { RIcon } from '@/components'
|
||||
import {
|
||||
useAppNavigation,
|
||||
useBadge,
|
||||
@ -13,6 +12,7 @@ import {
|
||||
useWatermark,
|
||||
} from '@/hooks'
|
||||
import { useMenuGetters, useRuntimeGetters, useSettingGetters } from '@/store'
|
||||
import { RIcon } from '@ray-template/ui/icon'
|
||||
import { useTimeoutFn } from '@vueuse/core'
|
||||
import { NButton, NFlex, NInput, NTag } from 'naive-ui'
|
||||
import DemoPage from '../components/DemoPage'
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
import './index.scss'
|
||||
import AppPageHeader from '@/app-components/app/AppPageHeader'
|
||||
import { RIcon } from '@/components'
|
||||
import { useI18n } from '@/hooks'
|
||||
import { WELCOME_ROUTE_PATH } from '@/router/constant'
|
||||
import { resolveLandingPath } from '@/router/utils/resolve-landing-path'
|
||||
import { RIcon } from '@ray-template/ui/icon'
|
||||
import { NButton, NFlex, NResult, resultProps } from 'naive-ui'
|
||||
|
||||
const statusKeys = {
|
||||
|
||||
3
apps/admin/src/views/error/system-errors.ts
Normal file
3
apps/admin/src/views/error/system-errors.ts
Normal file
@ -0,0 +1,3 @@
|
||||
export { default as Error403 } from './views/Error403'
|
||||
export { default as Error404 } from './views/Error404'
|
||||
export { default as Error500 } from './views/Error500'
|
||||
@ -1,5 +1,5 @@
|
||||
import { RIcon } from '@/components'
|
||||
import type { IconName } from '@/icons'
|
||||
import { RIcon } from '@ray-template/ui/icon'
|
||||
import { NButton, NFlex, NTooltip } from 'naive-ui'
|
||||
|
||||
const providers = [
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
import { AdminApiError, apiMockEnabled } from '@/api/admin/client'
|
||||
import { RForm, useForm } from '@/components'
|
||||
import { useI18n } from '@/hooks'
|
||||
import { loadAccountRoutes } from '@/router'
|
||||
import { resolveLandingPath } from '@/router/utils/resolve-landing-path'
|
||||
import { useSigningActions } from '@/store'
|
||||
import { announceAdminSessionChange } from '@/store/modules/signing'
|
||||
import { RForm, useForm } from '@ray-template/ui/form'
|
||||
import { NButton, NFlex, NFormItem, NInput } from 'naive-ui'
|
||||
|
||||
export default defineComponent({
|
||||
|
||||
@ -2,10 +2,10 @@ import './index.scss'
|
||||
import { apiMockEnabled } from '@/api/admin/client'
|
||||
import AppShareLink from '@/app-components/app/AppShareLink'
|
||||
import { LOCAL_OPTIONS } from '@/app-config'
|
||||
import { RIcon } from '@/components'
|
||||
import { useI18n } from '@/hooks'
|
||||
import ThemeSwitch from '@/layout/components/SiderBar/components/SettingDrawer/components/ThemeSwitch'
|
||||
import { useSettingActions } from '@/store'
|
||||
import { RIcon } from '@ray-template/ui/icon'
|
||||
import { NButton, NDropdown, NFlex, NTabPane, NTabs } from 'naive-ui'
|
||||
import QRCodeSigning from './components/QRCodeSigning'
|
||||
import Register from './components/Register'
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
import { createUser, updateUser } from '@/api/admin'
|
||||
import { AdminApiError } from '@/api/admin/client'
|
||||
import type { AdminUser, UserInput, UserOptions } from '@/api/admin/contracts'
|
||||
import { RForm, useForm } from '@/components'
|
||||
import { useAccess, useI18n } from '@/hooks'
|
||||
import { RForm, useForm } from '@ray-template/ui/form'
|
||||
import {
|
||||
NAlert,
|
||||
NButton,
|
||||
|
||||
@ -12,15 +12,18 @@ import { AdminApiError, apiMockEnabled } from '@/api/admin/client'
|
||||
import type { AdminUser, UserOptions, UserStatus } from '@/api/admin/contracts'
|
||||
import AccountPasswordForm from '@/app-components/app/AccountPasswordForm'
|
||||
import AppPageHeader from '@/app-components/app/AppPageHeader'
|
||||
import { RIcon, RTablePro } from '@/components'
|
||||
import type { TableProInst } from '@/components'
|
||||
import { useAccess, useI18n } from '@/hooks'
|
||||
import {
|
||||
useSettingGetters,
|
||||
useSigningActions,
|
||||
useSigningGetters,
|
||||
} from '@/store'
|
||||
import type { TableProSearchFieldConfig } from '@ray-template/ui/table-pro'
|
||||
import { RIcon } from '@ray-template/ui/icon'
|
||||
import { RTablePro } from '@ray-template/ui/table-pro'
|
||||
import type {
|
||||
TableProInst,
|
||||
TableProSearchFieldConfig,
|
||||
} from '@ray-template/ui/table-pro'
|
||||
import { useElementSize } from '@vueuse/core'
|
||||
import {
|
||||
NAlert,
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
import './index.scss'
|
||||
import AppPageHeader from '@/app-components/app/AppPageHeader'
|
||||
import { RIcon } from '@/components'
|
||||
import { useI18n } from '@/hooks'
|
||||
import { useMenuGetters, useNavigationHistoryGetters } from '@/store'
|
||||
import type { AppMenuOption } from '@/types'
|
||||
import { RIcon } from '@ray-template/ui/icon'
|
||||
import { RouterLink } from 'vue-router'
|
||||
|
||||
export default defineComponent({
|
||||
|
||||
@ -79,6 +79,12 @@ The [root configuration](../tsconfig.json) references four projects. Strict mode
|
||||
|
||||
`pnpm build` produces admin output in `dist/production`; `pnpm docs:build` produces `apps/docs/.vitepress/dist`. `pnpm pages:build` combines them in `dist/pages`, with documentation under `docs/`. The default admin base is `/ray-template/`; the documentation base is `/ray-template/docs/`. For root hosting or another subpath, align the [admin base](../vite.custom.config.ts), [documentation base](../apps/docs/.vitepress/config.mts), and [legacy redirect targets](../scripts/assemble-pages.mjs).
|
||||
|
||||
The default production build clears its generated output directory before writing new assets. Custom output directories follow Vite's usual cleanup rules.
|
||||
|
||||
The admin entry includes the sign-in view so the browser discovers its assets during the initial HTML load. The example entry registers its own routes. The workspace layout and feature views load when their routes match. Both configured language packs are available at startup for synchronous language switching. In demo mode, the request interceptor starts MSW and checks readiness before the first mock API request can leave the client. The demo people generator loads when a people request needs data.
|
||||
|
||||
Built-in views import the [specific UI entry points](../packages/ui/package.json) so a shared component such as an icon can load independently of chart, flow, and barcode code. Keep `@/components` available as a compatibility entry. The [Vite groups](../vite.config.ts) collect shared framework and utility modules and split the chart renderer within the chart route. Group small views when users move among them and they share feature dependencies. Evaluate bundles by the requests and bytes each entry and route loads.
|
||||
|
||||
Every push to `main` triggers the Pages workflow. The build job runs `pnpm pages:build` on Ubuntu 24.04 and uploads `dist/pages` as a Pages artifact, including `.nojekyll`. The deployment job publishes that artifact using the `github-pages` environment. Manual dispatch also publishes from `main`. [Pages workflow](../.github/workflows/ci.yaml)
|
||||
|
||||
In the repository's Pages settings, set the publishing source to **GitHub Actions**. If the `github-pages` environment uses a branch allowlist, allow `main`. For manual publication from a branch, keep `.nojekyll` in the output so assets with underscore prefixes can load. [GitHub Pages source setup](https://docs.github.com/en/pages/getting-started-with-github-pages/configuring-a-publishing-source-for-your-github-pages-site) · [Admin .nojekyll file](../apps/admin/public/.nojekyll)
|
||||
|
||||
@ -285,3 +285,17 @@ Vitest and its UI move together to 5.1.0. The sidebar regression waits for the m
|
||||
Two earlier updates required follow-up before verification could pass. The five shared browser packages now declare the same Vue 3.5.45 peer as the apps. The mock client and Node test setup use the MSW 3.0.4 entry points and options, and the checked-in worker matches that release. Unhandled mock API calls fail locally as network errors. Other resources can pass through to the host. [MSW migration guide](https://mswjs.io/docs/migrations/2.x-to-3.x) · [MSW 3.0.4](https://github.com/mswjs/msw/releases/tag/v3.0.4)
|
||||
|
||||
On macOS with Node.js 26.13.0 and pnpm 12.16.1, the combined candidate passed frozen-lockfile installation, peer dependency checks, and `pnpm harness verify all`. The run covered 575 frontend tests, 12 backend tests, both site builds, and both source distributions. The optional real Redis test was skipped. The assembled Pages preview passed demo sign-in, dashboard navigation, and the embedded TablePro failure and retry flow in Chrome. An existing MSW 2 registration could stall startup after an update. The versioned script URL let Chrome register the 3.0.4 worker and sign in while a tab from the previous build remained open. The 3.0.4 worker answered 37 health probes over 362 seconds.
|
||||
|
||||
## 2026-11-10: Admin startup and bundles
|
||||
|
||||
The [admin entry](../apps/admin/src/main.ts) includes the sign-in view and both configured locale dictionaries in the initial module graph. The workspace shell, chart and flow libraries, lock dialog, route schema converter, and mock code load when needed. In demo mode, the request guard waits for MSW readiness, shares startup between concurrent requests, and retries after a startup failure. [Production bundle conventions](architecture.md#deployment-and-search-discovery)
|
||||
|
||||
The largest minified JS file went from 2,511.83 kB to 498.49 kB with the default 500 kB warning limit. The mock startup chunk dropped from 888.75 kB to 404.41 kB after the people generator moved behind its endpoint. The output grew from 96 to 113 JS files as features gained independent loading boundaries. Related table, nested menu, and error views share entry files.
|
||||
|
||||
The existing local production directory had accumulated 2,165 JS files because Vite's application root is below the workspace output directory. The default production build now clears its own output. The clean output occupies 6.8 MiB on this machine, down from 156 MiB with stale builds present.
|
||||
|
||||
Local Chrome comparison used three cold HTTP cache loads per build, a 390 × 844 viewport, 4× CPU slowdown, 150 ms added network latency, and 1.6 Mbit/s download. The English sign-in heading's median LCP went from 6.78 s to 2.51 s. CLS was 0 on each run. The page loaded 23 JS resources in both builds, and their combined encoded response bodies went from 1,330.43 kB to 359.24 kB. The measured demo sign-in Event Timing sample went from 88 ms to 72 ms. Field Core Web Vitals require real-user measurements. [Google's measurement guidance](https://web.dev/articles/vitals-measurement-getting-started)
|
||||
|
||||
`pnpm harness verify all` passed with loopback access for the server tests. The run covered 576 frontend tests, 12 server tests, both site builds, and both source distributions. The optional Redis integration test was skipped. The admin build stayed below the chunk warning limit. VitePress still reports a large chunk for the TablePro examples page.
|
||||
|
||||
The assembled Pages preview verified demo sign-in, session restoration, chart, flow, barcode, grouped table views, the 404 route, and the first opening of the lock dialog. The documentation iframe fetched rows, cleared them on a simulated failure, and restored them on retry. The example entry also rendered the workspace shell when requested. Browser evidence is in `.harness-local/browser/admin-startup-2026-11-10/report.json`.
|
||||
|
||||
@ -30,6 +30,14 @@ pnpm harness verify table-pro
|
||||
- Requests flow from `apps/admin/src/api` into `apps/admin/src/axios`. Mocks are for demos and local verification. Never place server secrets in `VITE_*` variables that are bundled into the browser.
|
||||
- When maintaining public APIs, inspect callers, exports, and existing regression tests. For engineering configuration changes, update the corresponding documentation and [verification record](../docs/toolchain-upgrade.md).
|
||||
|
||||
### Runtime import boundaries
|
||||
|
||||
Across workspaces, prefer the narrowest existing public entry point declared in `package.json#exports`, such as `@ray-template/ui/icon` or `@ray-template/routing/navigation`. Within a workspace, import the owning module or a focused feature entry point.
|
||||
|
||||
Keep aggregate exports for cohesive APIs and existing compatibility. Use feature entry points in startup and shared code to keep unrelated styles, module initialization, and large dependencies outside those paths. Point dynamic imports at the specific feature entry point.
|
||||
|
||||
When changing a startup or lazy loading boundary, inspect the production dependency graph and the requests and bytes loaded by the affected page.
|
||||
|
||||
## Verification and evidence
|
||||
|
||||
### Choosing the verification scope
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import './TopNavigation.scss'
|
||||
import { findMenuRoot, firstMenuLeaf } from '@ray-template/routing'
|
||||
import type { AppMenuKey, AppMenuOption } from '@ray-template/routing'
|
||||
import { findMenuRoot, firstMenuLeaf } from '@ray-template/routing/navigation'
|
||||
import { NMenu } from 'naive-ui'
|
||||
import type { MenuOption } from 'naive-ui'
|
||||
import { computed, defineComponent } from 'vue'
|
||||
|
||||
@ -6,7 +6,10 @@
|
||||
".": "./src/index.ts",
|
||||
"./schema": "./src/schema.ts",
|
||||
"./json-schema": "./src/json-schema.ts",
|
||||
"./expand-routes": "./src/expand-routes.ts",
|
||||
"./join-route-path": "./src/join-route-path.ts",
|
||||
"./navigation": "./src/navigation.ts",
|
||||
"./order-routes": "./src/order-routes.ts",
|
||||
"./contract": "./src/contract.ts",
|
||||
"./types": "./src/types.ts"
|
||||
},
|
||||
|
||||
@ -18,6 +18,7 @@ export default defineConfig(({ mode }) => {
|
||||
appPrimaryColor,
|
||||
base,
|
||||
} = config
|
||||
const defaultBuild = buildOptions(mode)
|
||||
|
||||
const __APP_CFG__ = {
|
||||
pkg: {
|
||||
@ -42,7 +43,27 @@ export default defineConfig(({ mode }) => {
|
||||
resolve: {
|
||||
alias: alias,
|
||||
},
|
||||
plugins: vitePlugins(mode),
|
||||
plugins: [
|
||||
vitePlugins(mode),
|
||||
mode === 'production' && {
|
||||
name: 'ray:clean-production-output',
|
||||
apply: 'build' as const,
|
||||
config({ build, environments }) {
|
||||
const client = environments?.client?.build
|
||||
|
||||
// 只清理项目默认产物,保留对自定义输出目录的 Vite 默认保护。
|
||||
if (
|
||||
(client?.outDir ?? build?.outDir) === defaultBuild.outDir &&
|
||||
client?.emptyOutDir == null &&
|
||||
build?.emptyOutDir == null
|
||||
) {
|
||||
return {
|
||||
environments: { client: { build: { emptyOutDir: true } } },
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
],
|
||||
optimizeDeps: {
|
||||
entries: ['index.html'],
|
||||
include: [
|
||||
@ -66,7 +87,7 @@ export default defineConfig(({ mode }) => {
|
||||
],
|
||||
},
|
||||
build: {
|
||||
...buildOptions(mode),
|
||||
...defaultBuild,
|
||||
target: 'baseline-widely-available',
|
||||
rolldownOptions: {
|
||||
input: {
|
||||
@ -78,7 +99,26 @@ export default defineConfig(({ mode }) => {
|
||||
),
|
||||
},
|
||||
output: {
|
||||
// 交由 Rolldown 按依赖图拆包,避免手动按 pnpm 目录分组造成循环依赖。
|
||||
// 只归并共用的框架与工具代码,图表渲染器随图表页加载。
|
||||
codeSplitting: {
|
||||
groups: [
|
||||
{
|
||||
name: 'app-framework',
|
||||
test: /[\\/]node_modules[\\/](?:vue|vue-router|vue-i18n|pinia|@vue[\\/](?:runtime-core|runtime-dom|reactivity|shared))[\\/]/,
|
||||
priority: 20,
|
||||
},
|
||||
{
|
||||
name: 'lodash-shared',
|
||||
test: /[\\/]node_modules[\\/]lodash-es[\\/]/,
|
||||
minShareCount: 2,
|
||||
priority: 10,
|
||||
},
|
||||
{
|
||||
name: 'chart-renderer',
|
||||
test: /[\\/]node_modules[\\/]zrender[\\/]/,
|
||||
},
|
||||
],
|
||||
},
|
||||
minify: {
|
||||
compress: {
|
||||
dropConsole: mode === 'production',
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user