@nokecy/qc-ui 1.1.65 → 1.1.67

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.
@@ -12,6 +12,7 @@ var _antd = require("antd");
12
12
  var _classnames = _interopRequireDefault(require("classnames"));
13
13
  var _react2 = _interopRequireWildcard(require("react"));
14
14
  var _queryForm = _interopRequireDefault(require("./queryForm"));
15
+ var _schemaKey = require("./schemaKey");
15
16
  var _boolSelect = _interopRequireDefault(require("../_utils/boolSelect"));
16
17
  require("./index.less");
17
18
  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); }
@@ -139,11 +140,15 @@ var FormRender = function FormRender(props) {
139
140
  }
140
141
  };
141
142
  var columns = colDefs === null || colDefs === void 0 ? void 0 : colDefs.map(function (colDef) {
143
+ var _searchComponentProps;
142
144
  var state = columnStates.find(function (x) {
143
145
  return x.colId == colDef.field;
144
146
  });
145
147
  var columnDefs = gridApi === null || gridApi === void 0 ? void 0 : gridApi.getColumnDef(colDef.field);
146
- return _objectSpread(_objectSpread(_objectSpread({}, colDef), columnDefs), state);
148
+ // 查询组件属性(下拉选项)以本次传入的列为准:AG Grid 在本副作用之后才应用新 columnDefs,此刻取到的还是上一版。@author nokecy
149
+ return _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, colDef), columnDefs), state), {}, {
150
+ searchComponentProps: (_searchComponentProps = colDef.searchComponentProps) !== null && _searchComponentProps !== void 0 ? _searchComponentProps : columnDefs === null || columnDefs === void 0 ? void 0 : columnDefs.searchComponentProps
151
+ });
147
152
  });
148
153
  columns = columns ? (_columns = columns) === null || _columns === void 0 ? void 0 : _columns.filter(function (i) {
149
154
  return (i === null || i === void 0 ? void 0 : i.visible) != false && !(i !== null && i !== void 0 && i.hide) && !(i !== null && i !== void 0 && i.hideInSearch) || (i === null || i === void 0 ? void 0 : i.hideInTable);
@@ -203,8 +208,19 @@ var FormRender = function FormRender(props) {
203
208
  // 【新增】用于追踪是否已完成首次初始化
204
209
  var initializedRef = (0, _react2.useRef)(false);
205
210
  (0, _react2.useEffect)(function () {
211
+ var _new_schema$propertie, _new_schema$propertie2;
206
212
  var new_schema = getSchema(onReset);
207
213
  setSchema(new_schema);
214
+ // Formily 只在字段首次创建时读取 schema:已有查询项要把新标题、组件属性(如下拉选项)写回字段。@author nokecy
215
+ Object.entries((_new_schema$propertie = (_new_schema$propertie2 = new_schema.properties) === null || _new_schema$propertie2 === void 0 || (_new_schema$propertie2 = _new_schema$propertie2.queryForm) === null || _new_schema$propertie2 === void 0 ? void 0 : _new_schema$propertie2.properties) !== null && _new_schema$propertie !== void 0 ? _new_schema$propertie : {}).forEach(function (_ref) {
216
+ var _ref2 = _slicedToArray(_ref, 2),
217
+ name = _ref2[0],
218
+ fieldSchema = _ref2[1];
219
+ form.query(name).take(function (field) {
220
+ field.title = fieldSchema.title;
221
+ field.setComponentProps(fieldSchema['x-component-props']);
222
+ });
223
+ });
208
224
 
209
225
  // 【修复】在 schema 设置完成后调用 onInit
210
226
  // 使用 setTimeout 确保 Formily 有时间处理 schema 并应用默认值
@@ -217,11 +233,7 @@ var FormRender = function FormRender(props) {
217
233
  }, 0);
218
234
  });
219
235
  }
220
- }, [columnStates === null || columnStates === void 0 ? void 0 : columnStates.map(function (c) {
221
- return c.colId;
222
- }).join('|'), colDefs === null || colDefs === void 0 ? void 0 : colDefs.map(function (c) {
223
- return "".concat(c.field, "|").concat(c.headerName);
224
- }).join('|')]);
236
+ }, [(0, _schemaKey.queryFormSchemaKey)(columnStates, colDefs)]);
225
237
  return /*#__PURE__*/_react2.default.createElement("div", {
226
238
  className: (0, _classnames.default)(className, "ag-grid-table-search ag-grid-table-search-query-filter"),
227
239
  style: {
@@ -0,0 +1,20 @@
1
+ type ColumnStateLike = {
2
+ colId?: string | null;
3
+ };
4
+ type QueryColumnLike = {
5
+ field?: string;
6
+ headerName?: string;
7
+ searchComponentProps?: {
8
+ options?: readonly {
9
+ value?: unknown;
10
+ label?: unknown;
11
+ }[];
12
+ };
13
+ };
14
+ /**
15
+ * 查询区 schema 的重建键:列(id、字段、标题)或下拉选项变了才重建。
16
+ * 下拉选项常在首帧之后才到(如从基础资料接口取名称),只看列与标题时选项停在首帧。
17
+ * @author nokecy
18
+ */
19
+ export declare const queryFormSchemaKey: (columnStates?: readonly ColumnStateLike[] | null, colDefs?: readonly QueryColumnLike[] | null) => string;
20
+ export {};
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.queryFormSchemaKey = void 0;
7
+ var optionsSignature = function optionsSignature(options) {
8
+ return Array.isArray(options) ? options.map(function (option) {
9
+ return "".concat(String(option === null || option === void 0 ? void 0 : option.value), "=").concat(String(option === null || option === void 0 ? void 0 : option.label));
10
+ }).join(',') : '';
11
+ };
12
+
13
+ /**
14
+ * 查询区 schema 的重建键:列(id、字段、标题)或下拉选项变了才重建。
15
+ * 下拉选项常在首帧之后才到(如从基础资料接口取名称),只看列与标题时选项停在首帧。
16
+ * @author nokecy
17
+ */
18
+ var queryFormSchemaKey = exports.queryFormSchemaKey = function queryFormSchemaKey(columnStates, colDefs) {
19
+ return [columnStates === null || columnStates === void 0 ? void 0 : columnStates.map(function (column) {
20
+ return column.colId;
21
+ }).join('|'), colDefs === null || colDefs === void 0 ? void 0 : colDefs.map(function (column) {
22
+ var _column$searchCompone;
23
+ return "".concat(column.field, "|").concat(column.headerName, "|").concat(optionsSignature((_column$searchCompone = column.searchComponentProps) === null || _column$searchCompone === void 0 ? void 0 : _column$searchCompone.options));
24
+ }).join('|')].join('#');
25
+ };
@@ -18,6 +18,7 @@ import { Button, theme } from 'antd';
18
18
  import classNames from 'classnames';
19
19
  import React, { useEffect, useMemo, useRef, useState } from 'react';
20
20
  import QueryForm from "./queryForm";
21
+ import { queryFormSchemaKey } from "./schemaKey";
21
22
  import BoolSelect from "../_utils/boolSelect";
22
23
  import "./index.less";
23
24
  var FormRender = function FormRender(props) {
@@ -131,11 +132,15 @@ var FormRender = function FormRender(props) {
131
132
  }
132
133
  };
133
134
  var columns = colDefs === null || colDefs === void 0 ? void 0 : colDefs.map(function (colDef) {
135
+ var _searchComponentProps;
134
136
  var state = columnStates.find(function (x) {
135
137
  return x.colId == colDef.field;
136
138
  });
137
139
  var columnDefs = gridApi === null || gridApi === void 0 ? void 0 : gridApi.getColumnDef(colDef.field);
138
- return _objectSpread(_objectSpread(_objectSpread({}, colDef), columnDefs), state);
140
+ // 查询组件属性(下拉选项)以本次传入的列为准:AG Grid 在本副作用之后才应用新 columnDefs,此刻取到的还是上一版。@author nokecy
141
+ return _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, colDef), columnDefs), state), {}, {
142
+ searchComponentProps: (_searchComponentProps = colDef.searchComponentProps) !== null && _searchComponentProps !== void 0 ? _searchComponentProps : columnDefs === null || columnDefs === void 0 ? void 0 : columnDefs.searchComponentProps
143
+ });
139
144
  });
140
145
  columns = columns ? (_columns = columns) === null || _columns === void 0 ? void 0 : _columns.filter(function (i) {
141
146
  return (i === null || i === void 0 ? void 0 : i.visible) != false && !(i !== null && i !== void 0 && i.hide) && !(i !== null && i !== void 0 && i.hideInSearch) || (i === null || i === void 0 ? void 0 : i.hideInTable);
@@ -195,8 +200,19 @@ var FormRender = function FormRender(props) {
195
200
  // 【新增】用于追踪是否已完成首次初始化
196
201
  var initializedRef = useRef(false);
197
202
  useEffect(function () {
203
+ var _new_schema$propertie, _new_schema$propertie2;
198
204
  var new_schema = getSchema(onReset);
199
205
  setSchema(new_schema);
206
+ // Formily 只在字段首次创建时读取 schema:已有查询项要把新标题、组件属性(如下拉选项)写回字段。@author nokecy
207
+ Object.entries((_new_schema$propertie = (_new_schema$propertie2 = new_schema.properties) === null || _new_schema$propertie2 === void 0 || (_new_schema$propertie2 = _new_schema$propertie2.queryForm) === null || _new_schema$propertie2 === void 0 ? void 0 : _new_schema$propertie2.properties) !== null && _new_schema$propertie !== void 0 ? _new_schema$propertie : {}).forEach(function (_ref) {
208
+ var _ref2 = _slicedToArray(_ref, 2),
209
+ name = _ref2[0],
210
+ fieldSchema = _ref2[1];
211
+ form.query(name).take(function (field) {
212
+ field.title = fieldSchema.title;
213
+ field.setComponentProps(fieldSchema['x-component-props']);
214
+ });
215
+ });
200
216
 
201
217
  // 【修复】在 schema 设置完成后调用 onInit
202
218
  // 使用 setTimeout 确保 Formily 有时间处理 schema 并应用默认值
@@ -209,11 +225,7 @@ var FormRender = function FormRender(props) {
209
225
  }, 0);
210
226
  });
211
227
  }
212
- }, [columnStates === null || columnStates === void 0 ? void 0 : columnStates.map(function (c) {
213
- return c.colId;
214
- }).join('|'), colDefs === null || colDefs === void 0 ? void 0 : colDefs.map(function (c) {
215
- return "".concat(c.field, "|").concat(c.headerName);
216
- }).join('|')]);
228
+ }, [queryFormSchemaKey(columnStates, colDefs)]);
217
229
  return /*#__PURE__*/React.createElement("div", {
218
230
  className: classNames(className, "ag-grid-table-search ag-grid-table-search-query-filter"),
219
231
  style: {
@@ -0,0 +1,20 @@
1
+ type ColumnStateLike = {
2
+ colId?: string | null;
3
+ };
4
+ type QueryColumnLike = {
5
+ field?: string;
6
+ headerName?: string;
7
+ searchComponentProps?: {
8
+ options?: readonly {
9
+ value?: unknown;
10
+ label?: unknown;
11
+ }[];
12
+ };
13
+ };
14
+ /**
15
+ * 查询区 schema 的重建键:列(id、字段、标题)或下拉选项变了才重建。
16
+ * 下拉选项常在首帧之后才到(如从基础资料接口取名称),只看列与标题时选项停在首帧。
17
+ * @author nokecy
18
+ */
19
+ export declare const queryFormSchemaKey: (columnStates?: readonly ColumnStateLike[] | null, colDefs?: readonly QueryColumnLike[] | null) => string;
20
+ export {};
@@ -0,0 +1,19 @@
1
+ var optionsSignature = function optionsSignature(options) {
2
+ return Array.isArray(options) ? options.map(function (option) {
3
+ return "".concat(String(option === null || option === void 0 ? void 0 : option.value), "=").concat(String(option === null || option === void 0 ? void 0 : option.label));
4
+ }).join(',') : '';
5
+ };
6
+
7
+ /**
8
+ * 查询区 schema 的重建键:列(id、字段、标题)或下拉选项变了才重建。
9
+ * 下拉选项常在首帧之后才到(如从基础资料接口取名称),只看列与标题时选项停在首帧。
10
+ * @author nokecy
11
+ */
12
+ export var queryFormSchemaKey = function queryFormSchemaKey(columnStates, colDefs) {
13
+ return [columnStates === null || columnStates === void 0 ? void 0 : columnStates.map(function (column) {
14
+ return column.colId;
15
+ }).join('|'), colDefs === null || colDefs === void 0 ? void 0 : colDefs.map(function (column) {
16
+ var _column$searchCompone;
17
+ return "".concat(column.field, "|").concat(column.headerName, "|").concat(optionsSignature((_column$searchCompone = column.searchComponentProps) === null || _column$searchCompone === void 0 ? void 0 : _column$searchCompone.options));
18
+ }).join('|')].join('#');
19
+ };