@nokecy/qc-ui 1.1.96 → 1.1.97
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/ag-grid-plus/utils/columnProcessors.js +5 -4
- package/dist/cjs/array-table/readOnlyFormatters.js +21 -16
- package/dist/cjs/array-table/utils.js +36 -13
- package/dist/cjs/readPretty/controls.js +18 -2
- package/dist/cjs/readPretty/decimal.d.ts +4 -1
- package/dist/cjs/readPretty/decimal.js +12 -2
- package/dist/cjs/readPretty/formily.js +13 -5
- package/dist/cjs/readPretty/selectValue.d.ts +11 -0
- package/dist/cjs/readPretty/selectValue.js +24 -0
- package/dist/cjs/readPretty/values.js +5 -4
- package/dist/cjs/toolBar/index.js +47 -3
- package/dist/cjs/utils/optionValue.d.ts +9 -0
- package/dist/cjs/utils/optionValue.js +28 -0
- package/dist/esm/ag-grid-plus/utils/columnProcessors.js +5 -4
- package/dist/esm/array-table/readOnlyFormatters.js +21 -16
- package/dist/esm/array-table/utils.js +36 -13
- package/dist/esm/readPretty/controls.js +18 -2
- package/dist/esm/readPretty/decimal.d.ts +4 -1
- package/dist/esm/readPretty/decimal.js +12 -2
- package/dist/esm/readPretty/formily.js +13 -5
- package/dist/esm/readPretty/selectValue.d.ts +11 -0
- package/dist/esm/readPretty/selectValue.js +23 -0
- package/dist/esm/readPretty/values.js +5 -4
- package/dist/esm/toolBar/index.js +49 -4
- package/dist/esm/utils/optionValue.d.ts +9 -0
- package/dist/esm/utils/optionValue.js +22 -0
- package/dist/umd/qc-ui.min.js +1 -1
- package/package.json +1 -1
|
@@ -21,6 +21,7 @@ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" ==
|
|
|
21
21
|
* @author nokecy
|
|
22
22
|
*/
|
|
23
23
|
import dayjs from 'dayjs';
|
|
24
|
+
import { findOptionByValue } from "../utils/optionValue";
|
|
24
25
|
|
|
25
26
|
/** 选择器的展示字段;只影响回显,不改变 labelInValue 的提交值。@author nokecy */
|
|
26
27
|
|
|
@@ -54,16 +55,18 @@ var resolveOptions = function resolveOptions(ctx) {
|
|
|
54
55
|
|
|
55
56
|
/** 单个值映射成 label:兼容 labelInValue 对象、{label,value} 选项、原始值 */
|
|
56
57
|
var mapOptionLabel = function mapOptionLabel(value, options) {
|
|
57
|
-
var _ref4,
|
|
58
|
+
var _ref4, _hit$label;
|
|
58
59
|
if (value == null) return '';
|
|
59
60
|
// labelInValue: 值本身就是 { label, value }
|
|
60
|
-
if (_typeof(value) === 'object')
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
61
|
+
if (_typeof(value) === 'object') {
|
|
62
|
+
var label = value.label;
|
|
63
|
+
return label != null && label !== value.value ? String(label) : mapOptionLabel(value.value, options);
|
|
64
|
+
}
|
|
65
|
+
// 定长码值可能带补齐空格;与编辑控件、列表使用同一选项匹配规则。@author nokecy
|
|
66
|
+
var hit = findOptionByValue(options, value, function (o) {
|
|
67
|
+
return o && _typeof(o) === 'object' ? o.value : o;
|
|
65
68
|
});
|
|
66
|
-
if (hit && _typeof(hit) === 'object') return String((
|
|
69
|
+
if (hit && _typeof(hit) === 'object') return String((_ref4 = (_hit$label = hit.label) !== null && _hit$label !== void 0 ? _hit$label : hit.value) !== null && _ref4 !== void 0 ? _ref4 : value);
|
|
67
70
|
return String(value);
|
|
68
71
|
};
|
|
69
72
|
var textFormatter = function textFormatter(value) {
|
|
@@ -183,9 +186,9 @@ export var fallbackFormatter = function fallbackFormatter(value, ctx) {
|
|
|
183
186
|
}).filter(Boolean).join(', ');
|
|
184
187
|
if (typeof value === 'boolean') return booleanFormatter(value, ctx);
|
|
185
188
|
if (_typeof(value) === 'object') {
|
|
186
|
-
var _value$
|
|
189
|
+
var _value$label2;
|
|
187
190
|
if (typeof value.format === 'function') return dateFormatter(value, ctx);
|
|
188
|
-
var shown = (_value$
|
|
191
|
+
var shown = (_value$label2 = value.label) !== null && _value$label2 !== void 0 ? _value$label2 : value.value;
|
|
189
192
|
return shown == null ? '' : String(shown);
|
|
190
193
|
}
|
|
191
194
|
return String(value);
|
|
@@ -215,18 +218,20 @@ export var registerReadOnlyLabels = function registerReadOnlyLabels(component, l
|
|
|
215
218
|
if (o && o.value != null) map.set(String(o.value), String((_o$label = o.label) !== null && _o$label !== void 0 ? _o$label : o.value));
|
|
216
219
|
});
|
|
217
220
|
} else {
|
|
218
|
-
Object.entries(labels !== null && labels !== void 0 ? labels : {}).forEach(function (
|
|
219
|
-
var
|
|
220
|
-
k =
|
|
221
|
-
v =
|
|
221
|
+
Object.entries(labels !== null && labels !== void 0 ? labels : {}).forEach(function (_ref5) {
|
|
222
|
+
var _ref6 = _slicedToArray(_ref5, 2),
|
|
223
|
+
k = _ref6[0],
|
|
224
|
+
v = _ref6[1];
|
|
222
225
|
return map.set(String(k), String(v));
|
|
223
226
|
});
|
|
224
227
|
}
|
|
225
228
|
var toText = function toText(v) {
|
|
226
|
-
var _ref8, _v$label, _map$get;
|
|
227
229
|
if (v == null || v === '') return '';
|
|
228
|
-
if (_typeof(v) === 'object') return
|
|
229
|
-
|
|
230
|
+
if (_typeof(v) === 'object') return v.label != null && v.label !== v.value ? String(v.label) : toText(v.value);
|
|
231
|
+
var key = findOptionByValue(Array.from(map.keys()), v, function (key) {
|
|
232
|
+
return key;
|
|
233
|
+
});
|
|
234
|
+
return key === undefined ? String(v) : map.get(key);
|
|
230
235
|
};
|
|
231
236
|
var formatter = function formatter(value) {
|
|
232
237
|
return Array.isArray(value) ? value.map(toText).filter(Boolean).join(', ') : toText(value);
|
|
@@ -525,12 +525,24 @@ var LazyAgField = function LazyAgField(params) {
|
|
|
525
525
|
// 改值(行引用不变 → AG-Grid 不刷新该格、外层 observer 也不重渲)时,本格能自行重渲刷新——
|
|
526
526
|
// 免去调用方加 forceAgField 逃生阀。字段名缺失才回退 params.value。@author nokecy
|
|
527
527
|
return /*#__PURE__*/React.createElement(Observer, null, function () {
|
|
528
|
+
var _fieldSchema$xCompon2;
|
|
528
529
|
var _resolveCellRow3 = resolveCellRow(field, record, node, dataSource),
|
|
529
530
|
currentRecord = _resolveCellRow3.record;
|
|
530
531
|
if (!currentRecord) return /*#__PURE__*/React.createElement(React.Fragment, null);
|
|
531
532
|
var activated = activeCells.has(key);
|
|
532
533
|
// 已挂载时不读值:挂载后每敲一个字都会变,追踪它会让整棵字段树跟着重渲
|
|
533
534
|
var liveValue = activated ? undefined : dataKey != null ? readByFieldPath(currentRecord, dataKey) : value;
|
|
535
|
+
// 解构选择值缺少名称时仍要让业务组件补全名称;有名称后才可降为静默文本。@author nokecy
|
|
536
|
+
if (!activated && formatter === fallbackFormatter && liveValue && _typeof(liveValue) === 'object' && !Array.isArray(liveValue) && liveValue.value != null && (liveValue.label == null || liveValue.label === '' || liveValue.label === liveValue.value) && (fieldSchema === null || fieldSchema === void 0 || (_fieldSchema$xCompon2 = fieldSchema['x-component-props']) === null || _fieldSchema$xCompon2 === void 0 ? void 0 : _fieldSchema$xCompon2.displayField) !== 'value') {
|
|
537
|
+
return /*#__PURE__*/React.createElement(AgField, {
|
|
538
|
+
value: value,
|
|
539
|
+
data: currentRecord,
|
|
540
|
+
dataSource: dataSource,
|
|
541
|
+
schema: schema,
|
|
542
|
+
field: field,
|
|
543
|
+
node: node
|
|
544
|
+
});
|
|
545
|
+
}
|
|
534
546
|
// Editable 装饰器会把非新增行的格转成只读态、不参与校验(见 editable/index.tsx),
|
|
535
547
|
// 这时挂了没用,还会把灰色「请输入」占位换成只读态的「N/A」,所以留在文本态
|
|
536
548
|
var editableWillReadPretty = (fieldSchema === null || fieldSchema === void 0 ? void 0 : fieldSchema['x-decorator']) === 'Editable' && currentRecord._isNew !== true;
|
|
@@ -701,7 +713,7 @@ var applyNumberInputDefaults = function applyNumberInputDefaults(dataField) {
|
|
|
701
713
|
var buildArrayTableColumns = function buildArrayTableColumns(dataSource, field, sources) {
|
|
702
714
|
var arrayPattern = field === null || field === void 0 ? void 0 : field.pattern;
|
|
703
715
|
return sources.reduce(function (buf, _ref7, key) {
|
|
704
|
-
var _dataField$xDecorato, _ref8, _getReadOnlyFormatter, _dataField$xComponen, _dataField$xComponen2;
|
|
716
|
+
var _dataField$xDecorato, _ref8, _getReadOnlyFormatter, _dataField$xComponen, _parseObjectDestructu, _dataField$xComponen2, _dataField$xComponen3, _dataField$xComponen4, _dataField$xComponen5;
|
|
705
717
|
var name = _ref7.name,
|
|
706
718
|
columnProps = _ref7.columnProps,
|
|
707
719
|
schema = _ref7.schema,
|
|
@@ -752,11 +764,15 @@ var buildArrayTableColumns = function buildArrayTableColumns(dataSource, field,
|
|
|
752
764
|
// 格子先出廉价文本、点击/导航(或必填且为空)才挂全树,焦点离开且校验通过再卸回文本。
|
|
753
765
|
// ③ 兜底全树:其余(无格式化器/带 reactions/forceAgField/复杂字段名/只读但无格式化器) -> AgField。
|
|
754
766
|
var component = dataField === null || dataField === void 0 ? void 0 : dataField['x-component'];
|
|
755
|
-
//
|
|
756
|
-
//
|
|
757
|
-
//
|
|
767
|
+
// 未声明显示规则的业务组件必须挂载:单位选择器等会读取同行名称或异步加载候选,
|
|
768
|
+
// 仅把标量码交给 fallback 会跳过这些逻辑。解构值自带名称、显式编码展示及已登记格式化器仍走快路径。
|
|
769
|
+
// 登记渲染器的组件只读列也可用兜底格式化器判空。@author nokecy
|
|
758
770
|
var renderer = getReadOnlyRenderer(component);
|
|
759
|
-
var formatter = (_ref8 = (_getReadOnlyFormatter = getReadOnlyFormatter(component, components)) !== null && _getReadOnlyFormatter !== void 0 ? _getReadOnlyFormatter : (dataField === null || dataField === void 0 || (_dataField$xComponen = dataField['x-component-props']) === null || _dataField$xComponen === void 0 ? void 0 : _dataField$xComponen.displayField) === 'value' ? fallbackFormatter : null) !== null && _ref8 !== void 0 ? _ref8 : (!readOnly || renderer) &&
|
|
771
|
+
var formatter = (_ref8 = (_getReadOnlyFormatter = getReadOnlyFormatter(component, components)) !== null && _getReadOnlyFormatter !== void 0 ? _getReadOnlyFormatter : (dataField === null || dataField === void 0 || (_dataField$xComponen = dataField['x-component-props']) === null || _dataField$xComponen === void 0 ? void 0 : _dataField$xComponen.displayField) === 'value' ? fallbackFormatter : null) !== null && _ref8 !== void 0 ? _ref8 : (!readOnly || renderer) && (renderer || (_parseObjectDestructu = parseObjectDestructure(dataField === null || dataField === void 0 ? void 0 : dataField.name)) !== null && _parseObjectDestructu !== void 0 && _parseObjectDestructu.some(function (_ref9) {
|
|
772
|
+
var _ref10 = _slicedToArray(_ref9, 1),
|
|
773
|
+
key = _ref10[0];
|
|
774
|
+
return key === 'label';
|
|
775
|
+
})) && component && (dataField === null || dataField === void 0 ? void 0 : dataField.type) !== 'void' ? fallbackFormatter : null;
|
|
760
776
|
var displayColumnProps = formatter && (getReadOnlyFormatter(component, components) !== getReadOnlyFormatter(component) || (dataField === null || dataField === void 0 || (_dataField$xComponen2 = dataField['x-component-props']) === null || _dataField$xComponen2 === void 0 ? void 0 : _dataField$xComponen2.displayField) === 'value') ? {
|
|
761
777
|
valueFormatter: function valueFormatter(params) {
|
|
762
778
|
return formatter(params.value, {
|
|
@@ -767,7 +783,14 @@ var buildArrayTableColumns = function buildArrayTableColumns(dataSource, field,
|
|
|
767
783
|
} : {};
|
|
768
784
|
var hasReactions = !!(dataField && dataField['x-reactions']);
|
|
769
785
|
if (!readOnly) applyNumberInputDefaults(dataField);
|
|
770
|
-
|
|
786
|
+
// 表达式或运行时选项必须创建字段才能求值/加载,不能在没有名称表时直接显示码值。@author nokecy
|
|
787
|
+
var hasOptionExpression = [dataField === null || dataField === void 0 ? void 0 : dataField.enum, dataField === null || dataField === void 0 || (_dataField$xComponen3 = dataField['x-component-props']) === null || _dataField$xComponen3 === void 0 ? void 0 : _dataField$xComponen3.options, dataField === null || dataField === void 0 || (_dataField$xComponen4 = dataField['x-component-props']) === null || _dataField$xComponen4 === void 0 ? void 0 : _dataField$xComponen4.dataSource, columnProps === null || columnProps === void 0 ? void 0 : columnProps.options, columnProps === null || columnProps === void 0 ? void 0 : columnProps.dataSource].some(function (options) {
|
|
788
|
+
return typeof options === 'string' && options.includes('{{');
|
|
789
|
+
});
|
|
790
|
+
// 格式化表达式依赖本页 scope 与本行字段,交给 Formily 创建真实字段后编译。@author nokecy
|
|
791
|
+
var schemaFormatter = dataField === null || dataField === void 0 || (_dataField$xComponen5 = dataField['x-component-props']) === null || _dataField$xComponen5 === void 0 ? void 0 : _dataField$xComponen5.formatter;
|
|
792
|
+
var hasFormatterExpression = typeof schemaFormatter === 'string' && schemaFormatter.includes('{{');
|
|
793
|
+
var forceEager = (columnProps === null || columnProps === void 0 ? void 0 : columnProps.forceAgField) === true || formatter === getReadOnlyFormatter('Select') && hasOptionExpression || hasFormatterExpression;
|
|
771
794
|
// Switch/Checkbox 是「单击直控」组件:可编辑态本就该常驻渲染真控件(优化前即如此)。
|
|
772
795
|
// 懒挂载会把它降成「是/否」纯文本(点击才挂出开关),用户会以为开关消失。故可编辑态强制 eager。
|
|
773
796
|
// 只读态(下方 ① 路径)仍走「是/否」文本快路径不受影响。@author nokecy
|
|
@@ -791,7 +814,7 @@ var buildArrayTableColumns = function buildArrayTableColumns(dataSource, field,
|
|
|
791
814
|
var canFastPath = !dataFieldName || isFastPathFieldName(dataFieldName);
|
|
792
815
|
|
|
793
816
|
// ① 只读纯文本
|
|
794
|
-
if (readOnly && formatter && canFastPath) {
|
|
817
|
+
if (readOnly && formatter && canFastPath && !forceEager) {
|
|
795
818
|
// 列级 readPretty 在「可编辑表」里是展示列(值可能被 setValuesIn 自动带出),静态 valueFormatter
|
|
796
819
|
// 读 AG-Grid 缓存值不刷新 → 反应式只读渲染。整表 readPretty(明细/详情页,数据 setValues 整体加载、
|
|
797
820
|
// 行引用整体替换、AG-Grid 自然刷新)仍走更廉价的静态 valueFormatter 快路径。@author nokecy
|
|
@@ -911,9 +934,9 @@ export var collectLazyDefaults = function collectLazyDefaults(columns) {
|
|
|
911
934
|
key: String((_fieldSchema$name3 = fieldSchema === null || fieldSchema === void 0 ? void 0 : fieldSchema.name) !== null && _fieldSchema$name3 !== void 0 ? _fieldSchema$name3 : col.field),
|
|
912
935
|
value: fieldSchema === null || fieldSchema === void 0 ? void 0 : fieldSchema.default
|
|
913
936
|
};
|
|
914
|
-
}).filter(function (
|
|
915
|
-
var key =
|
|
916
|
-
value =
|
|
937
|
+
}).filter(function (_ref11) {
|
|
938
|
+
var key = _ref11.key,
|
|
939
|
+
value = _ref11.value;
|
|
917
940
|
return SIMPLE_FIELD_NAME.test(key) && value !== undefined && value !== null && !(typeof value === 'string' && value.includes('{{'));
|
|
918
941
|
});
|
|
919
942
|
};
|
|
@@ -932,9 +955,9 @@ export var applyLazyDefaults = function applyLazyDefaults(arrayField, defaults,
|
|
|
932
955
|
// 已落库的行(带 id)保持库里的样子:补默认值会让受控字段凭空出现「变更」,
|
|
933
956
|
// 已审批的数据保存时还会被要求填变更原因。只补新增行(按钮之外的途径推进来的行)。
|
|
934
957
|
if (row.id != null || row._id != null) return;
|
|
935
|
-
defaults.forEach(function (
|
|
936
|
-
var key =
|
|
937
|
-
value =
|
|
958
|
+
defaults.forEach(function (_ref12) {
|
|
959
|
+
var key = _ref12.key,
|
|
960
|
+
value = _ref12.value;
|
|
938
961
|
if (row[key] == null) {
|
|
939
962
|
form.setValuesIn(arrayField.path.concat(index).concat(key), _typeof(value) === 'object' ? JSON.parse(JSON.stringify(value)) : value);
|
|
940
963
|
}
|
|
@@ -1,3 +1,9 @@
|
|
|
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); }
|
|
1
7
|
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
8
|
import { NumberPicker as FormilyNumberPicker, PreviewText } from '@formily/antd-v5';
|
|
3
9
|
import { AutoComplete as AntAutoComplete, ConfigProvider, Input as AntInput, InputNumber as AntInputNumber, Select as AntSelect, Switch as AntSwitch, Checkbox as AntCheckbox, Radio as AntRadio, DatePicker as AntDatePicker, TimePicker as AntTimePicker, TreeSelect as AntTreeSelect, Cascader as AntCascader } from 'antd';
|
|
@@ -5,6 +11,7 @@ import React from 'react';
|
|
|
5
11
|
import { hoistStatics } from "./hoistStatics";
|
|
6
12
|
import { selectNumberInputTextOnClick } from "./selectNumberInputTextOnClick";
|
|
7
13
|
import { flattenOptions, selectedLabels } from "./values";
|
|
14
|
+
import { matchSelectDisplayValue } from "./selectValue";
|
|
8
15
|
|
|
9
16
|
/** 普通表单控件统一阅读展示;数值控件禁用方向键步进,让表格负责上下导航。@author nokecy */
|
|
10
17
|
var readingControl = function readingControl(Control, Preview) {
|
|
@@ -19,7 +26,7 @@ var readingControl = function readingControl(Control, Preview) {
|
|
|
19
26
|
var reading = props.readOnly || ((_props$disabled = props.disabled) !== null && _props$disabled !== void 0 ? _props$disabled : componentDisabled);
|
|
20
27
|
return reading ? /*#__PURE__*/React.createElement(PreviewText.Placeholder, {
|
|
21
28
|
value: "\u2014"
|
|
22
|
-
}, /*#__PURE__*/React.createElement(Preview, map(props))) : /*#__PURE__*/React.createElement(Control, _extends({}, props, numericInput ? {
|
|
29
|
+
}, /*#__PURE__*/React.createElement(Preview, map(props))) : /*#__PURE__*/React.createElement(Control, _extends({}, map(props), numericInput ? {
|
|
23
30
|
keyboard: false,
|
|
24
31
|
onClick: selectNumberInputTextOnClick(props.onClick)
|
|
25
32
|
} : {}, {
|
|
@@ -42,6 +49,15 @@ var choiceOptions = function choiceOptions(props) {
|
|
|
42
49
|
var ChoicePreview = function ChoicePreview(props) {
|
|
43
50
|
return /*#__PURE__*/React.createElement("span", null, selectedLabels(props.value, flattenOptions(choiceOptions(props), props.fieldNames), props.labelInValue));
|
|
44
51
|
};
|
|
52
|
+
/** 候选值只在显示边界匹配;加载含空格的码值不会把单据标成已修改。@author nokecy */
|
|
53
|
+
var choiceDisplayProps = function choiceDisplayProps(props) {
|
|
54
|
+
var options = flattenOptions(choiceOptions(props), props.fieldNames);
|
|
55
|
+
return _objectSpread(_objectSpread(_objectSpread({}, props), 'value' in props ? {
|
|
56
|
+
value: matchSelectDisplayValue(props.value, options, props.labelInValue)
|
|
57
|
+
} : {}), 'defaultValue' in props ? {
|
|
58
|
+
defaultValue: matchSelectDisplayValue(props.defaultValue, options, props.labelInValue)
|
|
59
|
+
} : {});
|
|
60
|
+
};
|
|
45
61
|
var BooleanPreview = function BooleanPreview(props) {
|
|
46
62
|
return /*#__PURE__*/React.createElement("span", null, props.children, props.children ? ':' : '', props.checked == null ? '—' : props.checked ? '是' : '否');
|
|
47
63
|
};
|
|
@@ -55,7 +71,7 @@ Input.Search = readingControl(AntInput.Search, PreviewText.Input);
|
|
|
55
71
|
export var InputNumber = readingControl(AntInputNumber, PreviewText.NumberPicker, undefined, true);
|
|
56
72
|
/** Formily 数值控件同样关闭方向键步进,保留数值类型及原有表单绑定。@author nokecy */
|
|
57
73
|
export var NumberPicker = readingControl(FormilyNumberPicker, PreviewText.NumberPicker, undefined, true);
|
|
58
|
-
export var Select = readingControl(AntSelect, ChoicePreview);
|
|
74
|
+
export var Select = readingControl(AntSelect, ChoicePreview, choiceDisplayProps);
|
|
59
75
|
export var Switch = readingControl(AntSwitch, BooleanPreview);
|
|
60
76
|
export var Checkbox = readingControl(AntCheckbox, BooleanPreview);
|
|
61
77
|
Checkbox.Group = readingControl(AntCheckbox.Group, ChoicePreview);
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
/** 精确业务数值录入和阅读展示,零值与原始十进制字符串始终保留。@author nokecy */
|
|
3
3
|
export declare const DecimalInput: React.ForwardRefExoticComponent<Omit<any, "ref"> & React.RefAttributes<any>>;
|
|
4
|
-
|
|
4
|
+
/** 精确数值的静默态沿用自身阅读规则,允许表格按已知显示契约懒挂载。@author nokecy */
|
|
5
|
+
export declare const DecimalPicker: React.ForwardRefExoticComponent<Omit<Partial<Omit<any, "ref"> & React.RefAttributes<any>>, "ref"> & React.RefAttributes<unknown>> & {
|
|
6
|
+
readOnlyFormatter: import("../array-table/readOnlyFormatters").ReadOnlyFormatter;
|
|
7
|
+
};
|
|
@@ -3,6 +3,7 @@ import { connect, mapReadPretty } from '@formily/react';
|
|
|
3
3
|
import React from 'react';
|
|
4
4
|
import { InputNumber } from "./controls";
|
|
5
5
|
import { decimalText } from "../utils/businessDecimal";
|
|
6
|
+
import { withReadOnlyFormatter } from "../array-table/readOnlyFormatters";
|
|
6
7
|
|
|
7
8
|
/** 精确业务数值录入和阅读展示,零值与原始十进制字符串始终保留。@author nokecy */
|
|
8
9
|
export var DecimalInput = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
@@ -14,9 +15,18 @@ export var DecimalInput = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
14
15
|
var DecimalPreview = function DecimalPreview(_ref) {
|
|
15
16
|
var value = _ref.value,
|
|
16
17
|
formatter = _ref.formatter;
|
|
17
|
-
return /*#__PURE__*/React.createElement("span", null, value == null || value === '' ? '—' : formatter ? formatter(value, {
|
|
18
|
+
return /*#__PURE__*/React.createElement("span", null, value == null || value === '' ? '—' : typeof formatter === 'function' ? formatter(value, {
|
|
18
19
|
userTyping: false,
|
|
19
20
|
input: String(value)
|
|
20
21
|
}) : decimalText(value));
|
|
21
22
|
};
|
|
22
|
-
|
|
23
|
+
/** 精确数值的静默态沿用自身阅读规则,允许表格按已知显示契约懒挂载。@author nokecy */
|
|
24
|
+
export var DecimalPicker = withReadOnlyFormatter(connect(DecimalInput, mapReadPretty(DecimalPreview)), function (value, ctx) {
|
|
25
|
+
var _ctx$fieldSchema;
|
|
26
|
+
if (value == null || value === '') return '';
|
|
27
|
+
var formatter = (_ctx$fieldSchema = ctx.fieldSchema) === null || _ctx$fieldSchema === void 0 || (_ctx$fieldSchema = _ctx$fieldSchema['x-component-props']) === null || _ctx$fieldSchema === void 0 ? void 0 : _ctx$fieldSchema.formatter;
|
|
28
|
+
return typeof formatter === 'function' ? String(formatter(value, {
|
|
29
|
+
userTyping: false,
|
|
30
|
+
input: String(value)
|
|
31
|
+
})) : decimalText(value);
|
|
32
|
+
});
|
|
@@ -14,6 +14,8 @@ import { hoistStatics } from "./hoistStatics";
|
|
|
14
14
|
import * as Reading from "./controls";
|
|
15
15
|
import { selectNumberInputTextOnClick } from "./selectNumberInputTextOnClick";
|
|
16
16
|
import { withReadingArrayTable } from "./arrayTable";
|
|
17
|
+
import { flattenOptions } from "./values";
|
|
18
|
+
import { matchSelectDisplayValue } from "./selectValue";
|
|
17
19
|
export { withReactiveSchemaScope } from "./schemaScope";
|
|
18
20
|
|
|
19
21
|
/** 动态表单统一阅读展示;数值控件关闭方向键步进,保留表格导航与字段值。@author nokecy */
|
|
@@ -25,18 +27,24 @@ export function withReadingFields(components) {
|
|
|
25
27
|
});
|
|
26
28
|
var wrap = function wrap(Control, Preview) {
|
|
27
29
|
var numericInput = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
30
|
+
var choiceInput = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
28
31
|
var Component = observer(function (props) {
|
|
32
|
+
var _field$dataSource;
|
|
29
33
|
var field = useField();
|
|
30
|
-
|
|
31
|
-
|
|
34
|
+
var options = field !== null && field !== void 0 && (_field$dataSource = field.dataSource) !== null && _field$dataSource !== void 0 && _field$dataSource.length ? field.dataSource : props.options;
|
|
35
|
+
var displayProps = choiceInput ? _objectSpread(_objectSpread({}, props), {}, {
|
|
36
|
+
value: matchSelectDisplayValue(props.value, flattenOptions(options, props.fieldNames), props.labelInValue)
|
|
37
|
+
}) : props;
|
|
38
|
+
if (props.disabled || props.readOnly || field !== null && field !== void 0 && field.disabled || field !== null && field !== void 0 && field.readOnly || choiceInput && (field === null || field === void 0 ? void 0 : field.pattern) === 'readPretty') {
|
|
39
|
+
var _field$value, _field$value2, _field$dataSource2;
|
|
32
40
|
return /*#__PURE__*/React.createElement(Preview, _extends({}, props, {
|
|
33
41
|
value: (_field$value = field === null || field === void 0 ? void 0 : field.value) !== null && _field$value !== void 0 ? _field$value : props.value,
|
|
34
42
|
checked: (_field$value2 = field === null || field === void 0 ? void 0 : field.value) !== null && _field$value2 !== void 0 ? _field$value2 : props.checked,
|
|
35
|
-
options: field !== null && field !== void 0 && (_field$
|
|
43
|
+
options: field !== null && field !== void 0 && (_field$dataSource2 = field.dataSource) !== null && _field$dataSource2 !== void 0 && _field$dataSource2.length ? field.dataSource : props.options,
|
|
36
44
|
disabled: true
|
|
37
45
|
}));
|
|
38
46
|
}
|
|
39
|
-
return /*#__PURE__*/React.createElement(Control, _extends({},
|
|
47
|
+
return /*#__PURE__*/React.createElement(Control, _extends({}, displayProps, numericInput ? {
|
|
40
48
|
keyboard: false,
|
|
41
49
|
onClick: selectNumberInputTextOnClick(props.onClick)
|
|
42
50
|
} : {}));
|
|
@@ -56,7 +64,7 @@ export function withReadingFields(components) {
|
|
|
56
64
|
try {
|
|
57
65
|
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
58
66
|
var name = _step.value;
|
|
59
|
-
result[name] = wrap(components[name], previews[name], name === 'NumberPicker' || name === 'InputNumber');
|
|
67
|
+
result[name] = wrap(components[name], previews[name], name === 'NumberPicker' || name === 'InputNumber', name === 'Select');
|
|
60
68
|
}
|
|
61
69
|
// ArrayTable 阅读态保留动态列的标题和显隐状态。@author nokecy
|
|
62
70
|
} catch (err) {
|
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
import { type ReactNode } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* 仅为控件回显匹配候选中的原生值,不回写表单,不触发变更事件。
|
|
4
|
+
* @param value 原始单选或多选值。
|
|
5
|
+
* @param options 已展开的选项。
|
|
6
|
+
* @param labelInValue 是否使用名称编码对象。
|
|
7
|
+
* @returns 命中选项的控件值;未知值原样保留。
|
|
8
|
+
* @author nokecy
|
|
9
|
+
*/
|
|
10
|
+
export declare function matchSelectDisplayValue(value: any, options: readonly {
|
|
11
|
+
value?: unknown;
|
|
12
|
+
}[], labelInValue?: boolean): any;
|
|
2
13
|
/** 提取选择项的标量编码,兼容嵌套 labelInValue;保留编码 0 和显式空字符串选项。@author nokecy */
|
|
3
14
|
export declare function selectCode(value: unknown, depth?: number): string | number | undefined;
|
|
4
15
|
/** 标签只输出可渲染内容;选择项对象取名称后再回落编码,避免 React 对象子节点异常。@author nokecy */
|
|
@@ -5,6 +5,29 @@ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol"
|
|
|
5
5
|
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); }
|
|
6
6
|
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); }
|
|
7
7
|
import { isValidElement } from 'react';
|
|
8
|
+
import { findOptionByValue } from "../utils/optionValue";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* 仅为控件回显匹配候选中的原生值,不回写表单,不触发变更事件。
|
|
12
|
+
* @param value 原始单选或多选值。
|
|
13
|
+
* @param options 已展开的选项。
|
|
14
|
+
* @param labelInValue 是否使用名称编码对象。
|
|
15
|
+
* @returns 命中选项的控件值;未知值原样保留。
|
|
16
|
+
* @author nokecy
|
|
17
|
+
*/
|
|
18
|
+
export function matchSelectDisplayValue(value, options, labelInValue) {
|
|
19
|
+
if (Array.isArray(value)) return value.map(function (item) {
|
|
20
|
+
return matchSelectDisplayValue(item, options, labelInValue);
|
|
21
|
+
});
|
|
22
|
+
var raw = labelInValue && value && _typeof(value) === 'object' ? value.value : value;
|
|
23
|
+
var matched = findOptionByValue(options, raw, function (option) {
|
|
24
|
+
return option.value;
|
|
25
|
+
});
|
|
26
|
+
if (!matched) return value;
|
|
27
|
+
return labelInValue && value && _typeof(value) === 'object' ? _objectSpread(_objectSpread({}, value), {}, {
|
|
28
|
+
value: matched.value
|
|
29
|
+
}) : matched.value;
|
|
30
|
+
}
|
|
8
31
|
|
|
9
32
|
/** 提取选择项的标量编码,兼容嵌套 labelInValue;保留编码 0 和显式空字符串选项。@author nokecy */
|
|
10
33
|
export function selectCode(value) {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
2
|
import { normalizeSelectValue, selectLabel } from "./selectValue";
|
|
3
|
+
import { findOptionByValue } from "../utils/optionValue";
|
|
3
4
|
|
|
4
5
|
/** 阅读态选择项展开,保留分组内选项及自定义字段名。@author nokecy */
|
|
5
6
|
export function flattenOptions() {
|
|
@@ -30,11 +31,11 @@ export function selectedLabels(value, options, labelInValue) {
|
|
|
30
31
|
var values = Array.isArray(normalized) ? normalized : normalized == null ? [] : [normalized];
|
|
31
32
|
if (!values.length) return '—';
|
|
32
33
|
var labels = values.map(function (item) {
|
|
33
|
-
var _ref2, _selectLabel,
|
|
34
|
+
var _ref2, _selectLabel, _findOptionByValue, _item$label;
|
|
34
35
|
var raw = labelInValue ? item.value : item;
|
|
35
|
-
return (_ref2 = (_selectLabel = selectLabel((
|
|
36
|
-
return option.value
|
|
37
|
-
})) === null ||
|
|
36
|
+
return (_ref2 = (_selectLabel = selectLabel((_findOptionByValue = findOptionByValue(options, raw, function (option) {
|
|
37
|
+
return option.value;
|
|
38
|
+
})) === null || _findOptionByValue === void 0 ? void 0 : _findOptionByValue.label)) !== null && _selectLabel !== void 0 ? _selectLabel : selectLabel(labelInValue ? (_item$label = item.label) !== null && _item$label !== void 0 ? _item$label : raw : raw)) !== null && _ref2 !== void 0 ? _ref2 : '—';
|
|
38
39
|
});
|
|
39
40
|
// 选项标签可以是React节点,交由调用组件按顺序渲染。
|
|
40
41
|
return labels.flatMap(function (label, index) {
|
|
@@ -1,7 +1,19 @@
|
|
|
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); }
|
|
1
2
|
var _excluded = ["children", "className", "extra", "identity", "banner", "style", "renderContent", "getTargetContainer"];
|
|
3
|
+
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; }
|
|
4
|
+
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; }
|
|
5
|
+
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; }
|
|
6
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
7
|
+
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); }
|
|
8
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
9
|
+
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."); }
|
|
10
|
+
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); }
|
|
11
|
+
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; }
|
|
12
|
+
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; } }
|
|
13
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
2
14
|
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; }
|
|
3
15
|
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; }
|
|
4
|
-
import React, { useCallback, useRef } from 'react';
|
|
16
|
+
import React, { useCallback, useLayoutEffect, useRef, useState } from 'react';
|
|
5
17
|
import { Affix, theme } from 'antd';
|
|
6
18
|
import "./index.less";
|
|
7
19
|
|
|
@@ -19,10 +31,41 @@ var ToolBar = function ToolBar(props) {
|
|
|
19
31
|
var _theme$useToken = theme.useToken(),
|
|
20
32
|
token = _theme$useToken.token; // 单据操作栏跟随宿主主题。@author nokecy
|
|
21
33
|
var barRef = useRef(null);
|
|
34
|
+
var _useState = useState(),
|
|
35
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
36
|
+
barHeight = _useState2[0],
|
|
37
|
+
setBarHeight = _useState2[1];
|
|
38
|
+
/** 吸顶后 Affix 的占位会固定高度,动态提示及按钮换行仍须按内容重新占位。@author nokecy */
|
|
39
|
+
var measureHeight = useCallback(function () {
|
|
40
|
+
var _barRef$current;
|
|
41
|
+
var height = (_barRef$current = barRef.current) === null || _barRef$current === void 0 ? void 0 : _barRef$current.getBoundingClientRect().height;
|
|
42
|
+
// KeepAlive 隐藏页的零高度不能冲掉有效占位。@author nokecy
|
|
43
|
+
if (height && height > 0) setBarHeight(function (previous) {
|
|
44
|
+
return previous === Math.ceil(height) ? previous : Math.ceil(height);
|
|
45
|
+
});
|
|
46
|
+
}, []);
|
|
47
|
+
useLayoutEffect(function () {
|
|
48
|
+
measureHeight();
|
|
49
|
+
});
|
|
50
|
+
useLayoutEffect(function () {
|
|
51
|
+
var bar = barRef.current;
|
|
52
|
+
if (!bar) return;
|
|
53
|
+
if (typeof ResizeObserver !== 'undefined') {
|
|
54
|
+
var observer = new ResizeObserver(measureHeight);
|
|
55
|
+
observer.observe(bar);
|
|
56
|
+
return function () {
|
|
57
|
+
return observer.disconnect();
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
window.addEventListener('resize', measureHeight);
|
|
61
|
+
return function () {
|
|
62
|
+
return window.removeEventListener('resize', measureHeight);
|
|
63
|
+
};
|
|
64
|
+
}, [measureHeight]);
|
|
22
65
|
// @author nokecy:KeepAlive 内容区独立滚动,吸顶应相对其视口,避免定位到应用顶栏下面。
|
|
23
66
|
var defaultTarget = useCallback(function () {
|
|
24
|
-
var _barRef$current$paren, _barRef$
|
|
25
|
-
var parent = (_barRef$current$paren = (_barRef$
|
|
67
|
+
var _barRef$current$paren, _barRef$current2;
|
|
68
|
+
var parent = (_barRef$current$paren = (_barRef$current2 = barRef.current) === null || _barRef$current2 === void 0 ? void 0 : _barRef$current2.parentElement) !== null && _barRef$current$paren !== void 0 ? _barRef$current$paren : null;
|
|
26
69
|
while (parent) {
|
|
27
70
|
if (/auto|scroll/.test(getComputedStyle(parent).overflowY)) return parent;
|
|
28
71
|
parent = parent.parentElement;
|
|
@@ -31,7 +74,9 @@ var ToolBar = function ToolBar(props) {
|
|
|
31
74
|
}, []);
|
|
32
75
|
return /*#__PURE__*/React.createElement(Affix, {
|
|
33
76
|
offsetTop: 2,
|
|
34
|
-
style: style,
|
|
77
|
+
style: _objectSpread(_objectSpread({}, style), barHeight === undefined ? {} : {
|
|
78
|
+
height: barHeight
|
|
79
|
+
}),
|
|
35
80
|
offsetBottom: 2,
|
|
36
81
|
target: getTargetContainer || defaultTarget
|
|
37
82
|
}, /*#__PURE__*/React.createElement("div", {
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 精确匹配优先,再按去除首尾空格的标量码匹配选项;保留前导零、大小写及未知值。
|
|
3
|
+
* @param options 可选项。
|
|
4
|
+
* @param value 待显示的原始值。
|
|
5
|
+
* @param getValue 读取选项编码。
|
|
6
|
+
* @returns 命中的选项;未命中返回 undefined,不改写原始数据。
|
|
7
|
+
* @author nokecy
|
|
8
|
+
*/
|
|
9
|
+
export declare function findOptionByValue<T>(options: readonly T[], value: unknown, getValue: (option: T) => unknown): T | undefined;
|
|
@@ -0,0 +1,22 @@
|
|
|
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
|
+
/**
|
|
3
|
+
* 精确匹配优先,再按去除首尾空格的标量码匹配选项;保留前导零、大小写及未知值。
|
|
4
|
+
* @param options 可选项。
|
|
5
|
+
* @param value 待显示的原始值。
|
|
6
|
+
* @param getValue 读取选项编码。
|
|
7
|
+
* @returns 命中的选项;未命中返回 undefined,不改写原始数据。
|
|
8
|
+
* @author nokecy
|
|
9
|
+
*/
|
|
10
|
+
export function findOptionByValue(options, value, getValue) {
|
|
11
|
+
var exact = options.find(function (option) {
|
|
12
|
+
return getValue(option) === value;
|
|
13
|
+
});
|
|
14
|
+
if (exact !== undefined) return exact;
|
|
15
|
+
var code = function code(item) {
|
|
16
|
+
return ['string', 'number', 'boolean'].includes(_typeof(item)) ? String(item).trim() : undefined;
|
|
17
|
+
};
|
|
18
|
+
var target = code(value);
|
|
19
|
+
return target === undefined ? undefined : options.find(function (option) {
|
|
20
|
+
return code(getValue(option)) === target;
|
|
21
|
+
});
|
|
22
|
+
}
|