zmdms-webui 2.5.8 → 2.5.9

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.
@@ -1 +1 @@
1
- .ztxk-modal{top:8vh}.ztxk-modal .ant-modal-content{border-radius:8px}.ztxk-modal .ant-modal-content>.ant-modal-close{color:#333;height:40px;width:40px}.ztxk-modal .ant-modal-content>.ant-modal-close>.ant-modal-close-x{font-weight:400;height:40px;line-height:40px;width:40px}.ztxk-modal .ant-modal-content>.ant-modal-header{border-bottom:1px solid #f0f0f0;border-radius:8px 8px 0 0;padding:9px 20px 9px 24px}.ztxk-modal .ant-modal-content>.ant-modal-header>.ant-modal-title{color:#333;font-weight:400;line-height:22px;text-align:center}.ztxk-modal .ant-modal-content>.ant-modal-body{max-height:75vh;overflow:auto;padding:10px}.ztxk-modal .ant-modal-content>.ant-modal-footer{border-top:0;padding:10px 0;text-align:center}
1
+ .ztxk-modal{top:8vh}.ztxk-modal .ant-modal-content{border-radius:8px;display:flex;flex-direction:column}.ztxk-modal .ant-modal-content>.ant-modal-close{color:#333;height:40px;width:40px}.ztxk-modal .ant-modal-content>.ant-modal-close>.ant-modal-close-x{font-weight:400;height:40px;line-height:40px;width:40px}.ztxk-modal .ant-modal-content>.ant-modal-header{border-bottom:1px solid #f0f0f0;border-radius:8px 8px 0 0;flex-shrink:0;padding:9px 20px 9px 24px}.ztxk-modal .ant-modal-content>.ant-modal-header>.ant-modal-title{color:#333;font-weight:400;line-height:22px;text-align:center}.ztxk-modal .ant-modal-content>.ant-modal-body{flex:1;overflow:auto;padding:10px}.ztxk-modal .ant-modal-content>.ant-modal-footer{border-top:0;flex-shrink:0;padding:10px 0;text-align:center}.ztxk-modal-resizable-wrapper{position:relative}.ztxk-modal-resizable-wrapper .ztxk-modal-resize-handle{pointer-events:auto;position:absolute;z-index:1000}.ztxk-modal-resizable-wrapper .ztxk-modal-resize-handle-bl,.ztxk-modal-resizable-wrapper .ztxk-modal-resize-handle-br,.ztxk-modal-resizable-wrapper .ztxk-modal-resize-handle-tl,.ztxk-modal-resizable-wrapper .ztxk-modal-resize-handle-tr{height:12px;width:12px}.ztxk-modal-resizable-wrapper .ztxk-modal-resize-handle-tl{cursor:nwse-resize!important;left:0;top:0}.ztxk-modal-resizable-wrapper .ztxk-modal-resize-handle-tr{cursor:nesw-resize!important;right:0;top:0}.ztxk-modal-resizable-wrapper .ztxk-modal-resize-handle-bl{bottom:0;cursor:nesw-resize!important;left:0}.ztxk-modal-resizable-wrapper .ztxk-modal-resize-handle-br{bottom:0;cursor:nwse-resize!important;right:0}.ztxk-modal-resizable-wrapper .ztxk-modal-resize-handle-b,.ztxk-modal-resizable-wrapper .ztxk-modal-resize-handle-t{height:8px;left:12px;right:12px}.ztxk-modal-resizable-wrapper .ztxk-modal-resize-handle-t{cursor:ns-resize!important;top:0}.ztxk-modal-resizable-wrapper .ztxk-modal-resize-handle-b{bottom:0;cursor:ns-resize!important}.ztxk-modal-resizable-wrapper .ztxk-modal-resize-handle-l,.ztxk-modal-resizable-wrapper .ztxk-modal-resize-handle-r{bottom:12px;top:12px;width:8px}.ztxk-modal-resizable-wrapper .ztxk-modal-resize-handle-l{cursor:ew-resize!important;left:0}.ztxk-modal-resizable-wrapper .ztxk-modal-resize-handle-r{cursor:ew-resize!important;right:0}body.ztxk-modal-resizing,body.ztxk-modal-resizing *{-webkit-user-select:none!important;user-select:none!important}
@@ -82,6 +82,34 @@ interface IModalProps extends Omit<ModalProps, "onOk"> {
82
82
  * 是否可以拖拽
83
83
  */
84
84
  isDrag?: boolean;
85
+ /**
86
+ * 是否可以调整大小
87
+ */
88
+ isResize?: boolean;
89
+ /**
90
+ * 最小宽度
91
+ */
92
+ minWidth?: number;
93
+ /**
94
+ * 最小高度
95
+ */
96
+ minHeight?: number;
97
+ /**
98
+ * 最大宽度
99
+ */
100
+ maxWidth?: number;
101
+ /**
102
+ * 最大高度
103
+ */
104
+ maxHeight?: number;
105
+ /**
106
+ * 默认宽度
107
+ */
108
+ defaultWidth?: string | number;
109
+ /**
110
+ * 默认高度
111
+ */
112
+ defaultHeight?: string | number;
85
113
  }
86
114
  interface IModalComponent extends React__default.ForwardRefExoticComponent<IModalProps & React__default.RefAttributes<unknown>> {
87
115
  info: typeof Modal.info;
@@ -5,21 +5,22 @@ import { Modal as Modal$1 } from 'antd';
5
5
  import classNames from '../node_modules/classnames/index.js';
6
6
  import { setCancelBtnProps } from './utils.js';
7
7
  import useDraggable from './useDraggable.js';
8
+ import useResizable from './useResizable.js';
8
9
  import myMessage from '../message/index.js';
9
10
 
10
11
  var Modal = function (_a, ref) {
11
- var className = _a.className, defaultOpen = _a.defaultOpen, defaultTitle = _a.defaultTitle, defaultConfirmMsg = _a.defaultConfirmMsg, defaultConfirmOkText = _a.defaultConfirmOkText, defaultType = _a.defaultType, confirmPreHandle = _a.confirmPreHandle, confirmOnOk = _a.confirmOnOk, onOk = _a.onOk, footer = _a.footer, onOkValidate = _a.onOkValidate, _b = _a.isDrag, isDrag = _b === void 0 ? true : _b, modalTitle = _a.title, modalRender = _a.modalRender, resetProps = __rest(_a, ["className", "defaultOpen", "defaultTitle", "defaultConfirmMsg", "defaultConfirmOkText", "defaultType", "confirmPreHandle", "confirmOnOk", "onOk", "footer", "onOkValidate", "isDrag", "title", "modalRender"]);
12
+ var className = _a.className, defaultOpen = _a.defaultOpen, defaultTitle = _a.defaultTitle, defaultConfirmMsg = _a.defaultConfirmMsg, defaultConfirmOkText = _a.defaultConfirmOkText, defaultType = _a.defaultType, confirmPreHandle = _a.confirmPreHandle, confirmOnOk = _a.confirmOnOk, onOk = _a.onOk, footer = _a.footer, onOkValidate = _a.onOkValidate, _b = _a.isDrag, isDrag = _b === void 0 ? true : _b, _c = _a.isResize, isResize = _c === void 0 ? false : _c, minWidth = _a.minWidth, minHeight = _a.minHeight, maxWidth = _a.maxWidth, maxHeight = _a.maxHeight, defaultWidth = _a.defaultWidth, _d = _a.defaultHeight, defaultHeight = _d === void 0 ? 500 : _d, modalTitle = _a.title, modalRender = _a.modalRender, resetProps = __rest(_a, ["className", "defaultOpen", "defaultTitle", "defaultConfirmMsg", "defaultConfirmOkText", "defaultType", "confirmPreHandle", "confirmOnOk", "onOk", "footer", "onOkValidate", "isDrag", "isResize", "minWidth", "minHeight", "maxWidth", "maxHeight", "defaultWidth", "defaultHeight", "title", "modalRender"]);
12
13
  var classes = classNames("ztxk-modal", className);
13
14
  // 模态框基本属性
14
- var _c = useState(defaultOpen), open = _c[0], setOpen = _c[1];
15
- var _d = useState(defaultTitle), title = _d[0], setTitle = _d[1];
16
- var _e = useState(), loading = _e[0], setLoading = _e[1];
15
+ var _e = useState(defaultOpen), open = _e[0], setOpen = _e[1];
16
+ var _f = useState(defaultTitle), title = _f[0], setTitle = _f[1];
17
+ var _g = useState(), loading = _g[0], setLoading = _g[1];
17
18
  // 二次确认框相关配置
18
- var _f = useState(confirmOnOk ? true : false), isConfirm = _f[0], setIsConfirm = _f[1];
19
- var _g = useState(defaultConfirmMsg), confirmMsg = _g[0], setConfirmMsg = _g[1];
20
- var _h = useState(defaultConfirmOkText), confirmOkText = _h[0], setConfirmOkText = _h[1];
19
+ var _h = useState(confirmOnOk ? true : false), isConfirm = _h[0], setIsConfirm = _h[1];
20
+ var _j = useState(defaultConfirmMsg), confirmMsg = _j[0], setConfirmMsg = _j[1];
21
+ var _k = useState(defaultConfirmOkText), confirmOkText = _k[0], setConfirmOkText = _k[1];
21
22
  // 模态框类型
22
- var _j = useState(defaultType), type = _j[0], setType = _j[1];
23
+ var _l = useState(defaultType), type = _l[0], setType = _l[1];
23
24
  var close = useCallback(function () {
24
25
  setOpen(false);
25
26
  }, []);
@@ -141,12 +142,27 @@ var Modal = function (_a, ref) {
141
142
  setConfirmMsg: setConfirmOkText,
142
143
  };
143
144
  });
144
- var _k = useDraggable({
145
+ var _m = useResizable({
146
+ isResize: isResize,
147
+ minWidth: minWidth,
148
+ minHeight: minHeight,
149
+ maxWidth: maxWidth,
150
+ maxHeight: maxHeight,
151
+ defaultWidth: defaultWidth,
152
+ defaultHeight: defaultHeight,
153
+ modalRender: modalRender,
154
+ }), resizableWidth = _m.width, resizableModalRender = _m.resizableModalRender;
155
+ var _o = useDraggable({
145
156
  isDrag: isDrag,
146
157
  title: modalTitle || title,
147
158
  modalRender: modalRender,
148
- }), dragTitle = _k.dragTitle, dragModalRender = _k.dragModalRender;
149
- return (jsx(Modal$1, __assign({ open: open, onCancel: close, className: classes, okText: "\u4FDD\u5B58", onOk: footer ? undefined : onOkHandle, width: "70%", title: dragTitle, keyboard: false, maskClosable: false, confirmLoading: loading, cancelButtonProps: { loading: loading }, footer: footer, modalRender: dragModalRender }, resetProps)));
159
+ }), dragTitle = _o.dragTitle, dragModalRender = _o.dragModalRender;
160
+ var finalWidth = isResize ? resizableWidth : resetProps.width || "70%";
161
+ return (jsx(Modal$1, __assign({ open: open, onCancel: close, className: classes, okText: "\u4FDD\u5B58", onOk: footer ? undefined : onOkHandle, width: finalWidth, title: dragTitle, keyboard: false, maskClosable: false, confirmLoading: loading, cancelButtonProps: { loading: loading }, footer: footer, modalRender: function (modal) {
162
+ var resized = resizableModalRender(modal);
163
+ var dragged = dragModalRender(resized);
164
+ return dragged;
165
+ } }, resetProps)));
150
166
  };
151
167
  var ModalComponent = forwardRef(Modal);
152
168
  ModalComponent.displayName = "ZTXK_WEBUI_ModalComponent";
@@ -44,7 +44,7 @@ var useDraggable = function (options) {
44
44
  ? function (modal) {
45
45
  return (jsx(Draggable, __assign({ disabled: disabled, bounds: bounds, onStart: function (event, uiData) { return onStart(event, uiData); } }, { children: jsx("div", __assign({ ref: draggleRef }, { children: modal })) })));
46
46
  }
47
- : options.modalRender;
47
+ : function (modal) { return modal; };
48
48
  return { dragTitle: dragTitle, dragModalRender: dragModalRender };
49
49
  };
50
50
 
@@ -0,0 +1,141 @@
1
+ import { __assign } from '../_virtual/_tslib.js';
2
+ import { jsxs, jsx } from 'react/jsx-runtime';
3
+ import React__default, { useState, useRef, useCallback } from 'react';
4
+
5
+ var useResizable = function (options) {
6
+ var isResize = options.isResize, _a = options.minWidth, minWidth = _a === void 0 ? 400 : _a, _b = options.minHeight, minHeight = _b === void 0 ? 300 : _b, maxWidth = options.maxWidth, maxHeight = options.maxHeight, _c = options.defaultWidth, defaultWidth = _c === void 0 ? "70%" : _c, _d = options.defaultHeight, defaultHeight = _d === void 0 ? "auto" : _d;
7
+ var _e = useState({
8
+ width: defaultWidth,
9
+ height: defaultHeight,
10
+ }), size = _e[0], setSize = _e[1];
11
+ var resizeRef = useRef(null);
12
+ var resizingRef = useRef({
13
+ direction: null,
14
+ startX: 0,
15
+ startY: 0,
16
+ startWidth: 0,
17
+ startHeight: 0,
18
+ });
19
+ // 开始调整大小
20
+ var onResizeStart = useCallback(function (direction, e) {
21
+ var _a;
22
+ if (!isResize) {
23
+ return;
24
+ }
25
+ e.preventDefault();
26
+ e.stopPropagation();
27
+ e.nativeEvent.stopImmediatePropagation();
28
+ var modalElement = (_a = resizeRef.current) === null || _a === void 0 ? void 0 : _a.querySelector(".ant-modal-content");
29
+ if (!modalElement) {
30
+ return;
31
+ }
32
+ var rect = modalElement.getBoundingClientRect();
33
+ resizingRef.current = {
34
+ direction: direction,
35
+ startX: e.clientX,
36
+ startY: e.clientY,
37
+ startWidth: rect.width,
38
+ startHeight: rect.height,
39
+ };
40
+ document.addEventListener("mousemove", onResizeMove);
41
+ document.addEventListener("mouseup", onResizeEnd);
42
+ document.body.style.cursor = getCursor(direction);
43
+ document.body.style.userSelect = "none";
44
+ document.body.classList.add("ztxk-modal-resizing");
45
+ }, [isResize]);
46
+ // 调整大小中
47
+ var onResizeMove = useCallback(function (e) {
48
+ var _a = resizingRef.current, direction = _a.direction, startX = _a.startX, startY = _a.startY, startWidth = _a.startWidth, startHeight = _a.startHeight;
49
+ if (!direction) {
50
+ return;
51
+ }
52
+ var deltaX = e.clientX - startX;
53
+ var deltaY = e.clientY - startY;
54
+ var newWidth = startWidth;
55
+ var newHeight = startHeight;
56
+ // 根据拖拽方向计算新的尺寸
57
+ if (direction.includes("r")) {
58
+ newWidth = startWidth + deltaX;
59
+ }
60
+ else if (direction.includes("l")) {
61
+ newWidth = startWidth - deltaX;
62
+ }
63
+ if (direction.includes("b")) {
64
+ newHeight = startHeight + deltaY;
65
+ }
66
+ else if (direction.includes("t")) {
67
+ newHeight = startHeight - deltaY;
68
+ }
69
+ // 限制最小最大值
70
+ newWidth = Math.max(minWidth, newWidth);
71
+ newHeight = Math.max(minHeight, newHeight);
72
+ if (maxWidth) {
73
+ newWidth = Math.min(maxWidth, newWidth);
74
+ }
75
+ if (maxHeight) {
76
+ newHeight = Math.min(maxHeight, newHeight);
77
+ }
78
+ setSize({
79
+ width: newWidth,
80
+ height: newHeight,
81
+ });
82
+ }, [minWidth, minHeight, maxWidth, maxHeight]);
83
+ // 结束调整大小
84
+ var onResizeEnd = useCallback(function () {
85
+ resizingRef.current.direction = null;
86
+ document.removeEventListener("mousemove", onResizeMove);
87
+ document.removeEventListener("mouseup", onResizeEnd);
88
+ document.body.style.cursor = "";
89
+ document.body.style.userSelect = "";
90
+ document.body.classList.remove("ztxk-modal-resizing");
91
+ }, [onResizeMove]);
92
+ // 获取鼠标样式
93
+ var getCursor = function (direction) {
94
+ var cursorMap = {
95
+ tl: "nwse-resize",
96
+ tr: "nesw-resize",
97
+ bl: "nesw-resize",
98
+ br: "nwse-resize",
99
+ t: "ns-resize",
100
+ b: "ns-resize",
101
+ l: "ew-resize",
102
+ r: "ew-resize",
103
+ };
104
+ return cursorMap[direction];
105
+ };
106
+ // 渲染调整大小手柄
107
+ var renderResizeHandles = function () {
108
+ if (!isResize) {
109
+ return null;
110
+ }
111
+ var handles = [
112
+ "tl",
113
+ "tr",
114
+ "bl",
115
+ "br",
116
+ "t",
117
+ "b",
118
+ "l",
119
+ "r",
120
+ ];
121
+ return handles.map(function (direction) { return (jsx("div", { className: "ztxk-modal-resize-handle ztxk-modal-resize-handle-".concat(direction), onMouseDown: function (e) { return onResizeStart(direction, e); }, style: { cursor: getCursor(direction) } }, direction)); });
122
+ };
123
+ // 包装后的 modalRender
124
+ var resizableModalRender = function (modal) {
125
+ if (!isResize) {
126
+ return modal;
127
+ }
128
+ var modalElement = modal;
129
+ var modalWithHeight = React__default.cloneElement(modalElement, {
130
+ style: __assign(__assign({}, modalElement.props.style), { height: size.height }),
131
+ });
132
+ return (jsxs("div", __assign({ ref: resizeRef, className: "ztxk-modal-resizable-wrapper" }, { children: [modalWithHeight, renderResizeHandles()] })));
133
+ };
134
+ return {
135
+ width: size.width,
136
+ height: size.height,
137
+ resizableModalRender: resizableModalRender,
138
+ };
139
+ };
140
+
141
+ export { useResizable as default };