hwxc 1.0.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/README.md ADDED
@@ -0,0 +1,6 @@
1
+ // 安装
2
+ npm install hwxc
3
+
4
+ // pos自定义搜索弹窗(enter跳转光标)
5
+ import { PosSearchModal } from 'hwxc';
6
+ import type { PosSearchModalProps } from 'hwxc';
@@ -0,0 +1,22 @@
1
+ import { ProColumns } from '@ant-design/pro-table';
2
+ import React from 'react';
3
+
4
+ type Props = {
5
+ /** 是否显示弹窗 */
6
+ visible: boolean;
7
+ /** 关闭时是否销毁子元素 */
8
+ destroyOnClose?: boolean;
9
+ /** 自定义dom */
10
+ nodeDom?: React.ReactNode;
11
+ /** 取消回调 */
12
+ onCancle: () => void;
13
+ /** 确认回调,返回表单值 */
14
+ onOk: (res: any) => void;
15
+ /** ProTable 列配置,用于生成表单项 */
16
+ columns: ProColumns<any>[];
17
+ /** 确认按钮加载状态 */
18
+ loading?: boolean;
19
+ };
20
+ declare const PosSearchModal: (props: Props) => React.JSX.Element;
21
+
22
+ export { PosSearchModal, Props as PosSearchModalProps };
@@ -0,0 +1,22 @@
1
+ import { ProColumns } from '@ant-design/pro-table';
2
+ import React from 'react';
3
+
4
+ type Props = {
5
+ /** 是否显示弹窗 */
6
+ visible: boolean;
7
+ /** 关闭时是否销毁子元素 */
8
+ destroyOnClose?: boolean;
9
+ /** 自定义dom */
10
+ nodeDom?: React.ReactNode;
11
+ /** 取消回调 */
12
+ onCancle: () => void;
13
+ /** 确认回调,返回表单值 */
14
+ onOk: (res: any) => void;
15
+ /** ProTable 列配置,用于生成表单项 */
16
+ columns: ProColumns<any>[];
17
+ /** 确认按钮加载状态 */
18
+ loading?: boolean;
19
+ };
20
+ declare const PosSearchModal: (props: Props) => React.JSX.Element;
21
+
22
+ export { PosSearchModal, Props as PosSearchModalProps };
package/dist/index.js ADDED
@@ -0,0 +1,196 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __defProps = Object.defineProperties;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
7
+ var __getOwnPropNames = Object.getOwnPropertyNames;
8
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
9
+ var __getProtoOf = Object.getPrototypeOf;
10
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
11
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
12
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
13
+ var __spreadValues = (a, b) => {
14
+ for (var prop in b || (b = {}))
15
+ if (__hasOwnProp.call(b, prop))
16
+ __defNormalProp(a, prop, b[prop]);
17
+ if (__getOwnPropSymbols)
18
+ for (var prop of __getOwnPropSymbols(b)) {
19
+ if (__propIsEnum.call(b, prop))
20
+ __defNormalProp(a, prop, b[prop]);
21
+ }
22
+ return a;
23
+ };
24
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
25
+ var __export = (target, all) => {
26
+ for (var name in all)
27
+ __defProp(target, name, { get: all[name], enumerable: true });
28
+ };
29
+ var __copyProps = (to, from, except, desc) => {
30
+ if (from && typeof from === "object" || typeof from === "function") {
31
+ for (let key of __getOwnPropNames(from))
32
+ if (!__hasOwnProp.call(to, key) && key !== except)
33
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
34
+ }
35
+ return to;
36
+ };
37
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
38
+ // If the importer is in node compatibility mode or this is not an ESM
39
+ // file that has been converted to a CommonJS file using a Babel-
40
+ // compatible transform (i.e. "__esModule" has not been set), then set
41
+ // "default" to the CommonJS "module.exports" for node compatibility.
42
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
43
+ mod
44
+ ));
45
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
46
+
47
+ // src/index.ts
48
+ var src_exports = {};
49
+ __export(src_exports, {
50
+ PosSearchModal: () => PosSearchModal
51
+ });
52
+ module.exports = __toCommonJS(src_exports);
53
+
54
+ // src/components/PosSearchModal/index.tsx
55
+ var import_antd = require("antd");
56
+ var import_Form = require("antd/es/form/Form");
57
+ var import_react = require("react");
58
+ var import_ahooks = require("ahooks");
59
+ var import_react2 = __toESM(require("react"));
60
+ var { RangePicker } = import_antd.DatePicker;
61
+ var PosSearchModal = (props) => {
62
+ const { visible, nodeDom, onCancle, onOk, columns, destroyOnClose, loading } = props;
63
+ const [form] = (0, import_Form.useForm)();
64
+ const confirmRef = (0, import_react.useRef)();
65
+ const searchList = columns.filter((item) => item.search !== false);
66
+ const renderFormItem = (item, index) => {
67
+ const type = item.valueType;
68
+ if (type === "select")
69
+ return /* @__PURE__ */ import_react2.default.createElement(import_antd.Select, __spreadValues({ style: { width: 400 } }, item.fieldProps));
70
+ if (type === "dateTimeRange")
71
+ return /* @__PURE__ */ import_react2.default.createElement(
72
+ RangePicker,
73
+ __spreadProps(__spreadValues({
74
+ style: { width: 400 }
75
+ }, item.fieldProps), {
76
+ showTime: true
77
+ })
78
+ );
79
+ if (type === "dateRange")
80
+ return /* @__PURE__ */ import_react2.default.createElement(
81
+ RangePicker,
82
+ __spreadProps(__spreadValues({
83
+ style: { width: 400 }
84
+ }, item.fieldProps), {
85
+ format: "YYYYMMDD",
86
+ placeholder: ["19990101", "19990101"]
87
+ })
88
+ );
89
+ if (type === "date")
90
+ return /* @__PURE__ */ import_react2.default.createElement(
91
+ import_antd.DatePicker,
92
+ __spreadValues({
93
+ style: { width: 400 }
94
+ }, item.fieldProps)
95
+ );
96
+ return /* @__PURE__ */ import_react2.default.createElement(import_antd.Input, __spreadValues({ style: { width: 400 } }, item.fieldProps));
97
+ };
98
+ const handleSubmit = (0, import_ahooks.useLockFn)(() => {
99
+ form.validateFields().then((res) => {
100
+ onOk(res);
101
+ });
102
+ return new Promise((resolve) => {
103
+ setTimeout(() => {
104
+ resolve();
105
+ }, 2e3);
106
+ });
107
+ });
108
+ const enterJump = (e) => {
109
+ e.target.current = true;
110
+ const arr = Array.from(document.querySelectorAll("input"));
111
+ const index = arr.findIndex((item) => item.current);
112
+ const right = arr[index + 1];
113
+ if (e.key === "Enter") {
114
+ if (!e.target.closest(".ant-select-open")) {
115
+ e.stopPropagation();
116
+ }
117
+ if (right) {
118
+ right.select();
119
+ } else {
120
+ setTimeout(() => {
121
+ var _a;
122
+ (_a = confirmRef.current) == null ? void 0 : _a.focus();
123
+ }, 100);
124
+ }
125
+ }
126
+ e.target.current = false;
127
+ };
128
+ (0, import_react.useEffect)(() => {
129
+ var _a;
130
+ if (visible) {
131
+ setTimeout(() => {
132
+ var _a2, _b;
133
+ (_a2 = document.querySelector("#search-form")) == null ? void 0 : _a2.addEventListener("keydown", enterJump);
134
+ (_b = document.querySelector("#search-form input")) == null ? void 0 : _b.select();
135
+ }, 200);
136
+ } else {
137
+ (_a = document.querySelector("#search-form")) == null ? void 0 : _a.removeEventListener("keydown", enterJump);
138
+ }
139
+ }, [visible]);
140
+ const triggerDom = nodeDom ? import_react2.default.cloneElement(nodeDom) : "";
141
+ return /* @__PURE__ */ import_react2.default.createElement(
142
+ import_antd.Modal,
143
+ {
144
+ title: "\u67E5\u8BE2",
145
+ destroyOnClose,
146
+ visible,
147
+ onCancel: onCancle,
148
+ onOk: handleSubmit,
149
+ width: 600,
150
+ bodyStyle: { height: 400, overflowY: "auto" },
151
+ confirmLoading: loading,
152
+ footer: /* @__PURE__ */ import_react2.default.createElement("div", null, /* @__PURE__ */ import_react2.default.createElement(
153
+ "span",
154
+ {
155
+ style: {
156
+ float: "left",
157
+ color: "red"
158
+ }
159
+ },
160
+ "\u6E29\u99A8\u63D0\u793A: Enter\u56DE\u8F66\u952E\u5207\u6362\u5149\u6807"
161
+ ), /* @__PURE__ */ import_react2.default.createElement(import_antd.Button, { onClick: onCancle }, "\u53D6\u6D88"), /* @__PURE__ */ import_react2.default.createElement(import_antd.Button, { ref: confirmRef, type: "primary", onClick: handleSubmit }, "\u786E\u5B9A"))
162
+ },
163
+ /* @__PURE__ */ import_react2.default.createElement(
164
+ import_antd.Form,
165
+ {
166
+ id: "search-form",
167
+ form,
168
+ labelCol: { span: 6 },
169
+ labelAlign: "left",
170
+ preserve: false,
171
+ size: "middle"
172
+ },
173
+ searchList.map(
174
+ (item, index) => {
175
+ var _a;
176
+ return item.renderFormItem ? item.renderFormItem() : /* @__PURE__ */ import_react2.default.createElement(
177
+ import_antd.Form.Item,
178
+ {
179
+ key: item.dataIndex,
180
+ label: item.title,
181
+ name: item.dataIndex,
182
+ initialValue: item.initialValue,
183
+ rules: [{ required: (_a = item.fieldProps) == null ? void 0 : _a.required }]
184
+ },
185
+ renderFormItem(item, index)
186
+ );
187
+ }
188
+ )
189
+ ),
190
+ triggerDom
191
+ );
192
+ };
193
+ // Annotate the CommonJS export names for ESM import in node:
194
+ 0 && (module.exports = {
195
+ PosSearchModal
196
+ });
package/dist/index.mjs ADDED
@@ -0,0 +1,162 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __spreadValues = (a, b) => {
9
+ for (var prop in b || (b = {}))
10
+ if (__hasOwnProp.call(b, prop))
11
+ __defNormalProp(a, prop, b[prop]);
12
+ if (__getOwnPropSymbols)
13
+ for (var prop of __getOwnPropSymbols(b)) {
14
+ if (__propIsEnum.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ }
17
+ return a;
18
+ };
19
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
+
21
+ // src/components/PosSearchModal/index.tsx
22
+ import { Button, DatePicker, Form, Input, Modal, Select } from "antd";
23
+ import { useForm } from "antd/es/form/Form";
24
+ import { useEffect, useRef } from "react";
25
+ import { useLockFn } from "ahooks";
26
+ import React from "react";
27
+ var { RangePicker } = DatePicker;
28
+ var PosSearchModal = (props) => {
29
+ const { visible, nodeDom, onCancle, onOk, columns, destroyOnClose, loading } = props;
30
+ const [form] = useForm();
31
+ const confirmRef = useRef();
32
+ const searchList = columns.filter((item) => item.search !== false);
33
+ const renderFormItem = (item, index) => {
34
+ const type = item.valueType;
35
+ if (type === "select")
36
+ return /* @__PURE__ */ React.createElement(Select, __spreadValues({ style: { width: 400 } }, item.fieldProps));
37
+ if (type === "dateTimeRange")
38
+ return /* @__PURE__ */ React.createElement(
39
+ RangePicker,
40
+ __spreadProps(__spreadValues({
41
+ style: { width: 400 }
42
+ }, item.fieldProps), {
43
+ showTime: true
44
+ })
45
+ );
46
+ if (type === "dateRange")
47
+ return /* @__PURE__ */ React.createElement(
48
+ RangePicker,
49
+ __spreadProps(__spreadValues({
50
+ style: { width: 400 }
51
+ }, item.fieldProps), {
52
+ format: "YYYYMMDD",
53
+ placeholder: ["19990101", "19990101"]
54
+ })
55
+ );
56
+ if (type === "date")
57
+ return /* @__PURE__ */ React.createElement(
58
+ DatePicker,
59
+ __spreadValues({
60
+ style: { width: 400 }
61
+ }, item.fieldProps)
62
+ );
63
+ return /* @__PURE__ */ React.createElement(Input, __spreadValues({ style: { width: 400 } }, item.fieldProps));
64
+ };
65
+ const handleSubmit = useLockFn(() => {
66
+ form.validateFields().then((res) => {
67
+ onOk(res);
68
+ });
69
+ return new Promise((resolve) => {
70
+ setTimeout(() => {
71
+ resolve();
72
+ }, 2e3);
73
+ });
74
+ });
75
+ const enterJump = (e) => {
76
+ e.target.current = true;
77
+ const arr = Array.from(document.querySelectorAll("input"));
78
+ const index = arr.findIndex((item) => item.current);
79
+ const right = arr[index + 1];
80
+ if (e.key === "Enter") {
81
+ if (!e.target.closest(".ant-select-open")) {
82
+ e.stopPropagation();
83
+ }
84
+ if (right) {
85
+ right.select();
86
+ } else {
87
+ setTimeout(() => {
88
+ var _a;
89
+ (_a = confirmRef.current) == null ? void 0 : _a.focus();
90
+ }, 100);
91
+ }
92
+ }
93
+ e.target.current = false;
94
+ };
95
+ useEffect(() => {
96
+ var _a;
97
+ if (visible) {
98
+ setTimeout(() => {
99
+ var _a2, _b;
100
+ (_a2 = document.querySelector("#search-form")) == null ? void 0 : _a2.addEventListener("keydown", enterJump);
101
+ (_b = document.querySelector("#search-form input")) == null ? void 0 : _b.select();
102
+ }, 200);
103
+ } else {
104
+ (_a = document.querySelector("#search-form")) == null ? void 0 : _a.removeEventListener("keydown", enterJump);
105
+ }
106
+ }, [visible]);
107
+ const triggerDom = nodeDom ? React.cloneElement(nodeDom) : "";
108
+ return /* @__PURE__ */ React.createElement(
109
+ Modal,
110
+ {
111
+ title: "\u67E5\u8BE2",
112
+ destroyOnClose,
113
+ visible,
114
+ onCancel: onCancle,
115
+ onOk: handleSubmit,
116
+ width: 600,
117
+ bodyStyle: { height: 400, overflowY: "auto" },
118
+ confirmLoading: loading,
119
+ footer: /* @__PURE__ */ React.createElement("div", null, /* @__PURE__ */ React.createElement(
120
+ "span",
121
+ {
122
+ style: {
123
+ float: "left",
124
+ color: "red"
125
+ }
126
+ },
127
+ "\u6E29\u99A8\u63D0\u793A: Enter\u56DE\u8F66\u952E\u5207\u6362\u5149\u6807"
128
+ ), /* @__PURE__ */ React.createElement(Button, { onClick: onCancle }, "\u53D6\u6D88"), /* @__PURE__ */ React.createElement(Button, { ref: confirmRef, type: "primary", onClick: handleSubmit }, "\u786E\u5B9A"))
129
+ },
130
+ /* @__PURE__ */ React.createElement(
131
+ Form,
132
+ {
133
+ id: "search-form",
134
+ form,
135
+ labelCol: { span: 6 },
136
+ labelAlign: "left",
137
+ preserve: false,
138
+ size: "middle"
139
+ },
140
+ searchList.map(
141
+ (item, index) => {
142
+ var _a;
143
+ return item.renderFormItem ? item.renderFormItem() : /* @__PURE__ */ React.createElement(
144
+ Form.Item,
145
+ {
146
+ key: item.dataIndex,
147
+ label: item.title,
148
+ name: item.dataIndex,
149
+ initialValue: item.initialValue,
150
+ rules: [{ required: (_a = item.fieldProps) == null ? void 0 : _a.required }]
151
+ },
152
+ renderFormItem(item, index)
153
+ );
154
+ }
155
+ )
156
+ ),
157
+ triggerDom
158
+ );
159
+ };
160
+ export {
161
+ PosSearchModal
162
+ };
package/package.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "hwxc",
3
+ "version": "1.0.0",
4
+ "description": "HWXC 组件库",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.esm.js",
7
+ "types": "dist/index.d.ts",
8
+ "files": ["dist"],
9
+ "scripts": {
10
+ "build": "tsup",
11
+ "prepublishOnly": "npm run build"
12
+ },
13
+ "peerDependencies": {
14
+ "react": ">=16.9.0",
15
+ "react-dom": ">=16.9.0",
16
+ "antd": ">=4.0.0",
17
+ "@ant-design/pro-table": ">=2.0.0",
18
+ "ahooks": ">=2.0.0"
19
+ },
20
+ "devDependencies": {
21
+ "typescript": "^5.0.0",
22
+ "@types/react": "^18.0.0",
23
+ "@types/react-dom": "^18.0.0",
24
+ "tsup": "^7.0.0"
25
+ },
26
+ "keywords": ["react", "antd", "pro-table", "modal"],
27
+ "author": "your-name",
28
+ "license": "MIT"
29
+ }