@nokecy/qc-ui 1.1.46 → 1.1.47

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.
@@ -141,6 +141,34 @@ var AgField = function AgField(_ref) {
141
141
  return children;
142
142
  };
143
143
 
144
+ /**
145
+ * 快路径能否按这个字段名取到值。
146
+ *
147
+ * Formily 的字段名是「路径」不是「键」,支持点号嵌套(`item.qty`)、数组下标(`a[0]`)、
148
+ * 解构(`{value:code,label:name}`)等语法。快路径(只读文本/懒挂载)不挂 Formily 树,
149
+ * 取值得自己解析。这里只认「点号分段」这一种简单形态,其余一律判不合格 ->
150
+ * 调用方回退 AgField 全树(由 Formily 自己解析,正确优先于速度)。@author nokecy
151
+ */
152
+ var isSimpleFieldPath = function isSimpleFieldPath(name) {
153
+ return !!name && /^[^.{}[\]*]+(\.[^.{}[\]*]+)*$/.test(name);
154
+ };
155
+
156
+ /**
157
+ * 按 Formily 字段名从行数据取值。
158
+ *
159
+ * 曾经一律按扁平键取 record['item.qty'],而数据在 record.item.qty ->
160
+ * 嵌套字段名恒 undefined,单元格默认空白,点击挂上全树(按路径解析)才显出真值。
161
+ *
162
+ * 在 Observer 里逐层读可观察对象,依赖链完整,程序化改值(setValuesIn)照样刷新。@author nokecy
163
+ */
164
+ var readByFieldPath = function readByFieldPath(record, path) {
165
+ if (record == null) return undefined;
166
+ if (path.indexOf('.') < 0) return record[path];
167
+ return path.split('.').reduce(function (acc, key) {
168
+ return acc == null ? undefined : acc[key];
169
+ }, record);
170
+ };
171
+
144
172
  /**
145
173
  * 懒挂载单元格渲染器(可编辑列)。
146
174
  *
@@ -187,7 +215,7 @@ var LazyAgField = exports.LazyAgField = function LazyAgField(params) {
187
215
  // 免去调用方加 forceAgField 逃生阀。字段名缺失才回退 params.value。@author nokecy
188
216
  var dataKey = (_fieldSchema$name = fieldSchema === null || fieldSchema === void 0 ? void 0 : fieldSchema.name) !== null && _fieldSchema$name !== void 0 ? _fieldSchema$name : colDef === null || colDef === void 0 ? void 0 : colDef.field;
189
217
  return /*#__PURE__*/_react.default.createElement(_react2.Observer, null, function () {
190
- var liveValue = dataKey != null && record ? record[dataKey] : value;
218
+ var liveValue = dataKey != null && record ? readByFieldPath(record, dataKey) : value;
191
219
  var text = formatter ? formatter(liveValue, {
192
220
  columnProps: columnProps,
193
221
  fieldSchema: fieldSchema
@@ -224,7 +252,7 @@ var LazyReadOnlyText = exports.LazyReadOnlyText = function LazyReadOnlyText(para
224
252
  fieldSchema = params.fieldSchema;
225
253
  var dataKey = (_fieldSchema$name2 = fieldSchema === null || fieldSchema === void 0 ? void 0 : fieldSchema.name) !== null && _fieldSchema$name2 !== void 0 ? _fieldSchema$name2 : colDef === null || colDef === void 0 ? void 0 : colDef.field;
226
254
  return /*#__PURE__*/_react.default.createElement(_react2.Observer, null, function () {
227
- var liveValue = dataKey != null && record ? record[dataKey] : value;
255
+ var liveValue = dataKey != null && record ? readByFieldPath(record, dataKey) : value;
228
256
  var text = formatter ? formatter(liveValue, {
229
257
  columnProps: columnProps,
230
258
  fieldSchema: fieldSchema
@@ -317,7 +345,7 @@ var buildArrayTableColumns = exports.buildArrayTableColumns = function buildArra
317
345
  // ① 只读纯文本(永不可编辑):只读列 + 有格式化器 -> valueFormatter,不挂 Formily 树。
318
346
  // ② 可编辑懒挂载:可编辑列 + 有格式化器 + 无 reactions + 未强制 eager -> LazyAgField,
319
347
  // 存量格先出廉价文本、点击/导航才挂全树(挂了不卸)。
320
- // ③ 兜底全树:其余(无格式化器/带 reactions/forceAgField/只读但无格式化器) -> AgField。
348
+ // ③ 兜底全树:其余(无格式化器/带 reactions/forceAgField/复杂字段名/只读但无格式化器) -> AgField。
321
349
  var dataField = findDataFieldSchema(schema, name);
322
350
  var component = dataField === null || dataField === void 0 ? void 0 : dataField['x-component'];
323
351
  var formatter = (0, _readOnlyFormatters.getReadOnlyFormatter)(component);
@@ -335,12 +363,14 @@ var buildArrayTableColumns = exports.buildArrayTableColumns = function buildArra
335
363
  // 故按内层字段名补 valueGetter(仅在与 name 不一致时,保持 name===字段名 的现状)。@author nokecy
336
364
  var dataFieldName = dataField === null || dataField === void 0 ? void 0 : dataField.name;
337
365
  var valueGetter = dataFieldName && dataFieldName !== name ? function (params) {
338
- var _params$data;
339
- return params === null || params === void 0 || (_params$data = params.data) === null || _params$data === void 0 ? void 0 : _params$data[dataFieldName];
366
+ return readByFieldPath(params === null || params === void 0 ? void 0 : params.data, dataFieldName);
340
367
  } : undefined;
368
+ // 字段名是路径:`item.qty` 的值在 record.item.qty。快路径自己解析,只认点号分段;
369
+ // 解构(`{value:a,label:b}`)/数组下标等复杂语法解析不了,回退全树交给 Formily。@author nokecy
370
+ var canFastPath = !dataFieldName || isSimpleFieldPath(dataFieldName);
341
371
 
342
372
  // ① 只读纯文本
343
- if (readOnly && formatter) {
373
+ if (readOnly && formatter && canFastPath) {
344
374
  // 列级 readPretty 在「可编辑表」里是展示列(值可能被 setValuesIn 自动带出),静态 valueFormatter
345
375
  // 读 AG-Grid 缓存值不刷新 → 反应式只读渲染。整表 readPretty(明细/详情页,数据 setValues 整体加载、
346
376
  // 行引用整体替换、AG-Grid 自然刷新)仍走更廉价的静态 valueFormatter 快路径。@author nokecy
@@ -371,7 +401,7 @@ var buildArrayTableColumns = exports.buildArrayTableColumns = function buildArra
371
401
  }
372
402
 
373
403
  // ② 可编辑懒挂载(排除单击直控的 Switch/Checkbox:须 eager 出真控件)
374
- if (!readOnly && formatter && !hasReactions && !forceEager && !isInlineToggle) {
404
+ if (!readOnly && formatter && !hasReactions && !forceEager && !isInlineToggle && canFastPath) {
375
405
  return buf.concat(_objectSpread(_objectSpread(_objectSpread({}, base), valueGetter ? {
376
406
  valueGetter: valueGetter
377
407
  } : {}), {}, {
@@ -134,6 +134,34 @@ var AgField = function AgField(_ref) {
134
134
  return children;
135
135
  };
136
136
 
137
+ /**
138
+ * 快路径能否按这个字段名取到值。
139
+ *
140
+ * Formily 的字段名是「路径」不是「键」,支持点号嵌套(`item.qty`)、数组下标(`a[0]`)、
141
+ * 解构(`{value:code,label:name}`)等语法。快路径(只读文本/懒挂载)不挂 Formily 树,
142
+ * 取值得自己解析。这里只认「点号分段」这一种简单形态,其余一律判不合格 ->
143
+ * 调用方回退 AgField 全树(由 Formily 自己解析,正确优先于速度)。@author nokecy
144
+ */
145
+ var isSimpleFieldPath = function isSimpleFieldPath(name) {
146
+ return !!name && /^[^.{}[\]*]+(\.[^.{}[\]*]+)*$/.test(name);
147
+ };
148
+
149
+ /**
150
+ * 按 Formily 字段名从行数据取值。
151
+ *
152
+ * 曾经一律按扁平键取 record['item.qty'],而数据在 record.item.qty ->
153
+ * 嵌套字段名恒 undefined,单元格默认空白,点击挂上全树(按路径解析)才显出真值。
154
+ *
155
+ * 在 Observer 里逐层读可观察对象,依赖链完整,程序化改值(setValuesIn)照样刷新。@author nokecy
156
+ */
157
+ var readByFieldPath = function readByFieldPath(record, path) {
158
+ if (record == null) return undefined;
159
+ if (path.indexOf('.') < 0) return record[path];
160
+ return path.split('.').reduce(function (acc, key) {
161
+ return acc == null ? undefined : acc[key];
162
+ }, record);
163
+ };
164
+
137
165
  /**
138
166
  * 懒挂载单元格渲染器(可编辑列)。
139
167
  *
@@ -180,7 +208,7 @@ var LazyAgField = function LazyAgField(params) {
180
208
  // 免去调用方加 forceAgField 逃生阀。字段名缺失才回退 params.value。@author nokecy
181
209
  var dataKey = (_fieldSchema$name = fieldSchema === null || fieldSchema === void 0 ? void 0 : fieldSchema.name) !== null && _fieldSchema$name !== void 0 ? _fieldSchema$name : colDef === null || colDef === void 0 ? void 0 : colDef.field;
182
210
  return /*#__PURE__*/React.createElement(Observer, null, function () {
183
- var liveValue = dataKey != null && record ? record[dataKey] : value;
211
+ var liveValue = dataKey != null && record ? readByFieldPath(record, dataKey) : value;
184
212
  var text = formatter ? formatter(liveValue, {
185
213
  columnProps: columnProps,
186
214
  fieldSchema: fieldSchema
@@ -217,7 +245,7 @@ var LazyReadOnlyText = function LazyReadOnlyText(params) {
217
245
  fieldSchema = params.fieldSchema;
218
246
  var dataKey = (_fieldSchema$name2 = fieldSchema === null || fieldSchema === void 0 ? void 0 : fieldSchema.name) !== null && _fieldSchema$name2 !== void 0 ? _fieldSchema$name2 : colDef === null || colDef === void 0 ? void 0 : colDef.field;
219
247
  return /*#__PURE__*/React.createElement(Observer, null, function () {
220
- var liveValue = dataKey != null && record ? record[dataKey] : value;
248
+ var liveValue = dataKey != null && record ? readByFieldPath(record, dataKey) : value;
221
249
  var text = formatter ? formatter(liveValue, {
222
250
  columnProps: columnProps,
223
251
  fieldSchema: fieldSchema
@@ -310,7 +338,7 @@ var buildArrayTableColumns = function buildArrayTableColumns(dataSource, field,
310
338
  // ① 只读纯文本(永不可编辑):只读列 + 有格式化器 -> valueFormatter,不挂 Formily 树。
311
339
  // ② 可编辑懒挂载:可编辑列 + 有格式化器 + 无 reactions + 未强制 eager -> LazyAgField,
312
340
  // 存量格先出廉价文本、点击/导航才挂全树(挂了不卸)。
313
- // ③ 兜底全树:其余(无格式化器/带 reactions/forceAgField/只读但无格式化器) -> AgField。
341
+ // ③ 兜底全树:其余(无格式化器/带 reactions/forceAgField/复杂字段名/只读但无格式化器) -> AgField。
314
342
  var dataField = findDataFieldSchema(schema, name);
315
343
  var component = dataField === null || dataField === void 0 ? void 0 : dataField['x-component'];
316
344
  var formatter = getReadOnlyFormatter(component);
@@ -328,12 +356,14 @@ var buildArrayTableColumns = function buildArrayTableColumns(dataSource, field,
328
356
  // 故按内层字段名补 valueGetter(仅在与 name 不一致时,保持 name===字段名 的现状)。@author nokecy
329
357
  var dataFieldName = dataField === null || dataField === void 0 ? void 0 : dataField.name;
330
358
  var valueGetter = dataFieldName && dataFieldName !== name ? function (params) {
331
- var _params$data;
332
- return params === null || params === void 0 || (_params$data = params.data) === null || _params$data === void 0 ? void 0 : _params$data[dataFieldName];
359
+ return readByFieldPath(params === null || params === void 0 ? void 0 : params.data, dataFieldName);
333
360
  } : undefined;
361
+ // 字段名是路径:`item.qty` 的值在 record.item.qty。快路径自己解析,只认点号分段;
362
+ // 解构(`{value:a,label:b}`)/数组下标等复杂语法解析不了,回退全树交给 Formily。@author nokecy
363
+ var canFastPath = !dataFieldName || isSimpleFieldPath(dataFieldName);
334
364
 
335
365
  // ① 只读纯文本
336
- if (readOnly && formatter) {
366
+ if (readOnly && formatter && canFastPath) {
337
367
  // 列级 readPretty 在「可编辑表」里是展示列(值可能被 setValuesIn 自动带出),静态 valueFormatter
338
368
  // 读 AG-Grid 缓存值不刷新 → 反应式只读渲染。整表 readPretty(明细/详情页,数据 setValues 整体加载、
339
369
  // 行引用整体替换、AG-Grid 自然刷新)仍走更廉价的静态 valueFormatter 快路径。@author nokecy
@@ -364,7 +394,7 @@ var buildArrayTableColumns = function buildArrayTableColumns(dataSource, field,
364
394
  }
365
395
 
366
396
  // ② 可编辑懒挂载(排除单击直控的 Switch/Checkbox:须 eager 出真控件)
367
- if (!readOnly && formatter && !hasReactions && !forceEager && !isInlineToggle) {
397
+ if (!readOnly && formatter && !hasReactions && !forceEager && !isInlineToggle && canFastPath) {
368
398
  return buf.concat(_objectSpread(_objectSpread(_objectSpread({}, base), valueGetter ? {
369
399
  valueGetter: valueGetter
370
400
  } : {}), {}, {