@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,390 @@
|
|
|
1
|
+
<!-- 导出 Excel 文件 -->
|
|
2
|
+
<template>
|
|
3
|
+
<ElButton
|
|
4
|
+
:type="type"
|
|
5
|
+
:size="size"
|
|
6
|
+
:loading="isExporting"
|
|
7
|
+
:disabled="disabled || !hasData"
|
|
8
|
+
v-ripple
|
|
9
|
+
@click="handleExport"
|
|
10
|
+
>
|
|
11
|
+
<template #loading>
|
|
12
|
+
<ElIcon class="is-loading">
|
|
13
|
+
<Loading />
|
|
14
|
+
</ElIcon>
|
|
15
|
+
{{ loadingText }}
|
|
16
|
+
</template>
|
|
17
|
+
<slot>{{ buttonText }}</slot>
|
|
18
|
+
</ElButton>
|
|
19
|
+
</template>
|
|
20
|
+
|
|
21
|
+
<script setup lang="ts">
|
|
22
|
+
import * as XLSX from '@e965/xlsx'
|
|
23
|
+
import FileSaver from 'file-saver'
|
|
24
|
+
import { ref, computed, nextTick } from 'vue'
|
|
25
|
+
import { Loading } from '@element-plus/icons-vue'
|
|
26
|
+
import { ElMessage, type ButtonType } from 'element-plus'
|
|
27
|
+
import { useThrottleFn } from '@vueuse/core'
|
|
28
|
+
import AppConfig from '@/config'
|
|
29
|
+
|
|
30
|
+
defineOptions({ name: 'ArtExcelExport' })
|
|
31
|
+
|
|
32
|
+
/** 导出数据类型 */
|
|
33
|
+
type ExportValue = string | number | boolean | null | undefined | Date
|
|
34
|
+
|
|
35
|
+
interface ExportData {
|
|
36
|
+
[key: string]: ExportValue
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** 列配置 */
|
|
40
|
+
interface ColumnConfig {
|
|
41
|
+
/** 列标题 */
|
|
42
|
+
title: string
|
|
43
|
+
/** 列宽度 */
|
|
44
|
+
width?: number
|
|
45
|
+
/** 数据格式化函数 */
|
|
46
|
+
formatter?: (value: ExportValue, row: ExportData, index: number) => string
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** 导出配置选项 */
|
|
50
|
+
interface ExportOptions {
|
|
51
|
+
/** 数据源 */
|
|
52
|
+
data: ExportData[]
|
|
53
|
+
/** 文件名(不含扩展名) */
|
|
54
|
+
filename?: string
|
|
55
|
+
/** 工作表名称 */
|
|
56
|
+
sheetName?: string
|
|
57
|
+
/** 按钮类型 */
|
|
58
|
+
type?: ButtonType
|
|
59
|
+
/** 按钮尺寸 */
|
|
60
|
+
size?: 'large' | 'default' | 'small'
|
|
61
|
+
/** 是否禁用 */
|
|
62
|
+
disabled?: boolean
|
|
63
|
+
/** 按钮文本 */
|
|
64
|
+
buttonText?: string
|
|
65
|
+
/** 加载中文本 */
|
|
66
|
+
loadingText?: string
|
|
67
|
+
/** 是否自动添加序号列 */
|
|
68
|
+
autoIndex?: boolean
|
|
69
|
+
/** 序号列标题 */
|
|
70
|
+
indexColumnTitle?: string
|
|
71
|
+
/** 列配置映射 */
|
|
72
|
+
columns?: Record<string, ColumnConfig>
|
|
73
|
+
/** 表头映射(简化版本,向后兼容) */
|
|
74
|
+
headers?: Record<string, string>
|
|
75
|
+
/** 最大导出行数 */
|
|
76
|
+
maxRows?: number
|
|
77
|
+
/** 是否显示成功消息 */
|
|
78
|
+
showSuccessMessage?: boolean
|
|
79
|
+
/** 是否显示错误消息 */
|
|
80
|
+
showErrorMessage?: boolean
|
|
81
|
+
/** 工作簿配置 */
|
|
82
|
+
workbookOptions?: {
|
|
83
|
+
/** 创建者 */
|
|
84
|
+
creator?: string
|
|
85
|
+
/** 最后修改者 */
|
|
86
|
+
lastModifiedBy?: string
|
|
87
|
+
/** 创建时间 */
|
|
88
|
+
created?: Date
|
|
89
|
+
/** 修改时间 */
|
|
90
|
+
modified?: Date
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const props = withDefaults(defineProps<ExportOptions>(), {
|
|
95
|
+
filename: () => `export_${new Date().toISOString().slice(0, 10)}`,
|
|
96
|
+
sheetName: 'Sheet1',
|
|
97
|
+
type: 'primary',
|
|
98
|
+
size: 'default',
|
|
99
|
+
disabled: false,
|
|
100
|
+
buttonText: '导出 Excel',
|
|
101
|
+
loadingText: '导出中...',
|
|
102
|
+
autoIndex: false,
|
|
103
|
+
indexColumnTitle: '序号',
|
|
104
|
+
columns: () => ({}),
|
|
105
|
+
headers: () => ({}),
|
|
106
|
+
maxRows: 100000,
|
|
107
|
+
showSuccessMessage: true,
|
|
108
|
+
showErrorMessage: true,
|
|
109
|
+
workbookOptions: () => ({})
|
|
110
|
+
})
|
|
111
|
+
|
|
112
|
+
const emit = defineEmits<{
|
|
113
|
+
'before-export': [data: ExportData[]]
|
|
114
|
+
'export-success': [filename: string, rowCount: number]
|
|
115
|
+
'export-error': [error: ExportError]
|
|
116
|
+
'export-progress': [progress: number]
|
|
117
|
+
}>()
|
|
118
|
+
|
|
119
|
+
/** 导出错误类型 */
|
|
120
|
+
class ExportError extends Error {
|
|
121
|
+
constructor(
|
|
122
|
+
message: string,
|
|
123
|
+
public code: string,
|
|
124
|
+
public details?: any
|
|
125
|
+
) {
|
|
126
|
+
super(message)
|
|
127
|
+
this.name = 'ExportError'
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const isExporting = ref(false)
|
|
132
|
+
|
|
133
|
+
/** 是否有数据可导出 */
|
|
134
|
+
const hasData = computed(() => Array.isArray(props.data) && props.data.length > 0)
|
|
135
|
+
|
|
136
|
+
/** 验证导出数据 */
|
|
137
|
+
const validateData = (data: ExportData[]): void => {
|
|
138
|
+
if (!Array.isArray(data)) {
|
|
139
|
+
throw new ExportError('数据必须是数组格式', 'INVALID_DATA_TYPE')
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
if (data.length === 0) {
|
|
143
|
+
throw new ExportError('没有可导出的数据', 'NO_DATA')
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
if (data.length > props.maxRows) {
|
|
147
|
+
throw new ExportError(`数据行数超过限制(${props.maxRows}行)`, 'EXCEED_MAX_ROWS', {
|
|
148
|
+
currentRows: data.length,
|
|
149
|
+
maxRows: props.maxRows
|
|
150
|
+
})
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/** 格式化单元格值 */
|
|
155
|
+
const formatCellValue = (
|
|
156
|
+
value: ExportValue,
|
|
157
|
+
key: string,
|
|
158
|
+
row: ExportData,
|
|
159
|
+
index: number
|
|
160
|
+
): string => {
|
|
161
|
+
// 使用列配置的格式化函数
|
|
162
|
+
const column = props.columns[key]
|
|
163
|
+
if (column?.formatter) {
|
|
164
|
+
return column.formatter(value, row, index)
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// 处理特殊值
|
|
168
|
+
if (value === null || value === undefined) {
|
|
169
|
+
return ''
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
if (value instanceof Date) {
|
|
173
|
+
return value.toLocaleDateString('zh-CN')
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
if (typeof value === 'boolean') {
|
|
177
|
+
return value ? '是' : '否'
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
return String(value)
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/** 处理数据 */
|
|
184
|
+
const processData = (data: ExportData[]): Record<string, string>[] => {
|
|
185
|
+
const processedData = data.map((item, index) => {
|
|
186
|
+
const processedItem: Record<string, string> = {}
|
|
187
|
+
|
|
188
|
+
// 添加序号列
|
|
189
|
+
if (props.autoIndex) {
|
|
190
|
+
processedItem[props.indexColumnTitle] = String(index + 1)
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// 处理数据列
|
|
194
|
+
Object.entries(item).forEach(([key, value]) => {
|
|
195
|
+
// 获取列标题
|
|
196
|
+
let columnTitle = key
|
|
197
|
+
if (props.columns[key]?.title) {
|
|
198
|
+
columnTitle = props.columns[key].title
|
|
199
|
+
} else if (props.headers[key]) {
|
|
200
|
+
columnTitle = props.headers[key]
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// 格式化值
|
|
204
|
+
processedItem[columnTitle] = formatCellValue(value, key, item, index)
|
|
205
|
+
})
|
|
206
|
+
|
|
207
|
+
return processedItem
|
|
208
|
+
})
|
|
209
|
+
|
|
210
|
+
return processedData
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/** 计算列宽度 */
|
|
214
|
+
const calculateColumnWidths = (data: Record<string, string>[]): XLSX.ColInfo[] => {
|
|
215
|
+
if (data.length === 0) return []
|
|
216
|
+
|
|
217
|
+
const sampleSize = Math.min(data.length, 100) // 只取前100行计算列宽
|
|
218
|
+
const columns = Object.keys(data[0])
|
|
219
|
+
|
|
220
|
+
return columns.map((column) => {
|
|
221
|
+
// 使用配置的列宽度
|
|
222
|
+
const configWidth = Object.values(props.columns).find((col) => col.title === column)?.width
|
|
223
|
+
|
|
224
|
+
if (configWidth) {
|
|
225
|
+
return { wch: configWidth }
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// 自动计算列宽度
|
|
229
|
+
const maxLength = Math.max(
|
|
230
|
+
column.length, // 标题长度
|
|
231
|
+
...data.slice(0, sampleSize).map((row) => String(row[column] || '').length)
|
|
232
|
+
)
|
|
233
|
+
|
|
234
|
+
// 限制最小和最大宽度
|
|
235
|
+
const width = Math.min(Math.max(maxLength + 2, 8), 50)
|
|
236
|
+
return { wch: width }
|
|
237
|
+
})
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/** 导出到 Excel */
|
|
241
|
+
const exportToExcel = async (
|
|
242
|
+
data: ExportData[],
|
|
243
|
+
filename: string,
|
|
244
|
+
sheetName: string
|
|
245
|
+
): Promise<void> => {
|
|
246
|
+
try {
|
|
247
|
+
emit('export-progress', 10)
|
|
248
|
+
|
|
249
|
+
// 处理数据
|
|
250
|
+
const processedData = processData(data)
|
|
251
|
+
emit('export-progress', 30)
|
|
252
|
+
|
|
253
|
+
// 创建工作簿
|
|
254
|
+
const workbook = XLSX.utils.book_new()
|
|
255
|
+
|
|
256
|
+
// 设置工作簿属性
|
|
257
|
+
if (props.workbookOptions) {
|
|
258
|
+
workbook.Props = {
|
|
259
|
+
Title: filename,
|
|
260
|
+
Subject: '数据导出',
|
|
261
|
+
Author: props.workbookOptions.creator || AppConfig.systemInfo.name,
|
|
262
|
+
Manager: props.workbookOptions.lastModifiedBy || '',
|
|
263
|
+
Company: '系统导出',
|
|
264
|
+
Category: '数据',
|
|
265
|
+
Keywords: 'excel,export,data',
|
|
266
|
+
Comments: '由系统自动生成',
|
|
267
|
+
CreatedDate: props.workbookOptions.created || new Date(),
|
|
268
|
+
ModifiedDate: props.workbookOptions.modified || new Date()
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
emit('export-progress', 50)
|
|
273
|
+
|
|
274
|
+
// 创建工作表
|
|
275
|
+
const worksheet = XLSX.utils.json_to_sheet(processedData)
|
|
276
|
+
|
|
277
|
+
// 设置列宽度
|
|
278
|
+
worksheet['!cols'] = calculateColumnWidths(processedData)
|
|
279
|
+
|
|
280
|
+
emit('export-progress', 70)
|
|
281
|
+
|
|
282
|
+
// 添加工作表到工作簿
|
|
283
|
+
XLSX.utils.book_append_sheet(workbook, worksheet, sheetName)
|
|
284
|
+
|
|
285
|
+
emit('export-progress', 85)
|
|
286
|
+
|
|
287
|
+
// 生成 Excel 文件
|
|
288
|
+
const excelBuffer = XLSX.write(workbook, {
|
|
289
|
+
bookType: 'xlsx',
|
|
290
|
+
type: 'array',
|
|
291
|
+
compression: true
|
|
292
|
+
})
|
|
293
|
+
|
|
294
|
+
// 创建 Blob 并下载
|
|
295
|
+
const blob = new Blob([excelBuffer], {
|
|
296
|
+
type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
|
|
297
|
+
})
|
|
298
|
+
|
|
299
|
+
emit('export-progress', 95)
|
|
300
|
+
|
|
301
|
+
// 使用时间戳确保文件名唯一
|
|
302
|
+
const timestamp = new Date().toISOString().replace(/[:.]/g, '-')
|
|
303
|
+
const finalFilename = `${filename}_${timestamp}.xlsx`
|
|
304
|
+
|
|
305
|
+
FileSaver.saveAs(blob, finalFilename)
|
|
306
|
+
|
|
307
|
+
emit('export-progress', 100)
|
|
308
|
+
|
|
309
|
+
// 等待下载开始
|
|
310
|
+
await nextTick()
|
|
311
|
+
|
|
312
|
+
return Promise.resolve()
|
|
313
|
+
} catch (error) {
|
|
314
|
+
throw new ExportError(`Excel 导出失败: ${(error as Error).message}`, 'EXPORT_FAILED', error)
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
/** 处理导出 */
|
|
319
|
+
const handleExport = useThrottleFn(async () => {
|
|
320
|
+
if (isExporting.value) return
|
|
321
|
+
|
|
322
|
+
isExporting.value = true
|
|
323
|
+
|
|
324
|
+
try {
|
|
325
|
+
// 验证数据
|
|
326
|
+
validateData(props.data)
|
|
327
|
+
|
|
328
|
+
// 触发导出前事件
|
|
329
|
+
emit('before-export', props.data)
|
|
330
|
+
|
|
331
|
+
// 执行导出
|
|
332
|
+
await exportToExcel(props.data, props.filename, props.sheetName)
|
|
333
|
+
|
|
334
|
+
// 触发成功事件
|
|
335
|
+
emit('export-success', props.filename, props.data.length)
|
|
336
|
+
|
|
337
|
+
// 显示成功消息
|
|
338
|
+
if (props.showSuccessMessage) {
|
|
339
|
+
ElMessage.success({
|
|
340
|
+
message: `成功导出 ${props.data.length} 条数据`,
|
|
341
|
+
duration: 3000
|
|
342
|
+
})
|
|
343
|
+
}
|
|
344
|
+
} catch (error) {
|
|
345
|
+
const exportError =
|
|
346
|
+
error instanceof ExportError
|
|
347
|
+
? error
|
|
348
|
+
: new ExportError(`导出失败: ${(error as Error).message}`, 'UNKNOWN_ERROR', error)
|
|
349
|
+
|
|
350
|
+
// 触发错误事件
|
|
351
|
+
emit('export-error', exportError)
|
|
352
|
+
|
|
353
|
+
// 显示错误消息
|
|
354
|
+
if (props.showErrorMessage) {
|
|
355
|
+
ElMessage.error({
|
|
356
|
+
message: exportError.message,
|
|
357
|
+
duration: 5000
|
|
358
|
+
})
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
console.error('Excel 导出错误:', exportError)
|
|
362
|
+
} finally {
|
|
363
|
+
isExporting.value = false
|
|
364
|
+
emit('export-progress', 0)
|
|
365
|
+
}
|
|
366
|
+
}, 1000)
|
|
367
|
+
|
|
368
|
+
// 暴露方法供父组件调用
|
|
369
|
+
defineExpose({
|
|
370
|
+
exportData: handleExport,
|
|
371
|
+
isExporting: readonly(isExporting),
|
|
372
|
+
hasData
|
|
373
|
+
})
|
|
374
|
+
</script>
|
|
375
|
+
|
|
376
|
+
<style scoped>
|
|
377
|
+
.is-loading {
|
|
378
|
+
animation: rotating 2s linear infinite;
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
@keyframes rotating {
|
|
382
|
+
0% {
|
|
383
|
+
transform: rotate(0deg);
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
100% {
|
|
387
|
+
transform: rotate(360deg);
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
</style>
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
<!-- 导入 Excel 文件 -->
|
|
2
|
+
<template>
|
|
3
|
+
<div class="inline-block">
|
|
4
|
+
<ElUpload
|
|
5
|
+
:auto-upload="false"
|
|
6
|
+
accept=".xlsx, .xls"
|
|
7
|
+
:show-file-list="false"
|
|
8
|
+
@change="handleFileChange"
|
|
9
|
+
>
|
|
10
|
+
<ElButton type="primary" v-ripple>
|
|
11
|
+
<slot>导入 Excel</slot>
|
|
12
|
+
</ElButton>
|
|
13
|
+
</ElUpload>
|
|
14
|
+
</div>
|
|
15
|
+
</template>
|
|
16
|
+
|
|
17
|
+
<script setup lang="ts">
|
|
18
|
+
import * as XLSX from '@e965/xlsx'
|
|
19
|
+
import type { UploadFile } from 'element-plus'
|
|
20
|
+
|
|
21
|
+
defineOptions({ name: 'ArtExcelImport' })
|
|
22
|
+
|
|
23
|
+
// Excel 导入工具函数
|
|
24
|
+
async function importExcel(file: File): Promise<Array<Record<string, unknown>>> {
|
|
25
|
+
return new Promise((resolve, reject) => {
|
|
26
|
+
const reader = new FileReader()
|
|
27
|
+
|
|
28
|
+
reader.onload = (e) => {
|
|
29
|
+
try {
|
|
30
|
+
const data = e.target?.result
|
|
31
|
+
const workbook = XLSX.read(data, { type: 'array' })
|
|
32
|
+
const firstSheetName = workbook.SheetNames[0]
|
|
33
|
+
const worksheet = workbook.Sheets[firstSheetName]
|
|
34
|
+
const results = XLSX.utils.sheet_to_json(worksheet)
|
|
35
|
+
resolve(results as Array<Record<string, unknown>>)
|
|
36
|
+
} catch (error) {
|
|
37
|
+
reject(error)
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
reader.onerror = (error) => reject(error)
|
|
42
|
+
reader.readAsArrayBuffer(file)
|
|
43
|
+
})
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// 定义 emits
|
|
47
|
+
const emit = defineEmits<{
|
|
48
|
+
'import-success': [data: Array<Record<string, unknown>>]
|
|
49
|
+
'import-error': [error: Error]
|
|
50
|
+
}>()
|
|
51
|
+
|
|
52
|
+
// 处理文件导入
|
|
53
|
+
const handleFileChange = async (uploadFile: UploadFile) => {
|
|
54
|
+
try {
|
|
55
|
+
if (!uploadFile.raw) return
|
|
56
|
+
const results = await importExcel(uploadFile.raw)
|
|
57
|
+
emit('import-success', results)
|
|
58
|
+
} catch (error) {
|
|
59
|
+
emit('import-error', error as Error)
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
</script>
|