@teamias/rex-design 0.0.23 → 0.0.26
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/dist/components/base-form/components/ProFormDateRangePickerV2.d.ts +19 -0
- package/dist/components/base-form/components/ProFormDateRangePickerV2.js +176 -0
- package/dist/components/base-form/components/ProFormDigitRangeV2.d.ts +31 -0
- package/dist/components/base-form/components/ProFormDigitRangeV2.js +216 -0
- package/dist/components/base-form/components/RenderText.d.ts +7 -0
- package/dist/components/base-form/components/RenderText.js +9 -0
- package/dist/components/base-form/demo/BaseFormBasicTest.js +3 -2
- package/dist/components/base-form/demo/BaseFormCustomContent.js +6 -3
- package/dist/components/base-form/demo/BaseProFormDateRangePickerV2.d.ts +2 -0
- package/dist/components/base-form/demo/BaseProFormDateRangePickerV2.js +50 -0
- package/dist/components/base-form/demo/BaseProFormDigitRangeV2.d.ts +2 -0
- package/dist/components/base-form/demo/BaseProFormDigitRangeV2.js +58 -0
- package/dist/components/base-form/demo/index.js +7 -2
- package/dist/components/base-form/modules/renderComponentNode.js +34 -0
- package/dist/components/base-form/types.d.ts +6 -2
- package/dist/components/base-table/base-table.d.ts +6 -2
- package/dist/components/base-table/base-table.js +8 -1
- package/dist/components/base-table/demo/DynamicData.d.ts +2 -0
- package/dist/components/base-table/demo/DynamicData.js +67 -0
- package/dist/components/big-input/big-input.d.ts +0 -1
- package/dist/components/big-input/big-input.js +3 -4
- package/dist/components/big-input/demo/index.js +4 -4
- package/dist/components/data-cell/demo/DynamicData.d.ts +2 -0
- package/dist/components/data-cell/demo/DynamicData.js +80 -0
- package/dist/components/data-cell/index.d.ts +1 -0
- package/dist/components/data-cell/index.js +2 -1
- package/dist/components/data-cell/types.d.ts +6 -0
- package/dist/components/data-cell/utils/index.d.ts +3 -0
- package/dist/components/data-cell/utils/index.js +68 -0
- package/dist/components/index.d.ts +1 -1
- package/dist/components/index.js +1 -1
- package/dist/components/upload-plus/demo/index.js +5 -5
- package/dist/components/upload-plus/index.d.ts +1 -1
- package/dist/components/upload-plus/index.js +2 -2
- package/dist/components/upload-plus/types.d.ts +1 -2
- package/dist/components/upload-plus/upload-plus.d.ts +1 -2
- package/dist/components/upload-plus/upload-plus.js +2 -3
- package/package.json +3 -1
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { DatePicker, Form, GetProps } from 'antd';
|
|
2
|
+
import { Dayjs } from 'dayjs';
|
|
3
|
+
import { FC } from 'react';
|
|
4
|
+
export declare const ProFormDateRangePickerV2: FC<IProFormDateRangePickerV2Props>;
|
|
5
|
+
interface IProFormDateRangePickerV2Props {
|
|
6
|
+
name?: [string | string[], string | string[]];
|
|
7
|
+
placeholder?: [string, string];
|
|
8
|
+
label?: React.ReactNode;
|
|
9
|
+
formItemProps?: GetProps<typeof Form.Item>;
|
|
10
|
+
fieldProps?: GetProps<typeof DatePicker.RangePicker>;
|
|
11
|
+
required?: boolean;
|
|
12
|
+
dataFormat?: string;
|
|
13
|
+
allowClear?: boolean;
|
|
14
|
+
initialValue?: number | [
|
|
15
|
+
string | number | Dayjs | undefined,
|
|
16
|
+
string | number | Dayjs | undefined
|
|
17
|
+
];
|
|
18
|
+
}
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,176 @@
|
|
|
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 _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
|
|
8
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
9
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
10
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
11
|
+
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."); }
|
|
12
|
+
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); }
|
|
13
|
+
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; }
|
|
14
|
+
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; } }
|
|
15
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
16
|
+
import ProForm, { ProFormDependency, ProFormText } from '@ant-design/pro-form';
|
|
17
|
+
import { EditOrReadOnlyContext } from '@ant-design/pro-form/es/BaseForm/EditOrReadOnlyContext';
|
|
18
|
+
import { DatePicker, Form } from 'antd';
|
|
19
|
+
import dayjs from 'dayjs';
|
|
20
|
+
import { get } from 'radash';
|
|
21
|
+
import { useContext, useMemo, useState } from 'react';
|
|
22
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
23
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
24
|
+
export var ProFormDateRangePickerV2 = function ProFormDateRangePickerV2(_ref) {
|
|
25
|
+
var name = _ref.name,
|
|
26
|
+
placeholder = _ref.placeholder,
|
|
27
|
+
label = _ref.label,
|
|
28
|
+
formItemProps = _ref.formItemProps,
|
|
29
|
+
fieldProps = _ref.fieldProps,
|
|
30
|
+
required = _ref.required,
|
|
31
|
+
initialValue = _ref.initialValue,
|
|
32
|
+
_ref$dataFormat = _ref.dataFormat,
|
|
33
|
+
outsideDataFormat = _ref$dataFormat === void 0 ? 'YYYY-MM-DD' : _ref$dataFormat,
|
|
34
|
+
_ref$allowClear = _ref.allowClear,
|
|
35
|
+
allowClear = _ref$allowClear === void 0 ? true : _ref$allowClear;
|
|
36
|
+
var form = ProForm.useFormInstance();
|
|
37
|
+
var context = useContext(EditOrReadOnlyContext);
|
|
38
|
+
var formReadonly = context.mode === 'read';
|
|
39
|
+
var dataFormat = (fieldProps === null || fieldProps === void 0 ? void 0 : fieldProps.format) || outsideDataFormat;
|
|
40
|
+
|
|
41
|
+
// 校验状态
|
|
42
|
+
var _useState = useState(''),
|
|
43
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
44
|
+
validateStatus = _useState2[0],
|
|
45
|
+
setValidateStatus = _useState2[1];
|
|
46
|
+
var _useState3 = useState(''),
|
|
47
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
48
|
+
help = _useState4[0],
|
|
49
|
+
setHelp = _useState4[1];
|
|
50
|
+
|
|
51
|
+
// 获取字段名
|
|
52
|
+
var _useMemo = useMemo(function () {
|
|
53
|
+
return name || [undefined, undefined];
|
|
54
|
+
}, [name]),
|
|
55
|
+
_useMemo2 = _slicedToArray(_useMemo, 2),
|
|
56
|
+
startFieldName = _useMemo2[0],
|
|
57
|
+
endFieldName = _useMemo2[1];
|
|
58
|
+
var _useMemo3 = useMemo(function () {
|
|
59
|
+
var arr = [];
|
|
60
|
+
if (typeof initialValue === 'number') {
|
|
61
|
+
// 时间范围类型根据 initialValue 为数值的时候, 根据正负实现 当天距离之前或之后
|
|
62
|
+
var n = initialValue;
|
|
63
|
+
if (n > 0) {
|
|
64
|
+
// 今天到未来 n 天
|
|
65
|
+
arr.push(dayjs().startOf('day'), dayjs().add(n, 'day').endOf('day'));
|
|
66
|
+
} else if (n < 0) {
|
|
67
|
+
// 过去 n 天到今天
|
|
68
|
+
arr.push(dayjs().add(n, 'day').startOf('day'), dayjs().endOf('day'));
|
|
69
|
+
} else {
|
|
70
|
+
// n = 0,只有今天
|
|
71
|
+
arr.push(dayjs().startOf('day'), dayjs().endOf('day'));
|
|
72
|
+
}
|
|
73
|
+
} else if (Array.isArray(initialValue)) {
|
|
74
|
+
arr.push(initialValue[0] ? dayjs(initialValue[0]) : undefined, initialValue[1] ? dayjs(initialValue[1]) : undefined);
|
|
75
|
+
}
|
|
76
|
+
return arr.map(function (ii) {
|
|
77
|
+
return ii === null || ii === void 0 ? void 0 : ii.format(dataFormat);
|
|
78
|
+
});
|
|
79
|
+
// return arr;
|
|
80
|
+
}, [initialValue]),
|
|
81
|
+
_useMemo4 = _slicedToArray(_useMemo3, 2),
|
|
82
|
+
initialStartValue = _useMemo4[0],
|
|
83
|
+
initialEndValue = _useMemo4[1];
|
|
84
|
+
|
|
85
|
+
// 生成校验规则
|
|
86
|
+
var validateRules = useMemo(function () {
|
|
87
|
+
if (!required) return undefined;
|
|
88
|
+
return [{
|
|
89
|
+
validator: function () {
|
|
90
|
+
var _validator = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
91
|
+
var startValue, endValue;
|
|
92
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
93
|
+
while (1) switch (_context.prev = _context.next) {
|
|
94
|
+
case 0:
|
|
95
|
+
startValue = form.getFieldValue(startFieldName);
|
|
96
|
+
endValue = form.getFieldValue(endFieldName);
|
|
97
|
+
if (!(!startValue || !endValue)) {
|
|
98
|
+
_context.next = 6;
|
|
99
|
+
break;
|
|
100
|
+
}
|
|
101
|
+
setValidateStatus('error');
|
|
102
|
+
setHelp(!startValue && !endValue ? "\u8BF7\u9009\u62E9".concat(label || '') : '');
|
|
103
|
+
return _context.abrupt("return", Promise.reject(new Error("\u8BF7\u9009\u62E9".concat(label || ''))));
|
|
104
|
+
case 6:
|
|
105
|
+
setValidateStatus('');
|
|
106
|
+
setHelp('');
|
|
107
|
+
return _context.abrupt("return", Promise.resolve());
|
|
108
|
+
case 9:
|
|
109
|
+
case "end":
|
|
110
|
+
return _context.stop();
|
|
111
|
+
}
|
|
112
|
+
}, _callee);
|
|
113
|
+
}));
|
|
114
|
+
function validator() {
|
|
115
|
+
return _validator.apply(this, arguments);
|
|
116
|
+
}
|
|
117
|
+
return validator;
|
|
118
|
+
}()
|
|
119
|
+
}];
|
|
120
|
+
}, [required, startFieldName, endFieldName, form]);
|
|
121
|
+
var getKey = function getKey(key) {
|
|
122
|
+
if (Array.isArray(key)) {
|
|
123
|
+
return key.join('.');
|
|
124
|
+
}
|
|
125
|
+
return key || '';
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
// console.log(initialStartValue, initialEndValue);
|
|
129
|
+
|
|
130
|
+
return /*#__PURE__*/_jsxs(Form.Item, _objectSpread(_objectSpread({
|
|
131
|
+
label: label,
|
|
132
|
+
required: required,
|
|
133
|
+
validateStatus: validateStatus,
|
|
134
|
+
help: help
|
|
135
|
+
}, formItemProps), {}, {
|
|
136
|
+
children: [/*#__PURE__*/_jsx(ProFormText, {
|
|
137
|
+
hidden: true,
|
|
138
|
+
initialValue: initialStartValue,
|
|
139
|
+
name: startFieldName,
|
|
140
|
+
rules: validateRules
|
|
141
|
+
}), /*#__PURE__*/_jsx(ProFormText, {
|
|
142
|
+
hidden: true,
|
|
143
|
+
initialValue: initialEndValue,
|
|
144
|
+
name: endFieldName,
|
|
145
|
+
rules: validateRules
|
|
146
|
+
}), /*#__PURE__*/_jsx(ProFormDependency, {
|
|
147
|
+
name: [startFieldName, endFieldName],
|
|
148
|
+
children: function children(data) {
|
|
149
|
+
var startValue = get(data, getKey(startFieldName));
|
|
150
|
+
var endValue = get(data, getKey(endFieldName));
|
|
151
|
+
if (formReadonly) {
|
|
152
|
+
return /*#__PURE__*/_jsx("span", {
|
|
153
|
+
children: startValue && endValue ? "".concat(startValue, " ~ ").concat(endValue) : '-'
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
return /*#__PURE__*/_jsx(DatePicker.RangePicker, _objectSpread(_objectSpread({
|
|
157
|
+
placeholder: placeholder,
|
|
158
|
+
format: dataFormat,
|
|
159
|
+
allowClear: allowClear
|
|
160
|
+
}, fieldProps), {}, {
|
|
161
|
+
style: _objectSpread({
|
|
162
|
+
width: '100%'
|
|
163
|
+
}, fieldProps === null || fieldProps === void 0 ? void 0 : fieldProps.style),
|
|
164
|
+
value: startValue && endValue ? [dayjs(startValue), dayjs(endValue)] : undefined,
|
|
165
|
+
onChange: function onChange(dates, dateStrings) {
|
|
166
|
+
form.setFieldValue(startFieldName, dateStrings[0] || undefined);
|
|
167
|
+
form.setFieldValue(endFieldName, dateStrings[1] || undefined);
|
|
168
|
+
setTimeout(function () {
|
|
169
|
+
validateRules === null || validateRules === void 0 || validateRules[0].validator().catch(function () {});
|
|
170
|
+
}, 0);
|
|
171
|
+
}
|
|
172
|
+
}));
|
|
173
|
+
}
|
|
174
|
+
})]
|
|
175
|
+
}));
|
|
176
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Form, GetProps, InputNumber } from 'antd';
|
|
2
|
+
import { FC } from 'react';
|
|
3
|
+
export declare const ProFormDigitRangeV2: FC<IProFormDigitRangeV2Props>;
|
|
4
|
+
interface IProFormDigitRangeV2Props {
|
|
5
|
+
name?: [string | string[], string | string[]];
|
|
6
|
+
placeholder?: [string, string];
|
|
7
|
+
label?: React.ReactNode;
|
|
8
|
+
formItemProps?: GetProps<typeof Form.Item>;
|
|
9
|
+
fieldProps?: GetProps<typeof InputNumber>;
|
|
10
|
+
required?: boolean;
|
|
11
|
+
initialValue?: [number | undefined, number | undefined];
|
|
12
|
+
/**
|
|
13
|
+
* 必填模式
|
|
14
|
+
* - both: 两边都必填
|
|
15
|
+
* - either: 至少填一边
|
|
16
|
+
* @default 'both'
|
|
17
|
+
*/
|
|
18
|
+
requiredMode?: 'both' | 'either';
|
|
19
|
+
/**
|
|
20
|
+
* 自动交换最小值和最大值
|
|
21
|
+
* - 当最小值大于最大值时,自动交换两者的值
|
|
22
|
+
* @default true
|
|
23
|
+
*/
|
|
24
|
+
autoSwap?: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* 小数精度
|
|
27
|
+
* - 设置数值的小数位数
|
|
28
|
+
*/
|
|
29
|
+
precision?: number;
|
|
30
|
+
}
|
|
31
|
+
export {};
|
|
@@ -0,0 +1,216 @@
|
|
|
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 _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
|
|
8
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
9
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
10
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
11
|
+
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."); }
|
|
12
|
+
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); }
|
|
13
|
+
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; }
|
|
14
|
+
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; } }
|
|
15
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
16
|
+
import { ProForm } from '@ant-design/pro-components';
|
|
17
|
+
import { EditOrReadOnlyContext } from '@ant-design/pro-form/es/BaseForm/EditOrReadOnlyContext';
|
|
18
|
+
import { Form, Input, InputNumber, Space } from 'antd';
|
|
19
|
+
import { useCallback, useContext, useMemo } from 'react';
|
|
20
|
+
import { RenderText } from "./RenderText";
|
|
21
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
22
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
23
|
+
export var ProFormDigitRangeV2 = function ProFormDigitRangeV2(_ref) {
|
|
24
|
+
var name = _ref.name,
|
|
25
|
+
placeholder = _ref.placeholder,
|
|
26
|
+
label = _ref.label,
|
|
27
|
+
formItemProps = _ref.formItemProps,
|
|
28
|
+
fieldProps = _ref.fieldProps,
|
|
29
|
+
_ref$autoSwap = _ref.autoSwap,
|
|
30
|
+
autoSwap = _ref$autoSwap === void 0 ? true : _ref$autoSwap,
|
|
31
|
+
precision = _ref.precision,
|
|
32
|
+
required = _ref.required,
|
|
33
|
+
_ref$requiredMode = _ref.requiredMode,
|
|
34
|
+
requiredMode = _ref$requiredMode === void 0 ? 'both' : _ref$requiredMode,
|
|
35
|
+
initialValue = _ref.initialValue;
|
|
36
|
+
var form = ProForm.useFormInstance();
|
|
37
|
+
var context = useContext(EditOrReadOnlyContext);
|
|
38
|
+
var formReadonly = context.mode === 'read';
|
|
39
|
+
|
|
40
|
+
// 获取字段名
|
|
41
|
+
var _useMemo = useMemo(function () {
|
|
42
|
+
return name || [undefined, undefined];
|
|
43
|
+
}, [name]),
|
|
44
|
+
_useMemo2 = _slicedToArray(_useMemo, 2),
|
|
45
|
+
minFieldName = _useMemo2[0],
|
|
46
|
+
maxFieldName = _useMemo2[1];
|
|
47
|
+
|
|
48
|
+
// 生成校验规则
|
|
49
|
+
var minRules = useMemo(function () {
|
|
50
|
+
if (!required) return undefined;
|
|
51
|
+
if (requiredMode === 'both') {
|
|
52
|
+
// 两边都必填
|
|
53
|
+
return [{
|
|
54
|
+
required: true,
|
|
55
|
+
message: '请输入最小值'
|
|
56
|
+
}];
|
|
57
|
+
} else {
|
|
58
|
+
// 至少填一边
|
|
59
|
+
return [{
|
|
60
|
+
validator: function () {
|
|
61
|
+
var _validator = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(_, value) {
|
|
62
|
+
var maxValue;
|
|
63
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
64
|
+
while (1) switch (_context.prev = _context.next) {
|
|
65
|
+
case 0:
|
|
66
|
+
maxValue = form.getFieldValue(maxFieldName);
|
|
67
|
+
if (!((value === null || value === undefined || value === '') && (maxValue === null || maxValue === undefined || maxValue === ''))) {
|
|
68
|
+
_context.next = 3;
|
|
69
|
+
break;
|
|
70
|
+
}
|
|
71
|
+
return _context.abrupt("return", Promise.reject(new Error('请至少输入一个值')));
|
|
72
|
+
case 3:
|
|
73
|
+
return _context.abrupt("return", Promise.resolve());
|
|
74
|
+
case 4:
|
|
75
|
+
case "end":
|
|
76
|
+
return _context.stop();
|
|
77
|
+
}
|
|
78
|
+
}, _callee);
|
|
79
|
+
}));
|
|
80
|
+
function validator(_x, _x2) {
|
|
81
|
+
return _validator.apply(this, arguments);
|
|
82
|
+
}
|
|
83
|
+
return validator;
|
|
84
|
+
}()
|
|
85
|
+
}];
|
|
86
|
+
}
|
|
87
|
+
}, [required, requiredMode, maxFieldName, form]);
|
|
88
|
+
var maxRules = useMemo(function () {
|
|
89
|
+
if (!required) return undefined;
|
|
90
|
+
if (requiredMode === 'both') {
|
|
91
|
+
// 两边都必填
|
|
92
|
+
return [{
|
|
93
|
+
required: true,
|
|
94
|
+
message: '请输入最大值'
|
|
95
|
+
}];
|
|
96
|
+
} else {
|
|
97
|
+
// 至少填一边
|
|
98
|
+
return [{
|
|
99
|
+
validator: function () {
|
|
100
|
+
var _validator2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(_, value) {
|
|
101
|
+
var minValue;
|
|
102
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
103
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
104
|
+
case 0:
|
|
105
|
+
minValue = form.getFieldValue(minFieldName);
|
|
106
|
+
if (!((value === null || value === undefined || value === '') && (minValue === null || minValue === undefined || minValue === ''))) {
|
|
107
|
+
_context2.next = 3;
|
|
108
|
+
break;
|
|
109
|
+
}
|
|
110
|
+
return _context2.abrupt("return", Promise.reject(new Error('请至少输入一个值')));
|
|
111
|
+
case 3:
|
|
112
|
+
return _context2.abrupt("return", Promise.resolve());
|
|
113
|
+
case 4:
|
|
114
|
+
case "end":
|
|
115
|
+
return _context2.stop();
|
|
116
|
+
}
|
|
117
|
+
}, _callee2);
|
|
118
|
+
}));
|
|
119
|
+
function validator(_x3, _x4) {
|
|
120
|
+
return _validator2.apply(this, arguments);
|
|
121
|
+
}
|
|
122
|
+
return validator;
|
|
123
|
+
}()
|
|
124
|
+
}];
|
|
125
|
+
}
|
|
126
|
+
}, [required, requiredMode, minFieldName, form]);
|
|
127
|
+
|
|
128
|
+
// 处理最小值失去焦点
|
|
129
|
+
var handleMinBlur = useCallback(function () {
|
|
130
|
+
if (!autoSwap || !minFieldName || !maxFieldName) return;
|
|
131
|
+
|
|
132
|
+
// 使用 setTimeout 等待 InputNumber 完成内部的 min/max 校验
|
|
133
|
+
setTimeout(function () {
|
|
134
|
+
// 获取表单中的实际值
|
|
135
|
+
var actualMinValue = form.getFieldValue(minFieldName);
|
|
136
|
+
var maxValue = form.getFieldValue(maxFieldName);
|
|
137
|
+
if (actualMinValue !== null && actualMinValue !== undefined && maxValue !== null && maxValue !== undefined && actualMinValue > maxValue) {
|
|
138
|
+
form.setFieldValue(minFieldName, maxValue);
|
|
139
|
+
form.setFieldValue(maxFieldName, actualMinValue);
|
|
140
|
+
}
|
|
141
|
+
}, 0);
|
|
142
|
+
}, [autoSwap, minFieldName, maxFieldName, form]);
|
|
143
|
+
|
|
144
|
+
// 处理最大值失去焦点
|
|
145
|
+
var handleMaxBlur = useCallback(function () {
|
|
146
|
+
if (!autoSwap || !minFieldName || !maxFieldName) return;
|
|
147
|
+
|
|
148
|
+
// 使用 setTimeout 等待 InputNumber 完成内部的 min/max 校验
|
|
149
|
+
setTimeout(function () {
|
|
150
|
+
// 获取表单中的实际值
|
|
151
|
+
var minValue = form.getFieldValue(minFieldName);
|
|
152
|
+
var actualMaxValue = form.getFieldValue(maxFieldName);
|
|
153
|
+
if (minValue !== null && minValue !== undefined && actualMaxValue !== null && actualMaxValue !== undefined && actualMaxValue < minValue) {
|
|
154
|
+
form.setFieldValue(minFieldName, actualMaxValue);
|
|
155
|
+
form.setFieldValue(maxFieldName, minValue);
|
|
156
|
+
}
|
|
157
|
+
}, 0);
|
|
158
|
+
}, [autoSwap, minFieldName, maxFieldName, form]);
|
|
159
|
+
return /*#__PURE__*/_jsx(Form.Item, _objectSpread(_objectSpread({
|
|
160
|
+
label: label,
|
|
161
|
+
required: required
|
|
162
|
+
}, formItemProps), {}, {
|
|
163
|
+
children: /*#__PURE__*/_jsxs(Space.Compact, {
|
|
164
|
+
style: {
|
|
165
|
+
width: '100%'
|
|
166
|
+
},
|
|
167
|
+
children: [/*#__PURE__*/_jsx(Form.Item, {
|
|
168
|
+
noStyle: true,
|
|
169
|
+
name: minFieldName,
|
|
170
|
+
initialValue: initialValue === null || initialValue === void 0 ? void 0 : initialValue[0],
|
|
171
|
+
rules: minRules,
|
|
172
|
+
children: formReadonly ? /*#__PURE__*/_jsx(RenderText, {}) : /*#__PURE__*/_jsx(InputNumber, _objectSpread(_objectSpread({
|
|
173
|
+
placeholder: (placeholder === null || placeholder === void 0 ? void 0 : placeholder[0]) || '最小值',
|
|
174
|
+
precision: precision,
|
|
175
|
+
readOnly: formReadonly
|
|
176
|
+
}, fieldProps), {}, {
|
|
177
|
+
style: _objectSpread({
|
|
178
|
+
flex: 1
|
|
179
|
+
}, fieldProps === null || fieldProps === void 0 ? void 0 : fieldProps.style),
|
|
180
|
+
onBlur: handleMinBlur
|
|
181
|
+
}))
|
|
182
|
+
}), formReadonly ? /*#__PURE__*/_jsx(RenderText, {
|
|
183
|
+
value: "~",
|
|
184
|
+
style: {
|
|
185
|
+
padding: '0 4px'
|
|
186
|
+
}
|
|
187
|
+
}) : /*#__PURE__*/_jsx(Input, {
|
|
188
|
+
style: {
|
|
189
|
+
width: 30,
|
|
190
|
+
borderInlineStart: 0,
|
|
191
|
+
borderInlineEnd: 0,
|
|
192
|
+
pointerEvents: 'none',
|
|
193
|
+
textAlign: 'center'
|
|
194
|
+
},
|
|
195
|
+
placeholder: "~",
|
|
196
|
+
disabled: true,
|
|
197
|
+
readOnly: true
|
|
198
|
+
}), /*#__PURE__*/_jsx(Form.Item, {
|
|
199
|
+
noStyle: true,
|
|
200
|
+
name: maxFieldName,
|
|
201
|
+
initialValue: initialValue === null || initialValue === void 0 ? void 0 : initialValue[1],
|
|
202
|
+
rules: maxRules,
|
|
203
|
+
children: formReadonly ? /*#__PURE__*/_jsx(RenderText, {}) : /*#__PURE__*/_jsx(InputNumber, _objectSpread(_objectSpread({
|
|
204
|
+
placeholder: (placeholder === null || placeholder === void 0 ? void 0 : placeholder[1]) || '最大值',
|
|
205
|
+
precision: precision,
|
|
206
|
+
readOnly: formReadonly
|
|
207
|
+
}, fieldProps), {}, {
|
|
208
|
+
style: _objectSpread({
|
|
209
|
+
flex: 1
|
|
210
|
+
}, fieldProps === null || fieldProps === void 0 ? void 0 : fieldProps.style),
|
|
211
|
+
onBlur: handleMaxBlur
|
|
212
|
+
}))
|
|
213
|
+
})]
|
|
214
|
+
})
|
|
215
|
+
}));
|
|
216
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
export var RenderText = function RenderText(_ref) {
|
|
3
|
+
var value = _ref.value,
|
|
4
|
+
style = _ref.style;
|
|
5
|
+
return /*#__PURE__*/_jsx("span", {
|
|
6
|
+
style: style,
|
|
7
|
+
children: value !== null && value !== void 0 ? value : '-'
|
|
8
|
+
});
|
|
9
|
+
};
|
|
@@ -95,8 +95,9 @@ export default (function () {
|
|
|
95
95
|
field: ['select-false']
|
|
96
96
|
}]
|
|
97
97
|
}, {
|
|
98
|
-
valueType: '
|
|
99
|
-
field: ['start', 'end']
|
|
98
|
+
valueType: 'dateRangeV2',
|
|
99
|
+
field: ['start', 'end'],
|
|
100
|
+
required: true
|
|
100
101
|
// defaultValue: 1,
|
|
101
102
|
}];
|
|
102
103
|
var initialValues = dataToInitialValues({
|
|
@@ -14,7 +14,10 @@ import { getFieldsDefaultValues } from "../modules/handlerData";
|
|
|
14
14
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
15
15
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
16
16
|
export default (function () {
|
|
17
|
-
|
|
17
|
+
// const t: Exclude<
|
|
18
|
+
// GetProps<typeof BaseForm>['fields'],
|
|
19
|
+
// undefined
|
|
20
|
+
// >[number]['valueType'] = 'hidden';
|
|
18
21
|
var _useStateData = useStateData(function () {
|
|
19
22
|
return {
|
|
20
23
|
fields: [{
|
|
@@ -36,8 +39,8 @@ export default (function () {
|
|
|
36
39
|
colon: false
|
|
37
40
|
}
|
|
38
41
|
}, {
|
|
39
|
-
valueType: '
|
|
40
|
-
field: ['www.multipleComponents
|
|
42
|
+
valueType: 'inputNumberRangeV2',
|
|
43
|
+
field: ['www.multipleComponents.input', 'www.multipleComponents.input2']
|
|
41
44
|
}]
|
|
42
45
|
}],
|
|
43
46
|
initialValues: {},
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { RexProConfigProvider } from "../../../context";
|
|
2
|
+
import { ProForm, ProFormText } from '@ant-design/pro-components';
|
|
3
|
+
import { createIntl } from 'react-intl';
|
|
4
|
+
import { ProFormDateRangePickerV2 } from "../components/ProFormDateRangePickerV2";
|
|
5
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
6
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
7
|
+
export default (function () {
|
|
8
|
+
return /*#__PURE__*/_jsx(RexProConfigProvider, {
|
|
9
|
+
value: {
|
|
10
|
+
intl: createIntl({
|
|
11
|
+
locale: 'en-US',
|
|
12
|
+
messages: {}
|
|
13
|
+
})
|
|
14
|
+
// apiClient: (api, params) => {
|
|
15
|
+
// return fetch(api, {method: 'post', body: JSON.stringify(params)}).then((res) => ({data: []}));
|
|
16
|
+
// },
|
|
17
|
+
},
|
|
18
|
+
children: /*#__PURE__*/_jsxs(ProForm, {
|
|
19
|
+
initialValues: {
|
|
20
|
+
data: {
|
|
21
|
+
// min: 2,
|
|
22
|
+
// max: 1111,
|
|
23
|
+
},
|
|
24
|
+
testName: 'qweqwe'
|
|
25
|
+
}
|
|
26
|
+
// size="small"
|
|
27
|
+
// disabled
|
|
28
|
+
// readonly
|
|
29
|
+
,
|
|
30
|
+
layout: "horizontal",
|
|
31
|
+
onFinish: function onFinish(values) {
|
|
32
|
+
console.log(values);
|
|
33
|
+
},
|
|
34
|
+
children: [/*#__PURE__*/_jsx(ProFormDateRangePickerV2, {
|
|
35
|
+
required: false,
|
|
36
|
+
label: "\u65E5\u671F\u8303\u56F4",
|
|
37
|
+
name: [['data', 'start'], ['data', 'end']],
|
|
38
|
+
initialValue: -30
|
|
39
|
+
// dataFormat="YYYY-MM-DD"
|
|
40
|
+
}), /*#__PURE__*/_jsx(ProFormText, {
|
|
41
|
+
required: true,
|
|
42
|
+
rules: [{
|
|
43
|
+
required: true
|
|
44
|
+
}],
|
|
45
|
+
label: "\u6D4B\u8BD5\u6587\u672C",
|
|
46
|
+
name: "testName"
|
|
47
|
+
})]
|
|
48
|
+
})
|
|
49
|
+
});
|
|
50
|
+
});
|