@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,316 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 表单验证工具模块
|
|
3
|
+
*
|
|
4
|
+
* 提供全面的表单字段验证功能
|
|
5
|
+
*
|
|
6
|
+
* ## 主要功能
|
|
7
|
+
*
|
|
8
|
+
* - 手机号码验证(中国大陆格式)
|
|
9
|
+
* - 固定电话验证(支持区号格式)
|
|
10
|
+
* - 用户账号验证(字母开头,支持数字和下划线)
|
|
11
|
+
* - 密码强度验证(普通密码、强密码)
|
|
12
|
+
* - 密码强度评估(弱、中、强)
|
|
13
|
+
* - IPv4 地址验证
|
|
14
|
+
* - 邮箱地址验证(RFC 5322 标准)
|
|
15
|
+
* - URL 地址验证
|
|
16
|
+
* - 身份证号码验证(18位,含校验码验证)
|
|
17
|
+
* - 银行卡号验证(Luhn 算法)
|
|
18
|
+
* - 字符串空格处理
|
|
19
|
+
*
|
|
20
|
+
* ## 验证规则
|
|
21
|
+
*
|
|
22
|
+
* - 手机号:1开头,第二位3-9,共11位
|
|
23
|
+
* - 账号:字母开头,5-20位,支持字母数字下划线
|
|
24
|
+
* - 普通密码:6-20位,必须包含字母和数字
|
|
25
|
+
* - 强密码:8-20位,必须包含大小写字母、数字和特殊字符
|
|
26
|
+
* - 身份证:18位,含出生日期和校验码验证
|
|
27
|
+
* - 银行卡:13-19位,通过 Luhn 算法验证
|
|
28
|
+
*
|
|
29
|
+
* @module utils/validation/formValidator
|
|
30
|
+
* @author Art Design Pro Team
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* 密码强度级别枚举
|
|
35
|
+
*/
|
|
36
|
+
export enum PasswordStrength {
|
|
37
|
+
WEAK = '弱',
|
|
38
|
+
MEDIUM = '中',
|
|
39
|
+
STRONG = '强'
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* 去除字符串首尾空格
|
|
44
|
+
* @param value 待处理的字符串
|
|
45
|
+
* @returns 返回去除首尾空格后的字符串
|
|
46
|
+
*/
|
|
47
|
+
export function trimSpaces(value: string): string {
|
|
48
|
+
if (typeof value !== 'string') {
|
|
49
|
+
return ''
|
|
50
|
+
}
|
|
51
|
+
return value.trim()
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* 验证手机号码(中国大陆)
|
|
56
|
+
* @param value 手机号码字符串
|
|
57
|
+
* @returns 返回验证结果,true表示格式正确
|
|
58
|
+
*/
|
|
59
|
+
export function validatePhone(value: string): boolean {
|
|
60
|
+
if (!value || typeof value !== 'string') {
|
|
61
|
+
return false
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// 中国大陆手机号码:1开头,第二位为3-9,共11位数字
|
|
65
|
+
const phoneRegex = /^1[3-9]\d{9}$/
|
|
66
|
+
return phoneRegex.test(value.trim())
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* 验证固定电话号码(中国大陆)
|
|
71
|
+
* @param value 电话号码字符串
|
|
72
|
+
* @returns 返回验证结果,true表示格式正确
|
|
73
|
+
*/
|
|
74
|
+
export function validateTelPhone(value: string): boolean {
|
|
75
|
+
if (!value || typeof value !== 'string') {
|
|
76
|
+
return false
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// 支持格式:区号-号码,如:010-12345678、0755-1234567
|
|
80
|
+
const telRegex = /^0\d{2,3}-?\d{7,8}$/
|
|
81
|
+
return telRegex.test(value.trim().replace(/\s+/g, ''))
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* 验证用户账号
|
|
86
|
+
* @param value 账号字符串
|
|
87
|
+
* @returns 返回验证结果,true表示格式正确
|
|
88
|
+
* @description 规则:字母开头,5-20位,支持字母、数字、下划线
|
|
89
|
+
*/
|
|
90
|
+
export function validateAccount(value: string): boolean {
|
|
91
|
+
if (!value || typeof value !== 'string') {
|
|
92
|
+
return false
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// 字母开头,5-20位,支持字母、数字、下划线
|
|
96
|
+
const accountRegex = /^[a-zA-Z][a-zA-Z0-9_]{4,19}$/
|
|
97
|
+
return accountRegex.test(value.trim())
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* 验证密码
|
|
102
|
+
* @param value 密码字符串
|
|
103
|
+
* @returns 返回验证结果,true表示格式正确
|
|
104
|
+
* @description 规则:6-20位,必须包含字母和数字
|
|
105
|
+
*/
|
|
106
|
+
export function validatePassword(value: string): boolean {
|
|
107
|
+
if (!value || typeof value !== 'string') {
|
|
108
|
+
return false
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const trimmedValue = value.trim()
|
|
112
|
+
|
|
113
|
+
// 长度检查
|
|
114
|
+
if (trimmedValue.length < 6 || trimmedValue.length > 20) {
|
|
115
|
+
return false
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// 必须包含字母和数字
|
|
119
|
+
const hasLetter = /[a-zA-Z]/.test(trimmedValue)
|
|
120
|
+
const hasNumber = /\d/.test(trimmedValue)
|
|
121
|
+
|
|
122
|
+
return hasLetter && hasNumber
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* 验证强密码
|
|
127
|
+
* @param value 密码字符串
|
|
128
|
+
* @returns 返回验证结果,true表示格式正确
|
|
129
|
+
* @description 规则:8-20位,必须包含大写字母、小写字母、数字和特殊字符
|
|
130
|
+
*/
|
|
131
|
+
export function validateStrongPassword(value: string): boolean {
|
|
132
|
+
if (!value || typeof value !== 'string') {
|
|
133
|
+
return false
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const trimmedValue = value.trim()
|
|
137
|
+
|
|
138
|
+
// 长度检查
|
|
139
|
+
if (trimmedValue.length < 8 || trimmedValue.length > 20) {
|
|
140
|
+
return false
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// 必须包含:大写字母、小写字母、数字、特殊字符
|
|
144
|
+
const hasUpperCase = /[A-Z]/.test(trimmedValue)
|
|
145
|
+
const hasLowerCase = /[a-z]/.test(trimmedValue)
|
|
146
|
+
const hasNumber = /\d/.test(trimmedValue)
|
|
147
|
+
const hasSpecialChar = /[!@#$%^&*()_+\-=[\]{};':"\\|,.<>/?]/.test(trimmedValue)
|
|
148
|
+
|
|
149
|
+
return hasUpperCase && hasLowerCase && hasNumber && hasSpecialChar
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* 获取密码强度
|
|
154
|
+
* @param value 密码字符串
|
|
155
|
+
* @returns 返回密码强度:弱、中、强
|
|
156
|
+
* @description 弱:纯数字/纯字母/纯特殊字符;中:两种组合;强:三种或以上组合
|
|
157
|
+
*/
|
|
158
|
+
export function getPasswordStrength(value: string): PasswordStrength {
|
|
159
|
+
if (!value || typeof value !== 'string') {
|
|
160
|
+
return PasswordStrength.WEAK
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
const trimmedValue = value.trim()
|
|
164
|
+
|
|
165
|
+
if (trimmedValue.length < 6) {
|
|
166
|
+
return PasswordStrength.WEAK
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
const hasUpperCase = /[A-Z]/.test(trimmedValue)
|
|
170
|
+
const hasLowerCase = /[a-z]/.test(trimmedValue)
|
|
171
|
+
const hasNumber = /\d/.test(trimmedValue)
|
|
172
|
+
const hasSpecialChar = /[!@#$%^&*()_+\-=[\]{};':"\\|,.<>/?]/.test(trimmedValue)
|
|
173
|
+
|
|
174
|
+
const typeCount = [hasUpperCase, hasLowerCase, hasNumber, hasSpecialChar].filter(Boolean).length
|
|
175
|
+
|
|
176
|
+
if (typeCount >= 3) {
|
|
177
|
+
return PasswordStrength.STRONG
|
|
178
|
+
} else if (typeCount >= 2) {
|
|
179
|
+
return PasswordStrength.MEDIUM
|
|
180
|
+
} else {
|
|
181
|
+
return PasswordStrength.WEAK
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* 验证IPv4地址
|
|
187
|
+
* @param value IP地址字符串
|
|
188
|
+
* @returns 返回验证结果,true表示格式正确
|
|
189
|
+
*/
|
|
190
|
+
export function validateIPv4Address(value: string): boolean {
|
|
191
|
+
if (!value || typeof value !== 'string') {
|
|
192
|
+
return false
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
const trimmedValue = value.trim()
|
|
196
|
+
const ipRegex = /^((25[0-5]|2[0-4]\d|[01]?\d{1,2})\.){3}(25[0-5]|2[0-4]\d|[01]?\d{1,2})$/
|
|
197
|
+
|
|
198
|
+
if (!ipRegex.test(trimmedValue)) {
|
|
199
|
+
return false
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// 额外检查每个段是否在有效范围内
|
|
203
|
+
const segments = trimmedValue.split('.')
|
|
204
|
+
return segments.every((segment) => {
|
|
205
|
+
const num = parseInt(segment, 10)
|
|
206
|
+
return num >= 0 && num <= 255
|
|
207
|
+
})
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* 验证邮箱地址
|
|
212
|
+
* @param value 邮箱地址字符串
|
|
213
|
+
* @returns 返回验证结果,true表示格式正确
|
|
214
|
+
*/
|
|
215
|
+
export function validateEmail(value: string): boolean {
|
|
216
|
+
if (!value || typeof value !== 'string') {
|
|
217
|
+
return false
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
const trimmedValue = value.trim()
|
|
221
|
+
|
|
222
|
+
// RFC 5322 标准的简化版邮箱正则
|
|
223
|
+
const emailRegex =
|
|
224
|
+
/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/
|
|
225
|
+
|
|
226
|
+
return emailRegex.test(trimmedValue) && trimmedValue.length <= 254
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* 验证URL地址
|
|
231
|
+
* @param value URL字符串
|
|
232
|
+
* @returns 返回验证结果,true表示格式正确
|
|
233
|
+
*/
|
|
234
|
+
export function validateURL(value: string): boolean {
|
|
235
|
+
if (!value || typeof value !== 'string') {
|
|
236
|
+
return false
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
try {
|
|
240
|
+
new URL(value.trim())
|
|
241
|
+
return true
|
|
242
|
+
} catch {
|
|
243
|
+
return false
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* 验证身份证号码(中国大陆)
|
|
249
|
+
* @param value 身份证号码字符串
|
|
250
|
+
* @returns 返回验证结果,true表示格式正确
|
|
251
|
+
*/
|
|
252
|
+
export function validateChineseIDCard(value: string): boolean {
|
|
253
|
+
if (!value || typeof value !== 'string') {
|
|
254
|
+
return false
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
const trimmedValue = value.trim()
|
|
258
|
+
|
|
259
|
+
// 18位身份证号码正则
|
|
260
|
+
const idCardRegex =
|
|
261
|
+
/^[1-9]\d{5}(18|19|20)\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/
|
|
262
|
+
|
|
263
|
+
if (!idCardRegex.test(trimmedValue)) {
|
|
264
|
+
return false
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
// 验证校验码
|
|
268
|
+
const weights = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2]
|
|
269
|
+
const checkCodes = ['1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2']
|
|
270
|
+
|
|
271
|
+
let sum = 0
|
|
272
|
+
for (let i = 0; i < 17; i++) {
|
|
273
|
+
sum += parseInt(trimmedValue[i]) * weights[i]
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
const checkCode = checkCodes[sum % 11]
|
|
277
|
+
return trimmedValue[17].toUpperCase() === checkCode
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* 验证银行卡号
|
|
282
|
+
* @param value 银行卡号字符串
|
|
283
|
+
* @returns 返回验证结果,true表示格式正确
|
|
284
|
+
*/
|
|
285
|
+
export function validateBankCard(value: string): boolean {
|
|
286
|
+
if (!value || typeof value !== 'string') {
|
|
287
|
+
return false
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
const trimmedValue = value.trim().replace(/\s+/g, '')
|
|
291
|
+
|
|
292
|
+
// 银行卡号通常为13-19位数字
|
|
293
|
+
if (!/^\d{13,19}$/.test(trimmedValue)) {
|
|
294
|
+
return false
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
// Luhn算法验证
|
|
298
|
+
let sum = 0
|
|
299
|
+
let shouldDouble = false
|
|
300
|
+
|
|
301
|
+
for (let i = trimmedValue.length - 1; i >= 0; i--) {
|
|
302
|
+
let digit = parseInt(trimmedValue[i])
|
|
303
|
+
|
|
304
|
+
if (shouldDouble) {
|
|
305
|
+
digit *= 2
|
|
306
|
+
if (digit > 9) {
|
|
307
|
+
digit = (digit % 10) + 1
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
sum += digit
|
|
312
|
+
shouldDouble = !shouldDouble
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
return sum % 10 === 0
|
|
316
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { AxiosRequestConfig } from 'axios'
|
|
2
|
+
import { ApiStatus } from './status'
|
|
3
|
+
|
|
4
|
+
/** 将后端可能返回的数字或数字字符串统一成状态码。 */
|
|
5
|
+
export function normalizeApiCode(code: number | string | null | undefined): number {
|
|
6
|
+
if (code === undefined || code === null || code === '') return ApiStatus.error
|
|
7
|
+
const numericCode = Number(code)
|
|
8
|
+
return Number.isFinite(numericCode) ? numericCode : ApiStatus.error
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/** 模板兼容常见的 0 和 HTTP 200 两种业务成功码。 */
|
|
12
|
+
export function isApiSuccessCode(code: number): boolean {
|
|
13
|
+
return code === 0 || code === ApiStatus.success
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function stableSerialize(payload: unknown): string {
|
|
17
|
+
if (payload === undefined || payload === null) return ''
|
|
18
|
+
if (typeof payload !== 'object') return String(payload)
|
|
19
|
+
if (payload instanceof FormData || payload instanceof Blob || payload instanceof ArrayBuffer) {
|
|
20
|
+
return payload.constructor.name
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (Array.isArray(payload)) return `[${payload.map(stableSerialize).join(',')}]`
|
|
24
|
+
|
|
25
|
+
return `{${Object.entries(payload as Record<string, unknown>)
|
|
26
|
+
.sort(([left], [right]) => left.localeCompare(right))
|
|
27
|
+
.map(([key, value]) => `${key}:${stableSerialize(value)}`)
|
|
28
|
+
.join(',')}}`
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** 为重复请求取消生成与对象属性顺序无关的稳定键。 */
|
|
32
|
+
export function createRequestKey(config: AxiosRequestConfig): string {
|
|
33
|
+
return [
|
|
34
|
+
config.method?.toUpperCase() || 'GET',
|
|
35
|
+
config.url || '',
|
|
36
|
+
stableSerialize(config.params),
|
|
37
|
+
stableSerialize(config.data)
|
|
38
|
+
].join('|')
|
|
39
|
+
}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTTP 错误处理模块
|
|
3
|
+
*
|
|
4
|
+
* 提供统一的 HTTP 请求错误处理机制
|
|
5
|
+
*
|
|
6
|
+
* ## 主要功能
|
|
7
|
+
*
|
|
8
|
+
* - 自定义 HttpError 错误类,封装错误信息、状态码、时间戳等
|
|
9
|
+
* - 错误拦截和转换,将 Axios 错误转换为标准的 HttpError
|
|
10
|
+
* - 错误消息国际化处理,根据状态码返回对应的多语言错误提示
|
|
11
|
+
* - 错误日志记录,便于问题追踪和调试
|
|
12
|
+
* - 错误和成功消息的统一展示
|
|
13
|
+
* - 类型守卫函数,用于判断错误类型
|
|
14
|
+
*
|
|
15
|
+
* ## 使用场景
|
|
16
|
+
*
|
|
17
|
+
* - HTTP 请求拦截器中统一处理错误
|
|
18
|
+
* - 业务代码中捕获和处理特定错误
|
|
19
|
+
* - 错误日志收集和上报
|
|
20
|
+
*
|
|
21
|
+
* @module utils/http/error
|
|
22
|
+
* @author Art Design Pro Team
|
|
23
|
+
*/
|
|
24
|
+
import { AxiosError } from 'axios'
|
|
25
|
+
import { ApiStatus } from './status'
|
|
26
|
+
import { $t } from '@/locales'
|
|
27
|
+
|
|
28
|
+
// 错误响应接口
|
|
29
|
+
export interface ErrorResponse {
|
|
30
|
+
/** 错误状态码 */
|
|
31
|
+
code: number
|
|
32
|
+
/** 错误消息 */
|
|
33
|
+
msg: string
|
|
34
|
+
/** 错误附加数据 */
|
|
35
|
+
data?: unknown
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// 错误日志数据接口
|
|
39
|
+
export interface ErrorLogData {
|
|
40
|
+
/** 错误状态码 */
|
|
41
|
+
code: number
|
|
42
|
+
/** 错误消息 */
|
|
43
|
+
message: string
|
|
44
|
+
/** 错误附加数据 */
|
|
45
|
+
data?: unknown
|
|
46
|
+
/** 错误发生时间戳 */
|
|
47
|
+
timestamp: string
|
|
48
|
+
/** 请求 URL */
|
|
49
|
+
url?: string
|
|
50
|
+
/** 请求方法 */
|
|
51
|
+
method?: string
|
|
52
|
+
/** 错误堆栈信息 */
|
|
53
|
+
stack?: string
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// 自定义 HttpError 类
|
|
57
|
+
export class HttpError extends Error {
|
|
58
|
+
public readonly code: number
|
|
59
|
+
public readonly data?: unknown
|
|
60
|
+
public readonly timestamp: string
|
|
61
|
+
public readonly url?: string
|
|
62
|
+
public readonly method?: string
|
|
63
|
+
|
|
64
|
+
constructor(
|
|
65
|
+
message: string,
|
|
66
|
+
code: number,
|
|
67
|
+
options?: {
|
|
68
|
+
data?: unknown
|
|
69
|
+
url?: string
|
|
70
|
+
method?: string
|
|
71
|
+
}
|
|
72
|
+
) {
|
|
73
|
+
super(message)
|
|
74
|
+
this.name = 'HttpError'
|
|
75
|
+
this.code = code
|
|
76
|
+
this.data = options?.data
|
|
77
|
+
this.timestamp = new Date().toISOString()
|
|
78
|
+
this.url = options?.url
|
|
79
|
+
this.method = options?.method
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
public toLogData(): ErrorLogData {
|
|
83
|
+
return {
|
|
84
|
+
code: this.code,
|
|
85
|
+
message: this.message,
|
|
86
|
+
data: this.data,
|
|
87
|
+
timestamp: this.timestamp,
|
|
88
|
+
url: this.url,
|
|
89
|
+
method: this.method,
|
|
90
|
+
stack: this.stack
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* 获取错误消息
|
|
97
|
+
* @param status 错误状态码
|
|
98
|
+
* @returns 错误消息
|
|
99
|
+
*/
|
|
100
|
+
const getErrorMessage = (status: number): string => {
|
|
101
|
+
const errorMap: Record<number, string> = {
|
|
102
|
+
[ApiStatus.unauthorized]: 'httpMsg.unauthorized',
|
|
103
|
+
[ApiStatus.forbidden]: 'httpMsg.forbidden',
|
|
104
|
+
[ApiStatus.notFound]: 'httpMsg.notFound',
|
|
105
|
+
[ApiStatus.methodNotAllowed]: 'httpMsg.methodNotAllowed',
|
|
106
|
+
[ApiStatus.requestTimeout]: 'httpMsg.requestTimeout',
|
|
107
|
+
[ApiStatus.internalServerError]: 'httpMsg.internalServerError',
|
|
108
|
+
[ApiStatus.badGateway]: 'httpMsg.badGateway',
|
|
109
|
+
[ApiStatus.serviceUnavailable]: 'httpMsg.serviceUnavailable',
|
|
110
|
+
[ApiStatus.gatewayTimeout]: 'httpMsg.gatewayTimeout'
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return $t(errorMap[status] || 'httpMsg.internalServerError')
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* 处理错误
|
|
118
|
+
* @param error 错误对象
|
|
119
|
+
* @returns 错误对象
|
|
120
|
+
*/
|
|
121
|
+
export function handleError(error: AxiosError<ErrorResponse>): never {
|
|
122
|
+
// 处理取消的请求
|
|
123
|
+
if (error.code === 'ERR_CANCELED') {
|
|
124
|
+
console.warn('Request cancelled:', error.message)
|
|
125
|
+
throw new HttpError($t('httpMsg.requestCancelled'), ApiStatus.error)
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const statusCode = error.response?.status
|
|
129
|
+
const errorMessage = error.response?.data?.msg || error.message
|
|
130
|
+
const requestConfig = error.config
|
|
131
|
+
|
|
132
|
+
// 处理网络错误
|
|
133
|
+
if (!error.response) {
|
|
134
|
+
throw new HttpError($t('httpMsg.networkError'), ApiStatus.error, {
|
|
135
|
+
url: requestConfig?.url,
|
|
136
|
+
method: requestConfig?.method?.toUpperCase()
|
|
137
|
+
})
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// 处理 HTTP 状态码错误
|
|
141
|
+
const message = statusCode
|
|
142
|
+
? getErrorMessage(statusCode)
|
|
143
|
+
: errorMessage || $t('httpMsg.requestFailed')
|
|
144
|
+
throw new HttpError(message, statusCode || ApiStatus.error, {
|
|
145
|
+
data: error.response.data,
|
|
146
|
+
url: requestConfig?.url,
|
|
147
|
+
method: requestConfig?.method?.toUpperCase()
|
|
148
|
+
})
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* 显示错误消息
|
|
153
|
+
* @param error 错误对象
|
|
154
|
+
* @param showMessage 是否显示错误消息
|
|
155
|
+
*/
|
|
156
|
+
export function showError(error: HttpError, showMessage: boolean = true): void {
|
|
157
|
+
if (showMessage) {
|
|
158
|
+
ElMessage.error(error.message)
|
|
159
|
+
}
|
|
160
|
+
// 记录错误日志
|
|
161
|
+
console.error('[HTTP Error]', error.toLogData())
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* 显示成功消息
|
|
166
|
+
* @param message 成功消息
|
|
167
|
+
* @param showMessage 是否显示消息
|
|
168
|
+
*/
|
|
169
|
+
export function showSuccess(message: string, showMessage: boolean = true): void {
|
|
170
|
+
if (showMessage) {
|
|
171
|
+
ElMessage.success(message)
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* 判断是否为 HttpError 类型
|
|
177
|
+
* @param error 错误对象
|
|
178
|
+
* @returns 是否为 HttpError 类型
|
|
179
|
+
*/
|
|
180
|
+
export const isHttpError = (error: unknown): error is HttpError => {
|
|
181
|
+
return error instanceof HttpError
|
|
182
|
+
}
|