@nokecy/qc-ui 1.1.74 → 1.1.76
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/cjs/dialogSelect/index.d.ts +2 -2
- package/dist/cjs/dialogSelect/index.js +65 -10
- package/dist/cjs/entitySelect/index.d.ts +57 -0
- package/dist/cjs/entitySelect/index.js +172 -0
- package/dist/cjs/exportButton/exportAction.d.ts +74 -0
- package/dist/cjs/exportButton/exportAction.js +199 -0
- package/dist/cjs/exportButton/index.d.ts +39 -0
- package/dist/cjs/exportButton/index.js +295 -0
- package/dist/cjs/importModal/index.d.ts +9 -0
- package/dist/cjs/importModal/index.js +46 -8
- package/dist/cjs/index.d.ts +6 -0
- package/dist/cjs/index.js +74 -0
- package/dist/cjs/readPretty/arrayTable.d.ts +6 -0
- package/dist/cjs/readPretty/arrayTable.js +156 -0
- package/dist/cjs/readPretty/controls.d.ts +11 -0
- package/dist/cjs/readPretty/controls.js +68 -0
- package/dist/cjs/readPretty/decimal.d.ts +4 -0
- package/dist/cjs/readPretty/decimal.js +28 -0
- package/dist/cjs/readPretty/formily.d.ts +2 -0
- package/dist/cjs/readPretty/formily.js +71 -0
- package/dist/cjs/readPretty/hoistStatics.d.ts +1 -0
- package/dist/cjs/readPretty/hoistStatics.js +37 -0
- package/dist/cjs/readPretty/index.d.ts +11 -0
- package/dist/cjs/readPretty/index.js +70 -0
- package/dist/cjs/readPretty/selectValue.d.ts +7 -0
- package/dist/cjs/readPretty/selectValue.js +60 -0
- package/dist/cjs/readPretty/values.d.ts +4 -0
- package/dist/cjs/readPretty/values.js +49 -0
- package/dist/cjs/utils/download.d.ts +6 -0
- package/dist/cjs/utils/download.js +23 -0
- package/dist/esm/dialogSelect/index.d.ts +2 -2
- package/dist/esm/dialogSelect/index.js +59 -4
- package/dist/esm/entitySelect/index.d.ts +57 -0
- package/dist/esm/entitySelect/index.js +164 -0
- package/dist/esm/exportButton/exportAction.d.ts +74 -0
- package/dist/esm/exportButton/exportAction.js +193 -0
- package/dist/esm/exportButton/index.d.ts +39 -0
- package/dist/esm/exportButton/index.js +259 -0
- package/dist/esm/importModal/index.d.ts +9 -0
- package/dist/esm/importModal/index.js +46 -8
- package/dist/esm/index.d.ts +6 -0
- package/dist/esm/index.js +4 -0
- package/dist/esm/readPretty/arrayTable.d.ts +6 -0
- package/dist/esm/readPretty/arrayTable.js +147 -0
- package/dist/esm/readPretty/controls.d.ts +11 -0
- package/dist/esm/readPretty/controls.js +62 -0
- package/dist/esm/readPretty/decimal.d.ts +4 -0
- package/dist/esm/readPretty/decimal.js +22 -0
- package/dist/esm/readPretty/formily.d.ts +2 -0
- package/dist/esm/readPretty/formily.js +63 -0
- package/dist/esm/readPretty/hoistStatics.d.ts +1 -0
- package/dist/esm/readPretty/hoistStatics.js +31 -0
- package/dist/esm/readPretty/index.d.ts +11 -0
- package/dist/esm/readPretty/index.js +12 -0
- package/dist/esm/readPretty/selectValue.d.ts +7 -0
- package/dist/esm/readPretty/selectValue.js +53 -0
- package/dist/esm/readPretty/values.d.ts +4 -0
- package/dist/esm/readPretty/values.js +43 -0
- package/dist/esm/utils/download.d.ts +6 -0
- package/dist/esm/utils/download.js +17 -0
- package/dist/umd/qc-ui.min.js +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
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); }
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
Object.defineProperty(exports, "DecimalInput", {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: function get() {
|
|
10
|
+
return _decimal.DecimalInput;
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
Object.defineProperty(exports, "DecimalPicker", {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
get: function get() {
|
|
16
|
+
return _decimal.DecimalPicker;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
exports.ReadPrettyControls = void 0;
|
|
20
|
+
Object.defineProperty(exports, "flattenOptions", {
|
|
21
|
+
enumerable: true,
|
|
22
|
+
get: function get() {
|
|
23
|
+
return _values.flattenOptions;
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
Object.defineProperty(exports, "normalizeSelectValue", {
|
|
27
|
+
enumerable: true,
|
|
28
|
+
get: function get() {
|
|
29
|
+
return _selectValue.normalizeSelectValue;
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
Object.defineProperty(exports, "selectCode", {
|
|
33
|
+
enumerable: true,
|
|
34
|
+
get: function get() {
|
|
35
|
+
return _selectValue.selectCode;
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
Object.defineProperty(exports, "selectLabel", {
|
|
39
|
+
enumerable: true,
|
|
40
|
+
get: function get() {
|
|
41
|
+
return _selectValue.selectLabel;
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
Object.defineProperty(exports, "selectedLabels", {
|
|
45
|
+
enumerable: true,
|
|
46
|
+
get: function get() {
|
|
47
|
+
return _values.selectedLabels;
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
Object.defineProperty(exports, "withReadingArrayTable", {
|
|
51
|
+
enumerable: true,
|
|
52
|
+
get: function get() {
|
|
53
|
+
return _arrayTable.withReadingArrayTable;
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
Object.defineProperty(exports, "withReadingFields", {
|
|
57
|
+
enumerable: true,
|
|
58
|
+
get: function get() {
|
|
59
|
+
return _formily.withReadingFields;
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
var _ReadPrettyControls = _interopRequireWildcard(require("./controls"));
|
|
63
|
+
exports.ReadPrettyControls = _ReadPrettyControls;
|
|
64
|
+
var _formily = require("./formily");
|
|
65
|
+
var _arrayTable = require("./arrayTable");
|
|
66
|
+
var _decimal = require("./decimal");
|
|
67
|
+
var _values = require("./values");
|
|
68
|
+
var _selectValue = require("./selectValue");
|
|
69
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
70
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
/** 提取选择项的标量编码,兼容嵌套 labelInValue;保留编码 0 和显式空字符串选项。@author nokecy */
|
|
3
|
+
export declare function selectCode(value: unknown, depth?: number): string | number | undefined;
|
|
4
|
+
/** 标签只输出可渲染内容;选择项对象取名称后再回落编码,避免 React 对象子节点异常。@author nokecy */
|
|
5
|
+
export declare function selectLabel(value: unknown, depth?: number): ReactNode;
|
|
6
|
+
/** 单选、多选与阅读态共用同一值形状;名称缺省时保留组件按选项查名称的行为。@author nokecy */
|
|
7
|
+
export declare function normalizeSelectValue(value: unknown, labelInValue?: boolean): any;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.normalizeSelectValue = normalizeSelectValue;
|
|
7
|
+
exports.selectCode = selectCode;
|
|
8
|
+
exports.selectLabel = selectLabel;
|
|
9
|
+
var _react = require("react");
|
|
10
|
+
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; }
|
|
11
|
+
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; }
|
|
12
|
+
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; }
|
|
13
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
14
|
+
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); }
|
|
15
|
+
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); }
|
|
16
|
+
/** 提取选择项的标量编码,兼容嵌套 labelInValue;保留编码 0 和显式空字符串选项。@author nokecy */
|
|
17
|
+
function selectCode(value) {
|
|
18
|
+
var depth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
19
|
+
if (typeof value === 'string') return value;
|
|
20
|
+
if (typeof value === 'number') return Number.isFinite(value) ? value : undefined;
|
|
21
|
+
if (!value || _typeof(value) !== 'object' || depth >= 8 || /*#__PURE__*/(0, _react.isValidElement)(value)) return undefined;
|
|
22
|
+
return selectCode(value.value, depth + 1);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** 标签只输出可渲染内容;选择项对象取名称后再回落编码,避免 React 对象子节点异常。@author nokecy */
|
|
26
|
+
function selectLabel(value) {
|
|
27
|
+
var _selectLabel;
|
|
28
|
+
var depth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
29
|
+
if (value == null || typeof value === 'boolean' || depth >= 8) return undefined;
|
|
30
|
+
if (typeof value === 'string' || typeof value === 'number' || /*#__PURE__*/(0, _react.isValidElement)(value)) return value;
|
|
31
|
+
if (Array.isArray(value)) return value.map(function (item) {
|
|
32
|
+
return selectLabel(item, depth + 1);
|
|
33
|
+
});
|
|
34
|
+
if (_typeof(value) !== 'object') return undefined;
|
|
35
|
+
var item = value;
|
|
36
|
+
return (_selectLabel = selectLabel(item.label, depth + 1)) !== null && _selectLabel !== void 0 ? _selectLabel : selectLabel(item.value, depth + 1);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** 单选、多选与阅读态共用同一值形状;名称缺省时保留组件按选项查名称的行为。@author nokecy */
|
|
40
|
+
function normalizeSelectValue(value, labelInValue) {
|
|
41
|
+
var _selectLabel2;
|
|
42
|
+
if (Array.isArray(value)) return value.map(function (item) {
|
|
43
|
+
return normalizeSelectValue(item, labelInValue);
|
|
44
|
+
}).filter(function (item) {
|
|
45
|
+
return item !== undefined;
|
|
46
|
+
});
|
|
47
|
+
var code = selectCode(value);
|
|
48
|
+
if (code === undefined) return undefined;
|
|
49
|
+
if (!labelInValue) return code;
|
|
50
|
+
if (!value || _typeof(value) !== 'object') return {
|
|
51
|
+
value: code
|
|
52
|
+
};
|
|
53
|
+
var item = value;
|
|
54
|
+
var label = (_selectLabel2 = selectLabel(item.label)) !== null && _selectLabel2 !== void 0 ? _selectLabel2 : _typeof(item.value) === 'object' ? selectLabel(item.value) : undefined;
|
|
55
|
+
return _objectSpread({
|
|
56
|
+
value: code
|
|
57
|
+
}, label !== undefined ? {
|
|
58
|
+
label: label
|
|
59
|
+
} : {});
|
|
60
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/** 阅读态选择项展开,保留分组内选项及自定义字段名。@author nokecy */
|
|
2
|
+
export declare function flattenOptions(options?: any[], fieldNames?: any): any[];
|
|
3
|
+
/** 保留0和空选项标签;有 labelInValue 时优先使用已加载的名称。@author nokecy */
|
|
4
|
+
export declare function selectedLabels(value: any, options: any[], labelInValue?: boolean): any;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.flattenOptions = flattenOptions;
|
|
7
|
+
exports.selectedLabels = selectedLabels;
|
|
8
|
+
var _selectValue = require("./selectValue");
|
|
9
|
+
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); }
|
|
10
|
+
/** 阅读态选择项展开,保留分组内选项及自定义字段名。@author nokecy */
|
|
11
|
+
function flattenOptions() {
|
|
12
|
+
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
13
|
+
var fieldNames = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
14
|
+
var _ref = fieldNames || {},
|
|
15
|
+
_ref$label = _ref.label,
|
|
16
|
+
label = _ref$label === void 0 ? 'label' : _ref$label,
|
|
17
|
+
_ref$value = _ref.value,
|
|
18
|
+
value = _ref$value === void 0 ? 'value' : _ref$value,
|
|
19
|
+
_ref$options = _ref.options,
|
|
20
|
+
children = _ref$options === void 0 ? 'options' : _ref$options;
|
|
21
|
+
return options.flatMap(function (option) {
|
|
22
|
+
return _typeof(option) === 'object' && option !== null ? option[children] ? flattenOptions(option[children], fieldNames) : [{
|
|
23
|
+
value: option[value],
|
|
24
|
+
label: option[label]
|
|
25
|
+
}] : [{
|
|
26
|
+
value: option,
|
|
27
|
+
label: option
|
|
28
|
+
}];
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** 保留0和空选项标签;有 labelInValue 时优先使用已加载的名称。@author nokecy */
|
|
33
|
+
function selectedLabels(value, options, labelInValue) {
|
|
34
|
+
if (value == null || value === '' || Array.isArray(value) && !value.length) return '—';
|
|
35
|
+
var normalized = labelInValue ? (0, _selectValue.normalizeSelectValue)(value, true) : value;
|
|
36
|
+
var values = Array.isArray(normalized) ? normalized : normalized == null ? [] : [normalized];
|
|
37
|
+
if (!values.length) return '—';
|
|
38
|
+
var labels = values.map(function (item) {
|
|
39
|
+
var _ref2, _selectLabel, _options$find, _item$label;
|
|
40
|
+
var raw = labelInValue ? item.value : item;
|
|
41
|
+
return (_ref2 = (_selectLabel = (0, _selectValue.selectLabel)((_options$find = options.find(function (option) {
|
|
42
|
+
return option.value === raw;
|
|
43
|
+
})) === null || _options$find === void 0 ? void 0 : _options$find.label)) !== null && _selectLabel !== void 0 ? _selectLabel : (0, _selectValue.selectLabel)(labelInValue ? (_item$label = item.label) !== null && _item$label !== void 0 ? _item$label : raw : raw)) !== null && _ref2 !== void 0 ? _ref2 : '—';
|
|
44
|
+
});
|
|
45
|
+
// 选项标签可以是React节点,交由调用组件按顺序渲染。
|
|
46
|
+
return labels.flatMap(function (label, index) {
|
|
47
|
+
return index ? ['、', label] : [label];
|
|
48
|
+
});
|
|
49
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.saveAs = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* 把 Blob 存成本地文件。
|
|
9
|
+
*
|
|
10
|
+
* @author nokecy
|
|
11
|
+
*/
|
|
12
|
+
var saveAs = exports.saveAs = function saveAs(blob, filename) {
|
|
13
|
+
var nav = window.navigator;
|
|
14
|
+
if (typeof nav.msSaveBlob === 'function') {
|
|
15
|
+
nav.msSaveBlob(blob, filename);
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
var link = document.createElement('a');
|
|
19
|
+
link.href = window.URL.createObjectURL(blob);
|
|
20
|
+
link.download = filename;
|
|
21
|
+
link.click();
|
|
22
|
+
window.URL.revokeObjectURL(link.href);
|
|
23
|
+
};
|
|
@@ -43,6 +43,6 @@ interface IDialogSelectProps extends SelectProps<any> {
|
|
|
43
43
|
/** 选择窗口里使用的表格组件,默认 `AgGridPlus`;宿主可注入自己封装过的表格基座。 */
|
|
44
44
|
gridComponent?: React.ComponentType<any>;
|
|
45
45
|
}
|
|
46
|
-
declare const DialogSelect: (props: IDialogSelectProps) => React.JSX.Element;
|
|
47
46
|
export { IDialogSelectProps };
|
|
48
|
-
|
|
47
|
+
declare const _default: (props: IDialogSelectProps) => React.ReactElement;
|
|
48
|
+
export default _default;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
var _excluded = ["request", "columnDefs", "value", "labelField", "valueField", "onChangeItem", "hideBtn", "useAutoComplete", "queryFun", "pagedApiAdapter", "modalWidth", "dialogZIndex", "dialogMode", "dialogPageSize", "dialogPageSizeOptions", "dialogGridKey", "dialogDataSource", "dialogIsRowSelectable", "dialogRenderer", "gridComponent"]
|
|
1
|
+
var _excluded = ["request", "columnDefs", "value", "labelField", "valueField", "onChangeItem", "hideBtn", "useAutoComplete", "queryFun", "pagedApiAdapter", "modalWidth", "dialogZIndex", "dialogMode", "dialogPageSize", "dialogPageSizeOptions", "dialogGridKey", "dialogDataSource", "dialogIsRowSelectable", "dialogRenderer", "gridComponent"],
|
|
2
|
+
_excluded2 = ["request", "columnDefs", "labelField", "valueField", "onChangeItem", "hideBtn", "useAutoComplete", "queryFun", "pagedApiAdapter", "modalWidth", "dialogZIndex", "dialogMode", "dialogPageSize", "dialogPageSizeOptions", "dialogGridKey", "dialogDataSource", "dialogIsRowSelectable", "dialogRenderer", "gridComponent"];
|
|
2
3
|
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; }
|
|
3
4
|
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); } }
|
|
4
5
|
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); }); }; }
|
|
@@ -17,7 +18,8 @@ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" !=
|
|
|
17
18
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
18
19
|
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; }
|
|
19
20
|
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; }
|
|
20
|
-
import { AutoComplete, theme } from 'antd';
|
|
21
|
+
import { AutoComplete, ConfigProvider, theme } from 'antd';
|
|
22
|
+
import { observer, useField } from '@formily/react';
|
|
21
23
|
import { Select } from '@formily/antd-v5';
|
|
22
24
|
import { SearchOutlined } from '@ant-design/icons';
|
|
23
25
|
import React, { useState } from 'react';
|
|
@@ -25,11 +27,13 @@ import { AgGridPlus } from "../ag-grid-plus";
|
|
|
25
27
|
import { useBoolean, useControllableValue } from 'ahooks';
|
|
26
28
|
import DraggableModal from "../draggableModal";
|
|
27
29
|
import { abpPagedApiAdapter } from "../adapters";
|
|
30
|
+
import { Select as ReadingSelect } from "../readPretty/controls";
|
|
31
|
+
import { normalizeSelectValue } from "../readPretty/selectValue";
|
|
28
32
|
import "./index.less";
|
|
29
33
|
|
|
30
34
|
/** 选择窗口的行选择模式。 */
|
|
31
35
|
|
|
32
|
-
var
|
|
36
|
+
var DialogSelectInner = function DialogSelectInner(props) {
|
|
33
37
|
var _selectRows$length;
|
|
34
38
|
// 这些是本组件自己的属性,不能透传给 Select(否则会落到 DOM 上触发未知属性告警)。
|
|
35
39
|
var request = props.request,
|
|
@@ -170,7 +174,9 @@ var DialogSelect = function DialogSelect(props) {
|
|
|
170
174
|
marginBottom: 8,
|
|
171
175
|
textAlign: 'right'
|
|
172
176
|
}
|
|
173
|
-
}, "\u5DF2\u9009 ", (_selectRows$length = selectRows === null || selectRows === void 0 ? void 0 : selectRows.length) !== null && _selectRows$length !== void 0 ? _selectRows$length : 0, " \u9879"), /*#__PURE__*/React.createElement(Grid, _extends({
|
|
177
|
+
}, "\u5DF2\u9009 ", (_selectRows$length = selectRows === null || selectRows === void 0 ? void 0 : selectRows.length) !== null && _selectRows$length !== void 0 ? _selectRows$length : 0, " \u9879"), /*#__PURE__*/React.createElement(Grid, _extends({}, gridComponent ? {} : {
|
|
178
|
+
valueEnumContrast: true
|
|
179
|
+
}, {
|
|
174
180
|
gridKey: dialogGridKey,
|
|
175
181
|
dataSource: dialogDataSource,
|
|
176
182
|
hidePagination: localData
|
|
@@ -248,4 +254,53 @@ var DialogSelect = function DialogSelect(props) {
|
|
|
248
254
|
columnDefs: columnDefs
|
|
249
255
|
}))));
|
|
250
256
|
};
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* 选择字段。
|
|
260
|
+
*
|
|
261
|
+
* 不可编辑(自身 disabled、外层 ConfigProvider 禁用,或 Formily 字段 disabled / readOnly / readPretty)时
|
|
262
|
+
* 只显示名称,不保留输入框和弹窗入口;`value` / `defaultValue` 统一规范成 Select 能识别的形状
|
|
263
|
+
* (含 `{ value, label }` 嵌套对象),仅在调用方传了对应属性时才下发,以保持受控/非受控语义。
|
|
264
|
+
*
|
|
265
|
+
* @author nokecy
|
|
266
|
+
*/
|
|
267
|
+
var DialogSelect = observer(function (props) {
|
|
268
|
+
var _props$disabled;
|
|
269
|
+
var field = useField();
|
|
270
|
+
var _ConfigProvider$useCo = ConfigProvider.useConfig(),
|
|
271
|
+
componentDisabled = _ConfigProvider$useCo.componentDisabled;
|
|
272
|
+
var reading = (_props$disabled = props.disabled) !== null && _props$disabled !== void 0 ? _props$disabled : componentDisabled;
|
|
273
|
+
var safeProps = _objectSpread(_objectSpread(_objectSpread({}, props), 'value' in props ? {
|
|
274
|
+
value: normalizeSelectValue(props.value, props.labelInValue)
|
|
275
|
+
} : {}), 'defaultValue' in props ? {
|
|
276
|
+
defaultValue: normalizeSelectValue(props.defaultValue, props.labelInValue)
|
|
277
|
+
} : {});
|
|
278
|
+
if (reading || field !== null && field !== void 0 && field.disabled || field !== null && field !== void 0 && field.readOnly || field !== null && field !== void 0 && field.readPretty) {
|
|
279
|
+
// 阅读态只需要选项与值;弹窗、取数等属性不下发。
|
|
280
|
+
var request = safeProps.request,
|
|
281
|
+
columnDefs = safeProps.columnDefs,
|
|
282
|
+
labelField = safeProps.labelField,
|
|
283
|
+
valueField = safeProps.valueField,
|
|
284
|
+
onChangeItem = safeProps.onChangeItem,
|
|
285
|
+
hideBtn = safeProps.hideBtn,
|
|
286
|
+
useAutoComplete = safeProps.useAutoComplete,
|
|
287
|
+
queryFun = safeProps.queryFun,
|
|
288
|
+
pagedApiAdapter = safeProps.pagedApiAdapter,
|
|
289
|
+
modalWidth = safeProps.modalWidth,
|
|
290
|
+
dialogZIndex = safeProps.dialogZIndex,
|
|
291
|
+
dialogMode = safeProps.dialogMode,
|
|
292
|
+
dialogPageSize = safeProps.dialogPageSize,
|
|
293
|
+
dialogPageSizeOptions = safeProps.dialogPageSizeOptions,
|
|
294
|
+
dialogGridKey = safeProps.dialogGridKey,
|
|
295
|
+
dialogDataSource = safeProps.dialogDataSource,
|
|
296
|
+
dialogIsRowSelectable = safeProps.dialogIsRowSelectable,
|
|
297
|
+
dialogRenderer = safeProps.dialogRenderer,
|
|
298
|
+
gridComponent = safeProps.gridComponent,
|
|
299
|
+
selectProps = _objectWithoutProperties(safeProps, _excluded2);
|
|
300
|
+
return /*#__PURE__*/React.createElement(ReadingSelect, _extends({}, selectProps, {
|
|
301
|
+
disabled: true
|
|
302
|
+
}));
|
|
303
|
+
}
|
|
304
|
+
return /*#__PURE__*/React.createElement(DialogSelectInner, safeProps);
|
|
305
|
+
});
|
|
251
306
|
export default DialogSelect;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { SelectProps } from 'antd/lib/select';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
/**
|
|
4
|
+
* 实体选择器的骨架。
|
|
5
|
+
*
|
|
6
|
+
* 各业务模块的实体选择器(线体、车间、物料、供应商……)此前是逐个复制出来的:
|
|
7
|
+
* 取数、防抖、受控值、下拉即查、labelInValue、弹窗表格列,每份各写一遍,
|
|
8
|
+
* 真正不同的只有请求函数、提示语和表格列。骨架收在这里,各模块只填自己的那几项。
|
|
9
|
+
*
|
|
10
|
+
* 骨架不认识任何业务契约:请求函数由调用方传入,不引用任何生成服务客户端。
|
|
11
|
+
*
|
|
12
|
+
* @author nokecy
|
|
13
|
+
*/
|
|
14
|
+
/** 取数入参:与后端分页查询约定一致。 */
|
|
15
|
+
export interface EntitySelectQuery {
|
|
16
|
+
Filter?: string;
|
|
17
|
+
SkipCount?: number;
|
|
18
|
+
MaxResultCount?: number;
|
|
19
|
+
Sorting?: string;
|
|
20
|
+
}
|
|
21
|
+
export interface EntitySelectConfig {
|
|
22
|
+
/** 取数函数,通常是生成服务客户端里的 XxxGetListAsync。 */
|
|
23
|
+
request: (query: EntitySelectQuery) => Promise<any>;
|
|
24
|
+
/** 未选择时的提示语。 */
|
|
25
|
+
placeholder: string;
|
|
26
|
+
/** 弹窗内表格的列定义。 */
|
|
27
|
+
columnDefs: any[];
|
|
28
|
+
/** 下拉项与回填值取哪个字段。传字符串则固定;不传则由 useCode 在 code 与 id 之间切换。 */
|
|
29
|
+
valueField?: string;
|
|
30
|
+
/** 回填标签取哪个字段。不传则不向 DialogSelect 声明,沿用其自身默认。 */
|
|
31
|
+
labelField?: string;
|
|
32
|
+
/** 弹窗宽度,不传则用 DialogSelect 的默认值。 */
|
|
33
|
+
modalWidth?: number;
|
|
34
|
+
/** 单页取数条数,默认 300。 */
|
|
35
|
+
pageSize?: number;
|
|
36
|
+
/** useCode 的默认值,默认 true(以编码而非主键作为值)。 */
|
|
37
|
+
useCodeByDefault?: boolean;
|
|
38
|
+
/** 搜索关键字如何拼成后端过滤表达式,默认按 name 或 code 模糊匹配。返回 undefined 表示不带过滤条件。 */
|
|
39
|
+
buildFilter?: (keyword: string) => string | undefined;
|
|
40
|
+
/** 下拉项显示文本,默认「编码 - 名称」。 */
|
|
41
|
+
renderOptionLabel?: (item: any) => React.ReactNode;
|
|
42
|
+
/** 下拉项需要额外属性时的逃生舱:整项自渲染,优先于 renderOptionLabel。 */
|
|
43
|
+
renderOption?: (item: any, valueField: string) => React.ReactNode;
|
|
44
|
+
/** 联动回调的 prop 名,如 onWorkLineSelect。声明后组件支持 enableLinkage。 */
|
|
45
|
+
linkagePropName?: string;
|
|
46
|
+
/** 选择窗口里使用的表格组件,不传则用 AgGridPlus;宿主可注入自己封装过的表格基座。 */
|
|
47
|
+
gridComponent?: React.ComponentType<any>;
|
|
48
|
+
}
|
|
49
|
+
export interface EntitySelectProps extends SelectProps<any> {
|
|
50
|
+
/** 以编码而非主键作为选中值。 */
|
|
51
|
+
useCode?: boolean;
|
|
52
|
+
/** 选中后把整条记录回调给使用方,需配置 linkagePropName。 */
|
|
53
|
+
enableLinkage?: boolean;
|
|
54
|
+
}
|
|
55
|
+
declare const createEntitySelect: (config: EntitySelectConfig) => React.ForwardRefExoticComponent<Omit<any, "ref"> & React.RefAttributes<any>>;
|
|
56
|
+
export { createEntitySelect };
|
|
57
|
+
export default createEntitySelect;
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
2
|
+
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); }
|
|
3
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
4
|
+
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."); }
|
|
5
|
+
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); }
|
|
6
|
+
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; }
|
|
7
|
+
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; } }
|
|
8
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
9
|
+
import DialogSelect from "../dialogSelect";
|
|
10
|
+
import { useControllableValue, useRequest } from 'ahooks';
|
|
11
|
+
import { Select as AntSelect } from 'antd';
|
|
12
|
+
import React, { useRef } from 'react';
|
|
13
|
+
var Option = AntSelect.Option;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* 实体选择器的骨架。
|
|
17
|
+
*
|
|
18
|
+
* 各业务模块的实体选择器(线体、车间、物料、供应商……)此前是逐个复制出来的:
|
|
19
|
+
* 取数、防抖、受控值、下拉即查、labelInValue、弹窗表格列,每份各写一遍,
|
|
20
|
+
* 真正不同的只有请求函数、提示语和表格列。骨架收在这里,各模块只填自己的那几项。
|
|
21
|
+
*
|
|
22
|
+
* 骨架不认识任何业务契约:请求函数由调用方传入,不引用任何生成服务客户端。
|
|
23
|
+
*
|
|
24
|
+
* @author nokecy
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
/** 取数入参:与后端分页查询约定一致。 */
|
|
28
|
+
|
|
29
|
+
var createEntitySelect = function createEntitySelect(config) {
|
|
30
|
+
var request = config.request,
|
|
31
|
+
placeholder = config.placeholder,
|
|
32
|
+
columnDefs = config.columnDefs,
|
|
33
|
+
valueField = config.valueField,
|
|
34
|
+
labelField = config.labelField,
|
|
35
|
+
modalWidth = config.modalWidth,
|
|
36
|
+
_config$pageSize = config.pageSize,
|
|
37
|
+
pageSize = _config$pageSize === void 0 ? 300 : _config$pageSize,
|
|
38
|
+
_config$useCodeByDefa = config.useCodeByDefault,
|
|
39
|
+
useCodeByDefault = _config$useCodeByDefa === void 0 ? true : _config$useCodeByDefa,
|
|
40
|
+
_config$buildFilter = config.buildFilter,
|
|
41
|
+
buildFilter = _config$buildFilter === void 0 ? function (keyword) {
|
|
42
|
+
return "(name =* ".concat(keyword, ") | (code =* ").concat(keyword, ")");
|
|
43
|
+
} : _config$buildFilter,
|
|
44
|
+
_config$renderOptionL = config.renderOptionLabel,
|
|
45
|
+
renderOptionLabel = _config$renderOptionL === void 0 ? function (item) {
|
|
46
|
+
return "".concat(item.code, " - ").concat(item.name);
|
|
47
|
+
} : _config$renderOptionL,
|
|
48
|
+
renderOption = config.renderOption,
|
|
49
|
+
linkagePropName = config.linkagePropName,
|
|
50
|
+
gridComponent = config.gridComponent;
|
|
51
|
+
var getData = function getData(_ref) {
|
|
52
|
+
var Filter = _ref.Filter,
|
|
53
|
+
SkipCount = _ref.SkipCount,
|
|
54
|
+
MaxResultCount = _ref.MaxResultCount,
|
|
55
|
+
Sorting = _ref.Sorting;
|
|
56
|
+
return request({
|
|
57
|
+
Filter: Filter ? Filter : undefined,
|
|
58
|
+
SkipCount: SkipCount ? SkipCount : 0,
|
|
59
|
+
MaxResultCount: MaxResultCount ? MaxResultCount : pageSize,
|
|
60
|
+
Sorting: Sorting ? Sorting : undefined
|
|
61
|
+
});
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
// props 上不加索引签名、ref 不收窄:这些选择器会被当作 AgGridColumn 的 searchComponent 传递,
|
|
65
|
+
// 任一处收紧都会让 forwardRef 的推断结果与那处的 prop 类型不兼容。
|
|
66
|
+
var EntitySelect = function EntitySelect(props, ref) {
|
|
67
|
+
var _data$items2;
|
|
68
|
+
var _props$useCode = props.useCode,
|
|
69
|
+
useCode = _props$useCode === void 0 ? useCodeByDefault : _props$useCode,
|
|
70
|
+
_props$enableLinkage = props.enableLinkage,
|
|
71
|
+
enableLinkage = _props$enableLinkage === void 0 ? false : _props$enableLinkage;
|
|
72
|
+
var resolvedValueField = valueField !== null && valueField !== void 0 ? valueField : useCode ? 'code' : 'id';
|
|
73
|
+
var onLinkage = linkagePropName ? props[linkagePropName] : undefined;
|
|
74
|
+
var lastLinkedValueRef = useRef();
|
|
75
|
+
var _useControllableValue = useControllableValue(props),
|
|
76
|
+
_useControllableValue2 = _slicedToArray(_useControllableValue, 2),
|
|
77
|
+
state = _useControllableValue2[0],
|
|
78
|
+
setState = _useControllableValue2[1];
|
|
79
|
+
var _useRequest = useRequest(getData, {
|
|
80
|
+
debounceMaxWait: 500,
|
|
81
|
+
manual: true
|
|
82
|
+
}),
|
|
83
|
+
data = _useRequest.data,
|
|
84
|
+
loading = _useRequest.loading,
|
|
85
|
+
run = _useRequest.run,
|
|
86
|
+
cancel = _useRequest.cancel;
|
|
87
|
+
var handleChange = function handleChange(value) {
|
|
88
|
+
var _data$items;
|
|
89
|
+
setState(value);
|
|
90
|
+
if (!value) {
|
|
91
|
+
lastLinkedValueRef.current = undefined;
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
if (!enableLinkage || !onLinkage) return;
|
|
95
|
+
var picked = _typeof(value) === 'object' ? value.value : value;
|
|
96
|
+
var matched = data === null || data === void 0 || (_data$items = data.items) === null || _data$items === void 0 ? void 0 : _data$items.find(function (item) {
|
|
97
|
+
return item[resolvedValueField] === picked;
|
|
98
|
+
});
|
|
99
|
+
if (matched && lastLinkedValueRef.current !== picked) {
|
|
100
|
+
lastLinkedValueRef.current = picked;
|
|
101
|
+
onLinkage(matched);
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
return /*#__PURE__*/React.createElement("span", {
|
|
105
|
+
ref: ref,
|
|
106
|
+
style: {
|
|
107
|
+
display: 'block',
|
|
108
|
+
width: '100%',
|
|
109
|
+
minWidth: 0,
|
|
110
|
+
maxWidth: '100%'
|
|
111
|
+
}
|
|
112
|
+
}, /*#__PURE__*/React.createElement(DialogSelect, _extends({
|
|
113
|
+
placeholder: placeholder,
|
|
114
|
+
style: {
|
|
115
|
+
width: '100%',
|
|
116
|
+
maxWidth: '100%'
|
|
117
|
+
},
|
|
118
|
+
showSearch: true,
|
|
119
|
+
labelInValue: true,
|
|
120
|
+
filterOption: false
|
|
121
|
+
}, modalWidth ? {
|
|
122
|
+
modalWidth: modalWidth
|
|
123
|
+
} : {}, gridComponent ? {
|
|
124
|
+
gridComponent: gridComponent
|
|
125
|
+
} : {}, props, {
|
|
126
|
+
onSearch: function onSearch(value) {
|
|
127
|
+
run({
|
|
128
|
+
Filter: buildFilter(value)
|
|
129
|
+
});
|
|
130
|
+
},
|
|
131
|
+
onDropdownVisibleChange: function onDropdownVisibleChange(visible) {
|
|
132
|
+
visible && run({});
|
|
133
|
+
},
|
|
134
|
+
loading: loading,
|
|
135
|
+
onBlur: cancel,
|
|
136
|
+
value: JSON.stringify(state) === '{}' ? undefined : state,
|
|
137
|
+
onChange: handleChange,
|
|
138
|
+
valueField: resolvedValueField
|
|
139
|
+
}, labelField ? {
|
|
140
|
+
labelField: labelField
|
|
141
|
+
} : {}, {
|
|
142
|
+
request: getData,
|
|
143
|
+
columnDefs: columnDefs,
|
|
144
|
+
onChangeItem: function onChangeItem(item) {
|
|
145
|
+
if (!enableLinkage || !onLinkage || !item) return;
|
|
146
|
+
var selected = Array.isArray(item) ? item[0] : item;
|
|
147
|
+
if (!selected) return;
|
|
148
|
+
var picked = selected[resolvedValueField];
|
|
149
|
+
if (lastLinkedValueRef.current === picked) return;
|
|
150
|
+
lastLinkedValueRef.current = picked;
|
|
151
|
+
onLinkage(selected);
|
|
152
|
+
}
|
|
153
|
+
}), data === null || data === void 0 || (_data$items2 = data.items) === null || _data$items2 === void 0 ? void 0 : _data$items2.map(function (item) {
|
|
154
|
+
var _item$id;
|
|
155
|
+
return renderOption ? renderOption(item, resolvedValueField) : /*#__PURE__*/React.createElement(Option, {
|
|
156
|
+
key: (_item$id = item.id) !== null && _item$id !== void 0 ? _item$id : item[resolvedValueField],
|
|
157
|
+
value: item[resolvedValueField]
|
|
158
|
+
}, renderOptionLabel(item));
|
|
159
|
+
})));
|
|
160
|
+
};
|
|
161
|
+
return /*#__PURE__*/React.forwardRef(EntitySelect);
|
|
162
|
+
};
|
|
163
|
+
export { createEntitySelect };
|
|
164
|
+
export default createEntitySelect;
|