@nokecy/qc-ui 0.1.6 → 0.1.7

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.
@@ -31,6 +31,8 @@ var _icons = require("@ant-design/icons");
31
31
 
32
32
  var _utils = require("./utils");
33
33
 
34
+ var _setting = _interopRequireDefault(require("./setting"));
35
+
34
36
  var _excluded = ["style", "params", "request", "dataSource", "gridRef", "headerTitle", "toolBarRender", "search", "hideRedo", "onGridReady", "gridKey", "gridColumnState", "children"];
35
37
 
36
38
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -99,8 +101,8 @@ function AgGridPlus(props) {
99
101
 
100
102
  var _useState5 = (0, _react.useState)(),
101
103
  _useState6 = _slicedToArray(_useState5, 2),
102
- columnDefs = _useState6[0],
103
- setColumnDefs = _useState6[1];
104
+ columnState = _useState6[0],
105
+ setColumnState = _useState6[1];
104
106
 
105
107
  var _useState7 = (0, _react.useState)([]),
106
108
  _useState8 = _slicedToArray(_useState7, 2),
@@ -165,12 +167,14 @@ function AgGridPlus(props) {
165
167
  setRowData(dataSource || rowData);
166
168
  }, [dataSource, rowData]);
167
169
  var onGridReady = (0, _react.useCallback)(function (params) {
170
+ var _columnsRef$current;
171
+
168
172
  apiRef.current = params.api;
169
173
  columnsRef.current = params.columnApi;
170
174
  onReady && onReady(params); ///@ts-ignore
171
175
 
172
176
  dataSource && setRowData(dataSource);
173
- setColumnDefs(columnsRef.current.getColumns());
177
+ setColumnState((_columnsRef$current = columnsRef.current) === null || _columnsRef$current === void 0 ? void 0 : _columnsRef$current.getColumnState());
174
178
  sortChanged(params.columnApi);
175
179
  setReady(true);
176
180
  }, [dataSource]);
@@ -214,6 +218,8 @@ function AgGridPlus(props) {
214
218
  request && onRequest(queryFilter);
215
219
  };
216
220
 
221
+ var onSaveColumnState = function onSaveColumnState(columnState) {};
222
+
217
223
  (0, _react.useEffect)(function () {
218
224
  gridRef.current = {
219
225
  onRefresh: onRefresh
@@ -231,7 +237,7 @@ function AgGridPlus(props) {
231
237
  height: "100%"
232
238
  }
233
239
  }, search == false ? null : /*#__PURE__*/_react.default.createElement(_queryForm.default, {
234
- columns: columnDefs,
240
+ columnStates: columnState || [],
235
241
  gridApi: apiRef.current,
236
242
  onQuery: function onQuery(formValues) {
237
243
  setQueryFilter(_objectSpread({}, formValues));
@@ -265,9 +271,10 @@ function AgGridPlus(props) {
265
271
  settings: [/*#__PURE__*/_react.default.createElement(_settingItem.default, {
266
272
  onClick: onRefresh,
267
273
  icon: /*#__PURE__*/_react.default.createElement(_icons.RedoOutlined, null)
268
- }), /*#__PURE__*/_react.default.createElement(_settingItem.default, {
269
- onClick: onRefresh,
270
- icon: /*#__PURE__*/_react.default.createElement(_icons.SettingOutlined, null)
274
+ }), /*#__PURE__*/_react.default.createElement(_setting.default, {
275
+ gridApi: apiRef.current,
276
+ columnApi: columnsRef.current,
277
+ onSaveColumnState: onSaveColumnState
271
278
  })]
272
279
  }), /*#__PURE__*/_react.default.createElement(_agGridReact.AgGridReact, _extends({
273
280
  className: "ag-theme-alpine"
@@ -284,6 +291,28 @@ function AgGridPlus(props) {
284
291
  props.onSelectionChanged && props.onSelectionChanged(e);
285
292
  setSelectRows(e.api.getSelectedRows());
286
293
  },
294
+ onDragStopped: function onDragStopped(e) {
295
+ if (columnsRef.current) {
296
+ var _columnsRef$current2;
297
+
298
+ setColumnState((_columnsRef$current2 = columnsRef.current) === null || _columnsRef$current2 === void 0 ? void 0 : _columnsRef$current2.getColumnState());
299
+ }
300
+ },
301
+ onColumnResized: function onColumnResized(e) {
302
+ if (columnsRef.current) {
303
+ var _columnsRef$current3, _columnsRef$current4;
304
+
305
+ console.log((_columnsRef$current3 = columnsRef.current) === null || _columnsRef$current3 === void 0 ? void 0 : _columnsRef$current3.getColumnState());
306
+ setColumnState((_columnsRef$current4 = columnsRef.current) === null || _columnsRef$current4 === void 0 ? void 0 : _columnsRef$current4.getColumnState());
307
+ }
308
+ },
309
+ onColumnMoved: function onColumnMoved() {
310
+ if (columnsRef.current) {
311
+ var _columnsRef$current5;
312
+
313
+ setColumnState((_columnsRef$current5 = columnsRef.current) === null || _columnsRef$current5 === void 0 ? void 0 : _columnsRef$current5.getColumnState());
314
+ }
315
+ },
287
316
  columnTypes: {
288
317
  bool: {
289
318
  cellRenderer: function cellRenderer(params) {
@@ -1,10 +1,10 @@
1
1
  /// <reference types="react" />
2
- import { GridApi } from 'ag-grid-community';
2
+ import { ColumnState, GridApi } from 'ag-grid-community';
3
3
  import './index.less';
4
4
  declare const FormRender: (props: {
5
5
  className?: any;
6
6
  gridApi?: GridApi<any> | undefined;
7
- columns: any[];
7
+ columnStates: ColumnState[];
8
8
  onQuery: (formValue: any) => void;
9
9
  }) => JSX.Element;
10
10
  export default FormRender;
@@ -56,7 +56,7 @@ function _asyncToGenerator(fn) { return function () { var self = this, args = ar
56
56
  var FormRender = function FormRender(props) {
57
57
  var className = props.className,
58
58
  gridApi = props.gridApi,
59
- columns = props.columns,
59
+ columnStates = props.columnStates,
60
60
  onQuery = props.onQuery;
61
61
  var form = (0, _react2.useMemo)(function () {
62
62
  return (0, _core.createForm)();
@@ -119,7 +119,7 @@ var FormRender = function FormRender(props) {
119
119
  properties: {}
120
120
  };
121
121
 
122
- if (!columns) {
122
+ if (!columnStates) {
123
123
  return rootSchema;
124
124
  }
125
125
 
@@ -131,27 +131,18 @@ var FormRender = function FormRender(props) {
131
131
  },
132
132
  properties: {}
133
133
  };
134
- columns.forEach(function (i, index) {
135
- i.searchSort = i.getColDef().searchSort === 0 ? i.getColDef().searchSort : i.getColDef().searchSort || index;
136
- }); //ag-grid 列 添加属性 searchSort,冒泡排序表单
137
-
138
- for (var i = 0; i < columns.length - 1; i++) {
139
- for (var j = 0; j < columns.length - 1 - i; j++) {
140
- if (columns[j].searchSort > columns[j + 1].searchSort) {
141
- var temp = columns[j];
142
- columns[j] = columns[j + 1];
143
- columns[j + 1] = temp;
144
- }
145
- }
146
- }
147
-
148
- var arr = columns.filter(function (i) {
149
- return (i === null || i === void 0 ? void 0 : i.visible) != false && !i.getColDef().hideInSearch || i.getColDef().hideInTable;
134
+ var columns = columnStates.filter(function (x) {
135
+ return !x.hide;
136
+ }).map(function (columnState) {
137
+ return gridApi === null || gridApi === void 0 ? void 0 : gridApi.getColumnDef(columnState.colId);
138
+ });
139
+ columns = columns.filter(function (i) {
140
+ return (i === null || i === void 0 ? void 0 : i.visible) != false && !i.hideInSearch || i.hideInTable;
150
141
  });
151
- arr.map(function (col) {
142
+ columns.map(function (col) {
152
143
  var _colDef$queryField;
153
144
 
154
- var colDef = col.getColDef();
145
+ var colDef = col;
155
146
  var name = (_colDef$queryField = colDef.queryField) !== null && _colDef$queryField !== void 0 ? _colDef$queryField : colDef.field;
156
147
  var headerName = colDef.headerName; //表单自定义组件
157
148
 
@@ -182,7 +173,7 @@ var FormRender = function FormRender(props) {
182
173
 
183
174
  rootSchema.properties["grid"] = gridSchema;
184
175
 
185
- if (!arr.length) {
176
+ if (!columns.length) {
186
177
  ///@ts-ignore
187
178
  delete rootSchema.properties["grid"];
188
179
  }
@@ -193,7 +184,7 @@ var FormRender = function FormRender(props) {
193
184
  (0, _react2.useEffect)(function () {
194
185
  var new_schema = getSchema();
195
186
  setSchema(new_schema);
196
- }, [columns]);
187
+ }, [JSON.stringify(columnStates)]);
197
188
  return /*#__PURE__*/_react2.default.createElement("div", {
198
189
  className: (0, _classnames.default)(className, "ag-grid-table-search ag-grid-table-search-query-filter")
199
190
  }, /*#__PURE__*/_react2.default.createElement(_antd.Form, {
@@ -0,0 +1,8 @@
1
+ /// <reference types="react" />
2
+ import { ColumnApi, GridApi } from 'ag-grid-community';
3
+ declare const Setting: (props: {
4
+ gridApi?: GridApi<any> | undefined;
5
+ columnApi: ColumnApi;
6
+ onSaveColumnState: (state: any) => void;
7
+ }) => JSX.Element;
8
+ export default Setting;
@@ -0,0 +1,214 @@
1
+ "use strict";
2
+
3
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.default = void 0;
9
+
10
+ var _uniqueId2 = _interopRequireDefault(require("lodash/uniqueId"));
11
+
12
+ var _antd = require("@formily/antd");
13
+
14
+ var _react = require("@formily/react");
15
+
16
+ var _core = require("@formily/core");
17
+
18
+ var _react2 = _interopRequireWildcard(require("react"));
19
+
20
+ var _icons = require("@ant-design/icons");
21
+
22
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
23
+
24
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
25
+
26
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
27
+
28
+ 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 exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return generator._invoke = function (innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; }(innerFn, self, context), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; this._invoke = function (method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); }; } function maybeInvokeDelegate(delegate, context) { var method = delegate.iterator[context.method]; if (undefined === method) { if (context.delegate = null, "throw" === context.method) { if (delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method)) return ContinueSentinel; context.method = "throw", context.arg = new TypeError("The iterator does not provide a 'throw' method"); } return ContinueSentinel; } var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) { if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; } return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, define(Gp, "constructor", GeneratorFunctionPrototype), define(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (object) { var keys = []; for (var key in object) { keys.push(key); } return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) { "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); } }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, catch: function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
29
+
30
+ 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); } }
31
+
32
+ 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); }); }; }
33
+
34
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
35
+
36
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
37
+
38
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
39
+
40
+ var Setting = function Setting(props) {
41
+ var gridApi = props.gridApi,
42
+ columnApi = props.columnApi,
43
+ onSaveColumnState = props.onSaveColumnState;
44
+ var SchemaField = (0, _react2.useMemo)(function () {
45
+ return (0, _react.createSchemaField)({
46
+ components: {
47
+ FormTab: _antd.FormTab,
48
+ FormItem: _antd.FormItem,
49
+ FormGrid: _antd.FormGrid,
50
+ Space: _antd.Space,
51
+ Input: _antd.Input,
52
+ Select: _antd.Select,
53
+ ArrayTable: _antd.ArrayTable,
54
+ NumberPicker: _antd.NumberPicker,
55
+ Switch: _antd.Switch
56
+ }
57
+ });
58
+ }, []);
59
+ var formProps = {
60
+ effects: function effects() {
61
+ (0, _core.onFormInit)(function (form) {
62
+ form.setInitialValuesIn('items', getColumnData());
63
+ });
64
+ }
65
+ };
66
+
67
+ var getColumnData = function getColumnData() {
68
+ var columnStates = columnApi.getColumnState();
69
+ var columnRowData = [];
70
+ var columns = columnStates.map(function (columnState) {
71
+ var colDef = gridApi === null || gridApi === void 0 ? void 0 : gridApi.getColumnDef(columnState.colId);
72
+ columnRowData.push(_objectSpread({
73
+ field: colDef.field,
74
+ headerName: colDef.headerName,
75
+ width: columnState.width,
76
+ hide: columnState.hide
77
+ }, columnState));
78
+ });
79
+ return columnRowData;
80
+ };
81
+
82
+ var portalId = "workProcedure".concat((0, _uniqueId2.default)());
83
+ return /*#__PURE__*/_react2.default.createElement(_antd.FormDialog.Portal, {
84
+ id: portalId
85
+ }, /*#__PURE__*/_react2.default.createElement("div", {
86
+ style: {
87
+ margin: "0 4px",
88
+ color: "#000",
89
+ fontSize: 16,
90
+ cursor: "pointer"
91
+ },
92
+ onClick: /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
93
+ var formDialog;
94
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
95
+ while (1) {
96
+ switch (_context.prev = _context.next) {
97
+ case 0:
98
+ formDialog = (0, _antd.FormDialog)({
99
+ title: "个性化设置",
100
+ width: 960
101
+ }, portalId, function () {
102
+ return /*#__PURE__*/_react2.default.createElement(_antd.FormLayout, null, /*#__PURE__*/_react2.default.createElement(SchemaField, null, /*#__PURE__*/_react2.default.createElement(SchemaField.Void, {
103
+ "x-component": "FormGrid",
104
+ "x-component-props": {
105
+ maxColumns: [1, 3],
106
+ strictAutoFit: true
107
+ }
108
+ }, /*#__PURE__*/_react2.default.createElement(SchemaField.Array, {
109
+ name: "items",
110
+ title: "",
111
+ "x-component": "ArrayTable",
112
+ "x-validator": [{
113
+ message: ""
114
+ }],
115
+ "x-decorator": "FormItem",
116
+ "x-decorator-props": {
117
+ gridSpan: 3
118
+ }
119
+ }, /*#__PURE__*/_react2.default.createElement(SchemaField.Object, null, /*#__PURE__*/_react2.default.createElement(SchemaField.Void, {
120
+ "x-component": "ArrayTable.Column",
121
+ "x-component-props": {
122
+ width: 150,
123
+ title: "字段名"
124
+ }
125
+ }, /*#__PURE__*/_react2.default.createElement(SchemaField.String, {
126
+ name: "field",
127
+ "x-decorator": "FormItem",
128
+ "x-component": "Input",
129
+ "x-read-pretty": true
130
+ })), /*#__PURE__*/_react2.default.createElement(SchemaField.Void, {
131
+ "x-component": "ArrayTable.Column",
132
+ "x-component-props": {
133
+ width: 150,
134
+ title: "列名"
135
+ }
136
+ }, /*#__PURE__*/_react2.default.createElement(SchemaField.String, {
137
+ name: "headerName",
138
+ "x-decorator": "FormItem",
139
+ "x-component": "Input",
140
+ "x-read-pretty": true
141
+ })), /*#__PURE__*/_react2.default.createElement(SchemaField.Void, {
142
+ "x-component": "ArrayTable.Column",
143
+ "x-component-props": {
144
+ width: 150,
145
+ title: "宽度"
146
+ }
147
+ }, /*#__PURE__*/_react2.default.createElement(SchemaField.String, {
148
+ name: "width",
149
+ "x-decorator": "FormItem",
150
+ "x-component": "NumberPicker"
151
+ })), /*#__PURE__*/_react2.default.createElement(SchemaField.Void, {
152
+ "x-component": "ArrayTable.Column",
153
+ "x-component-props": {
154
+ width: 150,
155
+ title: "占满"
156
+ }
157
+ }, /*#__PURE__*/_react2.default.createElement(SchemaField.String, {
158
+ name: "flex",
159
+ "x-decorator": "FormItem",
160
+ "x-component": "Switch"
161
+ })), /*#__PURE__*/_react2.default.createElement(SchemaField.Void, {
162
+ "x-component": "ArrayTable.Column",
163
+ "x-component-props": {
164
+ width: 150,
165
+ title: '固定位置'
166
+ }
167
+ }, /*#__PURE__*/_react2.default.createElement(SchemaField.String, {
168
+ name: "pinned",
169
+ "x-decorator": "FormItem",
170
+ "x-component": "Select",
171
+ enum: [{
172
+ value: "left",
173
+ label: "左固定"
174
+ }, {
175
+ value: "right",
176
+ label: "右固定"
177
+ }, {
178
+ value: undefined,
179
+ label: "不固定"
180
+ }]
181
+ })), /*#__PURE__*/_react2.default.createElement(SchemaField.Void, {
182
+ "x-component": "ArrayTable.Column",
183
+ "x-component-props": {
184
+ width: 150,
185
+ title: '隐藏'
186
+ }
187
+ }, /*#__PURE__*/_react2.default.createElement(SchemaField.String, {
188
+ name: "hide",
189
+ "x-decorator": "FormItem",
190
+ "x-component": "Switch"
191
+ })))))));
192
+ });
193
+ formDialog.forConfirm(function (payload, next) {
194
+ var values = payload.values;
195
+ var falg = columnApi.applyColumnState({
196
+ state: values.items,
197
+ applyOrder: true
198
+ });
199
+ onSaveColumnState && onSaveColumnState(values.items);
200
+ next(payload);
201
+ }).open(formProps);
202
+
203
+ case 2:
204
+ case "end":
205
+ return _context.stop();
206
+ }
207
+ }
208
+ }, _callee);
209
+ }))
210
+ }, /*#__PURE__*/_react2.default.createElement(_icons.SettingOutlined, null)));
211
+ };
212
+
213
+ var _default = Setting;
214
+ exports.default = _default;
@@ -34,8 +34,9 @@ import { AgGridColumn } from "./interface";
34
34
  import FormRender from "./queryForm";
35
35
  import ToolBar from "./toolBar";
36
36
  import SettingItem from "./settingItem";
37
- import { RedoOutlined, SettingOutlined } from '@ant-design/icons';
37
+ import { RedoOutlined } from '@ant-design/icons';
38
38
  import { convertFilterModel, dateTimeValueFormatter, dateValueFormatter, flatten, toTree } from "./utils";
39
+ import Setting from "./setting";
39
40
 
40
41
  var getSort = function getSort(columnState) {
41
42
  return columnState ? "".concat(columnState.colId, " ").concat(columnState.sort) : "";
@@ -73,8 +74,8 @@ function AgGridPlus(props) {
73
74
 
74
75
  var _useState5 = useState(),
75
76
  _useState6 = _slicedToArray(_useState5, 2),
76
- columnDefs = _useState6[0],
77
- setColumnDefs = _useState6[1];
77
+ columnState = _useState6[0],
78
+ setColumnState = _useState6[1];
78
79
 
79
80
  var _useState7 = useState([]),
80
81
  _useState8 = _slicedToArray(_useState7, 2),
@@ -139,12 +140,14 @@ function AgGridPlus(props) {
139
140
  setRowData(dataSource || rowData);
140
141
  }, [dataSource, rowData]);
141
142
  var onGridReady = useCallback(function (params) {
143
+ var _columnsRef$current;
144
+
142
145
  apiRef.current = params.api;
143
146
  columnsRef.current = params.columnApi;
144
147
  onReady && onReady(params); ///@ts-ignore
145
148
 
146
149
  dataSource && setRowData(dataSource);
147
- setColumnDefs(columnsRef.current.getColumns());
150
+ setColumnState((_columnsRef$current = columnsRef.current) === null || _columnsRef$current === void 0 ? void 0 : _columnsRef$current.getColumnState());
148
151
  sortChanged(params.columnApi);
149
152
  setReady(true);
150
153
  }, [dataSource]);
@@ -188,6 +191,8 @@ function AgGridPlus(props) {
188
191
  request && onRequest(queryFilter);
189
192
  };
190
193
 
194
+ var onSaveColumnState = function onSaveColumnState(columnState) {};
195
+
191
196
  useEffect(function () {
192
197
  gridRef.current = {
193
198
  onRefresh: onRefresh
@@ -205,7 +210,7 @@ function AgGridPlus(props) {
205
210
  height: "100%"
206
211
  }
207
212
  }, search == false ? null : /*#__PURE__*/React.createElement(FormRender, {
208
- columns: columnDefs,
213
+ columnStates: columnState || [],
209
214
  gridApi: apiRef.current,
210
215
  onQuery: function onQuery(formValues) {
211
216
  setQueryFilter(_objectSpread({}, formValues));
@@ -239,9 +244,10 @@ function AgGridPlus(props) {
239
244
  settings: [/*#__PURE__*/React.createElement(SettingItem, {
240
245
  onClick: onRefresh,
241
246
  icon: /*#__PURE__*/React.createElement(RedoOutlined, null)
242
- }), /*#__PURE__*/React.createElement(SettingItem, {
243
- onClick: onRefresh,
244
- icon: /*#__PURE__*/React.createElement(SettingOutlined, null)
247
+ }), /*#__PURE__*/React.createElement(Setting, {
248
+ gridApi: apiRef.current,
249
+ columnApi: columnsRef.current,
250
+ onSaveColumnState: onSaveColumnState
245
251
  })]
246
252
  }), /*#__PURE__*/React.createElement(AgGridReact, _extends({
247
253
  className: "ag-theme-alpine"
@@ -258,6 +264,28 @@ function AgGridPlus(props) {
258
264
  props.onSelectionChanged && props.onSelectionChanged(e);
259
265
  setSelectRows(e.api.getSelectedRows());
260
266
  },
267
+ onDragStopped: function onDragStopped(e) {
268
+ if (columnsRef.current) {
269
+ var _columnsRef$current2;
270
+
271
+ setColumnState((_columnsRef$current2 = columnsRef.current) === null || _columnsRef$current2 === void 0 ? void 0 : _columnsRef$current2.getColumnState());
272
+ }
273
+ },
274
+ onColumnResized: function onColumnResized(e) {
275
+ if (columnsRef.current) {
276
+ var _columnsRef$current3, _columnsRef$current4;
277
+
278
+ console.log((_columnsRef$current3 = columnsRef.current) === null || _columnsRef$current3 === void 0 ? void 0 : _columnsRef$current3.getColumnState());
279
+ setColumnState((_columnsRef$current4 = columnsRef.current) === null || _columnsRef$current4 === void 0 ? void 0 : _columnsRef$current4.getColumnState());
280
+ }
281
+ },
282
+ onColumnMoved: function onColumnMoved() {
283
+ if (columnsRef.current) {
284
+ var _columnsRef$current5;
285
+
286
+ setColumnState((_columnsRef$current5 = columnsRef.current) === null || _columnsRef$current5 === void 0 ? void 0 : _columnsRef$current5.getColumnState());
287
+ }
288
+ },
261
289
  columnTypes: {
262
290
  bool: {
263
291
  cellRenderer: function cellRenderer(params) {
@@ -1,10 +1,10 @@
1
1
  /// <reference types="react" />
2
- import { GridApi } from 'ag-grid-community';
2
+ import { ColumnState, GridApi } from 'ag-grid-community';
3
3
  import './index.less';
4
4
  declare const FormRender: (props: {
5
5
  className?: any;
6
6
  gridApi?: GridApi<any> | undefined;
7
- columns: any[];
7
+ columnStates: ColumnState[];
8
8
  onQuery: (formValue: any) => void;
9
9
  }) => JSX.Element;
10
10
  export default FormRender;
@@ -36,7 +36,7 @@ import "./index.less";
36
36
  var FormRender = function FormRender(props) {
37
37
  var className = props.className,
38
38
  gridApi = props.gridApi,
39
- columns = props.columns,
39
+ columnStates = props.columnStates,
40
40
  onQuery = props.onQuery;
41
41
  var form = useMemo(function () {
42
42
  return createForm();
@@ -99,7 +99,7 @@ var FormRender = function FormRender(props) {
99
99
  properties: {}
100
100
  };
101
101
 
102
- if (!columns) {
102
+ if (!columnStates) {
103
103
  return rootSchema;
104
104
  }
105
105
 
@@ -111,27 +111,18 @@ var FormRender = function FormRender(props) {
111
111
  },
112
112
  properties: {}
113
113
  };
114
- columns.forEach(function (i, index) {
115
- i.searchSort = i.getColDef().searchSort === 0 ? i.getColDef().searchSort : i.getColDef().searchSort || index;
116
- }); //ag-grid 列 添加属性 searchSort,冒泡排序表单
117
-
118
- for (var i = 0; i < columns.length - 1; i++) {
119
- for (var j = 0; j < columns.length - 1 - i; j++) {
120
- if (columns[j].searchSort > columns[j + 1].searchSort) {
121
- var temp = columns[j];
122
- columns[j] = columns[j + 1];
123
- columns[j + 1] = temp;
124
- }
125
- }
126
- }
127
-
128
- var arr = columns.filter(function (i) {
129
- return (i === null || i === void 0 ? void 0 : i.visible) != false && !i.getColDef().hideInSearch || i.getColDef().hideInTable;
114
+ var columns = columnStates.filter(function (x) {
115
+ return !x.hide;
116
+ }).map(function (columnState) {
117
+ return gridApi === null || gridApi === void 0 ? void 0 : gridApi.getColumnDef(columnState.colId);
118
+ });
119
+ columns = columns.filter(function (i) {
120
+ return (i === null || i === void 0 ? void 0 : i.visible) != false && !i.hideInSearch || i.hideInTable;
130
121
  });
131
- arr.map(function (col) {
122
+ columns.map(function (col) {
132
123
  var _colDef$queryField;
133
124
 
134
- var colDef = col.getColDef();
125
+ var colDef = col;
135
126
  var name = (_colDef$queryField = colDef.queryField) !== null && _colDef$queryField !== void 0 ? _colDef$queryField : colDef.field;
136
127
  var headerName = colDef.headerName; //表单自定义组件
137
128
 
@@ -162,7 +153,7 @@ var FormRender = function FormRender(props) {
162
153
 
163
154
  rootSchema.properties["grid"] = gridSchema;
164
155
 
165
- if (!arr.length) {
156
+ if (!columns.length) {
166
157
  ///@ts-ignore
167
158
  delete rootSchema.properties["grid"];
168
159
  }
@@ -173,7 +164,7 @@ var FormRender = function FormRender(props) {
173
164
  useEffect(function () {
174
165
  var new_schema = getSchema();
175
166
  setSchema(new_schema);
176
- }, [columns]);
167
+ }, [JSON.stringify(columnStates)]);
177
168
  return /*#__PURE__*/React.createElement("div", {
178
169
  className: classNames(className, "ag-grid-table-search ag-grid-table-search-query-filter")
179
170
  }, /*#__PURE__*/React.createElement(Form, {
@@ -0,0 +1,8 @@
1
+ /// <reference types="react" />
2
+ import { ColumnApi, GridApi } from 'ag-grid-community';
3
+ declare const Setting: (props: {
4
+ gridApi?: GridApi<any> | undefined;
5
+ columnApi: ColumnApi;
6
+ onSaveColumnState: (state: any) => void;
7
+ }) => JSX.Element;
8
+ export default Setting;