@ccs-ui/rc-pro 2.0.3 → 2.0.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/es/dialog/DialogRequestButton.d.ts +1 -1
- package/es/layout-keep-alive/page.js +4 -7
- package/es/layout-single-page/page.js +6 -6
- package/es/pro-table/index.less +5 -2
- package/es/pro-table/table.js +16 -11
- package/es/pro-table/tree.d.ts +2 -1
- package/es/pro-table/tree.js +3 -1
- package/es/table/index.d.ts +1 -0
- package/es/table/index.js +15 -16
- package/es/water-mark/relative.d.ts +62 -0
- package/es/water-mark/relative.js +130 -0
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { FormProps } from 'antd';
|
|
2
2
|
import { DialogFormRef } from './form';
|
|
3
3
|
import { CcsDialogModalProps } from './hook';
|
|
4
|
-
declare const DialogRequestButton: ({ auth, formRef, extraBtn, formInitialValues, request, onCancel, onRequestBefore, }: Pick<CcsDialogModalProps, "onCancel" | "auth" | "request" | "
|
|
4
|
+
declare const DialogRequestButton: ({ auth, formRef, extraBtn, formInitialValues, request, onCancel, onRequestBefore, }: Pick<CcsDialogModalProps, "onCancel" | "auth" | "request" | "extraBtn" | "onRequestBefore"> & {
|
|
5
5
|
formRef: React.RefObject<DialogFormRef>;
|
|
6
6
|
formInitialValues: FormProps['initialValues'];
|
|
7
7
|
}) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -28,16 +28,13 @@ export default /*#__PURE__*/memo(function (props) {
|
|
|
28
28
|
"data-display": active,
|
|
29
29
|
children: /*#__PURE__*/_jsx(Scrollbars, {
|
|
30
30
|
style: {
|
|
31
|
-
|
|
31
|
+
padding: 16,
|
|
32
|
+
flexDirection: 'column',
|
|
33
|
+
display: active ? 'flex' : 'none'
|
|
32
34
|
},
|
|
33
35
|
autoHide: true,
|
|
34
36
|
className: "ccs-table-item-scroll",
|
|
35
|
-
children:
|
|
36
|
-
style: {
|
|
37
|
-
margin: 16
|
|
38
|
-
},
|
|
39
|
-
children: children
|
|
40
|
-
})
|
|
37
|
+
children: children
|
|
41
38
|
})
|
|
42
39
|
})
|
|
43
40
|
});
|
|
@@ -21,12 +21,12 @@ export default /*#__PURE__*/memo(function (props) {
|
|
|
21
21
|
children: /*#__PURE__*/_jsx(Scrollbars, {
|
|
22
22
|
autoHide: true,
|
|
23
23
|
className: "ccs-table-item-scroll",
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
24
|
+
style: {
|
|
25
|
+
padding: 16,
|
|
26
|
+
flexDirection: 'column',
|
|
27
|
+
display: 'flex'
|
|
28
|
+
},
|
|
29
|
+
children: children
|
|
30
30
|
})
|
|
31
31
|
});
|
|
32
32
|
});
|
package/es/pro-table/index.less
CHANGED
|
@@ -20,6 +20,10 @@
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
.ccs-pl {
|
|
23
|
+
flex: auto;
|
|
24
|
+
display: flex;
|
|
25
|
+
flex-direction: column;
|
|
26
|
+
|
|
23
27
|
.ant-pagination {
|
|
24
28
|
margin: 0 !important;
|
|
25
29
|
}
|
|
@@ -34,9 +38,8 @@
|
|
|
34
38
|
}
|
|
35
39
|
|
|
36
40
|
&-table-content {
|
|
37
|
-
// margin: 10px;
|
|
38
|
-
// background: #fff;
|
|
39
41
|
position: relative;
|
|
42
|
+
flex: auto;
|
|
40
43
|
}
|
|
41
44
|
|
|
42
45
|
&-adaptation {
|
package/es/pro-table/table.js
CHANGED
|
@@ -18,9 +18,9 @@ import { useSize, useUpdateEffect } from 'ahooks';
|
|
|
18
18
|
import { Empty, Form, theme } from 'antd';
|
|
19
19
|
import classNames from 'classnames';
|
|
20
20
|
import React, { useEffect, useImperativeHandle, useMemo, useRef, useState } from 'react';
|
|
21
|
-
import { CcsWaterMark } from '..';
|
|
22
21
|
import { useCcsPage } from "../";
|
|
23
22
|
import CcsTable from "../table";
|
|
23
|
+
import WaterMarkRelative from "../water-mark/relative";
|
|
24
24
|
import { getAllChildrenId, getDataById, onTableInModalOrDrawer, onTableInTabItem } from "./_utils";
|
|
25
25
|
import HeadComponent from "./head";
|
|
26
26
|
import "./index.less";
|
|
@@ -41,6 +41,7 @@ export var TableSelectionContext = /*#__PURE__*/React.createContext({
|
|
|
41
41
|
* @returns
|
|
42
42
|
*/
|
|
43
43
|
var InternalProTable = function InternalProTable(props) {
|
|
44
|
+
var _table$scroll2, _table$scroll3;
|
|
44
45
|
var init = props.init,
|
|
45
46
|
auth = props.auth,
|
|
46
47
|
table = props.table,
|
|
@@ -465,6 +466,7 @@ var InternalProTable = function InternalProTable(props) {
|
|
|
465
466
|
}),
|
|
466
467
|
treeRef: treeRef,
|
|
467
468
|
tableRef: tableRef,
|
|
469
|
+
tableContentRef: tableContentRef,
|
|
468
470
|
tableRowSize: tableRowSize,
|
|
469
471
|
sticky: stickyRef.current || true,
|
|
470
472
|
parentFieldName: parentFieldName,
|
|
@@ -477,6 +479,7 @@ var InternalProTable = function InternalProTable(props) {
|
|
|
477
479
|
return /*#__PURE__*/_jsx(CcsTable, _objectSpread(_objectSpread({
|
|
478
480
|
data: data,
|
|
479
481
|
tableRef: tableRef,
|
|
482
|
+
tableContentRef: tableContentRef,
|
|
480
483
|
onChange: handlePageChange,
|
|
481
484
|
sticky: stickyRef.current || true
|
|
482
485
|
}, table), {}, {
|
|
@@ -510,11 +513,17 @@ var InternalProTable = function InternalProTable(props) {
|
|
|
510
513
|
borderRadius: 4
|
|
511
514
|
}, rootStyle);
|
|
512
515
|
}
|
|
513
|
-
|
|
516
|
+
return /*#__PURE__*/_jsxs("div", {
|
|
514
517
|
className: classNames(classPrefix, className, _defineProperty({}, 'dark-table', isDark)),
|
|
515
|
-
style: rootStyle,
|
|
518
|
+
style: _objectSpread(_objectSpread({}, rootStyle), {}, {
|
|
519
|
+
overflow: (table === null || table === void 0 || (_table$scroll2 = table.scroll) === null || _table$scroll2 === void 0 ? void 0 : _table$scroll2.y) === 'auto' ? 'hidden' : 'unset'
|
|
520
|
+
}),
|
|
516
521
|
ref: containerRef,
|
|
517
|
-
children: [
|
|
522
|
+
children: [watermark && /*#__PURE__*/_jsx(WaterMarkRelative, {
|
|
523
|
+
content: watermark,
|
|
524
|
+
fontColor: "rgba(0,0,0,.15)",
|
|
525
|
+
zIndex: 105
|
|
526
|
+
}), !(!formItems.length && !toolbar) && isAuth && /*#__PURE__*/_jsx(HeadComponent, {
|
|
518
527
|
form: form,
|
|
519
528
|
toolbar: newToolbar,
|
|
520
529
|
formItems: formItems,
|
|
@@ -535,16 +544,12 @@ var InternalProTable = function InternalProTable(props) {
|
|
|
535
544
|
children: newToolbarExtra
|
|
536
545
|
}), /*#__PURE__*/_jsxs("div", {
|
|
537
546
|
className: "".concat(classPrefix, "-table-content"),
|
|
538
|
-
style: styles === null || styles === void 0 ? void 0 : styles.table,
|
|
547
|
+
style: _objectSpread(_objectSpread({}, styles === null || styles === void 0 ? void 0 : styles.table), {}, {
|
|
548
|
+
overflow: (table === null || table === void 0 || (_table$scroll3 = table.scroll) === null || _table$scroll3 === void 0 ? void 0 : _table$scroll3.y) === 'auto' ? 'hidden' : 'unset'
|
|
549
|
+
}),
|
|
539
550
|
ref: tableContentRef,
|
|
540
551
|
children: [renderTable(), children]
|
|
541
552
|
})]
|
|
542
553
|
});
|
|
543
|
-
return watermark ? /*#__PURE__*/_jsx(CcsWaterMark, {
|
|
544
|
-
content: watermark,
|
|
545
|
-
fontColor: "rgba(0,0,0,.15)",
|
|
546
|
-
zIndex: 105,
|
|
547
|
-
children: render
|
|
548
|
-
}) : render;
|
|
549
554
|
};
|
|
550
555
|
export default InternalProTable;
|
package/es/pro-table/tree.d.ts
CHANGED
|
@@ -15,11 +15,12 @@ type TreeTableProps<T> = Pick<CcsProTableProps<T>, 'table' | 'onSearchBefore' |
|
|
|
15
15
|
tableRowSize: TableProps['size'];
|
|
16
16
|
treeRef: RefObject<TreeInstance<T>>;
|
|
17
17
|
tableRef: React.MutableRefObject<TableRefType | undefined>;
|
|
18
|
+
tableContentRef: React.RefObject<HTMLDivElement>;
|
|
18
19
|
setData: React.Dispatch<React.SetStateAction<CCS.TableData<T>>>;
|
|
19
20
|
handlePageChange: any;
|
|
20
21
|
onSearchAfter: (data: HttpResult<T[]>, eventType?: SearchEventType) => HttpResult<(T & {
|
|
21
22
|
children: T[];
|
|
22
23
|
})[]>;
|
|
23
24
|
};
|
|
24
|
-
declare const TableTree: <T extends object = any>({ data, table, sticky, treeRef, tableRef, tableRowSize, parentFieldName, handlePageChange, setData, onSearchAfter, onSearchBefore, }: TreeTableProps<T>) => import("react/jsx-runtime").JSX.Element;
|
|
25
|
+
declare const TableTree: <T extends object = any>({ data, table, sticky, treeRef, tableRef, tableRowSize, tableContentRef, parentFieldName, handlePageChange, setData, onSearchAfter, onSearchBefore, }: TreeTableProps<T>) => import("react/jsx-runtime").JSX.Element;
|
|
25
26
|
export default TableTree;
|
package/es/pro-table/tree.js
CHANGED
|
@@ -28,6 +28,7 @@ var TableTree = function TableTree(_ref) {
|
|
|
28
28
|
treeRef = _ref.treeRef,
|
|
29
29
|
tableRef = _ref.tableRef,
|
|
30
30
|
tableRowSize = _ref.tableRowSize,
|
|
31
|
+
tableContentRef = _ref.tableContentRef,
|
|
31
32
|
parentFieldName = _ref.parentFieldName,
|
|
32
33
|
handlePageChange = _ref.handlePageChange,
|
|
33
34
|
setData = _ref.setData,
|
|
@@ -160,7 +161,8 @@ var TableTree = function TableTree(_ref) {
|
|
|
160
161
|
return /*#__PURE__*/_jsx(CcsTable, _objectSpread(_objectSpread({
|
|
161
162
|
onChange: handlePageChange,
|
|
162
163
|
data: data,
|
|
163
|
-
tableRef: tableRef
|
|
164
|
+
tableRef: tableRef,
|
|
165
|
+
tableContentRef: tableContentRef
|
|
164
166
|
}, tableParams), {}, {
|
|
165
167
|
size: tableRowSize,
|
|
166
168
|
columns: columns,
|
package/es/table/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ import './index.less';
|
|
|
4
4
|
type TableProps<T> = Omit<CcsTableProps<T>, 'request' | 'requestParam' | 'title'> & Pick<CcsProTableProps<T>, 'showNumber'> & {
|
|
5
5
|
title?: any;
|
|
6
6
|
tableRef?: React.MutableRefObject<TableRefType | undefined>;
|
|
7
|
+
tableContentRef: React.RefObject<HTMLDivElement>;
|
|
7
8
|
};
|
|
8
9
|
export type TableRefType = {
|
|
9
10
|
/** 列筛选 */
|
package/es/table/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
2
|
var _excluded = ["onResize", "width"],
|
|
3
|
-
_excluded2 = ["data", "style", "scroll", "rowKey", "columns", "tableRef", "pagination", "rowSelection", "className"];
|
|
3
|
+
_excluded2 = ["data", "style", "scroll", "rowKey", "columns", "tableRef", "pagination", "rowSelection", "className", "tableContentRef"];
|
|
4
4
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
5
5
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
6
6
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
@@ -8,7 +8,7 @@ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol"
|
|
|
8
8
|
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
9
9
|
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
10
10
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
11
|
-
import { useDebounceFn,
|
|
11
|
+
import { useDebounceFn, useUpdate } from 'ahooks';
|
|
12
12
|
import { Table, Tooltip, theme } from 'antd';
|
|
13
13
|
import classNames from 'classnames';
|
|
14
14
|
import { useEffect, useImperativeHandle, useRef } from 'react';
|
|
@@ -55,6 +55,7 @@ var CustomTable = function CustomTable(props) {
|
|
|
55
55
|
rowSelection = props.rowSelection,
|
|
56
56
|
_props$className = props.className,
|
|
57
57
|
className = _props$className === void 0 ? '' : _props$className,
|
|
58
|
+
tableContentRef = props.tableContentRef,
|
|
58
59
|
restProps = _objectWithoutProperties(props, _excluded2);
|
|
59
60
|
|
|
60
61
|
// 固定表头获取table可视高度
|
|
@@ -69,27 +70,27 @@ var CustomTable = function CustomTable(props) {
|
|
|
69
70
|
// table 固定表头,内容滚动
|
|
70
71
|
var _useDebounceFn = useDebounceFn(function () {
|
|
71
72
|
if ((scroll === null || scroll === void 0 ? void 0 : scroll.y) === 'auto') {
|
|
72
|
-
var _ref$current, _ref$current2;
|
|
73
|
+
var _ref$current, _ref$current2, _ref$current3, _tableContentRef$curr;
|
|
73
74
|
var tableBody = ref.current.getElementsByClassName('ant-table-body')[0];
|
|
74
75
|
if (!tableBody) return;
|
|
75
|
-
var
|
|
76
|
-
|
|
77
|
-
},
|
|
78
|
-
top = _ref2.top;
|
|
79
|
-
var bodyHeight = document.body.clientHeight;
|
|
80
|
-
var pageHeight = 0,
|
|
76
|
+
var headerHeight = 0,
|
|
77
|
+
pageHeight = 0,
|
|
81
78
|
footerHeight = 0;
|
|
82
79
|
var _pagination = (_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.getElementsByClassName('ant-pagination');
|
|
83
80
|
if (_pagination && _pagination.length > 0) {
|
|
84
81
|
pageHeight = _pagination[0].clientHeight;
|
|
85
82
|
}
|
|
86
|
-
var
|
|
83
|
+
var header = (_ref$current2 = ref.current) === null || _ref$current2 === void 0 ? void 0 : _ref$current2.getElementsByClassName('ant-table-header');
|
|
84
|
+
var footer = (_ref$current3 = ref.current) === null || _ref$current3 === void 0 ? void 0 : _ref$current3.getElementsByClassName('ant-table-footer');
|
|
87
85
|
if (footer && footer.length > 0) {
|
|
88
86
|
footerHeight = footer[0].clientHeight;
|
|
89
87
|
}
|
|
88
|
+
if (header && header.length > 0) {
|
|
89
|
+
headerHeight = header[0].clientHeight;
|
|
90
|
+
}
|
|
90
91
|
|
|
91
92
|
// 计算table数据区高度
|
|
92
|
-
var scrollHeight =
|
|
93
|
+
var scrollHeight = (((_tableContentRef$curr = tableContentRef.current) === null || _tableContentRef$curr === void 0 ? void 0 : _tableContentRef$curr.clientHeight) || 0) - headerHeight - pageHeight - footerHeight;
|
|
93
94
|
|
|
94
95
|
// 固定tbody高度
|
|
95
96
|
tableBody.style.height = "".concat(scrollHeight, "px");
|
|
@@ -104,9 +105,7 @@ var CustomTable = function CustomTable(props) {
|
|
|
104
105
|
}, [totalNum]);
|
|
105
106
|
|
|
106
107
|
// 监听窗口变化
|
|
107
|
-
useEventListener('resize', onFixedThead, {
|
|
108
|
-
target: window
|
|
109
|
-
});
|
|
108
|
+
// useEventListener('resize', onFixedThead, { target: window });
|
|
110
109
|
|
|
111
110
|
// 监听列筛选事件
|
|
112
111
|
useImperativeHandle(tableRef, function () {
|
|
@@ -124,8 +123,8 @@ var CustomTable = function CustomTable(props) {
|
|
|
124
123
|
|
|
125
124
|
// 改变列宽
|
|
126
125
|
var onResize = function onResize(dataIndex) {
|
|
127
|
-
return function (_,
|
|
128
|
-
var size =
|
|
126
|
+
return function (_, _ref2) {
|
|
127
|
+
var size = _ref2.size;
|
|
129
128
|
var column = columns === null || columns === void 0 ? void 0 : columns.find(function (c) {
|
|
130
129
|
return c.dataIndex === dataIndex;
|
|
131
130
|
});
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { PropsWithCss, PropsWithNodeChildren } from '../ccs';
|
|
3
|
+
export type WaterMarkProps = PropsWithNodeChildren & PropsWithCss & {
|
|
4
|
+
/** 水印文字内容 */
|
|
5
|
+
content?: string;
|
|
6
|
+
/** 水印样式 */
|
|
7
|
+
markStyle?: React.CSSProperties;
|
|
8
|
+
/** 水印类名 */
|
|
9
|
+
markClassName?: string;
|
|
10
|
+
/** 水印之间的水平间距 */
|
|
11
|
+
gapX?: number;
|
|
12
|
+
/** 水印之间的垂直间距 */
|
|
13
|
+
gapY?: number;
|
|
14
|
+
/** 追加的水印元素的z-index */
|
|
15
|
+
zIndex?: number;
|
|
16
|
+
/** 水印的宽度 */
|
|
17
|
+
width?: number;
|
|
18
|
+
/** 水印的高度 */
|
|
19
|
+
height?: number;
|
|
20
|
+
/** 水印在canvas 画布上绘制的垂直偏移量,正常情况下,水印绘制在中间位置, 即 offsetTop = gapY / 2 */
|
|
21
|
+
offsetTop?: number;
|
|
22
|
+
/** 水印在canvas 画布上绘制的水平偏移量, 正常情况下,水印绘制在中间位置, 即 offsetTop = gapX / 2 */
|
|
23
|
+
offsetLeft?: number;
|
|
24
|
+
/** 水印绘制时,旋转的角度,单位 ° */
|
|
25
|
+
rotate?: number;
|
|
26
|
+
/** ClassName 前缀 */
|
|
27
|
+
prefixCls?: string;
|
|
28
|
+
/** 高清印图片源, 为了高清屏幕显示,建议使用 2倍或3倍图,优先使用图片渲染水印。 */
|
|
29
|
+
image?: string;
|
|
30
|
+
/**
|
|
31
|
+
* @description 文字颜色
|
|
32
|
+
* @default rgba(0,0,0,.15)
|
|
33
|
+
*/
|
|
34
|
+
fontColor?: string;
|
|
35
|
+
/**
|
|
36
|
+
* @description 文字样式
|
|
37
|
+
* @default normal
|
|
38
|
+
*/
|
|
39
|
+
fontStyle?: 'none' | 'normal' | 'italic' | 'oblique';
|
|
40
|
+
/**
|
|
41
|
+
* @description 文字族
|
|
42
|
+
* @default sans-serif
|
|
43
|
+
*/
|
|
44
|
+
fontFamily?: string;
|
|
45
|
+
/**
|
|
46
|
+
* @description 文字粗细
|
|
47
|
+
* @default normal
|
|
48
|
+
*/
|
|
49
|
+
fontWeight?: 'normal' | 'light' | 'weight' | number;
|
|
50
|
+
/**
|
|
51
|
+
* @description 文字大小
|
|
52
|
+
* @default 16
|
|
53
|
+
*/
|
|
54
|
+
fontSize?: number | string;
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* 水印组件
|
|
58
|
+
* @param WaterMarkProps
|
|
59
|
+
* @returns
|
|
60
|
+
*/
|
|
61
|
+
declare const WaterMarkRelative: (props: WaterMarkProps) => import("react/jsx-runtime").JSX.Element;
|
|
62
|
+
export default WaterMarkRelative;
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
5
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
6
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
7
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
8
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
9
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
10
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
11
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
12
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
13
|
+
import { ConfigProvider } from 'antd';
|
|
14
|
+
import classNames from 'classnames';
|
|
15
|
+
import React, { useContext, useEffect, useState } from 'react';
|
|
16
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
17
|
+
import { Fragment as _Fragment } from "react/jsx-runtime";
|
|
18
|
+
/**
|
|
19
|
+
* 返回当前显示设备的物理像素分辨率与CSS像素分辨率之比
|
|
20
|
+
*
|
|
21
|
+
* @param context
|
|
22
|
+
* @see api 有些废弃了,其实类型 CanvasRenderingContext2D
|
|
23
|
+
*/
|
|
24
|
+
var getPixelRatio = function getPixelRatio(context) {
|
|
25
|
+
if (!context) {
|
|
26
|
+
return 1;
|
|
27
|
+
}
|
|
28
|
+
var backingStore = context.backingStorePixelRatio || context.webkitBackingStorePixelRatio || context.mozBackingStorePixelRatio || context.msBackingStorePixelRatio || context.oBackingStorePixelRatio || context.backingStorePixelRatio || 1;
|
|
29
|
+
return (window.devicePixelRatio || 1) / backingStore;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* 水印组件
|
|
34
|
+
* @param WaterMarkProps
|
|
35
|
+
* @returns
|
|
36
|
+
*/
|
|
37
|
+
var WaterMarkRelative = function WaterMarkRelative(props) {
|
|
38
|
+
var markStyle = props.markStyle,
|
|
39
|
+
markClassName = props.markClassName,
|
|
40
|
+
_props$zIndex = props.zIndex,
|
|
41
|
+
zIndex = _props$zIndex === void 0 ? 9 : _props$zIndex,
|
|
42
|
+
_props$gapX = props.gapX,
|
|
43
|
+
gapX = _props$gapX === void 0 ? 212 : _props$gapX,
|
|
44
|
+
_props$gapY = props.gapY,
|
|
45
|
+
gapY = _props$gapY === void 0 ? 222 : _props$gapY,
|
|
46
|
+
_props$width = props.width,
|
|
47
|
+
width = _props$width === void 0 ? 120 : _props$width,
|
|
48
|
+
_props$height = props.height,
|
|
49
|
+
height = _props$height === void 0 ? 64 : _props$height,
|
|
50
|
+
_props$rotate = props.rotate,
|
|
51
|
+
rotate = _props$rotate === void 0 ? -22 : _props$rotate,
|
|
52
|
+
image = props.image,
|
|
53
|
+
content = props.content,
|
|
54
|
+
offsetLeft = props.offsetLeft,
|
|
55
|
+
offsetTop = props.offsetTop,
|
|
56
|
+
_props$fontStyle = props.fontStyle,
|
|
57
|
+
fontStyle = _props$fontStyle === void 0 ? 'normal' : _props$fontStyle,
|
|
58
|
+
_props$fontWeight = props.fontWeight,
|
|
59
|
+
fontWeight = _props$fontWeight === void 0 ? 'normal' : _props$fontWeight,
|
|
60
|
+
_props$fontColor = props.fontColor,
|
|
61
|
+
fontColor = _props$fontColor === void 0 ? 'rgba(0,0,0,.15)' : _props$fontColor,
|
|
62
|
+
_props$fontSize = props.fontSize,
|
|
63
|
+
fontSize = _props$fontSize === void 0 ? 16 : _props$fontSize,
|
|
64
|
+
_props$fontFamily = props.fontFamily,
|
|
65
|
+
fontFamily = _props$fontFamily === void 0 ? 'sans-serif' : _props$fontFamily,
|
|
66
|
+
customizePrefixCls = props.prefixCls;
|
|
67
|
+
var _useContext = useContext(ConfigProvider.ConfigContext),
|
|
68
|
+
getPrefixCls = _useContext.getPrefixCls;
|
|
69
|
+
var prefixCls = getPrefixCls('pro-layout-watermark', customizePrefixCls);
|
|
70
|
+
var waterMakrCls = classNames(prefixCls, markClassName);
|
|
71
|
+
var _useState = useState(''),
|
|
72
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
73
|
+
base64Url = _useState2[0],
|
|
74
|
+
setBase64Url = _useState2[1];
|
|
75
|
+
useEffect(function () {
|
|
76
|
+
var canvas = document.createElement('canvas');
|
|
77
|
+
var ctx = canvas.getContext('2d');
|
|
78
|
+
var ratio = getPixelRatio(ctx);
|
|
79
|
+
var canvasWidth = "".concat((gapX + width) * ratio, "px");
|
|
80
|
+
var canvasHeight = "".concat((gapY + height) * ratio, "px");
|
|
81
|
+
var canvasOffsetLeft = offsetLeft || gapX / 2;
|
|
82
|
+
var canvasOffsetTop = offsetTop || gapY / 2;
|
|
83
|
+
canvas.setAttribute('width', canvasWidth);
|
|
84
|
+
canvas.setAttribute('height', canvasHeight);
|
|
85
|
+
if (ctx) {
|
|
86
|
+
// 旋转字符 rotate
|
|
87
|
+
ctx.translate(canvasOffsetLeft * ratio, canvasOffsetTop * ratio);
|
|
88
|
+
ctx.rotate(Math.PI / 180 * Number(rotate));
|
|
89
|
+
var markWidth = width * ratio;
|
|
90
|
+
var markHeight = height * ratio;
|
|
91
|
+
if (image) {
|
|
92
|
+
var img = new Image();
|
|
93
|
+
img.crossOrigin = 'anonymous';
|
|
94
|
+
img.referrerPolicy = 'no-referrer';
|
|
95
|
+
img.src = image;
|
|
96
|
+
img.onload = function () {
|
|
97
|
+
ctx.drawImage(img, 0, 0, markWidth, markHeight);
|
|
98
|
+
setBase64Url(canvas.toDataURL());
|
|
99
|
+
};
|
|
100
|
+
} else if (content) {
|
|
101
|
+
var markSize = Number(fontSize) * ratio;
|
|
102
|
+
ctx.font = "".concat(fontStyle, " normal ").concat(fontWeight, " ").concat(markSize, "px/").concat(markHeight, "px ").concat(fontFamily);
|
|
103
|
+
ctx.fillStyle = fontColor;
|
|
104
|
+
ctx.fillText(content, 0, 0);
|
|
105
|
+
setBase64Url(canvas.toDataURL());
|
|
106
|
+
}
|
|
107
|
+
} else {
|
|
108
|
+
// eslint-disable-next-line no-console
|
|
109
|
+
console.error('当前环境不支持Canvas');
|
|
110
|
+
}
|
|
111
|
+
}, [gapX, gapY, offsetLeft, offsetTop, rotate, fontStyle, fontWeight, width, height, fontFamily, fontColor, image, content, fontSize]);
|
|
112
|
+
return /*#__PURE__*/_jsx(_Fragment, {
|
|
113
|
+
children: base64Url && /*#__PURE__*/_jsx("div", {
|
|
114
|
+
className: waterMakrCls,
|
|
115
|
+
style: _objectSpread({
|
|
116
|
+
zIndex: zIndex,
|
|
117
|
+
position: 'fixed',
|
|
118
|
+
left: 0,
|
|
119
|
+
top: 0,
|
|
120
|
+
width: '100%',
|
|
121
|
+
height: '100%',
|
|
122
|
+
backgroundSize: "".concat(gapX + width, "px"),
|
|
123
|
+
pointerEvents: 'none',
|
|
124
|
+
backgroundRepeat: 'repeat',
|
|
125
|
+
backgroundImage: "url('".concat(base64Url, "')")
|
|
126
|
+
}, markStyle)
|
|
127
|
+
})
|
|
128
|
+
});
|
|
129
|
+
};
|
|
130
|
+
export default WaterMarkRelative;
|