@nokecy/qc-ui 0.1.6 → 0.1.8

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.
@@ -1,4 +1,4 @@
1
- var _excluded = ["style", "params", "request", "dataSource", "gridRef", "headerTitle", "toolBarRender", "search", "hideRedo", "onGridReady", "gridKey", "gridColumnState", "children"];
1
+ var _excluded = ["style", "params", "request", "dataSource", "rowData", "gridRef", "headerTitle", "toolBarRender", "search", "hideRedo", "onGridReady", "gridKey", "gridColumnState", "children"];
2
2
 
3
3
  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); }
4
4
 
@@ -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) : "";
@@ -46,6 +47,7 @@ function AgGridPlus(props) {
46
47
  gridParams = props.params,
47
48
  request = props.request,
48
49
  dataSource = props.dataSource,
50
+ propRowData = props.rowData,
49
51
  propsGridRef = props.gridRef,
50
52
  headerTitle = props.headerTitle,
51
53
  toolBarRender = props.toolBarRender,
@@ -73,8 +75,8 @@ function AgGridPlus(props) {
73
75
 
74
76
  var _useState5 = useState(),
75
77
  _useState6 = _slicedToArray(_useState5, 2),
76
- columnDefs = _useState6[0],
77
- setColumnDefs = _useState6[1];
78
+ columnState = _useState6[0],
79
+ setColumnState = _useState6[1];
78
80
 
79
81
  var _useState7 = useState([]),
80
82
  _useState8 = _slicedToArray(_useState7, 2),
@@ -136,15 +138,17 @@ function AgGridPlus(props) {
136
138
  }
137
139
  }, [gridColumnState, columnsRef.current]);
138
140
  useEffect(function () {
139
- setRowData(dataSource || rowData);
140
- }, [dataSource, rowData]);
141
+ setRowData(dataSource || propRowData || []);
142
+ }, [dataSource, propRowData]);
141
143
  var onGridReady = useCallback(function (params) {
144
+ var _columnsRef$current;
145
+
142
146
  apiRef.current = params.api;
143
147
  columnsRef.current = params.columnApi;
144
148
  onReady && onReady(params); ///@ts-ignore
145
149
 
146
150
  dataSource && setRowData(dataSource);
147
- setColumnDefs(columnsRef.current.getColumns());
151
+ setColumnState((_columnsRef$current = columnsRef.current) === null || _columnsRef$current === void 0 ? void 0 : _columnsRef$current.getColumnState());
148
152
  sortChanged(params.columnApi);
149
153
  setReady(true);
150
154
  }, [dataSource]);
@@ -188,6 +192,8 @@ function AgGridPlus(props) {
188
192
  request && onRequest(queryFilter);
189
193
  };
190
194
 
195
+ var onSaveColumnState = function onSaveColumnState(columnState) {};
196
+
191
197
  useEffect(function () {
192
198
  gridRef.current = {
193
199
  onRefresh: onRefresh
@@ -205,7 +211,7 @@ function AgGridPlus(props) {
205
211
  height: "100%"
206
212
  }
207
213
  }, search == false ? null : /*#__PURE__*/React.createElement(FormRender, {
208
- columns: columnDefs,
214
+ columnStates: columnState || [],
209
215
  gridApi: apiRef.current,
210
216
  onQuery: function onQuery(formValues) {
211
217
  setQueryFilter(_objectSpread({}, formValues));
@@ -239,9 +245,10 @@ function AgGridPlus(props) {
239
245
  settings: [/*#__PURE__*/React.createElement(SettingItem, {
240
246
  onClick: onRefresh,
241
247
  icon: /*#__PURE__*/React.createElement(RedoOutlined, null)
242
- }), /*#__PURE__*/React.createElement(SettingItem, {
243
- onClick: onRefresh,
244
- icon: /*#__PURE__*/React.createElement(SettingOutlined, null)
248
+ }), /*#__PURE__*/React.createElement(Setting, {
249
+ gridApi: apiRef.current,
250
+ columnApi: columnsRef.current,
251
+ onSaveColumnState: onSaveColumnState
245
252
  })]
246
253
  }), /*#__PURE__*/React.createElement(AgGridReact, _extends({
247
254
  className: "ag-theme-alpine"
@@ -258,8 +265,31 @@ function AgGridPlus(props) {
258
265
  props.onSelectionChanged && props.onSelectionChanged(e);
259
266
  setSelectRows(e.api.getSelectedRows());
260
267
  },
268
+ onDragStopped: function onDragStopped(e) {
269
+ if (columnsRef.current) {
270
+ var _columnsRef$current2;
271
+
272
+ setColumnState((_columnsRef$current2 = columnsRef.current) === null || _columnsRef$current2 === void 0 ? void 0 : _columnsRef$current2.getColumnState());
273
+ }
274
+ },
275
+ onColumnResized: function onColumnResized(e) {
276
+ if (columnsRef.current) {
277
+ var _columnsRef$current3, _columnsRef$current4;
278
+
279
+ console.log((_columnsRef$current3 = columnsRef.current) === null || _columnsRef$current3 === void 0 ? void 0 : _columnsRef$current3.getColumnState());
280
+ setColumnState((_columnsRef$current4 = columnsRef.current) === null || _columnsRef$current4 === void 0 ? void 0 : _columnsRef$current4.getColumnState());
281
+ }
282
+ },
283
+ onColumnMoved: function onColumnMoved() {
284
+ if (columnsRef.current) {
285
+ var _columnsRef$current5;
286
+
287
+ setColumnState((_columnsRef$current5 = columnsRef.current) === null || _columnsRef$current5 === void 0 ? void 0 : _columnsRef$current5.getColumnState());
288
+ }
289
+ },
261
290
  columnTypes: {
262
291
  bool: {
292
+ filter: 'boolFilter',
263
293
  cellRenderer: function cellRenderer(params) {
264
294
  switch (params.value) {
265
295
  case true:
@@ -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;
@@ -31,12 +31,13 @@ import { Button } from 'antd';
31
31
  import classNames from 'classnames';
32
32
  import React, { useEffect, useMemo, useState } from 'react';
33
33
  import QueryForm from "./queryForm";
34
+ import BoolSelect from "../_utils/boolSelect";
34
35
  import "./index.less";
35
36
 
36
37
  var FormRender = function FormRender(props) {
37
38
  var className = props.className,
38
39
  gridApi = props.gridApi,
39
- columns = props.columns,
40
+ columnStates = props.columnStates,
40
41
  onQuery = props.onQuery;
41
42
  var form = useMemo(function () {
42
43
  return createForm();
@@ -51,7 +52,8 @@ var FormRender = function FormRender(props) {
51
52
  FormGrid: FormGrid,
52
53
  FormButtonGroup: FormButtonGroup,
53
54
  Submit: Submit,
54
- Button: Button
55
+ Button: Button,
56
+ BoolSelect: BoolSelect
55
57
  }
56
58
  });
57
59
  }, []);
@@ -93,13 +95,31 @@ var FormRender = function FormRender(props) {
93
95
  schema = _useState2[0],
94
96
  setSchema = _useState2[1];
95
97
 
98
+ var getComponent = function getComponent(colDef) {
99
+ var component = colDef.searchComponent ? colDef.searchComponent : undefined;
100
+
101
+ if (!component) {
102
+ switch (colDef.filter) {
103
+ case "agDateColumnFilter":
104
+ component = "DatePicker.RangePicker";
105
+ break;
106
+
107
+ case "boolFilter":
108
+ component = "BoolSelect";
109
+ break;
110
+ }
111
+
112
+ return component ? component : "Input";
113
+ }
114
+ };
115
+
96
116
  var getSchema = function getSchema() {
97
117
  var rootSchema = {
98
118
  type: 'object',
99
119
  properties: {}
100
120
  };
101
121
 
102
- if (!columns) {
122
+ if (!columnStates) {
103
123
  return rootSchema;
104
124
  }
105
125
 
@@ -111,31 +131,22 @@ var FormRender = function FormRender(props) {
111
131
  },
112
132
  properties: {}
113
133
  };
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;
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;
130
141
  });
131
- arr.map(function (col) {
142
+ columns.map(function (col) {
132
143
  var _colDef$queryField;
133
144
 
134
- var colDef = col.getColDef();
145
+ var colDef = col;
135
146
  var name = (_colDef$queryField = colDef.queryField) !== null && _colDef$queryField !== void 0 ? _colDef$queryField : colDef.field;
136
147
  var headerName = colDef.headerName; //表单自定义组件
137
148
 
138
- var component = colDef.searchComponent ? colDef.searchComponent : colDef.filter == "agDateColumnFilter" ? "DatePicker.RangePicker" : "Input";
149
+ var component = getComponent(colDef);
139
150
 
140
151
  if (colDef.filter != false) {
141
152
  var _colDef$searchCompone, _colDef$searchCompone2;
@@ -162,7 +173,7 @@ var FormRender = function FormRender(props) {
162
173
 
163
174
  rootSchema.properties["grid"] = gridSchema;
164
175
 
165
- if (!arr.length) {
176
+ if (!columns.length) {
166
177
  ///@ts-ignore
167
178
  delete rootSchema.properties["grid"];
168
179
  }
@@ -173,7 +184,7 @@ var FormRender = function FormRender(props) {
173
184
  useEffect(function () {
174
185
  var new_schema = getSchema();
175
186
  setSchema(new_schema);
176
- }, [columns]);
187
+ }, [JSON.stringify(columnStates)]);
177
188
  return /*#__PURE__*/React.createElement("div", {
178
189
  className: classNames(className, "ag-grid-table-search ag-grid-table-search-query-filter")
179
190
  }, /*#__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;
@@ -0,0 +1,196 @@
1
+ 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); }
2
+
3
+ import _uniqueId from "lodash/uniqueId";
4
+
5
+ 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; }
6
+
7
+ 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); } }
8
+
9
+ 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); }); }; }
10
+
11
+ 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; }
12
+
13
+ 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; }
14
+
15
+ 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; }
16
+
17
+ import { ArrayTable, FormDialog, FormGrid, FormItem, FormLayout, FormTab, Input, Select, Space, NumberPicker, Switch } from '@formily/antd';
18
+ import { createSchemaField } from '@formily/react';
19
+ import { onFormInit } from '@formily/core';
20
+ import React, { useMemo } from "react";
21
+ import { SettingOutlined } from '@ant-design/icons';
22
+
23
+ var Setting = function Setting(props) {
24
+ var gridApi = props.gridApi,
25
+ columnApi = props.columnApi,
26
+ onSaveColumnState = props.onSaveColumnState;
27
+ var SchemaField = useMemo(function () {
28
+ return createSchemaField({
29
+ components: {
30
+ FormTab: FormTab,
31
+ FormItem: FormItem,
32
+ FormGrid: FormGrid,
33
+ Space: Space,
34
+ Input: Input,
35
+ Select: Select,
36
+ ArrayTable: ArrayTable,
37
+ NumberPicker: NumberPicker,
38
+ Switch: Switch
39
+ }
40
+ });
41
+ }, []);
42
+ var formProps = {
43
+ effects: function effects() {
44
+ onFormInit(function (form) {
45
+ form.setInitialValuesIn('items', getColumnData());
46
+ });
47
+ }
48
+ };
49
+
50
+ var getColumnData = function getColumnData() {
51
+ var columnStates = columnApi.getColumnState();
52
+ var columnRowData = [];
53
+ var columns = columnStates.map(function (columnState) {
54
+ var colDef = gridApi === null || gridApi === void 0 ? void 0 : gridApi.getColumnDef(columnState.colId);
55
+ columnRowData.push(_objectSpread({
56
+ field: colDef.field,
57
+ headerName: colDef.headerName,
58
+ width: columnState.width,
59
+ hide: columnState.hide
60
+ }, columnState));
61
+ });
62
+ return columnRowData;
63
+ };
64
+
65
+ var portalId = "workProcedure".concat(_uniqueId());
66
+ return /*#__PURE__*/React.createElement(FormDialog.Portal, {
67
+ id: portalId
68
+ }, /*#__PURE__*/React.createElement("div", {
69
+ style: {
70
+ margin: "0 4px",
71
+ color: "#000",
72
+ fontSize: 16,
73
+ cursor: "pointer"
74
+ },
75
+ onClick: /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
76
+ var formDialog;
77
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
78
+ while (1) {
79
+ switch (_context.prev = _context.next) {
80
+ case 0:
81
+ formDialog = FormDialog({
82
+ title: "个性化设置",
83
+ width: 960
84
+ }, portalId, function () {
85
+ return /*#__PURE__*/React.createElement(FormLayout, null, /*#__PURE__*/React.createElement(SchemaField, null, /*#__PURE__*/React.createElement(SchemaField.Void, {
86
+ "x-component": "FormGrid",
87
+ "x-component-props": {
88
+ maxColumns: [1, 3],
89
+ strictAutoFit: true
90
+ }
91
+ }, /*#__PURE__*/React.createElement(SchemaField.Array, {
92
+ name: "items",
93
+ title: "",
94
+ "x-component": "ArrayTable",
95
+ "x-validator": [{
96
+ message: ""
97
+ }],
98
+ "x-decorator": "FormItem",
99
+ "x-decorator-props": {
100
+ gridSpan: 3
101
+ }
102
+ }, /*#__PURE__*/React.createElement(SchemaField.Object, null, /*#__PURE__*/React.createElement(SchemaField.Void, {
103
+ "x-component": "ArrayTable.Column",
104
+ "x-component-props": {
105
+ width: 150,
106
+ title: "字段名"
107
+ }
108
+ }, /*#__PURE__*/React.createElement(SchemaField.String, {
109
+ name: "field",
110
+ "x-decorator": "FormItem",
111
+ "x-component": "Input",
112
+ "x-read-pretty": true
113
+ })), /*#__PURE__*/React.createElement(SchemaField.Void, {
114
+ "x-component": "ArrayTable.Column",
115
+ "x-component-props": {
116
+ width: 150,
117
+ title: "列名"
118
+ }
119
+ }, /*#__PURE__*/React.createElement(SchemaField.String, {
120
+ name: "headerName",
121
+ "x-decorator": "FormItem",
122
+ "x-component": "Input",
123
+ "x-read-pretty": true
124
+ })), /*#__PURE__*/React.createElement(SchemaField.Void, {
125
+ "x-component": "ArrayTable.Column",
126
+ "x-component-props": {
127
+ width: 150,
128
+ title: "宽度"
129
+ }
130
+ }, /*#__PURE__*/React.createElement(SchemaField.String, {
131
+ name: "width",
132
+ "x-decorator": "FormItem",
133
+ "x-component": "NumberPicker"
134
+ })), /*#__PURE__*/React.createElement(SchemaField.Void, {
135
+ "x-component": "ArrayTable.Column",
136
+ "x-component-props": {
137
+ width: 150,
138
+ title: "占满"
139
+ }
140
+ }, /*#__PURE__*/React.createElement(SchemaField.String, {
141
+ name: "flex",
142
+ "x-decorator": "FormItem",
143
+ "x-component": "Switch"
144
+ })), /*#__PURE__*/React.createElement(SchemaField.Void, {
145
+ "x-component": "ArrayTable.Column",
146
+ "x-component-props": {
147
+ width: 150,
148
+ title: '固定位置'
149
+ }
150
+ }, /*#__PURE__*/React.createElement(SchemaField.String, {
151
+ name: "pinned",
152
+ "x-decorator": "FormItem",
153
+ "x-component": "Select",
154
+ enum: [{
155
+ value: "left",
156
+ label: "左固定"
157
+ }, {
158
+ value: "right",
159
+ label: "右固定"
160
+ }, {
161
+ value: undefined,
162
+ label: "不固定"
163
+ }]
164
+ })), /*#__PURE__*/React.createElement(SchemaField.Void, {
165
+ "x-component": "ArrayTable.Column",
166
+ "x-component-props": {
167
+ width: 150,
168
+ title: '隐藏'
169
+ }
170
+ }, /*#__PURE__*/React.createElement(SchemaField.String, {
171
+ name: "hide",
172
+ "x-decorator": "FormItem",
173
+ "x-component": "Switch"
174
+ })))))));
175
+ });
176
+ formDialog.forConfirm(function (payload, next) {
177
+ var values = payload.values;
178
+ var falg = columnApi.applyColumnState({
179
+ state: values.items,
180
+ applyOrder: true
181
+ });
182
+ onSaveColumnState && onSaveColumnState(values.items);
183
+ next(payload);
184
+ }).open(formProps);
185
+
186
+ case 2:
187
+ case "end":
188
+ return _context.stop();
189
+ }
190
+ }
191
+ }, _callee);
192
+ }))
193
+ }, /*#__PURE__*/React.createElement(SettingOutlined, null)));
194
+ };
195
+
196
+ export default Setting;