@smallwei/avue 3.8.2 → 3.8.4
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/README.md +206 -86
- package/dist/avue.js +37302 -0
- package/dist/avue.js.map +1 -0
- package/dist/avue.min.js +6 -0
- package/dist/avue.min.mjs +2 -0
- package/dist/avue.mjs +2 -0
- package/dist/index.css +1 -0
- package/es/avue.min.mjs +2 -0
- package/es/avue.min.ts +2 -0
- package/es/avue.mjs +2 -0
- package/es/avue.ts +2 -0
- package/es/core/create.mjs +8 -0
- package/es/core/create.ts +16 -0
- package/es/core/dataformat.mjs +184 -0
- package/es/core/dataformat.ts +190 -0
- package/es/core/detail.mjs +74 -0
- package/es/core/detail.ts +81 -0
- package/es/core/dic.mjs +213 -0
- package/es/core/dic.ts +235 -0
- package/es/core/locale.mjs +8 -0
- package/es/core/locale.ts +9 -0
- package/es/core/packages.mjs +61 -0
- package/es/core/packages.ts +62 -0
- package/es/core/slot.mjs +32 -0
- package/es/core/slot.ts +30 -0
- package/es/global/variable.mjs +80 -0
- package/es/global/variable.ts +84 -0
- package/es/icon.mjs +9 -0
- package/es/icon.ts +11 -0
- package/es/index.mjs +127 -0
- package/es/index.ts +177 -0
- package/es/locale/browser/en.mjs +288 -0
- package/es/locale/browser/zh-cn.mjs +288 -0
- package/es/locale/browser/zh.mjs +288 -0
- package/es/locale/index.mjs +141 -0
- package/es/locale/index.ts +196 -0
- package/es/locale/lang/en.mjs +282 -0
- package/es/locale/lang/en.ts +282 -0
- package/es/locale/lang/zh-cn.mjs +282 -0
- package/es/locale/lang/zh-cn.ts +282 -0
- package/es/locale/lang/zh.mjs +282 -0
- package/es/locale/lang/zh.ts +282 -0
- package/es/packages/core/common/event.mjs +58 -0
- package/es/packages/core/common/event.ts +56 -0
- package/es/packages/core/common/init.mjs +134 -0
- package/es/packages/core/common/init.ts +133 -0
- package/es/packages/core/common/props.mjs +239 -0
- package/es/packages/core/common/props.ts +240 -0
- package/es/packages/core/components/dialog-form/index.mjs +29 -0
- package/es/packages/core/components/dialog-form/index.ts +29 -0
- package/es/packages/core/components/dialog-form/index.vue +108 -0
- package/es/packages/core/components/form/custom.mjs +41 -0
- package/es/packages/core/components/form/custom.ts +41 -0
- package/es/packages/core/components/form/index.vue +176 -0
- package/es/packages/core/components/icon/index.vue +37 -0
- package/es/packages/core/components/image-preview/index.mjs +34 -0
- package/es/packages/core/components/image-preview/index.ts +37 -0
- package/es/packages/core/components/image-preview/index.vue +215 -0
- package/es/packages/core/directive/contextmenu.mjs +92 -0
- package/es/packages/core/directive/contextmenu.ts +103 -0
- package/es/packages/core/directive/permission.mjs +19 -0
- package/es/packages/core/directive/permission.ts +18 -0
- package/es/packages/data/box/index.vue +66 -0
- package/es/packages/data/card/index.vue +62 -0
- package/es/packages/data/cardText/index.vue +56 -0
- package/es/packages/data/countdown/index.vue +81 -0
- package/es/packages/data/dashboard/index.vue +72 -0
- package/es/packages/data/display/index.vue +63 -0
- package/es/packages/data/icons/index.vue +68 -0
- package/es/packages/data/imgText/index.vue +72 -0
- package/es/packages/data/list/index.vue +69 -0
- package/es/packages/data/notice/index.vue +63 -0
- package/es/packages/data/operaText/index.vue +62 -0
- package/es/packages/data/panel/index.vue +62 -0
- package/es/packages/data/pay/index.vue +92 -0
- package/es/packages/data/price/index.vue +55 -0
- package/es/packages/data/product/index.vue +106 -0
- package/es/packages/data/profile/index.vue +91 -0
- package/es/packages/data/progress/index.vue +64 -0
- package/es/packages/data/rank/index.vue +92 -0
- package/es/packages/data/rotate/index.vue +69 -0
- package/es/packages/data/statistic/index.vue +71 -0
- package/es/packages/data/tabs/index.vue +64 -0
- package/es/packages/data/task/index.vue +82 -0
- package/es/packages/data/weather/index.vue +103 -0
- package/es/packages/element-plus/array/index.vue +115 -0
- package/es/packages/element-plus/article/index.vue +73 -0
- package/es/packages/element-plus/card/index.vue +103 -0
- package/es/packages/element-plus/cascader/index.vue +132 -0
- package/es/packages/element-plus/chat/index.vue +513 -0
- package/es/packages/element-plus/checkbox/index.vue +84 -0
- package/es/packages/element-plus/comment/index.vue +76 -0
- package/es/packages/element-plus/count-up/index.vue +109 -0
- package/es/packages/element-plus/crud/column/column-default.vue +128 -0
- package/es/packages/element-plus/crud/column/column-dynamic.vue +86 -0
- package/es/packages/element-plus/crud/column/column-menu.vue +267 -0
- package/es/packages/element-plus/crud/column/column-slot.vue +348 -0
- package/es/packages/element-plus/crud/column/column.vue +119 -0
- package/es/packages/element-plus/crud/column/menu.vue +78 -0
- package/es/packages/element-plus/crud/config.mjs +74 -0
- package/es/packages/element-plus/crud/config.ts +74 -0
- package/es/packages/element-plus/crud/dialog/dialog-column.vue +102 -0
- package/es/packages/element-plus/crud/dialog/dialog-excel.vue +204 -0
- package/es/packages/element-plus/crud/dialog/dialog-filter.vue +159 -0
- package/es/packages/element-plus/crud/dialog/dialog-form.vue +352 -0
- package/es/packages/element-plus/crud/grid/index.vue +271 -0
- package/es/packages/element-plus/crud/grid/item.vue +39 -0
- package/es/packages/element-plus/crud/index.vue +1018 -0
- package/es/packages/element-plus/crud/menu/header-menu.vue +175 -0
- package/es/packages/element-plus/crud/menu/header-search.vue +228 -0
- package/es/packages/element-plus/crud/menu/table-page.vue +108 -0
- package/es/packages/element-plus/date/index.vue +81 -0
- package/es/packages/element-plus/draggable/index.vue +444 -0
- package/es/packages/element-plus/dynamic/index.vue +353 -0
- package/es/packages/element-plus/flow/index.vue +339 -0
- package/es/packages/element-plus/flow/node.vue +84 -0
- package/es/packages/element-plus/form/config.mjs +6 -0
- package/es/packages/element-plus/form/config.ts +6 -0
- package/es/packages/element-plus/form/index.vue +954 -0
- package/es/packages/element-plus/form/menu.vue +63 -0
- package/es/packages/element-plus/group/index.vue +90 -0
- package/es/packages/element-plus/input/index.vue +1264 -0
- package/es/packages/element-plus/input-color/index.vue +70 -0
- package/es/packages/element-plus/input-cron/index.vue +363 -0
- package/es/packages/element-plus/input-icon/index.vue +143 -0
- package/es/packages/element-plus/input-map/index.vue +311 -0
- package/es/packages/element-plus/input-number/index.vue +91 -0
- package/es/packages/element-plus/input-table/index.vue +279 -0
- package/es/packages/element-plus/input-tag/index.vue +79 -0
- package/es/packages/element-plus/input-tree/index.vue +194 -0
- package/es/packages/element-plus/license/index.vue +155 -0
- package/es/packages/element-plus/login/index.vue +203 -0
- package/es/packages/element-plus/mention/index.vue +117 -0
- package/es/packages/element-plus/radio/index.vue +38 -0
- package/es/packages/element-plus/rate/index.vue +51 -0
- package/es/packages/element-plus/search/index.vue +129 -0
- package/es/packages/element-plus/select/index.vue +292 -0
- package/es/packages/element-plus/sign/index.vue +230 -0
- package/es/packages/element-plus/slider/index.vue +66 -0
- package/es/packages/element-plus/switch/index.vue +72 -0
- package/es/packages/element-plus/tabs/index.vue +62 -0
- package/es/packages/element-plus/text-ellipsis/index.vue +104 -0
- package/es/packages/element-plus/time/index.vue +81 -0
- package/es/packages/element-plus/title/index.vue +30 -0
- package/es/packages/element-plus/tree/index.vue +460 -0
- package/es/packages/element-plus/upload/index.vue +728 -0
- package/es/packages/element-plus/verify/index.vue +62 -0
- package/es/packages/element-plus/video/index.vue +90 -0
- package/es/plugin/ali/index.mjs +4 -0
- package/es/plugin/ali/index.ts +6 -0
- package/es/plugin/clipboard/index.mjs +61 -0
- package/es/plugin/clipboard/index.ts +67 -0
- package/es/plugin/export/_blob.mjs +151 -0
- package/es/plugin/export/_blob.ts +176 -0
- package/es/plugin/export/_export2Excel.mjs +141 -0
- package/es/plugin/export/_export2Excel.ts +166 -0
- package/es/plugin/export/index.mjs +263 -0
- package/es/plugin/export/index.ts +274 -0
- package/es/plugin/logs/index.mjs +46 -0
- package/es/plugin/logs/index.ts +66 -0
- package/es/plugin/print/index.mjs +145 -0
- package/es/plugin/print/index.ts +155 -0
- package/es/plugin/qiniu/index.mjs +78 -0
- package/es/plugin/qiniu/index.ts +88 -0
- package/es/plugin/screenshot/index.mjs +8 -0
- package/es/plugin/screenshot/index.ts +9 -0
- package/es/plugin/video/index.mjs +52 -0
- package/es/plugin/video/index.ts +60 -0
- package/es/plugin/watermark/index.mjs +114 -0
- package/es/plugin/watermark/index.ts +127 -0
- package/es/plugin/watermark/watermark.mjs +109 -0
- package/es/plugin/watermark/watermark.ts +121 -0
- package/es/ui/data/index.mjs +49 -0
- package/es/ui/data/index.ts +51 -0
- package/es/ui/element-plus/index.mjs +87 -0
- package/es/ui/element-plus/index.ts +89 -0
- package/es/ui/index.mjs +4 -0
- package/es/ui/index.ts +6 -0
- package/es/utils/bem.mjs +29 -0
- package/es/utils/bem.ts +36 -0
- package/es/utils/mock.mjs +137 -0
- package/es/utils/mock.ts +151 -0
- package/es/utils/util.mjs +370 -0
- package/es/utils/util.ts +392 -0
- package/es/utils/validate.mjs +18 -0
- package/es/utils/validate.ts +23 -0
- package/es/version.mjs +1 -0
- package/es/version.ts +1 -0
- package/lib/avue.js +11 -35880
- package/lib/avue.min.js +11 -6
- package/lib/avue.min.ts +2 -0
- package/lib/avue.ts +2 -0
- package/lib/core/create.js +14 -0
- package/lib/core/create.ts +16 -0
- package/lib/core/dataformat.js +194 -0
- package/lib/core/dataformat.ts +190 -0
- package/lib/core/detail.js +81 -0
- package/lib/core/detail.ts +81 -0
- package/lib/core/dic.js +220 -0
- package/lib/core/dic.ts +235 -0
- package/lib/core/locale.js +10 -0
- package/lib/core/locale.ts +9 -0
- package/lib/core/packages.js +66 -0
- package/lib/core/packages.ts +62 -0
- package/lib/core/slot.js +34 -0
- package/lib/core/slot.ts +30 -0
- package/lib/global/variable.js +83 -0
- package/lib/global/variable.ts +84 -0
- package/lib/icon.js +44 -0
- package/lib/icon.ts +11 -0
- package/lib/index.js +134 -0
- package/lib/index.ts +177 -0
- package/lib/locale/browser/en.js +288 -0
- package/lib/locale/browser/zh-cn.js +288 -0
- package/lib/locale/browser/zh.js +288 -0
- package/lib/locale/index.js +153 -47
- package/lib/locale/index.ts +196 -0
- package/lib/locale/lang/en.js +284 -100
- package/lib/locale/lang/en.ts +282 -0
- package/lib/locale/lang/zh-cn.js +284 -0
- package/lib/locale/lang/zh-cn.ts +282 -0
- package/lib/locale/lang/zh.js +284 -100
- package/lib/locale/lang/zh.ts +282 -0
- package/lib/packages/core/common/event.js +61 -0
- package/lib/packages/core/common/event.ts +56 -0
- package/lib/packages/core/common/init.js +140 -0
- package/lib/packages/core/common/init.ts +133 -0
- package/lib/packages/core/common/props.js +245 -0
- package/lib/packages/core/common/props.ts +240 -0
- package/lib/packages/core/components/dialog-form/index.js +35 -0
- package/lib/packages/core/components/dialog-form/index.ts +29 -0
- package/lib/packages/core/components/dialog-form/index.vue +108 -0
- package/lib/packages/core/components/form/custom.js +43 -0
- package/lib/packages/core/components/form/custom.ts +41 -0
- package/lib/packages/core/components/form/index.vue +176 -0
- package/lib/packages/core/components/icon/index.vue +37 -0
- package/lib/packages/core/components/image-preview/index.js +40 -0
- package/lib/packages/core/components/image-preview/index.ts +37 -0
- package/lib/packages/core/components/image-preview/index.vue +215 -0
- package/lib/packages/core/directive/contextmenu.js +94 -0
- package/lib/packages/core/directive/contextmenu.ts +103 -0
- package/lib/packages/core/directive/permission.js +21 -0
- package/lib/packages/core/directive/permission.ts +18 -0
- package/lib/packages/data/box/index.vue +66 -0
- package/lib/packages/data/card/index.vue +62 -0
- package/lib/packages/data/cardText/index.vue +56 -0
- package/lib/packages/data/countdown/index.vue +81 -0
- package/lib/packages/data/dashboard/index.vue +72 -0
- package/lib/packages/data/display/index.vue +63 -0
- package/lib/packages/data/icons/index.vue +68 -0
- package/lib/packages/data/imgText/index.vue +72 -0
- package/lib/packages/data/list/index.vue +69 -0
- package/lib/packages/data/notice/index.vue +63 -0
- package/lib/packages/data/operaText/index.vue +62 -0
- package/lib/packages/data/panel/index.vue +62 -0
- package/lib/packages/data/pay/index.vue +92 -0
- package/lib/packages/data/price/index.vue +55 -0
- package/lib/packages/data/product/index.vue +106 -0
- package/lib/packages/data/profile/index.vue +91 -0
- package/lib/packages/data/progress/index.vue +64 -0
- package/lib/packages/data/rank/index.vue +92 -0
- package/lib/packages/data/rotate/index.vue +69 -0
- package/lib/packages/data/statistic/index.vue +71 -0
- package/lib/packages/data/tabs/index.vue +64 -0
- package/lib/packages/data/task/index.vue +82 -0
- package/lib/packages/data/weather/index.vue +103 -0
- package/lib/packages/element-plus/array/index.vue +115 -0
- package/lib/packages/element-plus/article/index.vue +73 -0
- package/lib/packages/element-plus/card/index.vue +103 -0
- package/lib/packages/element-plus/cascader/index.vue +132 -0
- package/lib/packages/element-plus/chat/index.vue +513 -0
- package/lib/packages/element-plus/checkbox/index.vue +84 -0
- package/lib/packages/element-plus/comment/index.vue +76 -0
- package/lib/packages/element-plus/count-up/index.vue +109 -0
- package/lib/packages/element-plus/crud/column/column-default.vue +128 -0
- package/lib/packages/element-plus/crud/column/column-dynamic.vue +86 -0
- package/lib/packages/element-plus/crud/column/column-menu.vue +267 -0
- package/lib/packages/element-plus/crud/column/column-slot.vue +348 -0
- package/lib/packages/element-plus/crud/column/column.vue +119 -0
- package/lib/packages/element-plus/crud/column/menu.vue +78 -0
- package/lib/packages/element-plus/crud/config.js +76 -0
- package/lib/packages/element-plus/crud/config.ts +74 -0
- package/lib/packages/element-plus/crud/dialog/dialog-column.vue +102 -0
- package/lib/packages/element-plus/crud/dialog/dialog-excel.vue +204 -0
- package/lib/packages/element-plus/crud/dialog/dialog-filter.vue +159 -0
- package/lib/packages/element-plus/crud/dialog/dialog-form.vue +352 -0
- package/lib/packages/element-plus/crud/grid/index.vue +271 -0
- package/lib/packages/element-plus/crud/grid/item.vue +39 -0
- package/lib/packages/element-plus/crud/index.vue +1018 -0
- package/lib/packages/element-plus/crud/menu/header-menu.vue +175 -0
- package/lib/packages/element-plus/crud/menu/header-search.vue +228 -0
- package/lib/packages/element-plus/crud/menu/table-page.vue +108 -0
- package/lib/packages/element-plus/date/index.vue +81 -0
- package/lib/packages/element-plus/draggable/index.vue +444 -0
- package/lib/packages/element-plus/dynamic/index.vue +353 -0
- package/lib/packages/element-plus/flow/index.vue +339 -0
- package/lib/packages/element-plus/flow/node.vue +84 -0
- package/lib/packages/element-plus/form/config.js +8 -0
- package/lib/packages/element-plus/form/config.ts +6 -0
- package/lib/packages/element-plus/form/index.vue +954 -0
- package/lib/packages/element-plus/form/menu.vue +63 -0
- package/lib/packages/element-plus/group/index.vue +90 -0
- package/lib/packages/element-plus/input/index.vue +1264 -0
- package/lib/packages/element-plus/input-color/index.vue +70 -0
- package/lib/packages/element-plus/input-cron/index.vue +363 -0
- package/lib/packages/element-plus/input-icon/index.vue +143 -0
- package/lib/packages/element-plus/input-map/index.vue +311 -0
- package/lib/packages/element-plus/input-number/index.vue +91 -0
- package/lib/packages/element-plus/input-table/index.vue +279 -0
- package/lib/packages/element-plus/input-tag/index.vue +79 -0
- package/lib/packages/element-plus/input-tree/index.vue +194 -0
- package/lib/packages/element-plus/license/index.vue +155 -0
- package/lib/packages/element-plus/login/index.vue +203 -0
- package/lib/packages/element-plus/mention/index.vue +117 -0
- package/lib/packages/element-plus/radio/index.vue +38 -0
- package/lib/packages/element-plus/rate/index.vue +51 -0
- package/lib/packages/element-plus/search/index.vue +129 -0
- package/lib/packages/element-plus/select/index.vue +292 -0
- package/lib/packages/element-plus/sign/index.vue +230 -0
- package/lib/packages/element-plus/slider/index.vue +66 -0
- package/lib/packages/element-plus/switch/index.vue +72 -0
- package/lib/packages/element-plus/tabs/index.vue +62 -0
- package/lib/packages/element-plus/text-ellipsis/index.vue +104 -0
- package/lib/packages/element-plus/time/index.vue +81 -0
- package/lib/packages/element-plus/title/index.vue +30 -0
- package/lib/packages/element-plus/tree/index.vue +460 -0
- package/lib/packages/element-plus/upload/index.vue +728 -0
- package/lib/packages/element-plus/verify/index.vue +62 -0
- package/lib/packages/element-plus/video/index.vue +90 -0
- package/lib/plugin/ali/index.js +8 -0
- package/lib/plugin/ali/index.ts +6 -0
- package/lib/plugin/clipboard/index.js +64 -0
- package/lib/plugin/clipboard/index.ts +67 -0
- package/lib/plugin/export/_blob.js +151 -0
- package/lib/plugin/export/_blob.ts +176 -0
- package/lib/plugin/export/_export2Excel.js +145 -0
- package/lib/plugin/export/_export2Excel.ts +166 -0
- package/lib/plugin/export/index.js +268 -0
- package/lib/plugin/export/index.ts +274 -0
- package/lib/plugin/logs/index.js +48 -0
- package/lib/plugin/logs/index.ts +66 -0
- package/lib/plugin/print/index.js +147 -0
- package/lib/plugin/print/index.ts +155 -0
- package/lib/plugin/qiniu/index.js +82 -0
- package/lib/plugin/qiniu/index.ts +88 -0
- package/lib/plugin/screenshot/index.js +14 -0
- package/lib/plugin/screenshot/index.ts +9 -0
- package/lib/plugin/video/index.js +55 -0
- package/lib/plugin/video/index.ts +60 -0
- package/lib/plugin/watermark/index.js +121 -0
- package/lib/plugin/watermark/index.ts +127 -0
- package/lib/plugin/watermark/watermark.js +111 -0
- package/lib/plugin/watermark/watermark.ts +121 -0
- package/lib/ui/data/index.js +54 -0
- package/lib/ui/data/index.ts +51 -0
- package/lib/ui/element-plus/index.js +92 -0
- package/lib/ui/element-plus/index.ts +89 -0
- package/lib/ui/index.js +9 -0
- package/lib/ui/index.ts +6 -0
- package/lib/utils/bem.js +31 -0
- package/lib/utils/bem.ts +36 -0
- package/lib/utils/mock.js +142 -0
- package/lib/utils/mock.ts +151 -0
- package/lib/utils/util.js +403 -0
- package/lib/utils/util.ts +392 -0
- package/lib/utils/validate.js +21 -0
- package/lib/utils/validate.ts +23 -0
- package/lib/version.js +4 -0
- package/lib/version.ts +1 -0
- package/package.json +20 -10
- package/types/index.d.ts +139 -47
- package/types/shims-aliases.d.ts +4 -0
- package/lib/avue.js.map +0 -1
- package/lib/locale/format.js +0 -44
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
|
|
3
|
+
import { isJson, downFile, validData } from '../../utils/util';
|
|
4
|
+
import packages from '../../core/packages';
|
|
5
|
+
import dayjs from 'dayjs';
|
|
6
|
+
|
|
7
|
+
declare global {
|
|
8
|
+
interface Window {
|
|
9
|
+
XLSX: any;
|
|
10
|
+
saveAs: any;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const XLSX = window.XLSX;
|
|
15
|
+
|
|
16
|
+
export default {
|
|
17
|
+
buildHeader(revealList: any[]) {
|
|
18
|
+
const excelHeader: any[] = [];
|
|
19
|
+
this.getHeader(revealList, excelHeader, 0, 0);
|
|
20
|
+
const max = Math.max(...excelHeader.map((a: any[]) => a.length));
|
|
21
|
+
excelHeader
|
|
22
|
+
.filter((e: any[]) => e.length < max)
|
|
23
|
+
.forEach((e: any[]) => this.pushRowSpanPlaceHolder(e, max - e.length));
|
|
24
|
+
return excelHeader;
|
|
25
|
+
},
|
|
26
|
+
|
|
27
|
+
getHeader(headers: any[], excelHeader: any[], deep: number, perOffset: number) {
|
|
28
|
+
let offset = 0;
|
|
29
|
+
let cur = excelHeader[deep];
|
|
30
|
+
if (!cur) {
|
|
31
|
+
cur = excelHeader[deep] = [];
|
|
32
|
+
}
|
|
33
|
+
this.pushRowSpanPlaceHolder(cur, perOffset - cur.length);
|
|
34
|
+
for (let i = 0; i < headers.length; i++) {
|
|
35
|
+
const head = headers[i];
|
|
36
|
+
cur.push(head.label);
|
|
37
|
+
if (head.hasOwnProperty('children') && Array.isArray(head.children) && head.children.length > 0) {
|
|
38
|
+
const childOffset = this.getHeader(head.children, excelHeader, deep + 1, cur.length - 1);
|
|
39
|
+
this.pushColSpanPlaceHolder(cur, childOffset - 1);
|
|
40
|
+
offset += childOffset;
|
|
41
|
+
} else {
|
|
42
|
+
offset++;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return offset;
|
|
46
|
+
},
|
|
47
|
+
|
|
48
|
+
pushRowSpanPlaceHolder(arr: any[], count: number) {
|
|
49
|
+
for (let i = 0; i < count; i++) {
|
|
50
|
+
arr.push('!$ROW_SPAN_PLACEHOLDER');
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
|
|
54
|
+
pushColSpanPlaceHolder(arr: any[], count: number) {
|
|
55
|
+
for (let i = 0; i < count; i++) {
|
|
56
|
+
arr.push('!$COL_SPAN_PLACEHOLDER');
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
|
|
60
|
+
doMerges(arr: any[][]) {
|
|
61
|
+
const deep = arr.length;
|
|
62
|
+
const merges: any[] = [];
|
|
63
|
+
for (let y = 0; y < deep; y++) {
|
|
64
|
+
const row = arr[y];
|
|
65
|
+
let colSpan = 0;
|
|
66
|
+
for (let x = 0; x < row.length; x++) {
|
|
67
|
+
if (row[x] === '!$COL_SPAN_PLACEHOLDER') {
|
|
68
|
+
row[x] = undefined;
|
|
69
|
+
if (x + 1 === row.length) {
|
|
70
|
+
merges.push({ s: { r: y, c: x - colSpan - 1 }, e: { r: y, c: x } });
|
|
71
|
+
}
|
|
72
|
+
colSpan++;
|
|
73
|
+
} else if (colSpan > 0 && x > colSpan) {
|
|
74
|
+
merges.push({ s: { r: y, c: x - colSpan - 1 }, e: { r: y, c: x - 1 } });
|
|
75
|
+
colSpan = 0;
|
|
76
|
+
} else {
|
|
77
|
+
colSpan = 0;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
const colLength = arr[0].length;
|
|
82
|
+
for (let x = 0; x < colLength; x++) {
|
|
83
|
+
let rowSpan = 0;
|
|
84
|
+
for (let y = 0; y < deep; y++) {
|
|
85
|
+
if (arr[y][x] === '!$ROW_SPAN_PLACEHOLDER') {
|
|
86
|
+
arr[y][x] = undefined;
|
|
87
|
+
if (y + 1 === deep) {
|
|
88
|
+
merges.push({ s: { r: y - rowSpan, c: x }, e: { r: y, c: x } });
|
|
89
|
+
}
|
|
90
|
+
rowSpan++;
|
|
91
|
+
} else if (rowSpan > 0 && y > rowSpan) {
|
|
92
|
+
merges.push({ s: { r: y - rowSpan - 1, c: x }, e: { r: y - 1, c: x } });
|
|
93
|
+
rowSpan = 0;
|
|
94
|
+
} else {
|
|
95
|
+
rowSpan = 0;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return merges;
|
|
100
|
+
},
|
|
101
|
+
|
|
102
|
+
aoa_to_sheet(data: any[][], headerRows: number) {
|
|
103
|
+
const ws: Record<string, any> = {};
|
|
104
|
+
const range = { s: { c: 10000000, r: 10000000 }, e: { c: 0, r: 0 } };
|
|
105
|
+
for (let R = 0; R !== data.length; ++R) {
|
|
106
|
+
for (let C = 0; C !== data[R].length; ++C) {
|
|
107
|
+
if (range.s.r > R) {
|
|
108
|
+
range.s.r = R;
|
|
109
|
+
}
|
|
110
|
+
if (range.s.c > C) {
|
|
111
|
+
range.s.c = C;
|
|
112
|
+
}
|
|
113
|
+
if (range.e.r < R) {
|
|
114
|
+
range.e.r = R;
|
|
115
|
+
}
|
|
116
|
+
if (range.e.c < C) {
|
|
117
|
+
range.e.c = C;
|
|
118
|
+
}
|
|
119
|
+
const cell: any = {
|
|
120
|
+
v: validData(data[R][C], ''),
|
|
121
|
+
s: {
|
|
122
|
+
font: { name: '宋体', sz: 11, color: { auto: 1, rgb: '000000' }, bold: true },
|
|
123
|
+
alignment: {
|
|
124
|
+
wrapText: 1,
|
|
125
|
+
horizontal: 'center',
|
|
126
|
+
vertical: 'center',
|
|
127
|
+
indent: 0
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
if (R < headerRows) {
|
|
132
|
+
cell.s.border = {
|
|
133
|
+
top: { style: 'thin', color: { rgb: 'EBEEF5' } },
|
|
134
|
+
left: { style: 'thin', color: { rgb: 'EBEEF5' } },
|
|
135
|
+
bottom: { style: 'thin', color: { rgb: 'EBEEF5' } },
|
|
136
|
+
right: { style: 'thin', color: { rgb: 'EBEEF5' } }
|
|
137
|
+
};
|
|
138
|
+
cell.s.fill = {
|
|
139
|
+
patternType: 'solid',
|
|
140
|
+
fgColor: { theme: 3, tint: 0.3999755851924192, rgb: 'F5F7FA' },
|
|
141
|
+
bgColor: { theme: 7, tint: 0.3999755851924192, rgb: 'F5F7FA' }
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
const cell_ref = XLSX.utils.encode_cell({ c: C, r: R });
|
|
145
|
+
if (typeof cell.v === 'number') {
|
|
146
|
+
cell.t = 'n';
|
|
147
|
+
} else if (typeof cell.v === 'boolean') {
|
|
148
|
+
cell.t = 'b';
|
|
149
|
+
} else {
|
|
150
|
+
cell.t = 's';
|
|
151
|
+
}
|
|
152
|
+
ws[cell_ref] = cell;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
if (range.s.c < 10000000) {
|
|
156
|
+
ws['!ref'] = XLSX.utils.encode_range(range);
|
|
157
|
+
}
|
|
158
|
+
return ws;
|
|
159
|
+
},
|
|
160
|
+
|
|
161
|
+
s2ab(s: string) {
|
|
162
|
+
const buf = new ArrayBuffer(s.length);
|
|
163
|
+
const view = new Uint8Array(buf);
|
|
164
|
+
for (let i = 0; i !== s.length; ++i) {
|
|
165
|
+
view[i] = s.charCodeAt(i) & 0xff;
|
|
166
|
+
}
|
|
167
|
+
return buf;
|
|
168
|
+
},
|
|
169
|
+
|
|
170
|
+
excel(params: any) {
|
|
171
|
+
if (!window.XLSX) {
|
|
172
|
+
packages.logs('xlsx');
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
return new Promise<void>((resolve) => {
|
|
176
|
+
const _params: any = {
|
|
177
|
+
prop: []
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
_params.header = this.buildHeader(params.columns);
|
|
181
|
+
_params.title = params.title || dayjs().format('YYYY-MM-DD HH:mm:ss');
|
|
182
|
+
const callback = (list: any[]) => {
|
|
183
|
+
list.forEach((ele) => {
|
|
184
|
+
if (ele.children && ele.children instanceof Array) {
|
|
185
|
+
callback(ele.children);
|
|
186
|
+
} else {
|
|
187
|
+
_params.prop.push(ele.prop);
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
};
|
|
191
|
+
callback(params.columns);
|
|
192
|
+
_params.data = params.data.map((row: any) =>
|
|
193
|
+
_params.prop.map((prop: string) => {
|
|
194
|
+
let data = row[prop];
|
|
195
|
+
if (isJson(data)) data = JSON.stringify(data);
|
|
196
|
+
return data;
|
|
197
|
+
})
|
|
198
|
+
);
|
|
199
|
+
const headerRows = _params.header.length;
|
|
200
|
+
_params.header.push(..._params.data, []);
|
|
201
|
+
const merges = this.doMerges(_params.header);
|
|
202
|
+
const ws = this.aoa_to_sheet(_params.header, headerRows);
|
|
203
|
+
ws['!merges'] = merges;
|
|
204
|
+
ws['!freeze'] = {
|
|
205
|
+
xSplit: '1',
|
|
206
|
+
ySplit: '' + headerRows,
|
|
207
|
+
topLeftCell: 'B' + (headerRows + 1),
|
|
208
|
+
activePane: 'bottomRight',
|
|
209
|
+
state: 'frozen'
|
|
210
|
+
};
|
|
211
|
+
ws['!cols'] = [{ wpx: 165 }];
|
|
212
|
+
const workbook: any = {
|
|
213
|
+
SheetNames: ['Sheet1'],
|
|
214
|
+
Sheets: {}
|
|
215
|
+
};
|
|
216
|
+
workbook.Sheets.Sheet1 = ws;
|
|
217
|
+
const wopts = {
|
|
218
|
+
bookType: 'xlsx',
|
|
219
|
+
bookSST: false,
|
|
220
|
+
type: 'binary',
|
|
221
|
+
cellStyles: true
|
|
222
|
+
};
|
|
223
|
+
const wbout = XLSX.write(workbook, wopts);
|
|
224
|
+
const blob = new Blob([this.s2ab(wbout)], { type: 'application/octet-stream' });
|
|
225
|
+
downFile(blob, _params.title + '.xlsx');
|
|
226
|
+
resolve();
|
|
227
|
+
});
|
|
228
|
+
},
|
|
229
|
+
|
|
230
|
+
xlsx(file: File) {
|
|
231
|
+
if (!window.saveAs || !window.XLSX) {
|
|
232
|
+
packages.logs('file-saver');
|
|
233
|
+
packages.logs('xlsx');
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
const xlsx = window.XLSX;
|
|
237
|
+
return new Promise<{ header: any[]; results: any[] }>((resolve) => {
|
|
238
|
+
const reader = new FileReader();
|
|
239
|
+
const fixdata = (data: ArrayBuffer) => {
|
|
240
|
+
let o = '';
|
|
241
|
+
let l = 0;
|
|
242
|
+
const w = 10240;
|
|
243
|
+
for (; l < data.byteLength / w; ++l) {
|
|
244
|
+
o += String.fromCharCode.apply(null, Array.from(new Uint8Array(data.slice(l * w, l * w + w))) as any);
|
|
245
|
+
}
|
|
246
|
+
o += String.fromCharCode.apply(null, Array.from(new Uint8Array(data.slice(l * w))) as any);
|
|
247
|
+
return o;
|
|
248
|
+
};
|
|
249
|
+
const getHeaderRow = (sheet: any) => {
|
|
250
|
+
const headers = [];
|
|
251
|
+
const range = xlsx.utils.decode_range(sheet['!ref']);
|
|
252
|
+
const R = range.s.r;
|
|
253
|
+
for (let C = range.s.c; C <= range.e.c; ++C) {
|
|
254
|
+
const cell = sheet[xlsx.utils.encode_cell({ c: C, r: R })];
|
|
255
|
+
let hdr = 'UNKNOWN ' + C;
|
|
256
|
+
if (cell && cell.t) hdr = xlsx.utils.format_cell(cell);
|
|
257
|
+
headers.push(hdr);
|
|
258
|
+
}
|
|
259
|
+
return headers;
|
|
260
|
+
};
|
|
261
|
+
reader.onload = (e) => {
|
|
262
|
+
const data = e.target!.result as ArrayBuffer;
|
|
263
|
+
const fixedData = fixdata(data);
|
|
264
|
+
const workbook = xlsx.read(btoa(fixedData), { type: 'base64' });
|
|
265
|
+
const firstSheetName = workbook.SheetNames[0];
|
|
266
|
+
const worksheet = workbook.Sheets[firstSheetName];
|
|
267
|
+
const header = getHeaderRow(worksheet);
|
|
268
|
+
const results = xlsx.utils.sheet_to_json(worksheet);
|
|
269
|
+
resolve({ header, results });
|
|
270
|
+
};
|
|
271
|
+
reader.readAsArrayBuffer(file);
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
const log = {};
|
|
2
|
+
function typeColor(type = 'default') {
|
|
3
|
+
let color = '';
|
|
4
|
+
switch (type) {
|
|
5
|
+
case 'default':
|
|
6
|
+
color = '#35495E';
|
|
7
|
+
break;
|
|
8
|
+
case 'primary':
|
|
9
|
+
color = '#3488ff';
|
|
10
|
+
break;
|
|
11
|
+
case 'success':
|
|
12
|
+
color = '#43B883';
|
|
13
|
+
break;
|
|
14
|
+
case 'warning':
|
|
15
|
+
color = '#e6a23c';
|
|
16
|
+
break;
|
|
17
|
+
case 'danger':
|
|
18
|
+
color = '#f56c6c';
|
|
19
|
+
break;
|
|
20
|
+
default:
|
|
21
|
+
break;
|
|
22
|
+
}
|
|
23
|
+
return color;
|
|
24
|
+
}
|
|
25
|
+
log.capsule = function (title, info, type = 'primary') {
|
|
26
|
+
console.log(`%c ${title} %c ${info} %c`, 'background:#35495E; padding: 1px; border-radius: 3px 0 0 3px; color: #fff;', `background:${typeColor(type)}; padding: 1px; border-radius: 0 3px 3px 0; color: #fff;`, 'background:transparent');
|
|
27
|
+
};
|
|
28
|
+
log.colorful = function (textArr) {
|
|
29
|
+
console.log(`%c${textArr.map((t) => t.text || '').join('%c')}`, ...textArr.map((t) => `color: ${typeColor(t.type)};`));
|
|
30
|
+
};
|
|
31
|
+
log.default = function (text) {
|
|
32
|
+
log.colorful([{ text }]);
|
|
33
|
+
};
|
|
34
|
+
log.primary = function (text) {
|
|
35
|
+
log.colorful([{ text, type: 'primary' }]);
|
|
36
|
+
};
|
|
37
|
+
log.success = function (text) {
|
|
38
|
+
log.colorful([{ text, type: 'success' }]);
|
|
39
|
+
};
|
|
40
|
+
log.warning = function (text) {
|
|
41
|
+
log.colorful([{ text, type: 'warning' }]);
|
|
42
|
+
};
|
|
43
|
+
log.danger = function (text) {
|
|
44
|
+
log.colorful([{ text, type: 'danger' }]);
|
|
45
|
+
};
|
|
46
|
+
export default log;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
type LogType = 'default' | 'primary' | 'success' | 'warning' | 'danger';
|
|
2
|
+
type ColorfulText = { text?: string; type?: LogType };
|
|
3
|
+
|
|
4
|
+
const log: Record<string, any> = {};
|
|
5
|
+
|
|
6
|
+
function typeColor(type: LogType = 'default') {
|
|
7
|
+
let color = '';
|
|
8
|
+
switch (type) {
|
|
9
|
+
case 'default':
|
|
10
|
+
color = '#35495E';
|
|
11
|
+
break;
|
|
12
|
+
case 'primary':
|
|
13
|
+
color = '#3488ff';
|
|
14
|
+
break;
|
|
15
|
+
case 'success':
|
|
16
|
+
color = '#43B883';
|
|
17
|
+
break;
|
|
18
|
+
case 'warning':
|
|
19
|
+
color = '#e6a23c';
|
|
20
|
+
break;
|
|
21
|
+
case 'danger':
|
|
22
|
+
color = '#f56c6c';
|
|
23
|
+
break;
|
|
24
|
+
default:
|
|
25
|
+
break;
|
|
26
|
+
}
|
|
27
|
+
return color;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
log.capsule = function (title: string, info: string, type: LogType = 'primary') {
|
|
31
|
+
console.log(
|
|
32
|
+
`%c ${title} %c ${info} %c`,
|
|
33
|
+
'background:#35495E; padding: 1px; border-radius: 3px 0 0 3px; color: #fff;',
|
|
34
|
+
`background:${typeColor(type)}; padding: 1px; border-radius: 0 3px 3px 0; color: #fff;`,
|
|
35
|
+
'background:transparent'
|
|
36
|
+
);
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
log.colorful = function (textArr: ColorfulText[]) {
|
|
40
|
+
console.log(
|
|
41
|
+
`%c${textArr.map((t) => t.text || '').join('%c')}`,
|
|
42
|
+
...textArr.map((t) => `color: ${typeColor(t.type)};`)
|
|
43
|
+
);
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
log.default = function (text: string) {
|
|
47
|
+
log.colorful([{ text }]);
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
log.primary = function (text: string) {
|
|
51
|
+
log.colorful([{ text, type: 'primary' }]);
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
log.success = function (text: string) {
|
|
55
|
+
log.colorful([{ text, type: 'success' }]);
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
log.warning = function (text: string) {
|
|
59
|
+
log.colorful([{ text, type: 'warning' }]);
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
log.danger = function (text: string) {
|
|
63
|
+
log.colorful([{ text, type: 'danger' }]);
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
export default log;
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
const Print = function (dom, options) {
|
|
2
|
+
if (!(this instanceof Print))
|
|
3
|
+
return new Print(dom, options);
|
|
4
|
+
this.options = this.extend({
|
|
5
|
+
noPrint: '.no-print',
|
|
6
|
+
}, options);
|
|
7
|
+
if (typeof dom === 'string') {
|
|
8
|
+
this.dom = document.querySelector(dom);
|
|
9
|
+
}
|
|
10
|
+
else {
|
|
11
|
+
this.isDOM(dom);
|
|
12
|
+
this.dom = this.isDOM(dom) ? dom : dom.$el;
|
|
13
|
+
}
|
|
14
|
+
this.init();
|
|
15
|
+
};
|
|
16
|
+
Print.prototype = {
|
|
17
|
+
init: function () {
|
|
18
|
+
const content = this.getStyle() + this.getHtml();
|
|
19
|
+
this.writeIframe(content);
|
|
20
|
+
},
|
|
21
|
+
extend: function (obj, obj2) {
|
|
22
|
+
for (const k in obj2) {
|
|
23
|
+
obj[k] = obj2[k];
|
|
24
|
+
}
|
|
25
|
+
return obj;
|
|
26
|
+
},
|
|
27
|
+
getStyle: function () {
|
|
28
|
+
let str = '';
|
|
29
|
+
const styles = document.querySelectorAll('style,link');
|
|
30
|
+
for (let i = 0; i < styles.length; i++) {
|
|
31
|
+
str += styles[i].outerHTML;
|
|
32
|
+
}
|
|
33
|
+
str += `<style>${this.options.noPrint ? this.options.noPrint : '.no-print'}{display:none;}</style>`;
|
|
34
|
+
return str;
|
|
35
|
+
},
|
|
36
|
+
getHtml: function () {
|
|
37
|
+
const inputs = document.querySelectorAll('input');
|
|
38
|
+
const textareas = document.querySelectorAll('textarea');
|
|
39
|
+
const selects = document.querySelectorAll('select');
|
|
40
|
+
for (let k = 0; k < inputs.length; k++) {
|
|
41
|
+
const input = inputs[k];
|
|
42
|
+
if (input.type == 'checkbox' || input.type == 'radio') {
|
|
43
|
+
if (input.checked == true) {
|
|
44
|
+
input.setAttribute('checked', 'checked');
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
input.removeAttribute('checked');
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
input.setAttribute('value', input.value);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
for (let k2 = 0; k2 < textareas.length; k2++) {
|
|
55
|
+
if (textareas[k2].type == 'textarea') {
|
|
56
|
+
textareas[k2].innerHTML = textareas[k2].value;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
for (let k3 = 0; k3 < selects.length; k3++) {
|
|
60
|
+
if (selects[k3].type == 'select-one') {
|
|
61
|
+
const child = selects[k3].children;
|
|
62
|
+
for (const i in child) {
|
|
63
|
+
const option = child[i];
|
|
64
|
+
if (option && option.tagName == 'OPTION') {
|
|
65
|
+
if (option.selected == true) {
|
|
66
|
+
option.setAttribute('selected', 'selected');
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
option.removeAttribute('selected');
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return this.wrapperRefDom(this.dom).outerHTML;
|
|
76
|
+
},
|
|
77
|
+
wrapperRefDom: function (refDom) {
|
|
78
|
+
let prevDom = null;
|
|
79
|
+
let currDom = refDom;
|
|
80
|
+
if (!this.isInBody(currDom))
|
|
81
|
+
return currDom;
|
|
82
|
+
while (currDom) {
|
|
83
|
+
if (prevDom) {
|
|
84
|
+
const element = currDom.cloneNode(false);
|
|
85
|
+
element.appendChild(prevDom);
|
|
86
|
+
prevDom = element;
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
prevDom = currDom.cloneNode(true);
|
|
90
|
+
}
|
|
91
|
+
currDom = currDom.parentElement;
|
|
92
|
+
}
|
|
93
|
+
return prevDom;
|
|
94
|
+
},
|
|
95
|
+
writeIframe: function (content) {
|
|
96
|
+
let w;
|
|
97
|
+
let doc;
|
|
98
|
+
const iframe = document.createElement('iframe');
|
|
99
|
+
const f = document.body.appendChild(iframe);
|
|
100
|
+
iframe.id = 'myIframe';
|
|
101
|
+
iframe.setAttribute('style', 'position:absolute;width:0;height:0;top:-10px;left:-10px;');
|
|
102
|
+
w = f.contentWindow || f.contentDocument;
|
|
103
|
+
doc = f.contentDocument || f.contentWindow.document;
|
|
104
|
+
doc.open();
|
|
105
|
+
doc.write(content);
|
|
106
|
+
doc.close();
|
|
107
|
+
const _this = this;
|
|
108
|
+
iframe.onload = function () {
|
|
109
|
+
_this.toPrint(w);
|
|
110
|
+
setTimeout(function () {
|
|
111
|
+
document.body.removeChild(iframe);
|
|
112
|
+
}, 100);
|
|
113
|
+
};
|
|
114
|
+
},
|
|
115
|
+
toPrint: function (frameWindow) {
|
|
116
|
+
try {
|
|
117
|
+
setTimeout(function () {
|
|
118
|
+
frameWindow.focus();
|
|
119
|
+
try {
|
|
120
|
+
if (!frameWindow.document.execCommand('print', false, null)) {
|
|
121
|
+
frameWindow.print();
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
catch (e) {
|
|
125
|
+
frameWindow.print();
|
|
126
|
+
}
|
|
127
|
+
frameWindow.close();
|
|
128
|
+
}, 10);
|
|
129
|
+
}
|
|
130
|
+
catch (err) {
|
|
131
|
+
console.log('err', err);
|
|
132
|
+
}
|
|
133
|
+
},
|
|
134
|
+
isInBody: function (node) {
|
|
135
|
+
return node === document.body ? false : document.body.contains(node);
|
|
136
|
+
},
|
|
137
|
+
isDOM: typeof HTMLElement === 'object'
|
|
138
|
+
? function (obj) {
|
|
139
|
+
return obj instanceof HTMLElement;
|
|
140
|
+
}
|
|
141
|
+
: function (obj) {
|
|
142
|
+
return obj && typeof obj === 'object' && obj.nodeType === 1 && typeof obj.nodeName === 'string';
|
|
143
|
+
},
|
|
144
|
+
};
|
|
145
|
+
export default Print;
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
const Print: any = function (dom: any, options: Record<string, any>) {
|
|
2
|
+
if (!(this instanceof Print)) return new Print(dom, options);
|
|
3
|
+
|
|
4
|
+
this.options = this.extend(
|
|
5
|
+
{
|
|
6
|
+
noPrint: '.no-print',
|
|
7
|
+
},
|
|
8
|
+
options
|
|
9
|
+
);
|
|
10
|
+
|
|
11
|
+
if (typeof dom === 'string') {
|
|
12
|
+
this.dom = document.querySelector(dom);
|
|
13
|
+
} else {
|
|
14
|
+
this.isDOM(dom);
|
|
15
|
+
this.dom = this.isDOM(dom) ? dom : dom.$el;
|
|
16
|
+
}
|
|
17
|
+
this.init();
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
Print.prototype = {
|
|
21
|
+
init: function () {
|
|
22
|
+
const content = this.getStyle() + this.getHtml();
|
|
23
|
+
this.writeIframe(content);
|
|
24
|
+
},
|
|
25
|
+
extend: function (obj: Record<string, any>, obj2: Record<string, any>) {
|
|
26
|
+
for (const k in obj2) {
|
|
27
|
+
obj[k] = obj2[k];
|
|
28
|
+
}
|
|
29
|
+
return obj;
|
|
30
|
+
},
|
|
31
|
+
|
|
32
|
+
getStyle: function () {
|
|
33
|
+
let str = '';
|
|
34
|
+
const styles = document.querySelectorAll('style,link');
|
|
35
|
+
for (let i = 0; i < styles.length; i++) {
|
|
36
|
+
str += (styles[i] as HTMLElement).outerHTML;
|
|
37
|
+
}
|
|
38
|
+
str += `<style>${this.options.noPrint ? this.options.noPrint : '.no-print'}{display:none;}</style>`;
|
|
39
|
+
|
|
40
|
+
return str;
|
|
41
|
+
},
|
|
42
|
+
|
|
43
|
+
getHtml: function () {
|
|
44
|
+
const inputs = document.querySelectorAll('input');
|
|
45
|
+
const textareas = document.querySelectorAll('textarea');
|
|
46
|
+
const selects = document.querySelectorAll('select');
|
|
47
|
+
|
|
48
|
+
for (let k = 0; k < inputs.length; k++) {
|
|
49
|
+
const input = inputs[k];
|
|
50
|
+
if (input.type == 'checkbox' || input.type == 'radio') {
|
|
51
|
+
if (input.checked == true) {
|
|
52
|
+
input.setAttribute('checked', 'checked');
|
|
53
|
+
} else {
|
|
54
|
+
input.removeAttribute('checked');
|
|
55
|
+
}
|
|
56
|
+
} else {
|
|
57
|
+
input.setAttribute('value', input.value);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
for (let k2 = 0; k2 < textareas.length; k2++) {
|
|
62
|
+
if (textareas[k2].type == 'textarea') {
|
|
63
|
+
textareas[k2].innerHTML = textareas[k2].value;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
for (let k3 = 0; k3 < selects.length; k3++) {
|
|
68
|
+
if (selects[k3].type == 'select-one') {
|
|
69
|
+
const child = selects[k3].children;
|
|
70
|
+
for (const i in child) {
|
|
71
|
+
const option = child[i as any] as HTMLOptionElement | undefined;
|
|
72
|
+
if (option && option.tagName == 'OPTION') {
|
|
73
|
+
if (option.selected == true) {
|
|
74
|
+
option.setAttribute('selected', 'selected');
|
|
75
|
+
} else {
|
|
76
|
+
option.removeAttribute('selected');
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return this.wrapperRefDom(this.dom).outerHTML;
|
|
83
|
+
},
|
|
84
|
+
wrapperRefDom: function (refDom: HTMLElement) {
|
|
85
|
+
let prevDom: HTMLElement | null = null;
|
|
86
|
+
let currDom: HTMLElement | null = refDom;
|
|
87
|
+
if (!this.isInBody(currDom)) return currDom;
|
|
88
|
+
|
|
89
|
+
while (currDom) {
|
|
90
|
+
if (prevDom) {
|
|
91
|
+
const element = currDom.cloneNode(false) as HTMLElement;
|
|
92
|
+
element.appendChild(prevDom);
|
|
93
|
+
prevDom = element;
|
|
94
|
+
} else {
|
|
95
|
+
prevDom = currDom.cloneNode(true) as HTMLElement;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
currDom = currDom.parentElement;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return prevDom;
|
|
102
|
+
},
|
|
103
|
+
|
|
104
|
+
writeIframe: function (content: string) {
|
|
105
|
+
let w;
|
|
106
|
+
let doc;
|
|
107
|
+
const iframe = document.createElement('iframe');
|
|
108
|
+
const f = document.body.appendChild(iframe);
|
|
109
|
+
iframe.id = 'myIframe';
|
|
110
|
+
iframe.setAttribute('style', 'position:absolute;width:0;height:0;top:-10px;left:-10px;');
|
|
111
|
+
w = f.contentWindow || f.contentDocument;
|
|
112
|
+
doc = f.contentDocument || f.contentWindow.document;
|
|
113
|
+
doc.open();
|
|
114
|
+
doc.write(content);
|
|
115
|
+
doc.close();
|
|
116
|
+
const _this = this;
|
|
117
|
+
iframe.onload = function () {
|
|
118
|
+
_this.toPrint(w);
|
|
119
|
+
setTimeout(function () {
|
|
120
|
+
document.body.removeChild(iframe);
|
|
121
|
+
}, 100);
|
|
122
|
+
};
|
|
123
|
+
},
|
|
124
|
+
|
|
125
|
+
toPrint: function (frameWindow: Window) {
|
|
126
|
+
try {
|
|
127
|
+
setTimeout(function () {
|
|
128
|
+
frameWindow.focus();
|
|
129
|
+
try {
|
|
130
|
+
if (!frameWindow.document.execCommand('print', false, null)) {
|
|
131
|
+
frameWindow.print();
|
|
132
|
+
}
|
|
133
|
+
} catch (e) {
|
|
134
|
+
frameWindow.print();
|
|
135
|
+
}
|
|
136
|
+
frameWindow.close();
|
|
137
|
+
}, 10);
|
|
138
|
+
} catch (err) {
|
|
139
|
+
console.log('err', err);
|
|
140
|
+
}
|
|
141
|
+
},
|
|
142
|
+
isInBody: function (node: HTMLElement) {
|
|
143
|
+
return node === document.body ? false : document.body.contains(node);
|
|
144
|
+
},
|
|
145
|
+
isDOM:
|
|
146
|
+
typeof HTMLElement === 'object'
|
|
147
|
+
? function (obj: any) {
|
|
148
|
+
return obj instanceof HTMLElement;
|
|
149
|
+
}
|
|
150
|
+
: function (obj: any) {
|
|
151
|
+
return obj && typeof obj === 'object' && obj.nodeType === 1 && typeof obj.nodeName === 'string';
|
|
152
|
+
},
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
export default Print;
|