@kevairy/template 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/README.md +14 -0
- package/package.json +37 -0
- package/template/.env +22 -0
- package/template/.env.development +13 -0
- package/template/.env.production +10 -0
- package/template/.prettierignore +3 -0
- package/template/.prettierrc +20 -0
- package/template/.stylelintignore +9 -0
- package/template/.stylelintrc.cjs +84 -0
- package/template/LICENSE +21 -0
- package/template/README.md +22 -0
- package/template/_gitignore +19 -0
- package/template/eslint-auto-import.json +324 -0
- package/template/eslint.config.mjs +83 -0
- package/template/index.html +25 -0
- package/template/package.json +79 -0
- package/template/playwright.config.ts +25 -0
- package/template/public/favicon.ico +0 -0
- package/template/src/App.vue +39 -0
- package/template/src/adapters/auth/index.ts +9 -0
- package/template/src/adapters/auth/mock.ts +10 -0
- package/template/src/adapters/auth/types.ts +11 -0
- package/template/src/adapters/navigation/index.ts +13 -0
- package/template/src/adapters/navigation/types.ts +6 -0
- package/template/src/api/auth.ts +23 -0
- package/template/src/assets/images/avatar/avatar.webp +0 -0
- package/template/src/assets/images/avatar/avatar1.webp +0 -0
- package/template/src/assets/images/avatar/avatar10.webp +0 -0
- package/template/src/assets/images/avatar/avatar2.webp +0 -0
- package/template/src/assets/images/avatar/avatar3.webp +0 -0
- package/template/src/assets/images/avatar/avatar4.webp +0 -0
- package/template/src/assets/images/avatar/avatar5.webp +0 -0
- package/template/src/assets/images/avatar/avatar6.webp +0 -0
- package/template/src/assets/images/avatar/avatar7.webp +0 -0
- package/template/src/assets/images/avatar/avatar8.webp +0 -0
- package/template/src/assets/images/avatar/avatar9.webp +0 -0
- package/template/src/assets/images/ceremony/hb.png +0 -0
- package/template/src/assets/images/ceremony/sd.png +0 -0
- package/template/src/assets/images/ceremony/xc.png +0 -0
- package/template/src/assets/images/ceremony/yd.png +0 -0
- package/template/src/assets/images/common/logo.webp +0 -0
- package/template/src/assets/images/draw/draw1.png +0 -0
- package/template/src/assets/images/favicon.ico +0 -0
- package/template/src/assets/images/lock/bg_dark.webp +0 -0
- package/template/src/assets/images/lock/bg_light.webp +0 -0
- package/template/src/assets/images/login/kylin-hero-source.png +0 -0
- package/template/src/assets/images/login/lf_icon2.webp +0 -0
- package/template/src/assets/images/settings/menu_layouts/dual_column.png +0 -0
- package/template/src/assets/images/settings/menu_layouts/horizontal.png +0 -0
- package/template/src/assets/images/settings/menu_layouts/mixed.png +0 -0
- package/template/src/assets/images/settings/menu_layouts/vertical.png +0 -0
- package/template/src/assets/images/settings/menu_styles/dark.png +0 -0
- package/template/src/assets/images/settings/menu_styles/design.png +0 -0
- package/template/src/assets/images/settings/menu_styles/light.png +0 -0
- package/template/src/assets/images/settings/theme_styles/dark.png +0 -0
- package/template/src/assets/images/settings/theme_styles/light.png +0 -0
- package/template/src/assets/images/settings/theme_styles/system.png +0 -0
- package/template/src/assets/images/svg/403.svg +1 -0
- package/template/src/assets/images/svg/404.svg +1 -0
- package/template/src/assets/images/svg/500.svg +5 -0
- package/template/src/assets/images/svg/login_icon.svg +1 -0
- package/template/src/assets/images/user/avatar.webp +0 -0
- package/template/src/assets/images/user/bg.webp +0 -0
- package/template/src/assets/styles/core/app.scss +227 -0
- package/template/src/assets/styles/core/dark.scss +93 -0
- package/template/src/assets/styles/core/el-dark.scss +2 -0
- package/template/src/assets/styles/core/el-light.scss +34 -0
- package/template/src/assets/styles/core/el-ui.scss +519 -0
- package/template/src/assets/styles/core/md.scss +1036 -0
- package/template/src/assets/styles/core/mixin.scss +157 -0
- package/template/src/assets/styles/core/reset.scss +41 -0
- package/template/src/assets/styles/core/router-transition.scss +104 -0
- package/template/src/assets/styles/core/tailwind.css +219 -0
- package/template/src/assets/styles/core/theme-animation.scss +63 -0
- package/template/src/assets/styles/core/theme-change.scss +11 -0
- package/template/src/assets/styles/custom/one-dark-pro.scss +98 -0
- package/template/src/assets/styles/index.scss +23 -0
- package/template/src/assets/svg/loading.ts +32 -0
- package/template/src/bootstrap/initializeApp.ts +30 -0
- package/template/src/components/core/banners/art-basic-banner/index.vue +343 -0
- package/template/src/components/core/banners/art-card-banner/index.vue +114 -0
- package/template/src/components/core/base/art-back-to-top/index.vue +40 -0
- package/template/src/components/core/base/art-logo/index.vue +34 -0
- package/template/src/components/core/base/art-svg-icon/index.vue +24 -0
- package/template/src/components/core/cards/art-bar-chart-card/index.vue +103 -0
- package/template/src/components/core/cards/art-data-list-card/index.vue +74 -0
- package/template/src/components/core/cards/art-donut-chart-card/index.vue +124 -0
- package/template/src/components/core/cards/art-image-card/index.vue +89 -0
- package/template/src/components/core/cards/art-line-chart-card/index.vue +126 -0
- package/template/src/components/core/cards/art-progress-card/index.vue +86 -0
- package/template/src/components/core/cards/art-stats-card/index.vue +67 -0
- package/template/src/components/core/cards/art-timeline-list-card/index.vue +69 -0
- package/template/src/components/core/charts/art-bar-chart/index.vue +203 -0
- package/template/src/components/core/charts/art-dual-bar-compare-chart/index.vue +195 -0
- package/template/src/components/core/charts/art-h-bar-chart/index.vue +208 -0
- package/template/src/components/core/charts/art-k-line-chart/index.vue +152 -0
- package/template/src/components/core/charts/art-line-chart/index.vue +371 -0
- package/template/src/components/core/charts/art-radar-chart/index.vue +105 -0
- package/template/src/components/core/charts/art-ring-chart/index.vue +133 -0
- package/template/src/components/core/charts/art-scatter-chart/index.vue +115 -0
- package/template/src/components/core/feedback/art-page-loading/index.vue +281 -0
- package/template/src/components/core/forms/art-button-more/index.vue +71 -0
- package/template/src/components/core/forms/art-button-table/index.vue +59 -0
- package/template/src/components/core/forms/art-drag-verify/index.vue +430 -0
- package/template/src/components/core/forms/art-excel-export/index.vue +390 -0
- package/template/src/components/core/forms/art-excel-import/index.vue +62 -0
- package/template/src/components/core/forms/art-form/index.vue +507 -0
- package/template/src/components/core/forms/art-wang-editor/index.vue +261 -0
- package/template/src/components/core/forms/art-wang-editor/style.scss +273 -0
- package/template/src/components/core/layouts/art-breadcrumb/index.vue +142 -0
- package/template/src/components/core/layouts/art-chat-window/index.vue +262 -0
- package/template/src/components/core/layouts/art-fast-enter/index.vue +113 -0
- package/template/src/components/core/layouts/art-fireworks-effect/index.vue +633 -0
- package/template/src/components/core/layouts/art-global-component/index.vue +14 -0
- package/template/src/components/core/layouts/art-global-search/index.vue +431 -0
- package/template/src/components/core/layouts/art-header-bar/index.vue +485 -0
- package/template/src/components/core/layouts/art-header-bar/widget/ArtUserMenu.vue +118 -0
- package/template/src/components/core/layouts/art-menus/art-horizontal-menu/index.vue +110 -0
- package/template/src/components/core/layouts/art-menus/art-horizontal-menu/widget/HorizontalSubmenu.vue +106 -0
- package/template/src/components/core/layouts/art-menus/art-mixed-menu/index.vue +279 -0
- package/template/src/components/core/layouts/art-menus/art-sidebar-menu/index.vue +354 -0
- package/template/src/components/core/layouts/art-menus/art-sidebar-menu/style.scss +251 -0
- package/template/src/components/core/layouts/art-menus/art-sidebar-menu/theme.scss +258 -0
- package/template/src/components/core/layouts/art-menus/art-sidebar-menu/widget/SidebarSubmenu.vue +190 -0
- package/template/src/components/core/layouts/art-notification/index.vue +456 -0
- package/template/src/components/core/layouts/art-page-content/index.vue +137 -0
- package/template/src/components/core/layouts/art-settings-panel/composables/useSettingsConfig.ts +248 -0
- package/template/src/components/core/layouts/art-settings-panel/composables/useSettingsHandlers.ts +167 -0
- package/template/src/components/core/layouts/art-settings-panel/composables/useSettingsPanel.ts +233 -0
- package/template/src/components/core/layouts/art-settings-panel/composables/useSettingsState.ts +37 -0
- package/template/src/components/core/layouts/art-settings-panel/index.vue +72 -0
- package/template/src/components/core/layouts/art-settings-panel/style.scss +92 -0
- package/template/src/components/core/layouts/art-settings-panel/widget/BasicSettings.vue +77 -0
- package/template/src/components/core/layouts/art-settings-panel/widget/BoxStyleSettings.vue +38 -0
- package/template/src/components/core/layouts/art-settings-panel/widget/ColorSettings.vue +35 -0
- package/template/src/components/core/layouts/art-settings-panel/widget/ContainerSettings.vue +33 -0
- package/template/src/components/core/layouts/art-settings-panel/widget/MenuLayoutSettings.vue +31 -0
- package/template/src/components/core/layouts/art-settings-panel/widget/MenuStyleSettings.vue +44 -0
- package/template/src/components/core/layouts/art-settings-panel/widget/SectionTitle.vue +17 -0
- package/template/src/components/core/layouts/art-settings-panel/widget/SettingActions.vue +236 -0
- package/template/src/components/core/layouts/art-settings-panel/widget/SettingDrawer.vue +51 -0
- package/template/src/components/core/layouts/art-settings-panel/widget/SettingHeader.vue +18 -0
- package/template/src/components/core/layouts/art-settings-panel/widget/SettingItem.vue +101 -0
- package/template/src/components/core/layouts/art-settings-panel/widget/ThemeSettings.vue +28 -0
- package/template/src/components/core/layouts/art-work-tab/index.vue +584 -0
- package/template/src/components/core/media/art-cutter-img/index.vue +350 -0
- package/template/src/components/core/media/art-video-player/index.vue +111 -0
- package/template/src/components/core/others/art-menu-right/index.vue +415 -0
- package/template/src/components/core/others/art-watermark/index.vue +64 -0
- package/template/src/components/core/text-effect/art-count-to/index.vue +310 -0
- package/template/src/components/core/text-effect/art-festival-text-scroll/index.vue +32 -0
- package/template/src/components/core/text-effect/art-text-scroll/index.vue +285 -0
- package/template/src/components/core/theme/theme-svg/index.vue +100 -0
- package/template/src/components/core/views/exception/ArtException.vue +55 -0
- package/template/src/components/core/views/login/AuthTopBar.vue +149 -0
- package/template/src/components/core/views/login/LoginLeftView.vue +602 -0
- package/template/src/components/core/views/result/ArtResultPage.vue +43 -0
- package/template/src/components/core/widget/art-icon-button/index.vue +23 -0
- package/template/src/config/assets/images.ts +61 -0
- package/template/src/config/index.ts +170 -0
- package/template/src/config/modules/component.ts +98 -0
- package/template/src/config/modules/fastEnter.ts +16 -0
- package/template/src/config/modules/festival.ts +51 -0
- package/template/src/config/modules/headerBar.ts +64 -0
- package/template/src/config/setting.ts +109 -0
- package/template/src/directives/core/auth.ts +66 -0
- package/template/src/directives/core/highlight-loader.ts +37 -0
- package/template/src/directives/core/highlight.ts +253 -0
- package/template/src/directives/core/ripple.ts +116 -0
- package/template/src/directives/core/roles.ts +87 -0
- package/template/src/directives/index.ts +14 -0
- package/template/src/enums/appEnum.ts +81 -0
- package/template/src/enums/formEnum.ts +17 -0
- package/template/src/env.d.ts +32 -0
- package/template/src/hooks/core/useAppMode.ts +45 -0
- package/template/src/hooks/core/useAuth.ts +74 -0
- package/template/src/hooks/core/useCeremony.ts +184 -0
- package/template/src/hooks/core/useChart.ts +745 -0
- package/template/src/hooks/core/useCommon.ts +87 -0
- package/template/src/hooks/core/useFastEnter.ts +55 -0
- package/template/src/hooks/core/useHeaderBar.ts +201 -0
- package/template/src/hooks/core/useLayoutHeight.ts +148 -0
- package/template/src/hooks/core/useTableColumns.ts +313 -0
- package/template/src/hooks/core/useTheme.ts +174 -0
- package/template/src/hooks/index.ts +29 -0
- package/template/src/locales/index.ts +123 -0
- package/template/src/locales/langs/en.json +283 -0
- package/template/src/locales/langs/zh.json +283 -0
- package/template/src/main.ts +29 -0
- package/template/src/mock/auth.ts +46 -0
- package/template/src/plugins/echarts.ts +76 -0
- package/template/src/plugins/index.ts +6 -0
- package/template/src/router/core/ComponentLoader.ts +82 -0
- package/template/src/router/core/IframeRouteManager.ts +78 -0
- package/template/src/router/core/MenuProcessor.ts +280 -0
- package/template/src/router/core/RoutePermissionValidator.ts +161 -0
- package/template/src/router/core/RouteRegistry.ts +90 -0
- package/template/src/router/core/RouteTransformer.ts +132 -0
- package/template/src/router/core/RouteValidator.ts +187 -0
- package/template/src/router/core/index.ts +14 -0
- package/template/src/router/guards/afterEach.ts +34 -0
- package/template/src/router/guards/beforeEach.ts +442 -0
- package/template/src/router/index.ts +24 -0
- package/template/src/router/modules/dashboard.ts +23 -0
- package/template/src/router/modules/examples.ts +109 -0
- package/template/src/router/modules/exception.ts +46 -0
- package/template/src/router/modules/index.ts +12 -0
- package/template/src/router/modules/result.ts +32 -0
- package/template/src/router/routes/asyncRoutes.ts +9 -0
- package/template/src/router/routes/staticRoutes.ts +60 -0
- package/template/src/router/routesAlias.ts +8 -0
- package/template/src/services/auth.ts +15 -0
- package/template/src/store/index.ts +52 -0
- package/template/src/store/modules/menu.ts +109 -0
- package/template/src/store/modules/setting.ts +450 -0
- package/template/src/store/modules/user.ts +218 -0
- package/template/src/store/modules/worktab.ts +568 -0
- package/template/src/types/api/api.d.ts +86 -0
- package/template/src/types/common/index.ts +95 -0
- package/template/src/types/common/response.ts +32 -0
- package/template/src/types/component/chart.ts +324 -0
- package/template/src/types/component/index.ts +86 -0
- package/template/src/types/config/index.ts +253 -0
- package/template/src/types/directive/directive.d.ts +15 -0
- package/template/src/types/import/auto-imports.d.ts +319 -0
- package/template/src/types/import/components.d.ts +126 -0
- package/template/src/types/index.ts +22 -0
- package/template/src/types/router/index.ts +80 -0
- package/template/src/types/store/index.ts +157 -0
- package/template/src/utils/form/index.ts +9 -0
- package/template/src/utils/form/validator.ts +316 -0
- package/template/src/utils/http/contract.ts +39 -0
- package/template/src/utils/http/error.ts +182 -0
- package/template/src/utils/http/index.ts +226 -0
- package/template/src/utils/http/status.ts +18 -0
- package/template/src/utils/index.ts +31 -0
- package/template/src/utils/navigation/index.ts +10 -0
- package/template/src/utils/navigation/jump.ts +68 -0
- package/template/src/utils/navigation/route.ts +85 -0
- package/template/src/utils/navigation/worktab.ts +67 -0
- package/template/src/utils/router.ts +63 -0
- package/template/src/utils/socket/index.ts +423 -0
- package/template/src/utils/storage/index.ts +7 -0
- package/template/src/utils/storage/storage-config.ts +127 -0
- package/template/src/utils/storage/storage-key-manager.ts +97 -0
- package/template/src/utils/storage/storage.ts +250 -0
- package/template/src/utils/sys/console.ts +9 -0
- package/template/src/utils/sys/error-handle.ts +143 -0
- package/template/src/utils/sys/index.ts +2 -0
- package/template/src/utils/sys/mittBus.ts +61 -0
- package/template/src/utils/ui/animation.ts +80 -0
- package/template/src/utils/ui/colors.ts +273 -0
- package/template/src/utils/ui/emojo.ts +24 -0
- package/template/src/utils/ui/iconify-loader.ts +31 -0
- package/template/src/utils/ui/index.ts +11 -0
- package/template/src/utils/ui/loading.ts +158 -0
- package/template/src/utils/ui/tabs.ts +60 -0
- package/template/src/views/auth/forget-password/index.vue +62 -0
- package/template/src/views/auth/login/index.vue +166 -0
- package/template/src/views/auth/login/style.css +38 -0
- package/template/src/views/auth/register/index.vue +240 -0
- package/template/src/views/dashboard/console/index.vue +173 -0
- package/template/src/views/examples/analytics/index.vue +389 -0
- package/template/src/views/examples/complex-form/index.vue +395 -0
- package/template/src/views/examples/crud-workspace/index.vue +412 -0
- package/template/src/views/examples/navigation/detail/index.vue +151 -0
- package/template/src/views/examples/navigation/state/index.vue +226 -0
- package/template/src/views/examples/overview/index.vue +309 -0
- package/template/src/views/examples/permissions/index.vue +303 -0
- package/template/src/views/examples/search-table/index.vue +182 -0
- package/template/src/views/examples/search-table/search.config.ts +81 -0
- package/template/src/views/examples/search-table/service.ts +116 -0
- package/template/src/views/examples/search-table/table.config.ts +37 -0
- package/template/src/views/exception/403/index.vue +16 -0
- package/template/src/views/exception/404/index.vue +16 -0
- package/template/src/views/exception/500/index.vue +16 -0
- package/template/src/views/index/index.vue +29 -0
- package/template/src/views/index/style.scss +93 -0
- package/template/src/views/outside/Iframe.vue +42 -0
- package/template/src/views/result/fail/index.vue +28 -0
- package/template/src/views/result/success/index.vue +21 -0
- package/template/tests/e2e/auth.spec.ts +14 -0
- package/template/tests/e2e/search-table.spec.ts +154 -0
- package/template/tests/unit/adapters/auth.spec.ts +38 -0
- package/template/tests/unit/config/app-config.spec.ts +17 -0
- package/template/tests/unit/directives/highlight.spec.ts +20 -0
- package/template/tests/unit/http/contract.spec.ts +47 -0
- package/template/tests/unit/mock/search-table.spec.ts +62 -0
- package/template/tests/unit/router/examples.spec.ts +52 -0
- package/template/tsconfig.json +28 -0
- package/template/vite.config.ts +181 -0
- package/template/vitest.config.ts +27 -0
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
import axios, {
|
|
2
|
+
AxiosRequestConfig,
|
|
3
|
+
AxiosResponse,
|
|
4
|
+
InternalAxiosRequestConfig,
|
|
5
|
+
isAxiosError
|
|
6
|
+
} from 'axios'
|
|
7
|
+
import { useUserStore } from '@/store/modules/user'
|
|
8
|
+
import { ApiStatus } from './status'
|
|
9
|
+
import { HttpError, handleError, showError, showSuccess } from './error'
|
|
10
|
+
import { $t } from '@/locales'
|
|
11
|
+
import type { BaseResponse } from '@/types'
|
|
12
|
+
import { createRequestKey, isApiSuccessCode, normalizeApiCode } from './contract'
|
|
13
|
+
|
|
14
|
+
const REQUEST_TIMEOUT = 15000
|
|
15
|
+
const MAX_RETRIES = 0
|
|
16
|
+
const RETRY_DELAY = 1000
|
|
17
|
+
const UNAUTHORIZED_DEBOUNCE_TIME = 3000
|
|
18
|
+
const REQUEST_CANCELLED_CODE = 499
|
|
19
|
+
|
|
20
|
+
let isUnauthorizedErrorShown = false
|
|
21
|
+
let unauthorizedTimer: ReturnType<typeof setTimeout> | null = null
|
|
22
|
+
|
|
23
|
+
export interface ExtendedAxiosRequestConfig extends AxiosRequestConfig {
|
|
24
|
+
/** 是否展示业务错误消息,默认展示 */
|
|
25
|
+
showErrorMessage?: boolean
|
|
26
|
+
/** 是否展示业务成功消息,默认不展示 */
|
|
27
|
+
showSuccessMessage?: boolean
|
|
28
|
+
/** 相同请求发起时是否取消上一次请求,默认取消 */
|
|
29
|
+
cancelPrevious?: boolean
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
interface TrackedRequestConfig extends InternalAxiosRequestConfig {
|
|
33
|
+
requestKey?: string
|
|
34
|
+
abortController?: AbortController
|
|
35
|
+
cancelPrevious?: boolean
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const { VITE_API_URL, VITE_WITH_CREDENTIALS, VITE_AUTH_SCHEME } = import.meta.env
|
|
39
|
+
const pendingRequests = new Map<string, AbortController>()
|
|
40
|
+
let requestSequence = 0
|
|
41
|
+
|
|
42
|
+
const axiosInstance = axios.create({
|
|
43
|
+
timeout: REQUEST_TIMEOUT,
|
|
44
|
+
baseURL: VITE_API_URL,
|
|
45
|
+
withCredentials: VITE_WITH_CREDENTIALS === 'true',
|
|
46
|
+
validateStatus: (status) => status >= 200 && status < 300
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
axiosInstance.interceptors.request.use(
|
|
50
|
+
(request: TrackedRequestConfig) => {
|
|
51
|
+
const userStore = useUserStore()
|
|
52
|
+
if (userStore.accessToken) {
|
|
53
|
+
const scheme = VITE_AUTH_SCHEME ? `${VITE_AUTH_SCHEME.trim()} ` : ''
|
|
54
|
+
request.headers.set('Authorization', `${scheme}${userStore.accessToken}`)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (request.data && !(request.data instanceof FormData) && !request.headers['Content-Type']) {
|
|
58
|
+
request.headers.set('Content-Type', 'application/json')
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const baseRequestKey = createRequestKey(request)
|
|
62
|
+
const requestKey =
|
|
63
|
+
request.cancelPrevious === false ? `${baseRequestKey}|${++requestSequence}` : baseRequestKey
|
|
64
|
+
request.requestKey = requestKey
|
|
65
|
+
|
|
66
|
+
if (request.cancelPrevious !== false) {
|
|
67
|
+
pendingRequests.get(baseRequestKey)?.abort('Duplicated request cancelled')
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const controller = new AbortController()
|
|
71
|
+
request.abortController = controller
|
|
72
|
+
request.signal = controller.signal
|
|
73
|
+
pendingRequests.set(requestKey, controller)
|
|
74
|
+
|
|
75
|
+
return request
|
|
76
|
+
},
|
|
77
|
+
(error) => {
|
|
78
|
+
const httpError = createHttpError($t('httpMsg.requestConfigError'), ApiStatus.error)
|
|
79
|
+
showError(httpError)
|
|
80
|
+
return Promise.reject(error)
|
|
81
|
+
}
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
axiosInstance.interceptors.response.use(
|
|
85
|
+
(response: AxiosResponse<BaseResponse>) => {
|
|
86
|
+
removePendingRequest(response.config as TrackedRequestConfig)
|
|
87
|
+
|
|
88
|
+
if (response.status === 204) {
|
|
89
|
+
return response
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const code = normalizeApiCode(response.data?.code)
|
|
93
|
+
const message = response.data?.message || response.data?.msg
|
|
94
|
+
|
|
95
|
+
if (isApiSuccessCode(code)) return response
|
|
96
|
+
if (code === ApiStatus.unauthorized) handleUnauthorizedError(message)
|
|
97
|
+
|
|
98
|
+
throw createHttpError(message || $t('httpMsg.requestFailed'), code, {
|
|
99
|
+
data: response.data?.data,
|
|
100
|
+
url: response.config.url,
|
|
101
|
+
method: response.config.method?.toUpperCase()
|
|
102
|
+
})
|
|
103
|
+
},
|
|
104
|
+
(error) => {
|
|
105
|
+
if (error?.config) removePendingRequest(error.config as TrackedRequestConfig)
|
|
106
|
+
if (error instanceof HttpError) return Promise.reject(error)
|
|
107
|
+
|
|
108
|
+
if (axios.isCancel(error) || error?.code === 'ERR_CANCELED') {
|
|
109
|
+
return Promise.reject(
|
|
110
|
+
createHttpError($t('httpMsg.requestCancelled'), REQUEST_CANCELLED_CODE, {
|
|
111
|
+
url: error?.config?.url,
|
|
112
|
+
method: error?.config?.method?.toUpperCase()
|
|
113
|
+
})
|
|
114
|
+
)
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
if (isAxiosError(error) && error.response?.status === ApiStatus.unauthorized) {
|
|
118
|
+
handleUnauthorizedError(error.response.data?.message || error.response.data?.msg)
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
return Promise.reject(handleError(error))
|
|
122
|
+
}
|
|
123
|
+
)
|
|
124
|
+
|
|
125
|
+
function createHttpError(
|
|
126
|
+
message: string,
|
|
127
|
+
code: number,
|
|
128
|
+
options?: { data?: unknown; url?: string; method?: string }
|
|
129
|
+
) {
|
|
130
|
+
return new HttpError(message, code, options)
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function handleUnauthorizedError(message?: string): never {
|
|
134
|
+
const error = createHttpError(message || $t('httpMsg.unauthorized'), ApiStatus.unauthorized)
|
|
135
|
+
|
|
136
|
+
if (!isUnauthorizedErrorShown) {
|
|
137
|
+
isUnauthorizedErrorShown = true
|
|
138
|
+
useUserStore().clearAuthState()
|
|
139
|
+
unauthorizedTimer = setTimeout(resetUnauthorizedError, UNAUTHORIZED_DEBOUNCE_TIME)
|
|
140
|
+
showError(error)
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
throw error
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function resetUnauthorizedError() {
|
|
147
|
+
isUnauthorizedErrorShown = false
|
|
148
|
+
if (unauthorizedTimer) clearTimeout(unauthorizedTimer)
|
|
149
|
+
unauthorizedTimer = null
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function removePendingRequest(config: TrackedRequestConfig): void {
|
|
153
|
+
if (!config.requestKey) return
|
|
154
|
+
if (pendingRequests.get(config.requestKey) === config.abortController) {
|
|
155
|
+
pendingRequests.delete(config.requestKey)
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/** 取消当前尚未完成的全部请求。 */
|
|
160
|
+
export function cancelAllPendingRequests(): void {
|
|
161
|
+
pendingRequests.forEach((controller) => controller.abort('All pending requests cancelled'))
|
|
162
|
+
pendingRequests.clear()
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function shouldRetry(statusCode: number) {
|
|
166
|
+
return [
|
|
167
|
+
ApiStatus.requestTimeout,
|
|
168
|
+
ApiStatus.internalServerError,
|
|
169
|
+
ApiStatus.badGateway,
|
|
170
|
+
ApiStatus.serviceUnavailable,
|
|
171
|
+
ApiStatus.gatewayTimeout
|
|
172
|
+
].includes(statusCode)
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
async function retryRequest<T>(
|
|
176
|
+
config: ExtendedAxiosRequestConfig,
|
|
177
|
+
retries: number = MAX_RETRIES
|
|
178
|
+
): Promise<T> {
|
|
179
|
+
try {
|
|
180
|
+
return await request<T>(config)
|
|
181
|
+
} catch (error) {
|
|
182
|
+
if (retries > 0 && error instanceof HttpError && shouldRetry(error.code)) {
|
|
183
|
+
await new Promise((resolve) => setTimeout(resolve, RETRY_DELAY))
|
|
184
|
+
return retryRequest<T>(config, retries - 1)
|
|
185
|
+
}
|
|
186
|
+
throw error
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
async function request<T = unknown>(config: ExtendedAxiosRequestConfig): Promise<T> {
|
|
191
|
+
try {
|
|
192
|
+
const response = await axiosInstance.request<BaseResponse<T>>(config)
|
|
193
|
+
const message = response.data?.message || response.data?.msg
|
|
194
|
+
|
|
195
|
+
if (config.showSuccessMessage && message) showSuccess(message)
|
|
196
|
+
return response.status === 204 ? (undefined as T) : response.data.data
|
|
197
|
+
} catch (error) {
|
|
198
|
+
if (error instanceof HttpError) {
|
|
199
|
+
const shouldShow = config.showErrorMessage !== false
|
|
200
|
+
if (error.code !== ApiStatus.unauthorized && error.code !== REQUEST_CANCELLED_CODE) {
|
|
201
|
+
showError(error, shouldShow)
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
return Promise.reject(error)
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
const api = {
|
|
209
|
+
get<T>(config: ExtendedAxiosRequestConfig) {
|
|
210
|
+
return retryRequest<T>({ ...config, method: 'GET' })
|
|
211
|
+
},
|
|
212
|
+
post<T>(config: ExtendedAxiosRequestConfig) {
|
|
213
|
+
return retryRequest<T>({ ...config, method: 'POST' })
|
|
214
|
+
},
|
|
215
|
+
put<T>(config: ExtendedAxiosRequestConfig) {
|
|
216
|
+
return retryRequest<T>({ ...config, method: 'PUT' })
|
|
217
|
+
},
|
|
218
|
+
del<T>(config: ExtendedAxiosRequestConfig) {
|
|
219
|
+
return retryRequest<T>({ ...config, method: 'DELETE' })
|
|
220
|
+
},
|
|
221
|
+
request<T>(config: ExtendedAxiosRequestConfig) {
|
|
222
|
+
return retryRequest<T>(config)
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
export default api
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 接口状态码
|
|
3
|
+
*/
|
|
4
|
+
export enum ApiStatus {
|
|
5
|
+
success = 200, // 成功
|
|
6
|
+
error = 400, // 错误
|
|
7
|
+
unauthorized = 401, // 未授权
|
|
8
|
+
forbidden = 403, // 禁止访问
|
|
9
|
+
notFound = 404, // 未找到
|
|
10
|
+
methodNotAllowed = 405, // 方法不允许
|
|
11
|
+
requestTimeout = 408, // 请求超时
|
|
12
|
+
internalServerError = 500, // 服务器错误
|
|
13
|
+
notImplemented = 501, // 未实现
|
|
14
|
+
badGateway = 502, // 网关错误
|
|
15
|
+
serviceUnavailable = 503, // 服务不可用
|
|
16
|
+
gatewayTimeout = 504, // 网关超时
|
|
17
|
+
httpVersionNotSupported = 505 // HTTP版本不支持
|
|
18
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utils 工具函数统一导出
|
|
3
|
+
* 提供向后兼容性和便捷导入
|
|
4
|
+
*
|
|
5
|
+
* @module utils/index
|
|
6
|
+
* @author Art Design Pro Team
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
// UI 相关
|
|
10
|
+
export * from './ui'
|
|
11
|
+
|
|
12
|
+
// 路由相关
|
|
13
|
+
export * from './router'
|
|
14
|
+
|
|
15
|
+
// 路由导航相关
|
|
16
|
+
export * from './navigation'
|
|
17
|
+
|
|
18
|
+
// 系统级工具
|
|
19
|
+
export * from './sys'
|
|
20
|
+
|
|
21
|
+
// 存储相关
|
|
22
|
+
export * from './storage'
|
|
23
|
+
|
|
24
|
+
// HTTP 相关
|
|
25
|
+
export * from './http'
|
|
26
|
+
|
|
27
|
+
// 表单相关
|
|
28
|
+
export * from './form'
|
|
29
|
+
|
|
30
|
+
// socket 相关
|
|
31
|
+
export * from './socket'
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 导航跳转工具模块
|
|
3
|
+
*
|
|
4
|
+
* 提供统一的页面跳转和导航功能
|
|
5
|
+
*
|
|
6
|
+
* ## 主要功能
|
|
7
|
+
*
|
|
8
|
+
* - 外部链接打开(新窗口)
|
|
9
|
+
* - 菜单项跳转处理(支持内部路由和外部链接)
|
|
10
|
+
* - iframe 页面跳转支持
|
|
11
|
+
* - 递归查找并跳转到第一个可见的子菜单
|
|
12
|
+
* - 智能判断跳转目标类型(外部链接/内部路由)
|
|
13
|
+
*
|
|
14
|
+
* @module utils/navigation/jump
|
|
15
|
+
* @author Art Design Pro Team
|
|
16
|
+
*/
|
|
17
|
+
import { AppRouteRecord } from '@/types/router'
|
|
18
|
+
import { router } from '@/router'
|
|
19
|
+
import { isNavigableMenuItem } from './route'
|
|
20
|
+
|
|
21
|
+
// 打开外部链接
|
|
22
|
+
export const openExternalLink = (link: string) => {
|
|
23
|
+
window.open(link, '_blank')
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* 菜单跳转
|
|
28
|
+
* @param item 菜单项
|
|
29
|
+
* @param jumpToFirst 是否跳转到第一个子菜单
|
|
30
|
+
* @returns
|
|
31
|
+
*/
|
|
32
|
+
export const handleMenuJump = (item: AppRouteRecord, jumpToFirst: boolean = false) => {
|
|
33
|
+
// 处理外部链接
|
|
34
|
+
const { link, isIframe } = item.meta
|
|
35
|
+
if (link && !isIframe) {
|
|
36
|
+
return openExternalLink(link)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// 如果不需要跳转到第一个子菜单,或者没有子菜单,直接跳转当前路径
|
|
40
|
+
if (!jumpToFirst || !item.children?.length) {
|
|
41
|
+
return router.push(item.path)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// 递归查找第一个可导航的叶子节点菜单
|
|
45
|
+
const findFirstLeafMenu = (items: AppRouteRecord[]): AppRouteRecord | undefined => {
|
|
46
|
+
for (const child of items) {
|
|
47
|
+
if (isNavigableMenuItem(child)) {
|
|
48
|
+
return child.children?.length ? findFirstLeafMenu(child.children) || child : child
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return undefined
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const firstChild = findFirstLeafMenu(item.children)
|
|
55
|
+
|
|
56
|
+
// 如果子菜单都不可见,则回退到父级页面自身。
|
|
57
|
+
if (!firstChild) {
|
|
58
|
+
return router.push(item.path)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// 如果第一个子菜单是外部链接则打开新窗口
|
|
62
|
+
if (firstChild.meta?.link) {
|
|
63
|
+
return openExternalLink(firstChild.meta.link)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// 跳转到子菜单路径
|
|
67
|
+
router.push(firstChild.path)
|
|
68
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 路由工具模块
|
|
3
|
+
*
|
|
4
|
+
* 提供路由处理和菜单路径相关的工具函数
|
|
5
|
+
*
|
|
6
|
+
* ## 主要功能
|
|
7
|
+
*
|
|
8
|
+
* - iframe 路由检测,判断是否为外部嵌入页面
|
|
9
|
+
* - 菜单项有效性验证,过滤隐藏和无效菜单
|
|
10
|
+
* - 路径标准化处理,统一路径格式
|
|
11
|
+
* - 递归查找菜单树中第一个有效路径
|
|
12
|
+
* - 支持多级嵌套菜单的路径解析
|
|
13
|
+
*
|
|
14
|
+
* ## 使用场景
|
|
15
|
+
*
|
|
16
|
+
* - 系统初始化时获取默认跳转路径
|
|
17
|
+
* - 菜单权限过滤后获取首个可访问页面
|
|
18
|
+
* - 路由重定向逻辑处理
|
|
19
|
+
* - iframe 页面特殊处理
|
|
20
|
+
*
|
|
21
|
+
* @module utils/navigation/route
|
|
22
|
+
* @author Art Design Pro Team
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import { AppRouteRecord } from '@/types'
|
|
26
|
+
|
|
27
|
+
// 检查是否为 iframe 路由
|
|
28
|
+
export function isIframe(url: string): boolean {
|
|
29
|
+
return url.startsWith('/outside/iframe/')
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* 判断菜单项是否可作为默认导航落点
|
|
34
|
+
* 隐藏的全屏页面虽然不展示在菜单中,但仍然可能是合法首页。
|
|
35
|
+
*/
|
|
36
|
+
export const isNavigableMenuItem = (menuItem: AppRouteRecord): boolean => {
|
|
37
|
+
if (!menuItem.path || !menuItem.path.trim()) {
|
|
38
|
+
return false
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (!menuItem.meta?.isHide) {
|
|
42
|
+
return true
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return menuItem.meta?.isFullPage === true
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* 标准化路径格式
|
|
50
|
+
* @param path 路径
|
|
51
|
+
* @returns 标准化后的路径
|
|
52
|
+
*/
|
|
53
|
+
const normalizePath = (path: string): string => {
|
|
54
|
+
return path.startsWith('/') ? path : `/${path}`
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* 递归获取菜单的第一个有效路径
|
|
59
|
+
* @param menuList 菜单列表
|
|
60
|
+
* @returns 第一个有效路径,如果没有找到则返回空字符串
|
|
61
|
+
*/
|
|
62
|
+
export const getFirstMenuPath = (menuList: AppRouteRecord[]): string => {
|
|
63
|
+
if (!Array.isArray(menuList) || menuList.length === 0) {
|
|
64
|
+
return ''
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
for (const menuItem of menuList) {
|
|
68
|
+
if (!isNavigableMenuItem(menuItem)) {
|
|
69
|
+
continue
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// 如果有子菜单,优先查找子菜单
|
|
73
|
+
if (menuItem.children?.length) {
|
|
74
|
+
const childPath = getFirstMenuPath(menuItem.children)
|
|
75
|
+
if (childPath) {
|
|
76
|
+
return childPath
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// 返回当前菜单项的标准化路径
|
|
81
|
+
return normalizePath(menuItem.path!)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return ''
|
|
85
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 工作标签页管理模块
|
|
3
|
+
*
|
|
4
|
+
* 提供工作标签页(Worktab)的自动管理功能
|
|
5
|
+
*
|
|
6
|
+
* ## 主要功能
|
|
7
|
+
*
|
|
8
|
+
* - 根据路由导航自动创建和更新工作标签页
|
|
9
|
+
* - iframe 页面标签页特殊处理
|
|
10
|
+
* - 标签页信息提取(标题、路径、缓存状态等)
|
|
11
|
+
* - 固定标签页支持
|
|
12
|
+
* - 根据系统设置控制标签页显示
|
|
13
|
+
* - 首页标签页特殊处理
|
|
14
|
+
*
|
|
15
|
+
* ## 使用场景
|
|
16
|
+
*
|
|
17
|
+
* - 路由守卫中自动创建标签页
|
|
18
|
+
* - 页面切换时更新标签页状态
|
|
19
|
+
* - 多标签页导航系统
|
|
20
|
+
*
|
|
21
|
+
* @module utils/navigation/worktab
|
|
22
|
+
* @author Art Design Pro Team
|
|
23
|
+
*/
|
|
24
|
+
import { useWorktabStore } from '@/store/modules/worktab'
|
|
25
|
+
import { RouteLocationNormalized } from 'vue-router'
|
|
26
|
+
import { isIframe } from './route'
|
|
27
|
+
import { useSettingStore } from '@/store/modules/setting'
|
|
28
|
+
import { IframeRouteManager } from '@/router/core'
|
|
29
|
+
import { useCommon } from '@/hooks/core/useCommon'
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* 根据当前路由信息设置工作标签页(worktab)
|
|
33
|
+
* @param to 当前路由对象
|
|
34
|
+
*/
|
|
35
|
+
export const setWorktab = (to: RouteLocationNormalized): void => {
|
|
36
|
+
const worktabStore = useWorktabStore()
|
|
37
|
+
const { meta, path, name, params, query } = to
|
|
38
|
+
if (!meta.isHideTab) {
|
|
39
|
+
// 如果是 iframe 页面,则特殊处理工作标签页
|
|
40
|
+
if (isIframe(path)) {
|
|
41
|
+
const iframeRoute = IframeRouteManager.getInstance().findByPath(to.path)
|
|
42
|
+
|
|
43
|
+
if (iframeRoute?.meta) {
|
|
44
|
+
worktabStore.openTab({
|
|
45
|
+
title: iframeRoute.meta.title,
|
|
46
|
+
icon: meta.icon as string,
|
|
47
|
+
path,
|
|
48
|
+
name: name as string,
|
|
49
|
+
keepAlive: meta.keepAlive as boolean,
|
|
50
|
+
params,
|
|
51
|
+
query
|
|
52
|
+
})
|
|
53
|
+
}
|
|
54
|
+
} else if (useSettingStore().showWorkTab || path === useCommon().homePath.value) {
|
|
55
|
+
worktabStore.openTab({
|
|
56
|
+
title: meta.title as string,
|
|
57
|
+
icon: meta.icon as string,
|
|
58
|
+
path,
|
|
59
|
+
name: name as string,
|
|
60
|
+
keepAlive: meta.keepAlive as boolean,
|
|
61
|
+
params,
|
|
62
|
+
query,
|
|
63
|
+
fixedTab: meta.fixedTab as boolean
|
|
64
|
+
})
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 路由工具函数
|
|
3
|
+
*
|
|
4
|
+
* 提供路由相关的工具函数
|
|
5
|
+
*
|
|
6
|
+
* @module utils/router
|
|
7
|
+
*/
|
|
8
|
+
import { RouteLocationNormalized, RouteRecordRaw } from 'vue-router'
|
|
9
|
+
import AppConfig from '@/config'
|
|
10
|
+
import NProgress from 'nprogress'
|
|
11
|
+
import 'nprogress/nprogress.css'
|
|
12
|
+
import i18n, { $t } from '@/locales'
|
|
13
|
+
|
|
14
|
+
/** 扩展的路由配置类型 */
|
|
15
|
+
export type AppRouteRecordRaw = RouteRecordRaw & {
|
|
16
|
+
hidden?: boolean
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** 顶部进度条配置 */
|
|
20
|
+
export const configureNProgress = () => {
|
|
21
|
+
NProgress.configure({
|
|
22
|
+
easing: 'ease',
|
|
23
|
+
speed: 600,
|
|
24
|
+
showSpinner: false,
|
|
25
|
+
parent: 'body'
|
|
26
|
+
})
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* 设置页面标题,根据路由元信息和系统信息拼接标题
|
|
31
|
+
* @param to 当前路由对象
|
|
32
|
+
*/
|
|
33
|
+
export const setPageTitle = (to: RouteLocationNormalized): void => {
|
|
34
|
+
const { title } = to.meta
|
|
35
|
+
if (title) {
|
|
36
|
+
setTimeout(() => {
|
|
37
|
+
document.title = AppConfig.navigation.titleTemplate
|
|
38
|
+
.replace('{page}', formatMenuTitle(String(title)))
|
|
39
|
+
.replace('{app}', AppConfig.systemInfo.name)
|
|
40
|
+
}, 150)
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* 格式化菜单标题
|
|
46
|
+
* @param title 菜单标题,可以是 i18n 的 key,也可以是字符串
|
|
47
|
+
* @returns 格式化后的菜单标题
|
|
48
|
+
*/
|
|
49
|
+
export const formatMenuTitle = (title: string): string => {
|
|
50
|
+
if (title) {
|
|
51
|
+
if (title.startsWith('menus.')) {
|
|
52
|
+
// 使用 te() 方法检查翻译键值是否存在,避免控制台警告
|
|
53
|
+
if (i18n.global.te(title)) {
|
|
54
|
+
return $t(title)
|
|
55
|
+
} else {
|
|
56
|
+
// 如果翻译不存在,返回键值的最后部分作为fallback
|
|
57
|
+
return title.split('.').pop() || title
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return title
|
|
61
|
+
}
|
|
62
|
+
return ''
|
|
63
|
+
}
|