@nokecy/qc-ui 1.1.90 → 1.1.91
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/queryForm/queryForm.js +17 -29
- package/dist/cjs/ag-grid-plus/toolBar/index.js +23 -23
- package/dist/cjs/ag-grid-plus/toolBar/leftContent.d.ts +5 -0
- package/dist/cjs/ag-grid-plus/toolBar/leftContent.js +21 -0
- package/dist/cjs/array-table/index.js +2 -0
- package/dist/cjs/array-table/indexColumn.d.ts +2 -0
- package/dist/cjs/array-table/indexColumn.js +5 -13
- package/dist/cjs/array-table/preview.js +6 -0
- package/dist/cjs/array-table/utils.js +4 -1
- package/dist/cjs/dialogSelect/index.d.ts +4 -0
- package/dist/cjs/dialogSelect/index.js +30 -19
- package/dist/cjs/dialogSelect/selectedLabels.d.ts +34 -0
- package/dist/cjs/dialogSelect/selectedLabels.js +251 -0
- package/dist/cjs/entitySelect/index.d.ts +2 -0
- package/dist/cjs/entitySelect/index.js +2 -0
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.js +8 -0
- package/dist/cjs/readPretty/arrayTable.js +6 -2
- package/dist/cjs/readPretty/controls.d.ts +3 -0
- package/dist/cjs/readPretty/controls.js +7 -4
- package/dist/cjs/readPretty/formily.d.ts +1 -1
- package/dist/cjs/readPretty/formily.js +5 -4
- package/dist/cjs/standardList/StandardAgGridPlus.js +5 -32
- package/dist/cjs/utils/gridSequence.d.ts +9 -0
- package/dist/cjs/utils/gridSequence.js +110 -0
- package/dist/esm/ag-grid-plus/queryForm/queryForm.js +17 -29
- package/dist/esm/ag-grid-plus/toolBar/index.js +23 -23
- package/dist/esm/ag-grid-plus/toolBar/leftContent.d.ts +5 -0
- package/dist/esm/ag-grid-plus/toolBar/leftContent.js +13 -0
- package/dist/esm/array-table/index.js +2 -0
- package/dist/esm/array-table/indexColumn.d.ts +2 -0
- package/dist/esm/array-table/indexColumn.js +5 -12
- package/dist/esm/array-table/preview.js +6 -0
- package/dist/esm/array-table/utils.js +4 -1
- package/dist/esm/dialogSelect/index.d.ts +4 -0
- package/dist/esm/dialogSelect/index.js +30 -19
- package/dist/esm/dialogSelect/selectedLabels.d.ts +34 -0
- package/dist/esm/dialogSelect/selectedLabels.js +243 -0
- package/dist/esm/entitySelect/index.d.ts +2 -0
- package/dist/esm/entitySelect/index.js +2 -0
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/readPretty/arrayTable.js +6 -2
- package/dist/esm/readPretty/controls.d.ts +3 -0
- package/dist/esm/readPretty/controls.js +7 -4
- package/dist/esm/readPretty/formily.d.ts +1 -1
- package/dist/esm/readPretty/formily.js +5 -4
- package/dist/esm/standardList/StandardAgGridPlus.js +5 -32
- package/dist/esm/utils/gridSequence.d.ts +9 -0
- package/dist/esm/utils/gridSequence.js +104 -0
- package/dist/umd/qc-ui.min.js +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
type Option = {
|
|
3
|
+
value: any;
|
|
4
|
+
label: React.ReactNode;
|
|
5
|
+
};
|
|
6
|
+
type LabelProps = {
|
|
7
|
+
request?: (query: any) => Promise<any>;
|
|
8
|
+
valueField?: string;
|
|
9
|
+
labelField?: string;
|
|
10
|
+
displayField?: string;
|
|
11
|
+
options?: any[];
|
|
12
|
+
children?: React.ReactNode;
|
|
13
|
+
dialogDataSource?: any[];
|
|
14
|
+
resolveSelected?: (values: any[]) => Promise<any>;
|
|
15
|
+
selectedScopeKey?: string | number;
|
|
16
|
+
pagedApiAdapter?: {
|
|
17
|
+
toRequest: (query: any) => any;
|
|
18
|
+
getItems?: (result: any) => any[];
|
|
19
|
+
};
|
|
20
|
+
queryFun?: (filter: string) => any;
|
|
21
|
+
};
|
|
22
|
+
/** Gridify 的值转义仅用于查询,不改变表单中的编码。@author nokecy */
|
|
23
|
+
export declare const escapeSelectedValue: (value: any) => string;
|
|
24
|
+
/**
|
|
25
|
+
* 对程序带入但没有候选标签的编码精确查名;只补显示选项,不触发表单输入或联动。
|
|
26
|
+
* 请求仅承接当前选择,切换、清空及卸载后的返回不回填;不存在或无权读取时保留原值。
|
|
27
|
+
* @author nokecy
|
|
28
|
+
*/
|
|
29
|
+
export declare const useSelectedLabels: (props: LabelProps, value: any, enabled?: boolean) => Option[];
|
|
30
|
+
/** 追加选中项的显示标签,保留原有候选与分组结构。@author nokecy */
|
|
31
|
+
export declare const withSelectedLabels: <T extends LabelProps>(props: T, labels: Option[]) => T;
|
|
32
|
+
/** labelInValue中以编码占位的标签只在显示层补名,不改变值或发出onChange。@author nokecy */
|
|
33
|
+
export declare const selectedDisplayValue: (value: any, labels: Option[], labelInValue?: boolean) => any;
|
|
34
|
+
export {};
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
2
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
3
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
4
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
5
|
+
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; }
|
|
6
|
+
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; }
|
|
7
|
+
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; }
|
|
8
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
9
|
+
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); }
|
|
10
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
11
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
12
|
+
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."); }
|
|
13
|
+
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); }
|
|
14
|
+
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; }
|
|
15
|
+
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; } }
|
|
16
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
17
|
+
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); }
|
|
18
|
+
import React, { useEffect, useRef, useState } from 'react';
|
|
19
|
+
import { Select } from 'antd';
|
|
20
|
+
import { normalizeSelectValue } from "../readPretty/selectValue";
|
|
21
|
+
var hasValue = function hasValue(value) {
|
|
22
|
+
return value !== undefined && value !== null && value !== '';
|
|
23
|
+
};
|
|
24
|
+
var keyOf = function keyOf(value) {
|
|
25
|
+
return "".concat(_typeof(value), ":").concat(String(value));
|
|
26
|
+
};
|
|
27
|
+
var usefulLabel = function usefulLabel(value, label) {
|
|
28
|
+
return label !== undefined && label !== null && label !== '' && String(label).trim() !== String(value).trim();
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
/** Gridify 的值转义仅用于查询,不改变表单中的编码。@author nokecy */
|
|
32
|
+
export var escapeSelectedValue = function escapeSelectedValue(value) {
|
|
33
|
+
return String(value).replace(/([\\,|()/])/g, '\\$1');
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
/** 从下拉选项和分组选项读取已有标签,避免重复查询。@author nokecy */
|
|
37
|
+
var collectOptions = function collectOptions(props) {
|
|
38
|
+
var options = [];
|
|
39
|
+
var walkOptions = function walkOptions(items) {
|
|
40
|
+
return items === null || items === void 0 ? void 0 : items.forEach(function (item) {
|
|
41
|
+
if (item !== null && item !== void 0 && item.options) walkOptions(item.options);else if (hasValue(item === null || item === void 0 ? void 0 : item.value)) options.push(item);
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
var walkChildren = function walkChildren(children) {
|
|
45
|
+
return React.Children.forEach(children, function (child) {
|
|
46
|
+
var _child$props$label;
|
|
47
|
+
if (! /*#__PURE__*/React.isValidElement(child)) return;
|
|
48
|
+
if (hasValue(child.props.value)) options.push({
|
|
49
|
+
value: child.props.value,
|
|
50
|
+
label: (_child$props$label = child.props.label) !== null && _child$props$label !== void 0 ? _child$props$label : child.props.children
|
|
51
|
+
});else walkChildren(child.props.children);
|
|
52
|
+
});
|
|
53
|
+
};
|
|
54
|
+
walkOptions(props.options);
|
|
55
|
+
walkChildren(props.children);
|
|
56
|
+
return options;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* 对程序带入但没有候选标签的编码精确查名;只补显示选项,不触发表单输入或联动。
|
|
61
|
+
* 请求仅承接当前选择,切换、清空及卸载后的返回不回填;不存在或无权读取时保留原值。
|
|
62
|
+
* @author nokecy
|
|
63
|
+
*/
|
|
64
|
+
export var useSelectedLabels = function useSelectedLabels(props, value) {
|
|
65
|
+
var _props$valueField, _props$labelField, _props$selectedScopeK;
|
|
66
|
+
var enabled = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
|
|
67
|
+
var requestRef = useRef(props);
|
|
68
|
+
requestRef.current = props;
|
|
69
|
+
var _useState = useState({}),
|
|
70
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
71
|
+
resolved = _useState2[0],
|
|
72
|
+
setResolved = _useState2[1];
|
|
73
|
+
var valueField = (_props$valueField = props.valueField) !== null && _props$valueField !== void 0 ? _props$valueField : 'id';
|
|
74
|
+
var labelField = (_props$labelField = props.labelField) !== null && _props$labelField !== void 0 ? _props$labelField : 'name';
|
|
75
|
+
var scope = JSON.stringify((_props$selectedScopeK = props.selectedScopeKey) !== null && _props$selectedScopeK !== void 0 ? _props$selectedScopeK : null);
|
|
76
|
+
var cachePrefix = "".concat(scope, ":").concat(valueField, ":").concat(labelField, ":");
|
|
77
|
+
var existing = collectOptions(props);
|
|
78
|
+
var normalized = normalizeSelectValue(value, true);
|
|
79
|
+
var selected = (Array.isArray(normalized) ? normalized : [normalized]).map(function (item) {
|
|
80
|
+
return item && _typeof(item) === 'object' ? {
|
|
81
|
+
value: item.value,
|
|
82
|
+
label: item.label
|
|
83
|
+
} : {
|
|
84
|
+
value: item,
|
|
85
|
+
label: undefined
|
|
86
|
+
};
|
|
87
|
+
}).filter(function (item) {
|
|
88
|
+
return hasValue(item.value);
|
|
89
|
+
});
|
|
90
|
+
var options = selected.map(function (item) {
|
|
91
|
+
var _props$dialogDataSour, _resolved;
|
|
92
|
+
var known = existing.find(function (option) {
|
|
93
|
+
return option.value === item.value && usefulLabel(item.value, option.label);
|
|
94
|
+
});
|
|
95
|
+
var local = (_props$dialogDataSour = props.dialogDataSource) === null || _props$dialogDataSour === void 0 ? void 0 : _props$dialogDataSour.find(function (row) {
|
|
96
|
+
return row[valueField] === item.value;
|
|
97
|
+
});
|
|
98
|
+
return usefulLabel(item.value, item.label) ? item : known !== null && known !== void 0 ? known : usefulLabel(item.value, local === null || local === void 0 ? void 0 : local[labelField]) ? {
|
|
99
|
+
value: item.value,
|
|
100
|
+
label: local[labelField]
|
|
101
|
+
} : (_resolved = resolved["".concat(cachePrefix).concat(keyOf(item.value))]) !== null && _resolved !== void 0 ? _resolved : item;
|
|
102
|
+
});
|
|
103
|
+
var missing = options.filter(function (item) {
|
|
104
|
+
return !usefulLabel(item.value, item.label);
|
|
105
|
+
});
|
|
106
|
+
// JSON只作依赖签名,不进入过滤语法。每次查询使用编码等值条件,不受第一页或模糊候选影响。
|
|
107
|
+
var signature = JSON.stringify(enabled && (props.request || props.resolveSelected) && !Array.isArray(props.dialogDataSource) && props.displayField !== 'value' && labelField !== valueField ? Array.from(new Set(missing.map(function (item) {
|
|
108
|
+
return item.value;
|
|
109
|
+
}))) : []);
|
|
110
|
+
useEffect(function () {
|
|
111
|
+
var values = JSON.parse(signature);
|
|
112
|
+
if (!values.length) return;
|
|
113
|
+
var active = true;
|
|
114
|
+
var source = requestRef.current;
|
|
115
|
+
var filter = values.map(function (item) {
|
|
116
|
+
return "(".concat(valueField, " = ").concat(escapeSelectedValue(item), ")");
|
|
117
|
+
}).join(' | ');
|
|
118
|
+
var filtered = source.queryFun ? source.queryFun(filter) : filter;
|
|
119
|
+
var count = Math.max(20, values.length);
|
|
120
|
+
var query = source.pagedApiAdapter ? source.pagedApiAdapter.toRequest({
|
|
121
|
+
filter: filtered,
|
|
122
|
+
skipCount: 0,
|
|
123
|
+
maxResultCount: count
|
|
124
|
+
}) : {
|
|
125
|
+
Filter: filtered,
|
|
126
|
+
SkipCount: 0,
|
|
127
|
+
MaxResultCount: count
|
|
128
|
+
};
|
|
129
|
+
void Promise.resolve().then(function () {
|
|
130
|
+
return source.resolveSelected ? source.resolveSelected(values) : source.request(query);
|
|
131
|
+
}).then(function (result) {
|
|
132
|
+
var _source$pagedApiAdapt, _result$items;
|
|
133
|
+
if (!active) return;
|
|
134
|
+
var rows = (_source$pagedApiAdapt = source.pagedApiAdapter) !== null && _source$pagedApiAdapt !== void 0 && _source$pagedApiAdapt.getItems ? source.pagedApiAdapter.getItems(result) : Array.isArray(result) ? result : (_result$items = result === null || result === void 0 ? void 0 : result.items) !== null && _result$items !== void 0 ? _result$items : [];
|
|
135
|
+
var found = {};
|
|
136
|
+
var _iterator = _createForOfIteratorHelper(values),
|
|
137
|
+
_step;
|
|
138
|
+
try {
|
|
139
|
+
var _loop = function _loop() {
|
|
140
|
+
var original = _step.value;
|
|
141
|
+
var row = rows.find(function (item) {
|
|
142
|
+
var _item$valueField;
|
|
143
|
+
return String((_item$valueField = item === null || item === void 0 ? void 0 : item[valueField]) !== null && _item$valueField !== void 0 ? _item$valueField : '').trim().toLowerCase() === String(original).trim().toLowerCase();
|
|
144
|
+
});
|
|
145
|
+
var name = row === null || row === void 0 ? void 0 : row[labelField];
|
|
146
|
+
if (!usefulLabel(original, name)) return 1; // continue
|
|
147
|
+
var code = row === null || row === void 0 ? void 0 : row.code;
|
|
148
|
+
var label = labelField === 'name' && hasValue(code) && String(name).trim() !== String(code).trim() ? "".concat(String(code).trim(), " - ").concat(String(name).trim()) : name;
|
|
149
|
+
found["".concat(cachePrefix).concat(keyOf(original))] = {
|
|
150
|
+
value: original,
|
|
151
|
+
label: label
|
|
152
|
+
};
|
|
153
|
+
};
|
|
154
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
155
|
+
if (_loop()) continue;
|
|
156
|
+
}
|
|
157
|
+
} catch (err) {
|
|
158
|
+
_iterator.e(err);
|
|
159
|
+
} finally {
|
|
160
|
+
_iterator.f();
|
|
161
|
+
}
|
|
162
|
+
if (Object.keys(found).length) setResolved(function (previous) {
|
|
163
|
+
return _objectSpread(_objectSpread({}, previous), found);
|
|
164
|
+
});
|
|
165
|
+
}).catch(function () {/* 名称读取失败保留业务值,后续用户仍可展开选择。@author nokecy */});
|
|
166
|
+
return function () {
|
|
167
|
+
active = false;
|
|
168
|
+
};
|
|
169
|
+
}, [signature, valueField, labelField, scope]);
|
|
170
|
+
return options.filter(function (item) {
|
|
171
|
+
return usefulLabel(item.value, item.label);
|
|
172
|
+
});
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
/** 追加选中项的显示标签,保留原有候选与分组结构。@author nokecy */
|
|
176
|
+
export var withSelectedLabels = function withSelectedLabels(props, labels) {
|
|
177
|
+
if (!labels.length) return props;
|
|
178
|
+
var known = collectOptions(props);
|
|
179
|
+
var extra = labels.filter(function (item) {
|
|
180
|
+
return !known.some(function (option) {
|
|
181
|
+
return option.value === item.value && usefulLabel(item.value, option.label);
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
if (!extra.length) return props;
|
|
185
|
+
var added = extra.filter(function (item) {
|
|
186
|
+
return !known.some(function (option) {
|
|
187
|
+
return option.value === item.value;
|
|
188
|
+
});
|
|
189
|
+
});
|
|
190
|
+
if (props.options) {
|
|
191
|
+
var _update = function _update(items) {
|
|
192
|
+
return items.map(function (item) {
|
|
193
|
+
return item.options ? _objectSpread(_objectSpread({}, item), {}, {
|
|
194
|
+
options: _update(item.options)
|
|
195
|
+
}) : extra.find(function (option) {
|
|
196
|
+
return option.value === item.value;
|
|
197
|
+
}) ? _objectSpread(_objectSpread({}, item), {}, {
|
|
198
|
+
label: extra.find(function (option) {
|
|
199
|
+
return option.value === item.value;
|
|
200
|
+
}).label
|
|
201
|
+
}) : item;
|
|
202
|
+
});
|
|
203
|
+
};
|
|
204
|
+
return _objectSpread(_objectSpread({}, props), {}, {
|
|
205
|
+
options: [].concat(_toConsumableArray(_update(props.options)), _toConsumableArray(added))
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
// 保留自定义Option、分组与选项附加属性,补入的选项只参与显示。
|
|
209
|
+
var update = function update(children) {
|
|
210
|
+
return React.Children.map(children, function (child) {
|
|
211
|
+
if (! /*#__PURE__*/React.isValidElement(child)) return child;
|
|
212
|
+
var option = extra.find(function (item) {
|
|
213
|
+
return item.value === child.props.value;
|
|
214
|
+
});
|
|
215
|
+
if (option) return /*#__PURE__*/React.cloneElement(child, {}, option.label);
|
|
216
|
+
return child.props.children && !hasValue(child.props.value) ? /*#__PURE__*/React.cloneElement(child, {}, update(child.props.children)) : child;
|
|
217
|
+
});
|
|
218
|
+
};
|
|
219
|
+
return _objectSpread(_objectSpread({}, props), {}, {
|
|
220
|
+
children: [update(props.children)].concat(_toConsumableArray(added.map(function (item) {
|
|
221
|
+
return /*#__PURE__*/React.createElement(Select.Option, {
|
|
222
|
+
key: "selected:".concat(keyOf(item.value)),
|
|
223
|
+
value: item.value,
|
|
224
|
+
children: item.label
|
|
225
|
+
});
|
|
226
|
+
})))
|
|
227
|
+
});
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
/** labelInValue中以编码占位的标签只在显示层补名,不改变值或发出onChange。@author nokecy */
|
|
231
|
+
export var selectedDisplayValue = function selectedDisplayValue(value, labels, labelInValue) {
|
|
232
|
+
if (!labelInValue) return value;
|
|
233
|
+
if (Array.isArray(value)) return value.map(function (item) {
|
|
234
|
+
return selectedDisplayValue(item, labels, true);
|
|
235
|
+
});
|
|
236
|
+
if (!value || _typeof(value) !== 'object' || usefulLabel(value.value, value.label)) return value;
|
|
237
|
+
var option = labels.find(function (item) {
|
|
238
|
+
return item.value === value.value;
|
|
239
|
+
});
|
|
240
|
+
return option ? _objectSpread(_objectSpread({}, value), {}, {
|
|
241
|
+
label: option.label
|
|
242
|
+
}) : value;
|
|
243
|
+
};
|
|
@@ -21,6 +21,8 @@ export interface EntitySelectQuery {
|
|
|
21
21
|
export interface EntitySelectConfig {
|
|
22
22
|
/** 取数函数,通常是生成服务客户端里的 XxxGetListAsync。 */
|
|
23
23
|
request: (query: EntitySelectQuery) => Promise<any>;
|
|
24
|
+
/** 非标准查询接口按自身候选范围解析已选项名称。@author nokecy */
|
|
25
|
+
resolveSelected?: (values: any[]) => Promise<any>;
|
|
24
26
|
/** 未选择时的提示语。 */
|
|
25
27
|
placeholder: string;
|
|
26
28
|
/** 弹窗内表格的列定义。 */
|
|
@@ -28,6 +28,7 @@ var Option = AntSelect.Option;
|
|
|
28
28
|
|
|
29
29
|
var createEntitySelect = function createEntitySelect(config) {
|
|
30
30
|
var request = config.request,
|
|
31
|
+
resolveSelected = config.resolveSelected,
|
|
31
32
|
placeholder = config.placeholder,
|
|
32
33
|
columnDefs = config.columnDefs,
|
|
33
34
|
valueField = config.valueField,
|
|
@@ -140,6 +141,7 @@ var createEntitySelect = function createEntitySelect(config) {
|
|
|
140
141
|
labelField: labelField
|
|
141
142
|
} : {}, {
|
|
142
143
|
request: getData,
|
|
144
|
+
resolveSelected: resolveSelected,
|
|
143
145
|
columnDefs: columnDefs,
|
|
144
146
|
onChangeItem: function onChangeItem(item) {
|
|
145
147
|
if (!enableLinkage || !onLinkage || !item) return;
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ import { FormProLayout } from "./formPro";
|
|
|
13
13
|
import { FormProContext } from "./formPro/context/formProContext";
|
|
14
14
|
import QueryBuilder from "./queryBuilder";
|
|
15
15
|
import ToolBar from "./toolBar";
|
|
16
|
+
export { ListToolbarLeft } from './ag-grid-plus/toolBar/leftContent';
|
|
16
17
|
import ImportModal from "./importModal";
|
|
17
18
|
import FullScreenAlert from "./fullScreenAlert";
|
|
18
19
|
import ConfirmPro from "./ConfirmPro";
|
package/dist/esm/index.js
CHANGED
|
@@ -18,6 +18,7 @@ import { FormProLayout } from "./formPro";
|
|
|
18
18
|
import { FormProContext } from "./formPro/context/formProContext";
|
|
19
19
|
import QueryBuilder from "./queryBuilder";
|
|
20
20
|
import ToolBar from "./toolBar";
|
|
21
|
+
export { ListToolbarLeft } from "./ag-grid-plus/toolBar/leftContent";
|
|
21
22
|
import ImportModal from "./importModal";
|
|
22
23
|
import FullScreenAlert from "./fullScreenAlert";
|
|
23
24
|
import ConfirmPro from "./ConfirmPro";
|
|
@@ -15,6 +15,7 @@ import { ARRAY_TABLE_INDEX_FIELD, hasOwnIndexColumn, makeIndexColumn } from "../
|
|
|
15
15
|
import { ARRAY_TABLE_ROW_HEIGHT, useArrayTableTheme } from "../array-table/theme";
|
|
16
16
|
import { hoistStatics } from "./hoistStatics";
|
|
17
17
|
import React, { useMemo, useRef } from 'react';
|
|
18
|
+
import { installDisplaySequenceOrder } from "../utils/gridSequence";
|
|
18
19
|
|
|
19
20
|
/** 阅读态直接使用 ArrayTable 的列定义,避免 AgGridPlus 的原值渲染器覆盖格式化结果。@author nokecy */
|
|
20
21
|
|
|
@@ -29,7 +30,7 @@ var ReadingArrayTable = observer(function (_ref) {
|
|
|
29
30
|
} : _ref$rowSelection,
|
|
30
31
|
selectionColumnDef = _ref.selectionColumnDef,
|
|
31
32
|
onSelectionChanged = _ref.onSelectionChanged,
|
|
32
|
-
|
|
33
|
+
_onGridReady = _ref.onGridReady,
|
|
33
34
|
_onRowDataUpdated = _ref.onRowDataUpdated;
|
|
34
35
|
var field = useField();
|
|
35
36
|
var sources = useArrayTableSources();
|
|
@@ -62,7 +63,10 @@ var ReadingArrayTable = observer(function (_ref) {
|
|
|
62
63
|
suppressHeaderMenuButton: true
|
|
63
64
|
}, selectionColumnDef),
|
|
64
65
|
onSelectionChanged: onSelectionChanged,
|
|
65
|
-
onGridReady: onGridReady
|
|
66
|
+
onGridReady: function onGridReady(event) {
|
|
67
|
+
installDisplaySequenceOrder(event.api);
|
|
68
|
+
_onGridReady === null || _onGridReady === void 0 || _onGridReady(event);
|
|
69
|
+
},
|
|
66
70
|
columnDefs: groupColumnDefs(columns),
|
|
67
71
|
rowData: rows,
|
|
68
72
|
getRowId: function getRowId(_ref2) {
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
import { NumberPicker as FormilyNumberPicker } from '@formily/antd-v5';
|
|
1
2
|
import { 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';
|
|
2
3
|
export declare const Input: typeof AntInput;
|
|
3
4
|
export declare const InputNumber: typeof AntInputNumber;
|
|
5
|
+
/** Formily 数值控件同样关闭方向键步进,保留数值类型及原有表单绑定。@author nokecy */
|
|
6
|
+
export declare const NumberPicker: typeof FormilyNumberPicker;
|
|
4
7
|
export declare const Select: typeof AntSelect;
|
|
5
8
|
export declare const Switch: typeof AntSwitch;
|
|
6
9
|
export declare const Checkbox: typeof AntCheckbox;
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
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
|
-
import { PreviewText } from '@formily/antd-v5';
|
|
2
|
+
import { NumberPicker as FormilyNumberPicker, PreviewText } from '@formily/antd-v5';
|
|
3
3
|
import { 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';
|
|
4
4
|
import React from 'react';
|
|
5
5
|
import { hoistStatics } from "./hoistStatics";
|
|
6
6
|
import { selectNumberInputTextOnClick } from "./selectNumberInputTextOnClick";
|
|
7
7
|
import { flattenOptions, selectedLabels } from "./values";
|
|
8
8
|
|
|
9
|
-
/**
|
|
9
|
+
/** 普通表单控件统一阅读展示;数值控件禁用方向键步进,让表格负责上下导航。@author nokecy */
|
|
10
10
|
var readingControl = function readingControl(Control, Preview) {
|
|
11
11
|
var map = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : function (props) {
|
|
12
12
|
return props;
|
|
13
13
|
};
|
|
14
|
-
var
|
|
14
|
+
var numericInput = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
15
15
|
var Component = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
16
16
|
var _props$disabled;
|
|
17
17
|
var _ConfigProvider$useCo = ConfigProvider.useConfig(),
|
|
@@ -19,7 +19,8 @@ var readingControl = function readingControl(Control, Preview) {
|
|
|
19
19
|
var reading = props.readOnly || ((_props$disabled = props.disabled) !== null && _props$disabled !== void 0 ? _props$disabled : componentDisabled);
|
|
20
20
|
return reading ? /*#__PURE__*/React.createElement(PreviewText.Placeholder, {
|
|
21
21
|
value: "\u2014"
|
|
22
|
-
}, /*#__PURE__*/React.createElement(Preview, map(props))) : /*#__PURE__*/React.createElement(Control, _extends({}, props,
|
|
22
|
+
}, /*#__PURE__*/React.createElement(Preview, map(props))) : /*#__PURE__*/React.createElement(Control, _extends({}, props, numericInput ? {
|
|
23
|
+
keyboard: false,
|
|
23
24
|
onClick: selectNumberInputTextOnClick(props.onClick)
|
|
24
25
|
} : {}, {
|
|
25
26
|
ref: ref
|
|
@@ -52,6 +53,8 @@ Input.TextArea = readingControl(AntInput.TextArea, PreviewText.Input);
|
|
|
52
53
|
Input.Password = readingControl(AntInput.Password, PasswordPreview);
|
|
53
54
|
Input.Search = readingControl(AntInput.Search, PreviewText.Input);
|
|
54
55
|
export var InputNumber = readingControl(AntInputNumber, PreviewText.NumberPicker, undefined, true);
|
|
56
|
+
/** Formily 数值控件同样关闭方向键步进,保留数值类型及原有表单绑定。@author nokecy */
|
|
57
|
+
export var NumberPicker = readingControl(FormilyNumberPicker, PreviewText.NumberPicker, undefined, true);
|
|
55
58
|
export var Select = readingControl(AntSelect, ChoicePreview);
|
|
56
59
|
export var Switch = readingControl(AntSwitch, BooleanPreview);
|
|
57
60
|
export var Checkbox = readingControl(AntCheckbox, BooleanPreview);
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { withReactiveSchemaScope } from './schemaScope';
|
|
2
|
-
/**
|
|
2
|
+
/** 动态表单统一阅读展示;数值控件关闭方向键步进,保留表格导航与字段值。@author nokecy */
|
|
3
3
|
export declare function withReadingFields(components: Record<string, any>): Record<string, any>;
|
|
@@ -16,7 +16,7 @@ import { selectNumberInputTextOnClick } from "./selectNumberInputTextOnClick";
|
|
|
16
16
|
import { withReadingArrayTable } from "./arrayTable";
|
|
17
17
|
export { withReactiveSchemaScope } from "./schemaScope";
|
|
18
18
|
|
|
19
|
-
/**
|
|
19
|
+
/** 动态表单统一阅读展示;数值控件关闭方向键步进,保留表格导航与字段值。@author nokecy */
|
|
20
20
|
export function withReadingFields(components) {
|
|
21
21
|
var result = _objectSpread({}, components);
|
|
22
22
|
var previews = _objectSpread(_objectSpread({}, Reading), {}, {
|
|
@@ -24,7 +24,7 @@ export function withReadingFields(components) {
|
|
|
24
24
|
Password: Reading.Input.Password
|
|
25
25
|
});
|
|
26
26
|
var wrap = function wrap(Control, Preview) {
|
|
27
|
-
var
|
|
27
|
+
var numericInput = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
28
28
|
var Component = observer(function (props) {
|
|
29
29
|
var field = useField();
|
|
30
30
|
if (props.disabled || props.readOnly || field !== null && field !== void 0 && field.disabled || field !== null && field !== void 0 && field.readOnly) {
|
|
@@ -36,7 +36,8 @@ export function withReadingFields(components) {
|
|
|
36
36
|
disabled: true
|
|
37
37
|
}));
|
|
38
38
|
}
|
|
39
|
-
return /*#__PURE__*/React.createElement(Control, _extends({}, props,
|
|
39
|
+
return /*#__PURE__*/React.createElement(Control, _extends({}, props, numericInput ? {
|
|
40
|
+
keyboard: false,
|
|
40
41
|
onClick: selectNumberInputTextOnClick(props.onClick)
|
|
41
42
|
} : {}));
|
|
42
43
|
});
|
|
@@ -55,7 +56,7 @@ export function withReadingFields(components) {
|
|
|
55
56
|
try {
|
|
56
57
|
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
57
58
|
var name = _step.value;
|
|
58
|
-
result[name] = wrap(components[name], previews[name], name === 'NumberPicker');
|
|
59
|
+
result[name] = wrap(components[name], previews[name], name === 'NumberPicker' || name === 'InputNumber');
|
|
59
60
|
}
|
|
60
61
|
// ArrayTable 阅读态保留动态列的标题和显隐状态。@author nokecy
|
|
61
62
|
} catch (err) {
|
|
@@ -39,6 +39,7 @@ import "./groupedHeaders.less";
|
|
|
39
39
|
import { normalizeListDateColumn } from "./listDateDisplay";
|
|
40
40
|
import { flattenColumnDefs, inferListDefaultSort, resolveListSortPolicy, sortingText } from "./listDefaultSort";
|
|
41
41
|
import { shouldRefresh } from "./listRefresh";
|
|
42
|
+
import { installDisplaySequenceOrder, withDisplaySequencePolicy } from "../utils/gridSequence";
|
|
42
43
|
|
|
43
44
|
/**
|
|
44
45
|
* 标准列表的宿主口径。
|
|
@@ -55,11 +56,10 @@ import { shouldRefresh } from "./listRefresh";
|
|
|
55
56
|
// 序号列的字段名会随列方案保存在用户的列设置里,改名会让已保存的方案失效,所以沿用最初的字面量。
|
|
56
57
|
var SYSTEM_SEQUENCE_FIELD = '__smartErpDisplaySequence';
|
|
57
58
|
var GENERATED_SEQUENCE_FIELD = '序号';
|
|
58
|
-
var SELECTION_COLUMN_ID = 'ag-Grid-SelectionColumn';
|
|
59
59
|
|
|
60
|
-
/**
|
|
60
|
+
/** 前端生成的显示序号:固定在左侧,排在复选列之后、业务列之前。@author nokecy */
|
|
61
61
|
var makeSequenceColumn = function makeSequenceColumn() {
|
|
62
|
-
return {
|
|
62
|
+
return withDisplaySequencePolicy({
|
|
63
63
|
field: SYSTEM_SEQUENCE_FIELD,
|
|
64
64
|
headerName: GENERATED_SEQUENCE_FIELD,
|
|
65
65
|
width: 76,
|
|
@@ -76,7 +76,7 @@ var makeSequenceColumn = function makeSequenceColumn() {
|
|
|
76
76
|
var rowIndex = (_params$node2 = params.node) === null || _params$node2 === void 0 ? void 0 : _params$node2.rowIndex;
|
|
77
77
|
return rowIndex == null ? '' : rowIndex + 1;
|
|
78
78
|
}
|
|
79
|
-
};
|
|
79
|
+
});
|
|
80
80
|
};
|
|
81
81
|
var isInternalField = function isInternalField(field, headerName) {
|
|
82
82
|
return headerName.trim() === GENERATED_SEQUENCE_FIELD || /^(?:id|.*(?:lineNo|lineNumber))$/i.test(field) || /^(?:.*Id|tenantId|creatorId|lastModifierId|deleterId|extraProperties|concurrencyStamp|isDeleted|deletionTime)$/i.test(field);
|
|
@@ -391,7 +391,6 @@ var StandardAgGridPlus = function StandardAgGridPlus(props) {
|
|
|
391
391
|
_useState4 = _slicedToArray(_useState3, 2),
|
|
392
392
|
lastError = _useState4[0],
|
|
393
393
|
setLastError = _useState4[1];
|
|
394
|
-
var selectionColumnOrderSyncPending = useRef(false);
|
|
395
394
|
var sequenceColumn = useMemo(function () {
|
|
396
395
|
return makeSequenceColumn();
|
|
397
396
|
}, []);
|
|
@@ -592,32 +591,7 @@ var StandardAgGridPlus = function StandardAgGridPlus(props) {
|
|
|
592
591
|
});
|
|
593
592
|
});
|
|
594
593
|
};
|
|
595
|
-
|
|
596
|
-
if (selectionColumnOrderSyncPending.current) return;
|
|
597
|
-
selectionColumnOrderSyncPending.current = true;
|
|
598
|
-
Promise.resolve().then(function () {
|
|
599
|
-
selectionColumnOrderSyncPending.current = false;
|
|
600
|
-
if (api.isDestroyed()) return;
|
|
601
|
-
var columnState = api.getColumnState();
|
|
602
|
-
var selectionIndex = columnState.findIndex(function (column) {
|
|
603
|
-
return column.colId === SELECTION_COLUMN_ID;
|
|
604
|
-
});
|
|
605
|
-
if (selectionIndex < 0) return;
|
|
606
|
-
var selectionColumn = columnState[selectionIndex];
|
|
607
|
-
if (selectionIndex === 0 && selectionColumn.pinned === 'left') return;
|
|
608
|
-
columnState.splice(selectionIndex, 1);
|
|
609
|
-
api.applyColumnState({
|
|
610
|
-
state: [_objectSpread(_objectSpread({}, selectionColumn), {}, {
|
|
611
|
-
pinned: 'left'
|
|
612
|
-
})].concat(_toConsumableArray(columnState)),
|
|
613
|
-
applyOrder: true
|
|
614
|
-
});
|
|
615
|
-
});
|
|
616
|
-
};
|
|
617
|
-
// 复选列固定在最左侧;序号列默认排在其后,用户仍可拖动或通过列方案调整。
|
|
618
|
-
api.addEventListener('columnEverythingChanged', keepSelectionColumnFirst);
|
|
619
|
-
api.addEventListener('columnPinned', keepSelectionColumnFirst);
|
|
620
|
-
api.addEventListener('columnMoved', keepSelectionColumnFirst);
|
|
594
|
+
installDisplaySequenceOrder(api);
|
|
621
595
|
// 列方案、显隐、拖动、固定或折叠分组后,按当前显示分组更新边框。@author nokecy
|
|
622
596
|
var compositeRefreshPending = false;
|
|
623
597
|
var styledRuntimeColumns = new WeakSet();
|
|
@@ -658,7 +632,6 @@ var StandardAgGridPlus = function StandardAgGridPlus(props) {
|
|
|
658
632
|
api.addEventListener('paginationChanged', refreshSequence);
|
|
659
633
|
api.addEventListener('sortChanged', refreshSequence);
|
|
660
634
|
api.addEventListener('filterChanged', refreshSequence);
|
|
661
|
-
keepSelectionColumnFirst();
|
|
662
635
|
(_restProps$onGridRead = restProps.onGridReady) === null || _restProps$onGridRead === void 0 || _restProps$onGridRead.call(restProps, event);
|
|
663
636
|
}, [restProps.onGridReady]);
|
|
664
637
|
var columnDefs = useMemo(function () {
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ColDef, GridApi } from 'ag-grid-community';
|
|
2
|
+
/** 显示序号始终可见、左固定;列方案仍可调整其他业务列。@author nokecy */
|
|
3
|
+
export declare const withDisplaySequencePolicy: <T extends ColDef<any, any>>(column: T) => T;
|
|
4
|
+
/**
|
|
5
|
+
* 首次加载及列方案恢复后,保持“选择框、显示序号、业务列”的顺序。
|
|
6
|
+
* 只校正系统列的位置和可见性,保留业务列的宽度、固定、显隐及相对顺序。
|
|
7
|
+
* @author nokecy
|
|
8
|
+
*/
|
|
9
|
+
export declare const installDisplaySequenceOrder: (api: GridApi) => void;
|
|
@@ -0,0 +1,104 @@
|
|
|
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 _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
3
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
4
|
+
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); }
|
|
5
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
6
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
7
|
+
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; }
|
|
8
|
+
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; }
|
|
9
|
+
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; }
|
|
10
|
+
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; }
|
|
11
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
12
|
+
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); }
|
|
13
|
+
/** 由表格生成、与业务行号无关的显示序号标记。@author nokecy */
|
|
14
|
+
var DISPLAY_SEQUENCE_CONTEXT_KEY = 'qcDisplaySequence';
|
|
15
|
+
var SELECTION_COLUMN_ID = 'ag-Grid-SelectionColumn';
|
|
16
|
+
var GENERATED_SEQUENCE_IDS = new Set(['__arrayTableIndex', '__smartErpDisplaySequence', '序号']);
|
|
17
|
+
var installedGrids = new WeakSet();
|
|
18
|
+
|
|
19
|
+
/** 显示序号始终可见、左固定;列方案仍可调整其他业务列。@author nokecy */
|
|
20
|
+
export var withDisplaySequencePolicy = function withDisplaySequencePolicy(column) {
|
|
21
|
+
return _objectSpread(_objectSpread({}, column), {}, {
|
|
22
|
+
context: _objectSpread(_objectSpread({}, column.context), {}, _defineProperty({}, DISPLAY_SEQUENCE_CONTEXT_KEY, true)),
|
|
23
|
+
pinned: 'left',
|
|
24
|
+
hide: false,
|
|
25
|
+
initialHide: false,
|
|
26
|
+
lockPosition: false,
|
|
27
|
+
lockPinned: true,
|
|
28
|
+
lockVisible: true,
|
|
29
|
+
suppressMovable: true,
|
|
30
|
+
suppressColumnsToolPanel: true,
|
|
31
|
+
sortable: false,
|
|
32
|
+
filter: false,
|
|
33
|
+
editable: false
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* 首次加载及列方案恢复后,保持“选择框、显示序号、业务列”的顺序。
|
|
39
|
+
* 只校正系统列的位置和可见性,保留业务列的宽度、固定、显隐及相对顺序。
|
|
40
|
+
* @author nokecy
|
|
41
|
+
*/
|
|
42
|
+
export var installDisplaySequenceOrder = function installDisplaySequenceOrder(api) {
|
|
43
|
+
if (installedGrids.has(api)) return;
|
|
44
|
+
installedGrids.add(api);
|
|
45
|
+
var pending = false;
|
|
46
|
+
var applying = false;
|
|
47
|
+
var schedule = function schedule() {
|
|
48
|
+
if (pending || applying) return;
|
|
49
|
+
pending = true;
|
|
50
|
+
Promise.resolve().then(function () {
|
|
51
|
+
var _api$getColumns;
|
|
52
|
+
pending = false;
|
|
53
|
+
if (api.isDestroyed()) return;
|
|
54
|
+
var markedIds = new Set(((_api$getColumns = api.getColumns()) !== null && _api$getColumns !== void 0 ? _api$getColumns : []).filter(function (column) {
|
|
55
|
+
var _column$getColDef$con;
|
|
56
|
+
return (_column$getColDef$con = column.getColDef().context) === null || _column$getColDef$con === void 0 ? void 0 : _column$getColDef$con[DISPLAY_SEQUENCE_CONTEXT_KEY];
|
|
57
|
+
}).map(function (column) {
|
|
58
|
+
return column.getColId();
|
|
59
|
+
}));
|
|
60
|
+
var state = api.getColumnState();
|
|
61
|
+
var isSequence = function isSequence(colId) {
|
|
62
|
+
return GENERATED_SEQUENCE_IDS.has(colId) || markedIds.has(colId);
|
|
63
|
+
};
|
|
64
|
+
var selection = state.find(function (column) {
|
|
65
|
+
return column.colId === SELECTION_COLUMN_ID;
|
|
66
|
+
});
|
|
67
|
+
var sequences = state.filter(function (column) {
|
|
68
|
+
return isSequence(column.colId);
|
|
69
|
+
});
|
|
70
|
+
var prefix = [].concat(_toConsumableArray(selection ? [_objectSpread(_objectSpread({}, selection), {}, {
|
|
71
|
+
pinned: 'left'
|
|
72
|
+
})] : []), _toConsumableArray(sequences.map(function (column) {
|
|
73
|
+
return _objectSpread(_objectSpread({}, column), {}, {
|
|
74
|
+
pinned: 'left',
|
|
75
|
+
hide: false
|
|
76
|
+
});
|
|
77
|
+
})));
|
|
78
|
+
if (prefix.every(function (column, index) {
|
|
79
|
+
var _state$index, _state$index2, _state$index3;
|
|
80
|
+
return ((_state$index = state[index]) === null || _state$index === void 0 ? void 0 : _state$index.colId) === column.colId && ((_state$index2 = state[index]) === null || _state$index2 === void 0 ? void 0 : _state$index2.pinned) === 'left' && (!isSequence(column.colId) || ((_state$index3 = state[index]) === null || _state$index3 === void 0 ? void 0 : _state$index3.hide) !== true);
|
|
81
|
+
})) return;
|
|
82
|
+
var prefixIds = new Set(prefix.map(function (column) {
|
|
83
|
+
return column.colId;
|
|
84
|
+
}));
|
|
85
|
+
applying = true;
|
|
86
|
+
try {
|
|
87
|
+
api.applyColumnState({
|
|
88
|
+
state: [].concat(_toConsumableArray(prefix), _toConsumableArray(state.filter(function (column) {
|
|
89
|
+
return !prefixIds.has(column.colId);
|
|
90
|
+
}))),
|
|
91
|
+
applyOrder: true
|
|
92
|
+
});
|
|
93
|
+
} finally {
|
|
94
|
+
applying = false;
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
};
|
|
98
|
+
api.addEventListener('newColumnsLoaded', schedule);
|
|
99
|
+
api.addEventListener('columnEverythingChanged', schedule);
|
|
100
|
+
api.addEventListener('columnPinned', schedule);
|
|
101
|
+
api.addEventListener('columnMoved', schedule);
|
|
102
|
+
api.addEventListener('columnVisible', schedule);
|
|
103
|
+
schedule();
|
|
104
|
+
};
|