@go-wind/admin-vben 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/package.json +38 -3
- package/src/base/design/css/global.css +169 -0
- package/src/base/design/css/nprogress.css +59 -0
- package/src/base/design/css/transition.css +236 -0
- package/src/base/design/css/ui.css +83 -0
- package/src/base/design/design-tokens/dark.css +448 -0
- package/src/base/design/design-tokens/default.css +396 -0
- package/src/base/design/design-tokens/index.ts +4 -0
- package/src/base/design/index.ts +8 -0
- package/src/base/design/scss-bem/bem.scss +34 -0
- package/src/base/design/scss-bem/constants.scss +5 -0
- package/src/base/icons/create-icon.ts +14 -0
- package/src/base/icons/index.ts +11 -0
- package/src/base/icons/lucide.ts +62 -0
- package/src/base/shared/cache/__tests__/storage-manager.test.ts +130 -0
- package/src/base/shared/cache/index.ts +1 -0
- package/src/base/shared/cache/storage-manager.ts +118 -0
- package/src/base/shared/cache/types.ts +17 -0
- package/src/base/shared/color/__tests__/convert.test.ts +58 -0
- package/src/base/shared/color/color.ts +10 -0
- package/src/base/shared/color/convert.ts +62 -0
- package/src/base/shared/color/generator.ts +45 -0
- package/src/base/shared/color/index.ts +3 -0
- package/src/base/shared/constants/globals.ts +16 -0
- package/src/base/shared/constants/index.ts +2 -0
- package/src/base/shared/constants/vben.ts +25 -0
- package/src/base/shared/global-state.ts +45 -0
- package/src/base/shared/store.ts +1 -0
- package/src/base/shared/utils/__tests__/diff.test.ts +53 -0
- package/src/base/shared/utils/__tests__/dom.test.ts +127 -0
- package/src/base/shared/utils/__tests__/inference.test.ts +183 -0
- package/src/base/shared/utils/__tests__/letter.test.ts +116 -0
- package/src/base/shared/utils/__tests__/state-handler.test.ts +60 -0
- package/src/base/shared/utils/__tests__/tree.test.ts +196 -0
- package/src/base/shared/utils/__tests__/unique.test.ts +60 -0
- package/src/base/shared/utils/__tests__/update-css-variables.test.ts +30 -0
- package/src/base/shared/utils/__tests__/util.test.ts +156 -0
- package/src/base/shared/utils/__tests__/window.test.ts +33 -0
- package/src/base/shared/utils/cn.ts +8 -0
- package/src/base/shared/utils/date.ts +57 -0
- package/src/base/shared/utils/diff.ts +96 -0
- package/src/base/shared/utils/dom.ts +95 -0
- package/src/base/shared/utils/download.ts +156 -0
- package/src/base/shared/utils/index.ts +19 -0
- package/src/base/shared/utils/inference.ts +164 -0
- package/src/base/shared/utils/letter.ts +47 -0
- package/src/base/shared/utils/merge.ts +10 -0
- package/src/base/shared/utils/nprogress.ts +43 -0
- package/src/base/shared/utils/state-handler.ts +50 -0
- package/src/base/shared/utils/to.ts +21 -0
- package/src/base/shared/utils/tree.ts +97 -0
- package/src/base/shared/utils/unique.ts +15 -0
- package/src/base/shared/utils/update-css-variables.ts +35 -0
- package/src/base/shared/utils/util.ts +44 -0
- package/src/base/shared/utils/window.ts +37 -0
- package/src/base/typings/app.d.ts +106 -0
- package/src/base/typings/basic.d.ts +39 -0
- package/src/base/typings/helper.d.ts +133 -0
- package/src/base/typings/index.ts +6 -0
- package/src/base/typings/menu-record.ts +77 -0
- package/src/base/typings/tabs.ts +3 -0
- package/src/base/typings/vue-router.d.ts +143 -0
- package/src/constants/core.ts +31 -0
- package/src/constants/index.ts +2 -0
- package/src/core/composables/__tests__/use-sortable.test.ts +48 -0
- package/src/core/composables/index.ts +13 -0
- package/src/core/composables/use-is-mobile.ts +7 -0
- package/src/core/composables/use-layout-style.ts +87 -0
- package/src/core/composables/use-namespace.ts +106 -0
- package/src/core/composables/use-priority-value.ts +93 -0
- package/src/core/composables/use-scroll-lock.ts +54 -0
- package/src/core/composables/use-simple-locale/README.md +3 -0
- package/src/core/composables/use-simple-locale/index.ts +25 -0
- package/src/core/composables/use-simple-locale/messages.ts +22 -0
- package/src/core/composables/use-sortable.ts +29 -0
- package/src/core/preferences/config.ts +115 -0
- package/src/core/preferences/constants.ts +88 -0
- package/src/core/preferences/index.ts +35 -0
- package/src/core/preferences/preferences.ts +231 -0
- package/src/core/preferences/types.ts +281 -0
- package/src/core/preferences/update-css-variables.ts +116 -0
- package/src/core/preferences/use-preferences.ts +232 -0
- package/src/effects/access/access-control.vue +47 -0
- package/src/effects/access/accessible.ts +86 -0
- package/src/effects/access/directive.ts +42 -0
- package/src/effects/access/index.ts +4 -0
- package/src/effects/access/use-access.ts +53 -0
- package/src/effects/common-ui/components/api-component/api-component.vue +205 -0
- package/src/effects/common-ui/components/api-component/index.ts +1 -0
- package/src/effects/common-ui/components/captcha/hooks/useCaptchaPoints.ts +19 -0
- package/src/effects/common-ui/components/captcha/index.ts +6 -0
- package/src/effects/common-ui/components/captcha/point-selection-captcha/index.vue +175 -0
- package/src/effects/common-ui/components/captcha/point-selection-captcha/point-selection-captcha-card.vue +83 -0
- package/src/effects/common-ui/components/captcha/slider-captcha/index.vue +243 -0
- package/src/effects/common-ui/components/captcha/slider-captcha/slider-captcha-action.vue +63 -0
- package/src/effects/common-ui/components/captcha/slider-captcha/slider-captcha-bar.vue +38 -0
- package/src/effects/common-ui/components/captcha/slider-captcha/slider-captcha-content.vue +52 -0
- package/src/effects/common-ui/components/captcha/slider-rotate-captcha/index.vue +213 -0
- package/src/effects/common-ui/components/captcha/types.ts +175 -0
- package/src/effects/common-ui/components/col-page/col-page.vue +107 -0
- package/src/effects/common-ui/components/col-page/index.ts +2 -0
- package/src/effects/common-ui/components/col-page/types.ts +26 -0
- package/src/effects/common-ui/components/ellipsis-text/ellipsis-text.vue +142 -0
- package/src/effects/common-ui/components/ellipsis-text/index.ts +1 -0
- package/src/effects/common-ui/components/icon-picker/icon-picker.vue +230 -0
- package/src/effects/common-ui/components/icon-picker/index.ts +1 -0
- package/src/effects/common-ui/components/index.ts +23 -0
- package/src/effects/common-ui/components/json-viewer/index.ts +3 -0
- package/src/effects/common-ui/components/json-viewer/index.vue +114 -0
- package/src/effects/common-ui/components/json-viewer/style.scss +98 -0
- package/src/effects/common-ui/components/json-viewer/types.ts +44 -0
- package/src/effects/common-ui/components/page/__tests__/page.test.ts +89 -0
- package/src/effects/common-ui/components/page/index.ts +2 -0
- package/src/effects/common-ui/components/page/page.vue +99 -0
- package/src/effects/common-ui/components/page/types.ts +17 -0
- package/src/effects/common-ui/components/resize/index.ts +1 -0
- package/src/effects/common-ui/components/resize/resize.vue +1122 -0
- package/src/effects/common-ui/index.ts +2 -0
- package/src/effects/common-ui/ui/about/about.ts +14 -0
- package/src/effects/common-ui/ui/about/about.vue +182 -0
- package/src/effects/common-ui/ui/about/index.ts +1 -0
- package/src/effects/common-ui/ui/authentication/auth-title.vue +13 -0
- package/src/effects/common-ui/ui/authentication/code-login.vue +118 -0
- package/src/effects/common-ui/ui/authentication/forget-password.vue +115 -0
- package/src/effects/common-ui/ui/authentication/index.ts +7 -0
- package/src/effects/common-ui/ui/authentication/login-expired-modal.vue +56 -0
- package/src/effects/common-ui/ui/authentication/login.vue +184 -0
- package/src/effects/common-ui/ui/authentication/qrcode-login.vue +94 -0
- package/src/effects/common-ui/ui/authentication/register.vue +119 -0
- package/src/effects/common-ui/ui/authentication/third-party-login.vue +36 -0
- package/src/effects/common-ui/ui/authentication/types.ts +70 -0
- package/src/effects/common-ui/ui/dashboard/analysis/analysis-chart-card.vue +24 -0
- package/src/effects/common-ui/ui/dashboard/analysis/analysis-charts-tabs.vue +40 -0
- package/src/effects/common-ui/ui/dashboard/analysis/analysis-overview.vue +55 -0
- package/src/effects/common-ui/ui/dashboard/analysis/index.ts +3 -0
- package/src/effects/common-ui/ui/dashboard/index.ts +3 -0
- package/src/effects/common-ui/ui/dashboard/typing.ts +32 -0
- package/src/effects/common-ui/ui/dashboard/workbench/index.ts +3 -0
- package/src/effects/common-ui/ui/dashboard/workbench/workbench-header.vue +46 -0
- package/src/effects/common-ui/ui/dashboard/workbench/workbench-project.vue +63 -0
- package/src/effects/common-ui/ui/dashboard/workbench/workbench-quick-nav.vue +54 -0
- package/src/effects/common-ui/ui/fallback/fallback.ts +25 -0
- package/src/effects/common-ui/ui/fallback/fallback.vue +163 -0
- package/src/effects/common-ui/ui/fallback/icons/icon-403.vue +151 -0
- package/src/effects/common-ui/ui/fallback/icons/icon-404.vue +154 -0
- package/src/effects/common-ui/ui/fallback/icons/icon-500.vue +215 -0
- package/src/effects/common-ui/ui/fallback/icons/icon-coming-soon.vue +262 -0
- package/src/effects/common-ui/ui/fallback/icons/icon-offline.vue +112 -0
- package/src/effects/common-ui/ui/fallback/index.ts +2 -0
- package/src/effects/common-ui/ui/index.ts +4 -0
- package/src/effects/hooks/index.ts +8 -0
- package/src/effects/hooks/use-app-config.ts +23 -0
- package/src/effects/hooks/use-content-maximize.ts +24 -0
- package/src/effects/hooks/use-design-tokens.ts +280 -0
- package/src/effects/hooks/use-pagination.ts +57 -0
- package/src/effects/hooks/use-refresh.ts +16 -0
- package/src/effects/hooks/use-tabs.ts +113 -0
- package/src/effects/hooks/use-watermark.ts +88 -0
- package/src/icons/iconify/index.ts +79 -0
- package/src/icons/icons/empty-icon.vue +27 -0
- package/src/icons/index.ts +3 -0
- package/src/icons/svg/icons/antdv-logo.svg +29 -0
- package/src/icons/svg/icons/avatar-1.svg +1 -0
- package/src/icons/svg/icons/avatar-2.svg +1 -0
- package/src/icons/svg/icons/avatar-3.svg +1 -0
- package/src/icons/svg/icons/avatar-4.svg +1 -0
- package/src/icons/svg/icons/bell.svg +1 -0
- package/src/icons/svg/icons/cake.svg +1 -0
- package/src/icons/svg/icons/card.svg +1 -0
- package/src/icons/svg/icons/download.svg +1 -0
- package/src/icons/svg/icons/language.svg +1 -0
- package/src/icons/svg/icons/setting.svg +1 -0
- package/src/icons/svg/index.ts +29 -0
- package/src/icons/svg/load.ts +61 -0
- package/src/locales/i18n.ts +146 -0
- package/src/locales/index.ts +30 -0
- package/src/locales/langs/en-US/authentication.json +97 -0
- package/src/locales/langs/en-US/common.json +27 -0
- package/src/locales/langs/en-US/preferences.json +169 -0
- package/src/locales/langs/en-US/ui.json +87 -0
- package/src/locales/langs/zh-CN/authentication.json +97 -0
- package/src/locales/langs/zh-CN/common.json +27 -0
- package/src/locales/langs/zh-CN/preferences.json +169 -0
- package/src/locales/langs/zh-CN/ui.json +87 -0
- package/src/locales/typing.ts +25 -0
- package/src/preferences/index.ts +17 -0
- package/src/stores/index.ts +3 -0
- package/src/stores/modules/access.test.ts +46 -0
- package/src/stores/modules/access.ts +130 -0
- package/src/stores/modules/index.ts +4 -0
- package/src/stores/modules/lock.test.ts +31 -0
- package/src/stores/modules/lock.ts +38 -0
- package/src/stores/modules/tabbar.test.ts +295 -0
- package/src/stores/modules/tabbar.ts +558 -0
- package/src/stores/modules/user.test.ts +37 -0
- package/src/stores/modules/user.ts +92 -0
- package/src/stores/setup.ts +43 -0
- package/src/styles/antd/index.css +292 -0
- package/src/styles/ele/index.css +3 -0
- package/src/styles/global/index.scss +1 -0
- package/src/styles/index.ts +1 -0
- package/src/types/global.d.ts +23 -0
- package/src/types/index.ts +2 -0
- package/src/types/user.ts +26 -0
- package/src/ui-kit/form-ui/components/form-actions.vue +205 -0
- package/src/ui-kit/form-ui/config.ts +82 -0
- package/src/ui-kit/form-ui/form-api.ts +351 -0
- package/src/ui-kit/form-ui/form-render/context.ts +24 -0
- package/src/ui-kit/form-ui/form-render/dependencies.ts +124 -0
- package/src/ui-kit/form-ui/form-render/expandable.ts +99 -0
- package/src/ui-kit/form-ui/form-render/form-field.vue +350 -0
- package/src/ui-kit/form-ui/form-render/form-label.vue +22 -0
- package/src/ui-kit/form-ui/form-render/form.vue +160 -0
- package/src/ui-kit/form-ui/form-render/helper.ts +60 -0
- package/src/ui-kit/form-ui/form-render/index.ts +3 -0
- package/src/ui-kit/form-ui/index.ts +12 -0
- package/src/ui-kit/form-ui/types.ts +395 -0
- package/src/ui-kit/form-ui/use-form-context.ts +59 -0
- package/src/ui-kit/form-ui/use-vben-form.ts +50 -0
- package/src/ui-kit/form-ui/vben-form.vue +77 -0
- package/src/ui-kit/form-ui/vben-use-form.vue +113 -0
- package/src/ui-kit/layout-ui/components/index.ts +5 -0
- package/src/ui-kit/layout-ui/components/layout-content.vue +63 -0
- package/src/ui-kit/layout-ui/components/layout-footer.vue +43 -0
- package/src/ui-kit/layout-ui/components/layout-header.vue +76 -0
- package/src/ui-kit/layout-ui/components/layout-sidebar.vue +315 -0
- package/src/ui-kit/layout-ui/components/layout-tabbar.vue +29 -0
- package/src/ui-kit/layout-ui/components/widgets/index.ts +2 -0
- package/src/ui-kit/layout-ui/components/widgets/sidebar-collapse-button.vue +19 -0
- package/src/ui-kit/layout-ui/components/widgets/sidebar-fixed-button.vue +19 -0
- package/src/ui-kit/layout-ui/hooks/use-layout.ts +41 -0
- package/src/ui-kit/layout-ui/index.ts +2 -0
- package/src/ui-kit/layout-ui/vben-layout.ts +165 -0
- package/src/ui-kit/layout-ui/vben-layout.vue +596 -0
- package/src/ui-kit/menu-ui/components/collapse-transition.vue +96 -0
- package/src/ui-kit/menu-ui/components/index.ts +4 -0
- package/src/ui-kit/menu-ui/components/menu-badge-dot.vue +28 -0
- package/src/ui-kit/menu-ui/components/menu-badge.vue +57 -0
- package/src/ui-kit/menu-ui/components/menu-item.vue +122 -0
- package/src/ui-kit/menu-ui/components/menu.vue +859 -0
- package/src/ui-kit/menu-ui/components/normal-menu/index.ts +2 -0
- package/src/ui-kit/menu-ui/components/normal-menu/normal-menu.ts +27 -0
- package/src/ui-kit/menu-ui/components/normal-menu/normal-menu.vue +162 -0
- package/src/ui-kit/menu-ui/components/sub-menu-content.vue +105 -0
- package/src/ui-kit/menu-ui/components/sub-menu.vue +273 -0
- package/src/ui-kit/menu-ui/hooks/index.ts +2 -0
- package/src/ui-kit/menu-ui/hooks/use-menu-context.ts +55 -0
- package/src/ui-kit/menu-ui/hooks/use-menu.ts +48 -0
- package/src/ui-kit/menu-ui/index.ts +3 -0
- package/src/ui-kit/menu-ui/menu.vue +38 -0
- package/src/ui-kit/menu-ui/sub-menu.vue +71 -0
- package/src/ui-kit/menu-ui/types.ts +139 -0
- package/src/ui-kit/menu-ui/utils/index.ts +51 -0
- package/src/ui-kit/popup-ui/drawer/__tests__/drawer-api.test.ts +132 -0
- package/src/ui-kit/popup-ui/drawer/drawer-api.ts +144 -0
- package/src/ui-kit/popup-ui/drawer/drawer.ts +152 -0
- package/src/ui-kit/popup-ui/drawer/drawer.vue +251 -0
- package/src/ui-kit/popup-ui/drawer/index.ts +3 -0
- package/src/ui-kit/popup-ui/drawer/use-drawer.ts +105 -0
- package/src/ui-kit/popup-ui/index.ts +2 -0
- package/src/ui-kit/popup-ui/modal/__tests__/modal-api.test.ts +128 -0
- package/src/ui-kit/popup-ui/modal/index.ts +3 -0
- package/src/ui-kit/popup-ui/modal/modal-api.ts +172 -0
- package/src/ui-kit/popup-ui/modal/modal.ts +175 -0
- package/src/ui-kit/popup-ui/modal/modal.vue +311 -0
- package/src/ui-kit/popup-ui/modal/use-modal-draggable.ts +116 -0
- package/src/ui-kit/popup-ui/modal/use-modal.ts +117 -0
- package/src/ui-kit/shadcn-ui/components/avatar/avatar.vue +49 -0
- package/src/ui-kit/shadcn-ui/components/avatar/index.ts +1 -0
- package/src/ui-kit/shadcn-ui/components/back-top/back-top.vue +43 -0
- package/src/ui-kit/shadcn-ui/components/back-top/backtop.ts +38 -0
- package/src/ui-kit/shadcn-ui/components/back-top/index.ts +1 -0
- package/src/ui-kit/shadcn-ui/components/back-top/use-backtop.ts +45 -0
- package/src/ui-kit/shadcn-ui/components/breadcrumb/breadcrumb-background.vue +109 -0
- package/src/ui-kit/shadcn-ui/components/breadcrumb/breadcrumb-view.vue +22 -0
- package/src/ui-kit/shadcn-ui/components/breadcrumb/breadcrumb.vue +98 -0
- package/src/ui-kit/shadcn-ui/components/breadcrumb/index.ts +3 -0
- package/src/ui-kit/shadcn-ui/components/breadcrumb/types.ts +17 -0
- package/src/ui-kit/shadcn-ui/components/button/button.ts +24 -0
- package/src/ui-kit/shadcn-ui/components/button/button.vue +42 -0
- package/src/ui-kit/shadcn-ui/components/button/icon-button.vue +78 -0
- package/src/ui-kit/shadcn-ui/components/button/index.ts +3 -0
- package/src/ui-kit/shadcn-ui/components/checkbox/checkbox.vue +26 -0
- package/src/ui-kit/shadcn-ui/components/checkbox/index.ts +1 -0
- package/src/ui-kit/shadcn-ui/components/context-menu/context-menu.vue +96 -0
- package/src/ui-kit/shadcn-ui/components/context-menu/index.ts +3 -0
- package/src/ui-kit/shadcn-ui/components/context-menu/interface.ts +38 -0
- package/src/ui-kit/shadcn-ui/components/count-to-animator/count-to-animator.vue +111 -0
- package/src/ui-kit/shadcn-ui/components/count-to-animator/index.ts +1 -0
- package/src/ui-kit/shadcn-ui/components/dropdown-menu/dropdown-menu.vue +49 -0
- package/src/ui-kit/shadcn-ui/components/dropdown-menu/dropdown-radio-menu.vue +52 -0
- package/src/ui-kit/shadcn-ui/components/dropdown-menu/index.ts +4 -0
- package/src/ui-kit/shadcn-ui/components/dropdown-menu/interface.ts +32 -0
- package/src/ui-kit/shadcn-ui/components/expandable-arrow/expandable-arrow.vue +31 -0
- package/src/ui-kit/shadcn-ui/components/expandable-arrow/index.ts +1 -0
- package/src/ui-kit/shadcn-ui/components/full-screen/full-screen.vue +51 -0
- package/src/ui-kit/shadcn-ui/components/full-screen/index.ts +1 -0
- package/src/ui-kit/shadcn-ui/components/hover-card/hover-card.vue +54 -0
- package/src/ui-kit/shadcn-ui/components/hover-card/index.ts +2 -0
- package/src/ui-kit/shadcn-ui/components/icon/icon.vue +33 -0
- package/src/ui-kit/shadcn-ui/components/icon/index.ts +1 -0
- package/src/ui-kit/shadcn-ui/components/index.ts +23 -0
- package/src/ui-kit/shadcn-ui/components/input-password/index.ts +1 -0
- package/src/ui-kit/shadcn-ui/components/input-password/input-password.vue +57 -0
- package/src/ui-kit/shadcn-ui/components/input-password/password-strength.vue +66 -0
- package/src/ui-kit/shadcn-ui/components/logo/index.ts +1 -0
- package/src/ui-kit/shadcn-ui/components/logo/logo.vue +65 -0
- package/src/ui-kit/shadcn-ui/components/pin-input/index.ts +3 -0
- package/src/ui-kit/shadcn-ui/components/pin-input/input.vue +116 -0
- package/src/ui-kit/shadcn-ui/components/pin-input/types.ts +30 -0
- package/src/ui-kit/shadcn-ui/components/popover/index.ts +1 -0
- package/src/ui-kit/shadcn-ui/components/popover/popover.vue +57 -0
- package/src/ui-kit/shadcn-ui/components/render-content/index.ts +1 -0
- package/src/ui-kit/shadcn-ui/components/render-content/render-content.vue +39 -0
- package/src/ui-kit/shadcn-ui/components/scrollbar/index.ts +1 -0
- package/src/ui-kit/shadcn-ui/components/scrollbar/scrollbar.vue +153 -0
- package/src/ui-kit/shadcn-ui/components/segmented/index.ts +3 -0
- package/src/ui-kit/shadcn-ui/components/segmented/segmented.vue +59 -0
- package/src/ui-kit/shadcn-ui/components/segmented/tabs-indicator.vue +37 -0
- package/src/ui-kit/shadcn-ui/components/segmented/types.ts +6 -0
- package/src/ui-kit/shadcn-ui/components/select/index.ts +1 -0
- package/src/ui-kit/shadcn-ui/components/select/select.vue +29 -0
- package/src/ui-kit/shadcn-ui/components/spine-text/index.ts +1 -0
- package/src/ui-kit/shadcn-ui/components/spine-text/spine-text.vue +49 -0
- package/src/ui-kit/shadcn-ui/components/spinner/index.ts +2 -0
- package/src/ui-kit/shadcn-ui/components/spinner/loading.vue +137 -0
- package/src/ui-kit/shadcn-ui/components/spinner/spinner.vue +125 -0
- package/src/ui-kit/shadcn-ui/components/tooltip/help-tooltip.vue +31 -0
- package/src/ui-kit/shadcn-ui/components/tooltip/index.ts +2 -0
- package/src/ui-kit/shadcn-ui/components/tooltip/tooltip.vue +43 -0
- package/src/ui-kit/shadcn-ui/index.ts +3 -0
- package/src/ui-kit/shadcn-ui/ui/accordion/Accordion.vue +19 -0
- package/src/ui-kit/shadcn-ui/ui/accordion/AccordionContent.vue +26 -0
- package/src/ui-kit/shadcn-ui/ui/accordion/AccordionItem.vue +27 -0
- package/src/ui-kit/shadcn-ui/ui/accordion/AccordionTrigger.vue +41 -0
- package/src/ui-kit/shadcn-ui/ui/accordion/index.ts +4 -0
- package/src/ui-kit/shadcn-ui/ui/alert-dialog/AlertDialog.vue +16 -0
- package/src/ui-kit/shadcn-ui/ui/alert-dialog/AlertDialogAction.vue +13 -0
- package/src/ui-kit/shadcn-ui/ui/alert-dialog/AlertDialogCancel.vue +13 -0
- package/src/ui-kit/shadcn-ui/ui/alert-dialog/AlertDialogContent.vue +101 -0
- package/src/ui-kit/shadcn-ui/ui/alert-dialog/AlertDialogDescription.vue +28 -0
- package/src/ui-kit/shadcn-ui/ui/alert-dialog/AlertDialogOverlay.vue +8 -0
- package/src/ui-kit/shadcn-ui/ui/alert-dialog/AlertDialogTitle.vue +30 -0
- package/src/ui-kit/shadcn-ui/ui/alert-dialog/index.ts +6 -0
- package/src/ui-kit/shadcn-ui/ui/avatar/Avatar.vue +25 -0
- package/src/ui-kit/shadcn-ui/ui/avatar/AvatarFallback.vue +11 -0
- package/src/ui-kit/shadcn-ui/ui/avatar/AvatarImage.vue +9 -0
- package/src/ui-kit/shadcn-ui/ui/avatar/avatar.ts +20 -0
- package/src/ui-kit/shadcn-ui/ui/avatar/index.ts +4 -0
- package/src/ui-kit/shadcn-ui/ui/badge/Badge.vue +16 -0
- package/src/ui-kit/shadcn-ui/ui/badge/badge.ts +23 -0
- package/src/ui-kit/shadcn-ui/ui/badge/index.ts +3 -0
- package/src/ui-kit/shadcn-ui/ui/breadcrumb/Breadcrumb.vue +11 -0
- package/src/ui-kit/shadcn-ui/ui/breadcrumb/BreadcrumbEllipsis.vue +22 -0
- package/src/ui-kit/shadcn-ui/ui/breadcrumb/BreadcrumbItem.vue +17 -0
- package/src/ui-kit/shadcn-ui/ui/breadcrumb/BreadcrumbLink.vue +19 -0
- package/src/ui-kit/shadcn-ui/ui/breadcrumb/BreadcrumbList.vue +20 -0
- package/src/ui-kit/shadcn-ui/ui/breadcrumb/BreadcrumbPage.vue +18 -0
- package/src/ui-kit/shadcn-ui/ui/breadcrumb/BreadcrumbSeparator.vue +21 -0
- package/src/ui-kit/shadcn-ui/ui/breadcrumb/index.ts +7 -0
- package/src/ui-kit/shadcn-ui/ui/button/Button.vue +30 -0
- package/src/ui-kit/shadcn-ui/ui/button/button.ts +34 -0
- package/src/ui-kit/shadcn-ui/ui/button/index.ts +5 -0
- package/src/ui-kit/shadcn-ui/ui/button/types.ts +20 -0
- package/src/ui-kit/shadcn-ui/ui/card/Card.vue +20 -0
- package/src/ui-kit/shadcn-ui/ui/card/CardContent.vue +13 -0
- package/src/ui-kit/shadcn-ui/ui/card/CardDescription.vue +13 -0
- package/src/ui-kit/shadcn-ui/ui/card/CardFooter.vue +13 -0
- package/src/ui-kit/shadcn-ui/ui/card/CardHeader.vue +13 -0
- package/src/ui-kit/shadcn-ui/ui/card/CardTitle.vue +13 -0
- package/src/ui-kit/shadcn-ui/ui/card/index.ts +6 -0
- package/src/ui-kit/shadcn-ui/ui/checkbox/Checkbox.vue +45 -0
- package/src/ui-kit/shadcn-ui/ui/checkbox/index.ts +1 -0
- package/src/ui-kit/shadcn-ui/ui/context-menu/ContextMenu.vue +18 -0
- package/src/ui-kit/shadcn-ui/ui/context-menu/ContextMenuCheckboxItem.vue +44 -0
- package/src/ui-kit/shadcn-ui/ui/context-menu/ContextMenuContent.vue +40 -0
- package/src/ui-kit/shadcn-ui/ui/context-menu/ContextMenuGroup.vue +11 -0
- package/src/ui-kit/shadcn-ui/ui/context-menu/ContextMenuItem.vue +40 -0
- package/src/ui-kit/shadcn-ui/ui/context-menu/ContextMenuLabel.vue +32 -0
- package/src/ui-kit/shadcn-ui/ui/context-menu/ContextMenuPortal.vue +11 -0
- package/src/ui-kit/shadcn-ui/ui/context-menu/ContextMenuRadioGroup.vue +19 -0
- package/src/ui-kit/shadcn-ui/ui/context-menu/ContextMenuRadioItem.vue +44 -0
- package/src/ui-kit/shadcn-ui/ui/context-menu/ContextMenuSeparator.vue +25 -0
- package/src/ui-kit/shadcn-ui/ui/context-menu/ContextMenuShortcut.vue +17 -0
- package/src/ui-kit/shadcn-ui/ui/context-menu/ContextMenuSub.vue +19 -0
- package/src/ui-kit/shadcn-ui/ui/context-menu/ContextMenuSubContent.vue +37 -0
- package/src/ui-kit/shadcn-ui/ui/context-menu/ContextMenuSubTrigger.vue +43 -0
- package/src/ui-kit/shadcn-ui/ui/context-menu/ContextMenuTrigger.vue +17 -0
- package/src/ui-kit/shadcn-ui/ui/context-menu/index.ts +14 -0
- package/src/ui-kit/shadcn-ui/ui/dialog/Dialog.vue +19 -0
- package/src/ui-kit/shadcn-ui/ui/dialog/DialogClose.vue +11 -0
- package/src/ui-kit/shadcn-ui/ui/dialog/DialogContent.vue +117 -0
- package/src/ui-kit/shadcn-ui/ui/dialog/DialogDescription.vue +30 -0
- package/src/ui-kit/shadcn-ui/ui/dialog/DialogFooter.vue +15 -0
- package/src/ui-kit/shadcn-ui/ui/dialog/DialogHeader.vue +15 -0
- package/src/ui-kit/shadcn-ui/ui/dialog/DialogOverlay.vue +11 -0
- package/src/ui-kit/shadcn-ui/ui/dialog/DialogScrollContent.vue +71 -0
- package/src/ui-kit/shadcn-ui/ui/dialog/DialogTitle.vue +28 -0
- package/src/ui-kit/shadcn-ui/ui/dialog/DialogTrigger.vue +11 -0
- package/src/ui-kit/shadcn-ui/ui/dialog/index.ts +9 -0
- package/src/ui-kit/shadcn-ui/ui/dropdown-menu/DropdownMenu.vue +21 -0
- package/src/ui-kit/shadcn-ui/ui/dropdown-menu/DropdownMenuCheckboxItem.vue +44 -0
- package/src/ui-kit/shadcn-ui/ui/dropdown-menu/DropdownMenuContent.vue +45 -0
- package/src/ui-kit/shadcn-ui/ui/dropdown-menu/DropdownMenuGroup.vue +11 -0
- package/src/ui-kit/shadcn-ui/ui/dropdown-menu/DropdownMenuItem.vue +38 -0
- package/src/ui-kit/shadcn-ui/ui/dropdown-menu/DropdownMenuLabel.vue +34 -0
- package/src/ui-kit/shadcn-ui/ui/dropdown-menu/DropdownMenuRadioGroup.vue +19 -0
- package/src/ui-kit/shadcn-ui/ui/dropdown-menu/DropdownMenuRadioItem.vue +45 -0
- package/src/ui-kit/shadcn-ui/ui/dropdown-menu/DropdownMenuSeparator.vue +29 -0
- package/src/ui-kit/shadcn-ui/ui/dropdown-menu/DropdownMenuShortcut.vue +13 -0
- package/src/ui-kit/shadcn-ui/ui/dropdown-menu/DropdownMenuSub.vue +19 -0
- package/src/ui-kit/shadcn-ui/ui/dropdown-menu/DropdownMenuSubContent.vue +37 -0
- package/src/ui-kit/shadcn-ui/ui/dropdown-menu/DropdownMenuSubTrigger.vue +37 -0
- package/src/ui-kit/shadcn-ui/ui/dropdown-menu/DropdownMenuTrigger.vue +17 -0
- package/src/ui-kit/shadcn-ui/ui/dropdown-menu/index.ts +16 -0
- package/src/ui-kit/shadcn-ui/ui/form/FormControl.vue +19 -0
- package/src/ui-kit/shadcn-ui/ui/form/FormDescription.vue +20 -0
- package/src/ui-kit/shadcn-ui/ui/form/FormItem.vue +20 -0
- package/src/ui-kit/shadcn-ui/ui/form/FormLabel.vue +18 -0
- package/src/ui-kit/shadcn-ui/ui/form/FormMessage.vue +18 -0
- package/src/ui-kit/shadcn-ui/ui/form/index.ts +11 -0
- package/src/ui-kit/shadcn-ui/ui/form/injectionKeys.ts +4 -0
- package/src/ui-kit/shadcn-ui/ui/form/useFormField.ts +38 -0
- package/src/ui-kit/shadcn-ui/ui/hover-card/HoverCard.vue +19 -0
- package/src/ui-kit/shadcn-ui/ui/hover-card/HoverCardContent.vue +43 -0
- package/src/ui-kit/shadcn-ui/ui/hover-card/HoverCardTrigger.vue +11 -0
- package/src/ui-kit/shadcn-ui/ui/hover-card/index.ts +3 -0
- package/src/ui-kit/shadcn-ui/ui/index.ts +30 -0
- package/src/ui-kit/shadcn-ui/ui/input/Input.vue +32 -0
- package/src/ui-kit/shadcn-ui/ui/input/index.ts +1 -0
- package/src/ui-kit/shadcn-ui/ui/label/Label.vue +29 -0
- package/src/ui-kit/shadcn-ui/ui/label/index.ts +1 -0
- package/src/ui-kit/shadcn-ui/ui/number-field/NumberField.vue +26 -0
- package/src/ui-kit/shadcn-ui/ui/number-field/NumberFieldContent.vue +20 -0
- package/src/ui-kit/shadcn-ui/ui/number-field/NumberFieldDecrement.vue +37 -0
- package/src/ui-kit/shadcn-ui/ui/number-field/NumberFieldIncrement.vue +37 -0
- package/src/ui-kit/shadcn-ui/ui/number-field/NumberFieldInput.vue +16 -0
- package/src/ui-kit/shadcn-ui/ui/number-field/index.ts +5 -0
- package/src/ui-kit/shadcn-ui/ui/pagination/PaginationEllipsis.vue +27 -0
- package/src/ui-kit/shadcn-ui/ui/pagination/PaginationFirst.vue +33 -0
- package/src/ui-kit/shadcn-ui/ui/pagination/PaginationLast.vue +33 -0
- package/src/ui-kit/shadcn-ui/ui/pagination/PaginationNext.vue +33 -0
- package/src/ui-kit/shadcn-ui/ui/pagination/PaginationPrev.vue +33 -0
- package/src/ui-kit/shadcn-ui/ui/pagination/index.ts +10 -0
- package/src/ui-kit/shadcn-ui/ui/pin-input/PinInput.vue +31 -0
- package/src/ui-kit/shadcn-ui/ui/pin-input/PinInputGroup.vue +23 -0
- package/src/ui-kit/shadcn-ui/ui/pin-input/PinInputInput.vue +32 -0
- package/src/ui-kit/shadcn-ui/ui/pin-input/PinInputSeparator.vue +15 -0
- package/src/ui-kit/shadcn-ui/ui/pin-input/index.ts +4 -0
- package/src/ui-kit/shadcn-ui/ui/popover/Popover.vue +16 -0
- package/src/ui-kit/shadcn-ui/ui/popover/PopoverContent.vue +50 -0
- package/src/ui-kit/shadcn-ui/ui/popover/PopoverTrigger.vue +11 -0
- package/src/ui-kit/shadcn-ui/ui/popover/index.ts +4 -0
- package/src/ui-kit/shadcn-ui/ui/radio-group/RadioGroup.vue +29 -0
- package/src/ui-kit/shadcn-ui/ui/radio-group/RadioGroupItem.vue +39 -0
- package/src/ui-kit/shadcn-ui/ui/radio-group/index.ts +2 -0
- package/src/ui-kit/shadcn-ui/ui/resizable/ResizableHandle.vue +49 -0
- package/src/ui-kit/shadcn-ui/ui/resizable/ResizablePanelGroup.vue +37 -0
- package/src/ui-kit/shadcn-ui/ui/resizable/index.ts +3 -0
- package/src/ui-kit/shadcn-ui/ui/scroll-area/ScrollArea.vue +49 -0
- package/src/ui-kit/shadcn-ui/ui/scroll-area/ScrollBar.vue +42 -0
- package/src/ui-kit/shadcn-ui/ui/scroll-area/index.ts +2 -0
- package/src/ui-kit/shadcn-ui/ui/select/Select.vue +16 -0
- package/src/ui-kit/shadcn-ui/ui/select/SelectContent.vue +67 -0
- package/src/ui-kit/shadcn-ui/ui/select/SelectGroup.vue +21 -0
- package/src/ui-kit/shadcn-ui/ui/select/SelectItem.vue +46 -0
- package/src/ui-kit/shadcn-ui/ui/select/SelectItemText.vue +11 -0
- package/src/ui-kit/shadcn-ui/ui/select/SelectLabel.vue +13 -0
- package/src/ui-kit/shadcn-ui/ui/select/SelectScrollDownButton.vue +35 -0
- package/src/ui-kit/shadcn-ui/ui/select/SelectScrollUpButton.vue +35 -0
- package/src/ui-kit/shadcn-ui/ui/select/SelectSeparator.vue +22 -0
- package/src/ui-kit/shadcn-ui/ui/select/SelectTrigger.vue +40 -0
- package/src/ui-kit/shadcn-ui/ui/select/SelectValue.vue +11 -0
- package/src/ui-kit/shadcn-ui/ui/select/index.ts +11 -0
- package/src/ui-kit/shadcn-ui/ui/separator/Separator.vue +42 -0
- package/src/ui-kit/shadcn-ui/ui/separator/index.ts +1 -0
- package/src/ui-kit/shadcn-ui/ui/sheet/Sheet.vue +19 -0
- package/src/ui-kit/shadcn-ui/ui/sheet/SheetClose.vue +11 -0
- package/src/ui-kit/shadcn-ui/ui/sheet/SheetContent.vue +83 -0
- package/src/ui-kit/shadcn-ui/ui/sheet/SheetDescription.vue +24 -0
- package/src/ui-kit/shadcn-ui/ui/sheet/SheetFooter.vue +15 -0
- package/src/ui-kit/shadcn-ui/ui/sheet/SheetHeader.vue +11 -0
- package/src/ui-kit/shadcn-ui/ui/sheet/SheetOverlay.vue +11 -0
- package/src/ui-kit/shadcn-ui/ui/sheet/SheetTitle.vue +24 -0
- package/src/ui-kit/shadcn-ui/ui/sheet/SheetTrigger.vue +11 -0
- package/src/ui-kit/shadcn-ui/ui/sheet/index.ts +10 -0
- package/src/ui-kit/shadcn-ui/ui/sheet/sheet.ts +22 -0
- package/src/ui-kit/shadcn-ui/ui/switch/Switch.vue +45 -0
- package/src/ui-kit/shadcn-ui/ui/switch/index.ts +1 -0
- package/src/ui-kit/shadcn-ui/ui/tabs/Tabs.vue +16 -0
- package/src/ui-kit/shadcn-ui/ui/tabs/TabsContent.vue +29 -0
- package/src/ui-kit/shadcn-ui/ui/tabs/TabsList.vue +29 -0
- package/src/ui-kit/shadcn-ui/ui/tabs/TabsTrigger.vue +31 -0
- package/src/ui-kit/shadcn-ui/ui/tabs/index.ts +5 -0
- package/src/ui-kit/shadcn-ui/ui/textarea/Textarea.vue +32 -0
- package/src/ui-kit/shadcn-ui/ui/textarea/index.ts +1 -0
- package/src/ui-kit/shadcn-ui/ui/toggle/Toggle.vue +48 -0
- package/src/ui-kit/shadcn-ui/ui/toggle/index.ts +2 -0
- package/src/ui-kit/shadcn-ui/ui/toggle/toggle.ts +25 -0
- package/src/ui-kit/shadcn-ui/ui/toggle-group/ToggleGroup.vue +48 -0
- package/src/ui-kit/shadcn-ui/ui/toggle-group/ToggleGroupItem.vue +51 -0
- package/src/ui-kit/shadcn-ui/ui/toggle-group/index.ts +2 -0
- package/src/ui-kit/shadcn-ui/ui/tooltip/Tooltip.vue +19 -0
- package/src/ui-kit/shadcn-ui/ui/tooltip/TooltipContent.vue +52 -0
- package/src/ui-kit/shadcn-ui/ui/tooltip/TooltipProvider.vue +11 -0
- package/src/ui-kit/shadcn-ui/ui/tooltip/TooltipTrigger.vue +11 -0
- package/src/ui-kit/shadcn-ui/ui/tooltip/index.ts +4 -0
- package/src/ui-kit/shadcn-ui/ui/tree/index.ts +4 -0
- package/src/ui-kit/shadcn-ui/ui/tree/tree.vue +464 -0
- package/src/ui-kit/shadcn-ui/ui/tree/types.ts +62 -0
- package/src/ui-kit/tabs-ui/components/index.ts +2 -0
- package/src/ui-kit/tabs-ui/components/tabs/tabs.vue +133 -0
- package/src/ui-kit/tabs-ui/components/tabs-chrome/tabs.vue +195 -0
- package/src/ui-kit/tabs-ui/components/widgets/index.ts +2 -0
- package/src/ui-kit/tabs-ui/components/widgets/tool-more.vue +18 -0
- package/src/ui-kit/tabs-ui/components/widgets/tool-screen.vue +19 -0
- package/src/ui-kit/tabs-ui/index.ts +3 -0
- package/src/ui-kit/tabs-ui/tabs-view.vue +95 -0
- package/src/ui-kit/tabs-ui/types.ts +64 -0
- package/src/ui-kit/tabs-ui/use-tabs-drag.ts +127 -0
- package/src/ui-kit/tabs-ui/use-tabs-view-scroll.ts +194 -0
- package/src/utils/helpers/__tests__/find-menu-by-path.test.ts +88 -0
- package/src/utils/helpers/__tests__/generate-menus.test.ts +236 -0
- package/src/utils/helpers/__tests__/generate-routes-frontend.test.ts +105 -0
- package/src/utils/helpers/__tests__/merge-route-modules.test.ts +68 -0
- package/src/utils/helpers/find-menu-by-path.ts +37 -0
- package/src/utils/helpers/generate-menus.ts +80 -0
- package/src/utils/helpers/generate-routes-backend.ts +81 -0
- package/src/utils/helpers/generate-routes-frontend.ts +58 -0
- package/src/utils/helpers/get-popup-container.ts +6 -0
- package/src/utils/helpers/index.ts +8 -0
- package/src/utils/helpers/merge-route-modules.ts +28 -0
- package/src/utils/helpers/reset-routes.ts +31 -0
- package/src/utils/helpers/unmount-global-loading.ts +31 -0
- package/src/utils/index.ts +4 -0
- package/README.md +0 -3
|
@@ -0,0 +1,558 @@
|
|
|
1
|
+
import type { TabDefinition } from '../../base/typings';
|
|
2
|
+
import type { Router, RouteRecordNormalized } from 'vue-router';
|
|
3
|
+
|
|
4
|
+
import { toRaw } from 'vue';
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
openRouteInNewWindow,
|
|
8
|
+
startProgress,
|
|
9
|
+
stopProgress,
|
|
10
|
+
} from '../../base/shared/utils';
|
|
11
|
+
|
|
12
|
+
import { acceptHMRUpdate, defineStore } from 'pinia';
|
|
13
|
+
|
|
14
|
+
interface TabbarState {
|
|
15
|
+
/**
|
|
16
|
+
* @zh_CN 当前打开的标签页列表缓存
|
|
17
|
+
*/
|
|
18
|
+
cachedTabs: Set<string>;
|
|
19
|
+
/**
|
|
20
|
+
* @zh_CN 拖拽结束的索引
|
|
21
|
+
*/
|
|
22
|
+
dragEndIndex: number;
|
|
23
|
+
/**
|
|
24
|
+
* @zh_CN 需要排除缓存的标签页
|
|
25
|
+
*/
|
|
26
|
+
excludeCachedTabs: Set<string>;
|
|
27
|
+
/**
|
|
28
|
+
* @zh_CN 是否刷新
|
|
29
|
+
*/
|
|
30
|
+
renderRouteView?: boolean;
|
|
31
|
+
/**
|
|
32
|
+
* @zh_CN 当前打开的标签页列表
|
|
33
|
+
*/
|
|
34
|
+
tabs: TabDefinition[];
|
|
35
|
+
/**
|
|
36
|
+
* @zh_CN 更新时间,用于一些更新场景,使用watch深度监听的话,会损耗性能
|
|
37
|
+
*/
|
|
38
|
+
updatedAt?: number;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* @zh_CN 访问权限相关
|
|
43
|
+
*/
|
|
44
|
+
export const useTabbarStore = defineStore('core-tabbar', {
|
|
45
|
+
actions: {
|
|
46
|
+
/**
|
|
47
|
+
* Close tabs in bulk
|
|
48
|
+
*/
|
|
49
|
+
async _bulkCloseByPaths(paths: string[]) {
|
|
50
|
+
this.tabs = this.tabs.filter((item) => {
|
|
51
|
+
return !paths.includes(getTabPath(item));
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
this.updateCacheTabs();
|
|
55
|
+
},
|
|
56
|
+
/**
|
|
57
|
+
* @zh_CN 关闭标签页
|
|
58
|
+
* @param tab
|
|
59
|
+
*/
|
|
60
|
+
_close(tab: TabDefinition) {
|
|
61
|
+
const { fullPath } = tab;
|
|
62
|
+
if (isAffixTab(tab)) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
const index = this.tabs.findIndex((item) => item.fullPath === fullPath);
|
|
66
|
+
index !== -1 && this.tabs.splice(index, 1);
|
|
67
|
+
},
|
|
68
|
+
/**
|
|
69
|
+
* @zh_CN 跳转到默认标签页
|
|
70
|
+
*/
|
|
71
|
+
async _goToDefaultTab(router: Router) {
|
|
72
|
+
if (this.getTabs.length <= 0) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
const firstTab = this.getTabs[0];
|
|
76
|
+
if (firstTab) {
|
|
77
|
+
await this._goToTab(firstTab, router);
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
/**
|
|
81
|
+
* @zh_CN 跳转到标签页
|
|
82
|
+
* @param tab
|
|
83
|
+
* @param router
|
|
84
|
+
*/
|
|
85
|
+
async _goToTab(tab: TabDefinition, router: Router) {
|
|
86
|
+
const { params, path, query } = tab;
|
|
87
|
+
const toParams = {
|
|
88
|
+
params: params || {},
|
|
89
|
+
path,
|
|
90
|
+
query: query || {},
|
|
91
|
+
};
|
|
92
|
+
await router.replace(toParams);
|
|
93
|
+
},
|
|
94
|
+
/**
|
|
95
|
+
* @zh_CN 添加标签页
|
|
96
|
+
* @param routeTab
|
|
97
|
+
*/
|
|
98
|
+
addTab(routeTab: TabDefinition) {
|
|
99
|
+
const tab = cloneTab(routeTab);
|
|
100
|
+
if (!isTabShown(tab)) {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const tabIndex = this.tabs.findIndex((tab) => {
|
|
105
|
+
return getTabPath(tab) === getTabPath(routeTab);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
if (tabIndex === -1) {
|
|
109
|
+
// 获取动态路由打开数,超过 0 即代表需要控制打开数
|
|
110
|
+
const maxNumOfOpenTab = (routeTab?.meta?.maxNumOfOpenTab ??
|
|
111
|
+
-1) as number;
|
|
112
|
+
// 如果动态路由层级大于 0 了,那么就要限制该路由的打开数限制了
|
|
113
|
+
// 获取到已经打开的动态路由数, 判断是否大于某一个值
|
|
114
|
+
if (
|
|
115
|
+
maxNumOfOpenTab > 0 &&
|
|
116
|
+
this.tabs.filter((tab) => tab.name === routeTab.name).length >=
|
|
117
|
+
maxNumOfOpenTab
|
|
118
|
+
) {
|
|
119
|
+
// 关闭第一个
|
|
120
|
+
const index = this.tabs.findIndex(
|
|
121
|
+
(item) => item.name === routeTab.name,
|
|
122
|
+
);
|
|
123
|
+
index !== -1 && this.tabs.splice(index, 1);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
this.tabs.push(tab);
|
|
127
|
+
} else {
|
|
128
|
+
// 页面已经存在,不重复添加选项卡,只更新选项卡参数
|
|
129
|
+
const currentTab = toRaw(this.tabs)[tabIndex];
|
|
130
|
+
const mergedTab = {
|
|
131
|
+
...currentTab,
|
|
132
|
+
...tab,
|
|
133
|
+
meta: { ...currentTab?.meta, ...tab.meta },
|
|
134
|
+
};
|
|
135
|
+
if (currentTab) {
|
|
136
|
+
const curMeta = currentTab.meta;
|
|
137
|
+
if (Reflect.has(curMeta, 'affixTab')) {
|
|
138
|
+
mergedTab.meta.affixTab = curMeta.affixTab;
|
|
139
|
+
}
|
|
140
|
+
if (Reflect.has(curMeta, 'newTabTitle')) {
|
|
141
|
+
mergedTab.meta.newTabTitle = curMeta.newTabTitle;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
this.tabs.splice(tabIndex, 1, mergedTab);
|
|
146
|
+
}
|
|
147
|
+
this.updateCacheTabs();
|
|
148
|
+
},
|
|
149
|
+
/**
|
|
150
|
+
* @zh_CN 关闭所有标签页
|
|
151
|
+
*/
|
|
152
|
+
async closeAllTabs(router: Router) {
|
|
153
|
+
const newTabs = this.tabs.filter((tab) => isAffixTab(tab));
|
|
154
|
+
this.tabs = newTabs.length > 0 ? newTabs : [...this.tabs].splice(0, 1);
|
|
155
|
+
await this._goToDefaultTab(router);
|
|
156
|
+
this.updateCacheTabs();
|
|
157
|
+
},
|
|
158
|
+
/**
|
|
159
|
+
* @zh_CN 关闭左侧标签页
|
|
160
|
+
* @param tab
|
|
161
|
+
*/
|
|
162
|
+
async closeLeftTabs(tab: TabDefinition) {
|
|
163
|
+
const index = this.tabs.findIndex(
|
|
164
|
+
(item) => getTabPath(item) === getTabPath(tab),
|
|
165
|
+
);
|
|
166
|
+
|
|
167
|
+
if (index < 1) {
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
const leftTabs = this.tabs.slice(0, index);
|
|
172
|
+
const paths: string[] = [];
|
|
173
|
+
|
|
174
|
+
for (const item of leftTabs) {
|
|
175
|
+
if (!isAffixTab(item)) {
|
|
176
|
+
paths.push(getTabPath(item));
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
await this._bulkCloseByPaths(paths);
|
|
180
|
+
},
|
|
181
|
+
/**
|
|
182
|
+
* @zh_CN 关闭其他标签页
|
|
183
|
+
* @param tab
|
|
184
|
+
*/
|
|
185
|
+
async closeOtherTabs(tab: TabDefinition) {
|
|
186
|
+
const closePaths = this.tabs.map((item) => getTabPath(item));
|
|
187
|
+
|
|
188
|
+
const paths: string[] = [];
|
|
189
|
+
|
|
190
|
+
for (const path of closePaths) {
|
|
191
|
+
if (path !== tab.fullPath) {
|
|
192
|
+
const closeTab = this.tabs.find((item) => getTabPath(item) === path);
|
|
193
|
+
if (!closeTab) {
|
|
194
|
+
continue;
|
|
195
|
+
}
|
|
196
|
+
if (!isAffixTab(closeTab)) {
|
|
197
|
+
paths.push(getTabPath(closeTab));
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
await this._bulkCloseByPaths(paths);
|
|
202
|
+
},
|
|
203
|
+
/**
|
|
204
|
+
* @zh_CN 关闭右侧标签页
|
|
205
|
+
* @param tab
|
|
206
|
+
*/
|
|
207
|
+
async closeRightTabs(tab: TabDefinition) {
|
|
208
|
+
const index = this.tabs.findIndex(
|
|
209
|
+
(item) => getTabPath(item) === getTabPath(tab),
|
|
210
|
+
);
|
|
211
|
+
|
|
212
|
+
if (index !== -1 && index < this.tabs.length - 1) {
|
|
213
|
+
const rightTabs = this.tabs.slice(index + 1);
|
|
214
|
+
|
|
215
|
+
const paths: string[] = [];
|
|
216
|
+
for (const item of rightTabs) {
|
|
217
|
+
if (!isAffixTab(item)) {
|
|
218
|
+
paths.push(getTabPath(item));
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
await this._bulkCloseByPaths(paths);
|
|
222
|
+
}
|
|
223
|
+
},
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* @zh_CN 关闭标签页
|
|
227
|
+
* @param tab
|
|
228
|
+
* @param router
|
|
229
|
+
*/
|
|
230
|
+
async closeTab(tab: TabDefinition, router: Router) {
|
|
231
|
+
const { currentRoute } = router;
|
|
232
|
+
|
|
233
|
+
// 关闭不是激活选项卡
|
|
234
|
+
if (getTabPath(currentRoute.value) !== getTabPath(tab)) {
|
|
235
|
+
this._close(tab);
|
|
236
|
+
this.updateCacheTabs();
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
const index = this.getTabs.findIndex(
|
|
240
|
+
(item) => getTabPath(item) === getTabPath(currentRoute.value),
|
|
241
|
+
);
|
|
242
|
+
|
|
243
|
+
const before = this.getTabs[index - 1];
|
|
244
|
+
const after = this.getTabs[index + 1];
|
|
245
|
+
|
|
246
|
+
// 下一个tab存在,跳转到下一个
|
|
247
|
+
if (after) {
|
|
248
|
+
this._close(tab);
|
|
249
|
+
await this._goToTab(after, router);
|
|
250
|
+
// 上一个tab存在,跳转到上一个
|
|
251
|
+
} else if (before) {
|
|
252
|
+
this._close(tab);
|
|
253
|
+
await this._goToTab(before, router);
|
|
254
|
+
} else {
|
|
255
|
+
console.error('Failed to close the tab; only one tab remains open.');
|
|
256
|
+
}
|
|
257
|
+
},
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* @zh_CN 通过key关闭标签页
|
|
261
|
+
* @param key
|
|
262
|
+
* @param router
|
|
263
|
+
*/
|
|
264
|
+
async closeTabByKey(key: string, router: Router) {
|
|
265
|
+
const originKey = decodeURIComponent(key);
|
|
266
|
+
const index = this.tabs.findIndex(
|
|
267
|
+
(item) => getTabPath(item) === originKey,
|
|
268
|
+
);
|
|
269
|
+
if (index === -1) {
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
const tab = this.tabs[index];
|
|
274
|
+
if (tab) {
|
|
275
|
+
await this.closeTab(tab, router);
|
|
276
|
+
}
|
|
277
|
+
},
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* 根据路径获取标签页
|
|
281
|
+
* @param path
|
|
282
|
+
*/
|
|
283
|
+
getTabByPath(path: string) {
|
|
284
|
+
return this.getTabs.find(
|
|
285
|
+
(item) => getTabPath(item) === path,
|
|
286
|
+
) as TabDefinition;
|
|
287
|
+
},
|
|
288
|
+
/**
|
|
289
|
+
* @zh_CN 新窗口打开标签页
|
|
290
|
+
* @param tab
|
|
291
|
+
*/
|
|
292
|
+
async openTabInNewWindow(tab: TabDefinition) {
|
|
293
|
+
openRouteInNewWindow(tab.fullPath || tab.path);
|
|
294
|
+
},
|
|
295
|
+
|
|
296
|
+
/**
|
|
297
|
+
* @zh_CN 固定标签页
|
|
298
|
+
* @param tab
|
|
299
|
+
*/
|
|
300
|
+
async pinTab(tab: TabDefinition) {
|
|
301
|
+
const index = this.tabs.findIndex(
|
|
302
|
+
(item) => getTabPath(item) === getTabPath(tab),
|
|
303
|
+
);
|
|
304
|
+
if (index !== -1) {
|
|
305
|
+
const oldTab = this.tabs[index];
|
|
306
|
+
tab.meta.affixTab = true;
|
|
307
|
+
tab.meta.title = oldTab?.meta?.title as string;
|
|
308
|
+
// this.addTab(tab);
|
|
309
|
+
this.tabs.splice(index, 1, tab);
|
|
310
|
+
}
|
|
311
|
+
// 过滤固定tabs,后面更改affixTabOrder的值的话可能会有问题,目前行464排序affixTabs没有设置值
|
|
312
|
+
const affixTabs = this.tabs.filter((tab) => isAffixTab(tab));
|
|
313
|
+
// 获得固定tabs的index
|
|
314
|
+
const newIndex = affixTabs.findIndex(
|
|
315
|
+
(item) => getTabPath(item) === getTabPath(tab),
|
|
316
|
+
);
|
|
317
|
+
// 交换位置重新排序
|
|
318
|
+
await this.sortTabs(index, newIndex);
|
|
319
|
+
},
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* 刷新标签页
|
|
323
|
+
*/
|
|
324
|
+
async refresh(router: Router) {
|
|
325
|
+
const { currentRoute } = router;
|
|
326
|
+
const { name } = currentRoute.value;
|
|
327
|
+
|
|
328
|
+
this.excludeCachedTabs.add(name as string);
|
|
329
|
+
this.renderRouteView = false;
|
|
330
|
+
startProgress();
|
|
331
|
+
|
|
332
|
+
await new Promise((resolve) => setTimeout(resolve, 200));
|
|
333
|
+
|
|
334
|
+
this.excludeCachedTabs.delete(name as string);
|
|
335
|
+
this.renderRouteView = true;
|
|
336
|
+
stopProgress();
|
|
337
|
+
},
|
|
338
|
+
|
|
339
|
+
/**
|
|
340
|
+
* @zh_CN 重置标签页标题
|
|
341
|
+
*/
|
|
342
|
+
async resetTabTitle(tab: TabDefinition) {
|
|
343
|
+
if (tab?.meta?.newTabTitle) {
|
|
344
|
+
return;
|
|
345
|
+
}
|
|
346
|
+
const findTab = this.tabs.find(
|
|
347
|
+
(item) => getTabPath(item) === getTabPath(tab),
|
|
348
|
+
);
|
|
349
|
+
if (findTab) {
|
|
350
|
+
findTab.meta.newTabTitle = undefined;
|
|
351
|
+
await this.updateCacheTabs();
|
|
352
|
+
}
|
|
353
|
+
},
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* 设置固定标签页
|
|
357
|
+
* @param tabs
|
|
358
|
+
*/
|
|
359
|
+
setAffixTabs(tabs: RouteRecordNormalized[]) {
|
|
360
|
+
for (const tab of tabs) {
|
|
361
|
+
tab.meta.affixTab = true;
|
|
362
|
+
this.addTab(routeToTab(tab));
|
|
363
|
+
}
|
|
364
|
+
},
|
|
365
|
+
|
|
366
|
+
/**
|
|
367
|
+
* @zh_CN 设置标签页标题
|
|
368
|
+
* @param tab
|
|
369
|
+
* @param title
|
|
370
|
+
*/
|
|
371
|
+
async setTabTitle(tab: TabDefinition, title: string) {
|
|
372
|
+
const findTab = this.tabs.find(
|
|
373
|
+
(item) => getTabPath(item) === getTabPath(tab),
|
|
374
|
+
);
|
|
375
|
+
|
|
376
|
+
if (findTab) {
|
|
377
|
+
findTab.meta.newTabTitle = title;
|
|
378
|
+
|
|
379
|
+
await this.updateCacheTabs();
|
|
380
|
+
}
|
|
381
|
+
},
|
|
382
|
+
|
|
383
|
+
setUpdateTime() {
|
|
384
|
+
this.updatedAt = Date.now();
|
|
385
|
+
},
|
|
386
|
+
/**
|
|
387
|
+
* @zh_CN 设置标签页顺序
|
|
388
|
+
* @param oldIndex
|
|
389
|
+
* @param newIndex
|
|
390
|
+
*/
|
|
391
|
+
async sortTabs(oldIndex: number, newIndex: number) {
|
|
392
|
+
const currentTab = this.tabs[oldIndex];
|
|
393
|
+
if (!currentTab) {
|
|
394
|
+
return;
|
|
395
|
+
}
|
|
396
|
+
this.tabs.splice(oldIndex, 1);
|
|
397
|
+
this.tabs.splice(newIndex, 0, currentTab);
|
|
398
|
+
this.dragEndIndex = this.dragEndIndex + 1;
|
|
399
|
+
},
|
|
400
|
+
/**
|
|
401
|
+
* @zh_CN 切换固定标签页
|
|
402
|
+
* @param tab
|
|
403
|
+
*/
|
|
404
|
+
async toggleTabPin(tab: TabDefinition) {
|
|
405
|
+
const affixTab = tab?.meta?.affixTab ?? false;
|
|
406
|
+
|
|
407
|
+
await (affixTab ? this.unpinTab(tab) : this.pinTab(tab));
|
|
408
|
+
},
|
|
409
|
+
|
|
410
|
+
/**
|
|
411
|
+
* @zh_CN 取消固定标签页
|
|
412
|
+
* @param tab
|
|
413
|
+
*/
|
|
414
|
+
async unpinTab(tab: TabDefinition) {
|
|
415
|
+
const index = this.tabs.findIndex(
|
|
416
|
+
(item) => getTabPath(item) === getTabPath(tab),
|
|
417
|
+
);
|
|
418
|
+
|
|
419
|
+
if (index !== -1) {
|
|
420
|
+
const oldTab = this.tabs[index];
|
|
421
|
+
tab.meta.affixTab = false;
|
|
422
|
+
tab.meta.title = oldTab?.meta?.title as string;
|
|
423
|
+
// this.addTab(tab);
|
|
424
|
+
this.tabs.splice(index, 1, tab);
|
|
425
|
+
}
|
|
426
|
+
// 过滤固定tabs,后面更改affixTabOrder的值的话可能会有问题,目前行464排序affixTabs没有设置值
|
|
427
|
+
const affixTabs = this.tabs.filter((tab) => isAffixTab(tab));
|
|
428
|
+
// 获得固定tabs的index,使用固定tabs的下一个位置也就是活动tabs的第一个位置
|
|
429
|
+
const newIndex = affixTabs.length;
|
|
430
|
+
// 交换位置重新排序
|
|
431
|
+
await this.sortTabs(index, newIndex);
|
|
432
|
+
},
|
|
433
|
+
|
|
434
|
+
/**
|
|
435
|
+
* 根据当前打开的选项卡更新缓存
|
|
436
|
+
*/
|
|
437
|
+
async updateCacheTabs() {
|
|
438
|
+
const cacheMap = new Set<string>();
|
|
439
|
+
|
|
440
|
+
for (const tab of this.tabs) {
|
|
441
|
+
// 跳过不需要持久化的标签页
|
|
442
|
+
const keepAlive = tab.meta?.keepAlive;
|
|
443
|
+
if (!keepAlive) {
|
|
444
|
+
continue;
|
|
445
|
+
}
|
|
446
|
+
(tab.matched || []).forEach((t, i) => {
|
|
447
|
+
if (i > 0) {
|
|
448
|
+
cacheMap.add(t.name as string);
|
|
449
|
+
}
|
|
450
|
+
});
|
|
451
|
+
|
|
452
|
+
const name = tab.name as string;
|
|
453
|
+
cacheMap.add(name);
|
|
454
|
+
}
|
|
455
|
+
this.cachedTabs = cacheMap;
|
|
456
|
+
},
|
|
457
|
+
},
|
|
458
|
+
getters: {
|
|
459
|
+
affixTabs(): TabDefinition[] {
|
|
460
|
+
const affixTabs = this.tabs.filter((tab) => isAffixTab(tab));
|
|
461
|
+
|
|
462
|
+
return affixTabs.sort((a, b) => {
|
|
463
|
+
const orderA = (a.meta?.affixTabOrder ?? 0) as number;
|
|
464
|
+
const orderB = (b.meta?.affixTabOrder ?? 0) as number;
|
|
465
|
+
return orderA - orderB;
|
|
466
|
+
});
|
|
467
|
+
},
|
|
468
|
+
getCachedTabs(): string[] {
|
|
469
|
+
return [...this.cachedTabs];
|
|
470
|
+
},
|
|
471
|
+
getExcludeCachedTabs(): string[] {
|
|
472
|
+
return [...this.excludeCachedTabs];
|
|
473
|
+
},
|
|
474
|
+
getTabs(): TabDefinition[] {
|
|
475
|
+
const normalTabs = this.tabs.filter((tab) => !isAffixTab(tab));
|
|
476
|
+
return [...this.affixTabs, ...normalTabs].filter(Boolean);
|
|
477
|
+
},
|
|
478
|
+
},
|
|
479
|
+
persist: [
|
|
480
|
+
// tabs不需要保存在localStorage
|
|
481
|
+
{
|
|
482
|
+
pick: ['tabs'],
|
|
483
|
+
storage: sessionStorage,
|
|
484
|
+
},
|
|
485
|
+
],
|
|
486
|
+
state: (): TabbarState => ({
|
|
487
|
+
cachedTabs: new Set(),
|
|
488
|
+
dragEndIndex: 0,
|
|
489
|
+
excludeCachedTabs: new Set(),
|
|
490
|
+
renderRouteView: true,
|
|
491
|
+
tabs: [],
|
|
492
|
+
updatedAt: Date.now(),
|
|
493
|
+
}),
|
|
494
|
+
});
|
|
495
|
+
|
|
496
|
+
// 解决热更新问题
|
|
497
|
+
const hot = import.meta.hot;
|
|
498
|
+
if (hot) {
|
|
499
|
+
hot.accept(acceptHMRUpdate(useTabbarStore, hot));
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
/**
|
|
503
|
+
* @zh_CN 克隆路由,防止路由被修改
|
|
504
|
+
* @param route
|
|
505
|
+
*/
|
|
506
|
+
function cloneTab(route: TabDefinition): TabDefinition {
|
|
507
|
+
if (!route) {
|
|
508
|
+
return route;
|
|
509
|
+
}
|
|
510
|
+
const { matched, meta, ...opt } = route;
|
|
511
|
+
return {
|
|
512
|
+
...opt,
|
|
513
|
+
matched: (matched
|
|
514
|
+
? matched.map((item) => ({
|
|
515
|
+
meta: item.meta,
|
|
516
|
+
name: item.name,
|
|
517
|
+
path: item.path,
|
|
518
|
+
}))
|
|
519
|
+
: undefined) as RouteRecordNormalized[],
|
|
520
|
+
meta: {
|
|
521
|
+
...meta,
|
|
522
|
+
newTabTitle: meta.newTabTitle,
|
|
523
|
+
},
|
|
524
|
+
};
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
/**
|
|
528
|
+
* @zh_CN 是否是固定标签页
|
|
529
|
+
* @param tab
|
|
530
|
+
*/
|
|
531
|
+
function isAffixTab(tab: TabDefinition) {
|
|
532
|
+
return tab?.meta?.affixTab ?? false;
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
/**
|
|
536
|
+
* @zh_CN 是否显示标签
|
|
537
|
+
* @param tab
|
|
538
|
+
*/
|
|
539
|
+
function isTabShown(tab: TabDefinition) {
|
|
540
|
+
const matched = tab?.matched ?? [];
|
|
541
|
+
return !tab.meta.hideInTab && matched.every((item) => !item.meta.hideInTab);
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
/**
|
|
545
|
+
* @zh_CN 获取标签页路径
|
|
546
|
+
* @param tab
|
|
547
|
+
*/
|
|
548
|
+
function getTabPath(tab: RouteRecordNormalized | TabDefinition) {
|
|
549
|
+
return decodeURIComponent((tab as TabDefinition).fullPath || tab.path);
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
function routeToTab(route: RouteRecordNormalized) {
|
|
553
|
+
return {
|
|
554
|
+
meta: route.meta,
|
|
555
|
+
name: route.name,
|
|
556
|
+
path: route.path,
|
|
557
|
+
} as TabDefinition;
|
|
558
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { createPinia, setActivePinia } from 'pinia';
|
|
2
|
+
import { beforeEach, describe, expect, it } from 'vitest';
|
|
3
|
+
|
|
4
|
+
import { useUserStore } from './user';
|
|
5
|
+
|
|
6
|
+
describe('useUserStore', () => {
|
|
7
|
+
beforeEach(() => {
|
|
8
|
+
setActivePinia(createPinia());
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it('returns correct userInfo', () => {
|
|
12
|
+
const store = useUserStore();
|
|
13
|
+
const userInfo: any = { name: 'Jane Doe', roles: [{ value: 'user' }] };
|
|
14
|
+
store.setUserInfo(userInfo);
|
|
15
|
+
expect(store.userInfo).toEqual(userInfo);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
// 测试重置用户信息时的行为
|
|
19
|
+
it('clears userInfo and userRoles when setting null userInfo', () => {
|
|
20
|
+
const store = useUserStore();
|
|
21
|
+
store.setUserInfo({
|
|
22
|
+
roles: [{ roleName: 'User', value: 'user' }],
|
|
23
|
+
} as any);
|
|
24
|
+
expect(store.userInfo).not.toBeNull();
|
|
25
|
+
expect(store.userRoles.length).toBeGreaterThan(0);
|
|
26
|
+
|
|
27
|
+
store.setUserInfo(null as any);
|
|
28
|
+
expect(store.userInfo).toBeNull();
|
|
29
|
+
expect(store.userRoles).toEqual([]);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
// 测试在没有用户角色时返回空数组
|
|
33
|
+
it('returns an empty array for userRoles if not set', () => {
|
|
34
|
+
const store = useUserStore();
|
|
35
|
+
expect(store.userRoles).toEqual([]);
|
|
36
|
+
});
|
|
37
|
+
});
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { computed, ref } from 'vue';
|
|
2
|
+
|
|
3
|
+
import { acceptHMRUpdate, defineStore } from 'pinia';
|
|
4
|
+
|
|
5
|
+
interface BasicUserInfo {
|
|
6
|
+
[key: string]: any;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* 头像
|
|
10
|
+
*/
|
|
11
|
+
avatar: string;
|
|
12
|
+
/**
|
|
13
|
+
* 用户id(后端 uint64 → proto3 JSON 为字符串)
|
|
14
|
+
*/
|
|
15
|
+
id: string;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* 用户昵称
|
|
19
|
+
*/
|
|
20
|
+
nickname: string;
|
|
21
|
+
/**
|
|
22
|
+
* 用户实名
|
|
23
|
+
*/
|
|
24
|
+
realname: string;
|
|
25
|
+
/**
|
|
26
|
+
* 用户角色
|
|
27
|
+
*/
|
|
28
|
+
roles?: string[];
|
|
29
|
+
/**
|
|
30
|
+
* 租户id(后端 uint64 → proto3 JSON 为字符串)
|
|
31
|
+
*/
|
|
32
|
+
tenantId: string;
|
|
33
|
+
/**
|
|
34
|
+
* 用户名
|
|
35
|
+
*/
|
|
36
|
+
username: string;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export type AccessState = {
|
|
40
|
+
userInfo: BasicUserInfo | null;
|
|
41
|
+
userRoles: string[];
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* @zh_CN 用户信息相关
|
|
46
|
+
*/
|
|
47
|
+
export const useUserStore = defineStore('core-user', () => {
|
|
48
|
+
const userInfo = ref<AccessState['userInfo']>(null);
|
|
49
|
+
const userRoles = ref<AccessState['userRoles']>([]);
|
|
50
|
+
|
|
51
|
+
function setUserInfo(info: BasicUserInfo | null) {
|
|
52
|
+
userInfo.value = info;
|
|
53
|
+
setUserRoles(info?.roles ?? []);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function setUserRoles(roles: string[]) {
|
|
57
|
+
userRoles.value = roles;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const tenantId = computed(() => userInfo.value?.tenantId ?? null);
|
|
61
|
+
const isLoggedIn = computed(() => userInfo.value !== null);
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* @zh_CN 判断当前用户是否为租户用户
|
|
65
|
+
*/
|
|
66
|
+
function isTenantUser(): boolean {
|
|
67
|
+
return (
|
|
68
|
+
tenantId.value !== null &&
|
|
69
|
+
tenantId.value !== undefined &&
|
|
70
|
+
tenantId.value !== ''
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function $reset() {}
|
|
75
|
+
|
|
76
|
+
return {
|
|
77
|
+
$reset,
|
|
78
|
+
isLoggedIn,
|
|
79
|
+
isTenantUser,
|
|
80
|
+
setUserInfo,
|
|
81
|
+
setUserRoles,
|
|
82
|
+
tenantId,
|
|
83
|
+
userInfo,
|
|
84
|
+
userRoles,
|
|
85
|
+
};
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
// 解决热更新问题
|
|
89
|
+
const hot = import.meta.hot;
|
|
90
|
+
if (hot) {
|
|
91
|
+
hot.accept(acceptHMRUpdate(useUserStore, hot));
|
|
92
|
+
}
|