@nokecy/qc-ui 1.1.54 → 1.1.55
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/ag-gridPlus.js +3 -52
- package/dist/cjs/ag-grid-plus/interface.d.ts +11 -1
- package/dist/cjs/ag-grid-plus/types.d.ts +7 -1
- package/dist/cjs/ag-grid-plus/utils/columnProcessors.d.ts +14 -2
- package/dist/cjs/ag-grid-plus/utils/columnProcessors.js +25 -8
- package/dist/esm/ag-grid-plus/ag-gridPlus.js +4 -53
- package/dist/esm/ag-grid-plus/interface.d.ts +11 -1
- package/dist/esm/ag-grid-plus/types.d.ts +7 -1
- package/dist/esm/ag-grid-plus/utils/columnProcessors.d.ts +14 -2
- package/dist/esm/ag-grid-plus/utils/columnProcessors.js +25 -8
- package/dist/umd/qc-ui.min.js +1 -1
- package/package.json +1 -1
|
@@ -30,7 +30,6 @@ var _constants = require("./utils/constants");
|
|
|
30
30
|
var _emptyState = require("./utils/emptyState");
|
|
31
31
|
var _processColumnGroups = _interopRequireDefault(require("./_utils/processColumnGroups"));
|
|
32
32
|
var _processFormColumnState = _interopRequireDefault(require("./_utils/processFormColumnState"));
|
|
33
|
-
var _antdV = require("@formily/antd-v5");
|
|
34
33
|
var _locale = require("./locale");
|
|
35
34
|
var _gridContext = require("./context/gridContext");
|
|
36
35
|
var _queryFormContext = require("./context/queryFormContext");
|
|
@@ -468,57 +467,9 @@ function AgGridPlus(props) {
|
|
|
468
467
|
var processColumnConfig = function processColumnConfig(col, data) {
|
|
469
468
|
var dataType = getDataType(data, col.field || '', col.valueEnum);
|
|
470
469
|
if (col.valueEnum && Array.isArray(col.valueEnum)) {
|
|
471
|
-
|
|
472
|
-
//
|
|
473
|
-
|
|
474
|
-
var defaultItems = valueEnum.filter(function (item) {
|
|
475
|
-
return item.default;
|
|
476
|
-
});
|
|
477
|
-
var isMultiple = defaultItems.length > 1;
|
|
478
|
-
var defaultValue = isMultiple ? defaultItems.map(function (item) {
|
|
479
|
-
return item.value;
|
|
480
|
-
}) : (_defaultItems$0$value = (_defaultItems$ = defaultItems[0]) === null || _defaultItems$ === void 0 ? void 0 : _defaultItems$.value) !== null && _defaultItems$0$value !== void 0 ? _defaultItems$0$value : undefined;
|
|
481
|
-
var valueFormatter = function valueFormatter(params) {
|
|
482
|
-
var match = valueEnum.find(function (item) {
|
|
483
|
-
return item.value == params.value;
|
|
484
|
-
});
|
|
485
|
-
return match ? match.label : params.value;
|
|
486
|
-
};
|
|
487
|
-
return _objectSpread(_objectSpread(_objectSpread({}, (0, _columnProcessors.toColumnType)(dataType)), col), {}, {
|
|
488
|
-
cellRenderer: function cellRenderer(params) {
|
|
489
|
-
var match = valueEnum.find(function (item) {
|
|
490
|
-
return item.value == params.value;
|
|
491
|
-
});
|
|
492
|
-
if (match) {
|
|
493
|
-
// 没配颜色的枚举项曾经默认成 '#ffffff'——白底白字,那一列直接看不见。
|
|
494
|
-
// 消费端为此在 global.less 里加了一整套 [style*="color: white"] → 紫色的覆盖来擦屁股,
|
|
495
|
-
// 顺带把别的颜色也一起改了。这里改成 inherit,跟着单元格的正文色走。@author nokecy
|
|
496
|
-
var color = match.color || 'inherit';
|
|
497
|
-
return /*#__PURE__*/_react.default.createElement("span", {
|
|
498
|
-
style: {
|
|
499
|
-
color: color,
|
|
500
|
-
backgroundColor: 'transparent',
|
|
501
|
-
fontWeight: 500
|
|
502
|
-
}
|
|
503
|
-
}, match.label);
|
|
504
|
-
}
|
|
505
|
-
return params.value;
|
|
506
|
-
},
|
|
507
|
-
filterParams: _objectSpread(_objectSpread({}, col.filterParams || {}), {}, {
|
|
508
|
-
valueFormatter: valueFormatter
|
|
509
|
-
}),
|
|
510
|
-
searchComponent: _antdV.Select,
|
|
511
|
-
searchComponentProps: {
|
|
512
|
-
options: col.valueEnum.map(function (item) {
|
|
513
|
-
return {
|
|
514
|
-
label: item.label,
|
|
515
|
-
value: item.value
|
|
516
|
-
};
|
|
517
|
-
}),
|
|
518
|
-
mode: isMultiple ? "multiple" : undefined,
|
|
519
|
-
defaultValue: defaultValue
|
|
520
|
-
}
|
|
521
|
-
});
|
|
470
|
+
// 枚举列渲染只走一处实现,见 columnProcessors.processEnumColumn
|
|
471
|
+
// (命中上色、未命中交给 col.enumFallbackRenderer,都没配则回原始码)
|
|
472
|
+
return (0, _columnProcessors.processEnumColumn)(col, dataType);
|
|
522
473
|
}
|
|
523
474
|
if (col.type || typeof col.cellRenderer == "string") {
|
|
524
475
|
return _objectSpread({}, col);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { GridApi, ColDef, ColGroupDef } from "ag-grid-community";
|
|
1
|
+
import { GridApi, ColDef, ColGroupDef, ICellRendererParams } from "ag-grid-community";
|
|
2
2
|
import { AgGridReactProps } from "ag-grid-react";
|
|
3
3
|
import React, { CSSProperties, ReactNode } from "react";
|
|
4
4
|
import type { GridPlusError } from "./errors";
|
|
@@ -157,6 +157,16 @@ interface AgGridColumnPropsClone extends ColDef {
|
|
|
157
157
|
color?: string;
|
|
158
158
|
default?: boolean;
|
|
159
159
|
}>;
|
|
160
|
+
/**
|
|
161
|
+
* `valueEnum` **未命中**时的渲染接管(`null` / `undefined` / 空串 / 后端新增码值都走这里)。
|
|
162
|
+
*
|
|
163
|
+
* 不传则原样输出该值(历史行为,向后兼容)。业务侧用它输出中性「—」/「未知(原码)」:
|
|
164
|
+
* ```tsx
|
|
165
|
+
* enumFallbackRenderer: ({ value }) => <span style={{ color: '#595959' }}>{enumDisplayText(value)}</span>
|
|
166
|
+
* ```
|
|
167
|
+
* 命中枚举项时不会调用它(那一支有固定的上色渲染)。
|
|
168
|
+
*/
|
|
169
|
+
enumFallbackRenderer?: (params: ICellRendererParams) => ReactNode;
|
|
160
170
|
searchComponent?: ReactNode | JSX.Element | ((props: any) => JSX.Element);
|
|
161
171
|
searchComponentProps?: any;
|
|
162
172
|
searchSort?: number;
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* 此文件定义了 AgGridPlus 组件的所有核心类型接口,
|
|
5
5
|
* 用于替换代码中的 any 类型,提高类型安全性
|
|
6
6
|
*/
|
|
7
|
-
import { ColumnState, GridApi, ColDef } from 'ag-grid-community';
|
|
7
|
+
import { ColumnState, GridApi, ColDef, ICellRendererParams } from 'ag-grid-community';
|
|
8
8
|
import { ReactNode } from 'react';
|
|
9
9
|
/**
|
|
10
10
|
* 分页状态
|
|
@@ -132,6 +132,12 @@ export interface ExtendedColDef extends ColDef {
|
|
|
132
132
|
ellipsis?: boolean;
|
|
133
133
|
/** 枚举值配置 */
|
|
134
134
|
valueEnum?: ValueEnumItem[];
|
|
135
|
+
/**
|
|
136
|
+
* `valueEnum` **未命中**时的渲染接管(`null` / `undefined` / 空串 / 后端新增码值都走这里)。
|
|
137
|
+
* 不传则原样输出该值(历史行为,向后兼容)。业务侧据此输出中性「—」/「未知(原码)」。
|
|
138
|
+
* 命中枚举项的渲染不受它影响。
|
|
139
|
+
*/
|
|
140
|
+
enumFallbackRenderer?: (params: ICellRendererParams) => ReactNode;
|
|
135
141
|
/** 自定义搜索组件 */
|
|
136
142
|
searchComponent?: ReactNode | ((props: any) => JSX.Element);
|
|
137
143
|
/** 搜索组件属性 */
|
|
@@ -66,11 +66,23 @@ export declare function toColumnType(dataType?: DataTypeInference): {
|
|
|
66
66
|
type?: string;
|
|
67
67
|
};
|
|
68
68
|
/**
|
|
69
|
-
* 处理枚举列定义
|
|
69
|
+
* 处理枚举列定义 —— **枚举列渲染的唯一实现**。
|
|
70
|
+
*
|
|
71
|
+
* `cellRenderer` 必须在 `...col` 展开**之后**写入:否则业务传入的 `cellRenderer` 会把枚举映射盖掉,
|
|
72
|
+
* 列退回原始码;反过来,业务也无法靠自己的 `cellRenderer` 接管枚举列(这正是本函数的职责边界)。
|
|
73
|
+
*
|
|
74
|
+
* 命中枚举项:按 `match.color` 上色。`color` 是 **CSS 颜色**,语义档名(`success` 等)不是合法 CSS,
|
|
75
|
+
* 会被浏览器静默忽略、整列退回正文色 —— 消费方需用 `gridValueEnum()` 之类适配层先转成色值。
|
|
76
|
+
*
|
|
77
|
+
* **未命中枚举**(`null` / `undefined` / 空串 / 后端新增了码值而前端枚举未跟上):
|
|
78
|
+
* - 列上配了 `enumFallbackRenderer` → 交给它渲染。业务侧据此输出中性「—」/「未知(原码)」,
|
|
79
|
+
* 不必再改壳;
|
|
80
|
+
* - 没配 → 原样返回该值(历史行为,保持向后兼容)。
|
|
70
81
|
*
|
|
71
82
|
* @param col 原始列定义
|
|
72
|
-
* @param dataType
|
|
83
|
+
* @param dataType 数据类型(决定是否右对齐,见 {@link toColumnType})
|
|
73
84
|
* @returns 处理后的列定义
|
|
85
|
+
* @author nokecy
|
|
74
86
|
*/
|
|
75
87
|
export declare function processEnumColumn(col: any, dataType?: DataTypeInference): ColDef;
|
|
76
88
|
/**
|
|
@@ -123,20 +123,33 @@ function toColumnType(dataType) {
|
|
|
123
123
|
}
|
|
124
124
|
|
|
125
125
|
/**
|
|
126
|
-
* 处理枚举列定义
|
|
126
|
+
* 处理枚举列定义 —— **枚举列渲染的唯一实现**。
|
|
127
|
+
*
|
|
128
|
+
* `cellRenderer` 必须在 `...col` 展开**之后**写入:否则业务传入的 `cellRenderer` 会把枚举映射盖掉,
|
|
129
|
+
* 列退回原始码;反过来,业务也无法靠自己的 `cellRenderer` 接管枚举列(这正是本函数的职责边界)。
|
|
130
|
+
*
|
|
131
|
+
* 命中枚举项:按 `match.color` 上色。`color` 是 **CSS 颜色**,语义档名(`success` 等)不是合法 CSS,
|
|
132
|
+
* 会被浏览器静默忽略、整列退回正文色 —— 消费方需用 `gridValueEnum()` 之类适配层先转成色值。
|
|
133
|
+
*
|
|
134
|
+
* **未命中枚举**(`null` / `undefined` / 空串 / 后端新增了码值而前端枚举未跟上):
|
|
135
|
+
* - 列上配了 `enumFallbackRenderer` → 交给它渲染。业务侧据此输出中性「—」/「未知(原码)」,
|
|
136
|
+
* 不必再改壳;
|
|
137
|
+
* - 没配 → 原样返回该值(历史行为,保持向后兼容)。
|
|
127
138
|
*
|
|
128
139
|
* @param col 原始列定义
|
|
129
|
-
* @param dataType
|
|
140
|
+
* @param dataType 数据类型(决定是否右对齐,见 {@link toColumnType})
|
|
130
141
|
* @returns 处理后的列定义
|
|
142
|
+
* @author nokecy
|
|
131
143
|
*/
|
|
132
144
|
function processEnumColumn(col, dataType) {
|
|
133
145
|
var _defaultItems$0$value, _defaultItems$;
|
|
134
|
-
|
|
146
|
+
var valueEnum = col === null || col === void 0 ? void 0 : col.valueEnum;
|
|
147
|
+
if (!valueEnum || !Array.isArray(valueEnum)) {
|
|
135
148
|
return col;
|
|
136
149
|
}
|
|
137
150
|
|
|
138
151
|
// 统计默认值
|
|
139
|
-
var defaultItems =
|
|
152
|
+
var defaultItems = valueEnum.filter(function (item) {
|
|
140
153
|
return item.default;
|
|
141
154
|
});
|
|
142
155
|
var isMultiple = defaultItems.length > 1;
|
|
@@ -146,14 +159,15 @@ function processEnumColumn(col, dataType) {
|
|
|
146
159
|
|
|
147
160
|
// 值格式化函数
|
|
148
161
|
var valueFormatter = function valueFormatter(params) {
|
|
149
|
-
var match =
|
|
162
|
+
var match = valueEnum.find(function (item) {
|
|
150
163
|
return item.value == params.value;
|
|
151
164
|
});
|
|
152
165
|
return match ? match.label : params.value;
|
|
153
166
|
};
|
|
154
|
-
|
|
167
|
+
var fallbackRenderer = col.enumFallbackRenderer;
|
|
168
|
+
return _objectSpread(_objectSpread(_objectSpread({}, toColumnType(dataType)), col), {}, {
|
|
155
169
|
cellRenderer: function cellRenderer(params) {
|
|
156
|
-
var match =
|
|
170
|
+
var match = valueEnum.find(function (item) {
|
|
157
171
|
return item.value == params.value;
|
|
158
172
|
});
|
|
159
173
|
if (match) {
|
|
@@ -169,6 +183,9 @@ function processEnumColumn(col, dataType) {
|
|
|
169
183
|
}
|
|
170
184
|
}, match.label);
|
|
171
185
|
}
|
|
186
|
+
if (typeof fallbackRenderer === 'function') {
|
|
187
|
+
return fallbackRenderer(params);
|
|
188
|
+
}
|
|
172
189
|
return params.value;
|
|
173
190
|
},
|
|
174
191
|
filterParams: _objectSpread(_objectSpread({}, col.filterParams || {}), {}, {
|
|
@@ -176,7 +193,7 @@ function processEnumColumn(col, dataType) {
|
|
|
176
193
|
}),
|
|
177
194
|
searchComponent: _antdV.Select,
|
|
178
195
|
searchComponentProps: {
|
|
179
|
-
options:
|
|
196
|
+
options: valueEnum.map(function (item) {
|
|
180
197
|
return {
|
|
181
198
|
label: item.label,
|
|
182
199
|
value: item.value
|
|
@@ -36,7 +36,7 @@ import ToolBar from "./toolBar";
|
|
|
36
36
|
import SettingItem from "./settingItem";
|
|
37
37
|
import { RedoOutlined, FilterOutlined } from '@ant-design/icons';
|
|
38
38
|
import { convertFilterModel, dateTimeValueFormatter, dateValueFormatter, flatten, toTree } from "./utils";
|
|
39
|
-
import { toColumnType } from "./utils/columnProcessors";
|
|
39
|
+
import { processEnumColumn, toColumnType } from "./utils/columnProcessors";
|
|
40
40
|
import AdvancedQueryBuilder from "./queryForm/AdvancedQueryBuilder";
|
|
41
41
|
import { v4 as uuidv4 } from 'uuid';
|
|
42
42
|
import Setting from "./setting";
|
|
@@ -49,7 +49,6 @@ import { DEFAULT_PAGE_SIZE_OPTIONS } from "./utils/constants";
|
|
|
49
49
|
import { hasEffectiveFilter, resolveEmptyBranch, resolveEmptyText } from "./utils/emptyState";
|
|
50
50
|
import processColumnGroups from "./_utils/processColumnGroups";
|
|
51
51
|
import flattenColumnState from "./_utils/processFormColumnState";
|
|
52
|
-
import { Select } from '@formily/antd-v5';
|
|
53
52
|
import { localeText } from "./locale";
|
|
54
53
|
import { GridPlusContext } from "./context/gridContext";
|
|
55
54
|
import { QueryFormContext } from "./context/queryFormContext";
|
|
@@ -460,57 +459,9 @@ function AgGridPlus(props) {
|
|
|
460
459
|
var processColumnConfig = function processColumnConfig(col, data) {
|
|
461
460
|
var dataType = getDataType(data, col.field || '', col.valueEnum);
|
|
462
461
|
if (col.valueEnum && Array.isArray(col.valueEnum)) {
|
|
463
|
-
|
|
464
|
-
//
|
|
465
|
-
|
|
466
|
-
var defaultItems = valueEnum.filter(function (item) {
|
|
467
|
-
return item.default;
|
|
468
|
-
});
|
|
469
|
-
var isMultiple = defaultItems.length > 1;
|
|
470
|
-
var defaultValue = isMultiple ? defaultItems.map(function (item) {
|
|
471
|
-
return item.value;
|
|
472
|
-
}) : (_defaultItems$0$value = (_defaultItems$ = defaultItems[0]) === null || _defaultItems$ === void 0 ? void 0 : _defaultItems$.value) !== null && _defaultItems$0$value !== void 0 ? _defaultItems$0$value : undefined;
|
|
473
|
-
var valueFormatter = function valueFormatter(params) {
|
|
474
|
-
var match = valueEnum.find(function (item) {
|
|
475
|
-
return item.value == params.value;
|
|
476
|
-
});
|
|
477
|
-
return match ? match.label : params.value;
|
|
478
|
-
};
|
|
479
|
-
return _objectSpread(_objectSpread(_objectSpread({}, toColumnType(dataType)), col), {}, {
|
|
480
|
-
cellRenderer: function cellRenderer(params) {
|
|
481
|
-
var match = valueEnum.find(function (item) {
|
|
482
|
-
return item.value == params.value;
|
|
483
|
-
});
|
|
484
|
-
if (match) {
|
|
485
|
-
// 没配颜色的枚举项曾经默认成 '#ffffff'——白底白字,那一列直接看不见。
|
|
486
|
-
// 消费端为此在 global.less 里加了一整套 [style*="color: white"] → 紫色的覆盖来擦屁股,
|
|
487
|
-
// 顺带把别的颜色也一起改了。这里改成 inherit,跟着单元格的正文色走。@author nokecy
|
|
488
|
-
var color = match.color || 'inherit';
|
|
489
|
-
return /*#__PURE__*/React.createElement("span", {
|
|
490
|
-
style: {
|
|
491
|
-
color: color,
|
|
492
|
-
backgroundColor: 'transparent',
|
|
493
|
-
fontWeight: 500
|
|
494
|
-
}
|
|
495
|
-
}, match.label);
|
|
496
|
-
}
|
|
497
|
-
return params.value;
|
|
498
|
-
},
|
|
499
|
-
filterParams: _objectSpread(_objectSpread({}, col.filterParams || {}), {}, {
|
|
500
|
-
valueFormatter: valueFormatter
|
|
501
|
-
}),
|
|
502
|
-
searchComponent: Select,
|
|
503
|
-
searchComponentProps: {
|
|
504
|
-
options: col.valueEnum.map(function (item) {
|
|
505
|
-
return {
|
|
506
|
-
label: item.label,
|
|
507
|
-
value: item.value
|
|
508
|
-
};
|
|
509
|
-
}),
|
|
510
|
-
mode: isMultiple ? "multiple" : undefined,
|
|
511
|
-
defaultValue: defaultValue
|
|
512
|
-
}
|
|
513
|
-
});
|
|
462
|
+
// 枚举列渲染只走一处实现,见 columnProcessors.processEnumColumn
|
|
463
|
+
// (命中上色、未命中交给 col.enumFallbackRenderer,都没配则回原始码)
|
|
464
|
+
return processEnumColumn(col, dataType);
|
|
514
465
|
}
|
|
515
466
|
if (col.type || typeof col.cellRenderer == "string") {
|
|
516
467
|
return _objectSpread({}, col);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { GridApi, ColDef, ColGroupDef } from "ag-grid-community";
|
|
1
|
+
import { GridApi, ColDef, ColGroupDef, ICellRendererParams } from "ag-grid-community";
|
|
2
2
|
import { AgGridReactProps } from "ag-grid-react";
|
|
3
3
|
import React, { CSSProperties, ReactNode } from "react";
|
|
4
4
|
import type { GridPlusError } from "./errors";
|
|
@@ -157,6 +157,16 @@ interface AgGridColumnPropsClone extends ColDef {
|
|
|
157
157
|
color?: string;
|
|
158
158
|
default?: boolean;
|
|
159
159
|
}>;
|
|
160
|
+
/**
|
|
161
|
+
* `valueEnum` **未命中**时的渲染接管(`null` / `undefined` / 空串 / 后端新增码值都走这里)。
|
|
162
|
+
*
|
|
163
|
+
* 不传则原样输出该值(历史行为,向后兼容)。业务侧用它输出中性「—」/「未知(原码)」:
|
|
164
|
+
* ```tsx
|
|
165
|
+
* enumFallbackRenderer: ({ value }) => <span style={{ color: '#595959' }}>{enumDisplayText(value)}</span>
|
|
166
|
+
* ```
|
|
167
|
+
* 命中枚举项时不会调用它(那一支有固定的上色渲染)。
|
|
168
|
+
*/
|
|
169
|
+
enumFallbackRenderer?: (params: ICellRendererParams) => ReactNode;
|
|
160
170
|
searchComponent?: ReactNode | JSX.Element | ((props: any) => JSX.Element);
|
|
161
171
|
searchComponentProps?: any;
|
|
162
172
|
searchSort?: number;
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* 此文件定义了 AgGridPlus 组件的所有核心类型接口,
|
|
5
5
|
* 用于替换代码中的 any 类型,提高类型安全性
|
|
6
6
|
*/
|
|
7
|
-
import { ColumnState, GridApi, ColDef } from 'ag-grid-community';
|
|
7
|
+
import { ColumnState, GridApi, ColDef, ICellRendererParams } from 'ag-grid-community';
|
|
8
8
|
import { ReactNode } from 'react';
|
|
9
9
|
/**
|
|
10
10
|
* 分页状态
|
|
@@ -132,6 +132,12 @@ export interface ExtendedColDef extends ColDef {
|
|
|
132
132
|
ellipsis?: boolean;
|
|
133
133
|
/** 枚举值配置 */
|
|
134
134
|
valueEnum?: ValueEnumItem[];
|
|
135
|
+
/**
|
|
136
|
+
* `valueEnum` **未命中**时的渲染接管(`null` / `undefined` / 空串 / 后端新增码值都走这里)。
|
|
137
|
+
* 不传则原样输出该值(历史行为,向后兼容)。业务侧据此输出中性「—」/「未知(原码)」。
|
|
138
|
+
* 命中枚举项的渲染不受它影响。
|
|
139
|
+
*/
|
|
140
|
+
enumFallbackRenderer?: (params: ICellRendererParams) => ReactNode;
|
|
135
141
|
/** 自定义搜索组件 */
|
|
136
142
|
searchComponent?: ReactNode | ((props: any) => JSX.Element);
|
|
137
143
|
/** 搜索组件属性 */
|
|
@@ -66,11 +66,23 @@ export declare function toColumnType(dataType?: DataTypeInference): {
|
|
|
66
66
|
type?: string;
|
|
67
67
|
};
|
|
68
68
|
/**
|
|
69
|
-
* 处理枚举列定义
|
|
69
|
+
* 处理枚举列定义 —— **枚举列渲染的唯一实现**。
|
|
70
|
+
*
|
|
71
|
+
* `cellRenderer` 必须在 `...col` 展开**之后**写入:否则业务传入的 `cellRenderer` 会把枚举映射盖掉,
|
|
72
|
+
* 列退回原始码;反过来,业务也无法靠自己的 `cellRenderer` 接管枚举列(这正是本函数的职责边界)。
|
|
73
|
+
*
|
|
74
|
+
* 命中枚举项:按 `match.color` 上色。`color` 是 **CSS 颜色**,语义档名(`success` 等)不是合法 CSS,
|
|
75
|
+
* 会被浏览器静默忽略、整列退回正文色 —— 消费方需用 `gridValueEnum()` 之类适配层先转成色值。
|
|
76
|
+
*
|
|
77
|
+
* **未命中枚举**(`null` / `undefined` / 空串 / 后端新增了码值而前端枚举未跟上):
|
|
78
|
+
* - 列上配了 `enumFallbackRenderer` → 交给它渲染。业务侧据此输出中性「—」/「未知(原码)」,
|
|
79
|
+
* 不必再改壳;
|
|
80
|
+
* - 没配 → 原样返回该值(历史行为,保持向后兼容)。
|
|
70
81
|
*
|
|
71
82
|
* @param col 原始列定义
|
|
72
|
-
* @param dataType
|
|
83
|
+
* @param dataType 数据类型(决定是否右对齐,见 {@link toColumnType})
|
|
73
84
|
* @returns 处理后的列定义
|
|
85
|
+
* @author nokecy
|
|
74
86
|
*/
|
|
75
87
|
export declare function processEnumColumn(col: any, dataType?: DataTypeInference): ColDef;
|
|
76
88
|
/**
|
|
@@ -108,20 +108,33 @@ export function toColumnType(dataType) {
|
|
|
108
108
|
}
|
|
109
109
|
|
|
110
110
|
/**
|
|
111
|
-
* 处理枚举列定义
|
|
111
|
+
* 处理枚举列定义 —— **枚举列渲染的唯一实现**。
|
|
112
|
+
*
|
|
113
|
+
* `cellRenderer` 必须在 `...col` 展开**之后**写入:否则业务传入的 `cellRenderer` 会把枚举映射盖掉,
|
|
114
|
+
* 列退回原始码;反过来,业务也无法靠自己的 `cellRenderer` 接管枚举列(这正是本函数的职责边界)。
|
|
115
|
+
*
|
|
116
|
+
* 命中枚举项:按 `match.color` 上色。`color` 是 **CSS 颜色**,语义档名(`success` 等)不是合法 CSS,
|
|
117
|
+
* 会被浏览器静默忽略、整列退回正文色 —— 消费方需用 `gridValueEnum()` 之类适配层先转成色值。
|
|
118
|
+
*
|
|
119
|
+
* **未命中枚举**(`null` / `undefined` / 空串 / 后端新增了码值而前端枚举未跟上):
|
|
120
|
+
* - 列上配了 `enumFallbackRenderer` → 交给它渲染。业务侧据此输出中性「—」/「未知(原码)」,
|
|
121
|
+
* 不必再改壳;
|
|
122
|
+
* - 没配 → 原样返回该值(历史行为,保持向后兼容)。
|
|
112
123
|
*
|
|
113
124
|
* @param col 原始列定义
|
|
114
|
-
* @param dataType
|
|
125
|
+
* @param dataType 数据类型(决定是否右对齐,见 {@link toColumnType})
|
|
115
126
|
* @returns 处理后的列定义
|
|
127
|
+
* @author nokecy
|
|
116
128
|
*/
|
|
117
129
|
export function processEnumColumn(col, dataType) {
|
|
118
130
|
var _defaultItems$0$value, _defaultItems$;
|
|
119
|
-
|
|
131
|
+
var valueEnum = col === null || col === void 0 ? void 0 : col.valueEnum;
|
|
132
|
+
if (!valueEnum || !Array.isArray(valueEnum)) {
|
|
120
133
|
return col;
|
|
121
134
|
}
|
|
122
135
|
|
|
123
136
|
// 统计默认值
|
|
124
|
-
var defaultItems =
|
|
137
|
+
var defaultItems = valueEnum.filter(function (item) {
|
|
125
138
|
return item.default;
|
|
126
139
|
});
|
|
127
140
|
var isMultiple = defaultItems.length > 1;
|
|
@@ -131,14 +144,15 @@ export function processEnumColumn(col, dataType) {
|
|
|
131
144
|
|
|
132
145
|
// 值格式化函数
|
|
133
146
|
var valueFormatter = function valueFormatter(params) {
|
|
134
|
-
var match =
|
|
147
|
+
var match = valueEnum.find(function (item) {
|
|
135
148
|
return item.value == params.value;
|
|
136
149
|
});
|
|
137
150
|
return match ? match.label : params.value;
|
|
138
151
|
};
|
|
139
|
-
|
|
152
|
+
var fallbackRenderer = col.enumFallbackRenderer;
|
|
153
|
+
return _objectSpread(_objectSpread(_objectSpread({}, toColumnType(dataType)), col), {}, {
|
|
140
154
|
cellRenderer: function cellRenderer(params) {
|
|
141
|
-
var match =
|
|
155
|
+
var match = valueEnum.find(function (item) {
|
|
142
156
|
return item.value == params.value;
|
|
143
157
|
});
|
|
144
158
|
if (match) {
|
|
@@ -154,6 +168,9 @@ export function processEnumColumn(col, dataType) {
|
|
|
154
168
|
}
|
|
155
169
|
}, match.label);
|
|
156
170
|
}
|
|
171
|
+
if (typeof fallbackRenderer === 'function') {
|
|
172
|
+
return fallbackRenderer(params);
|
|
173
|
+
}
|
|
157
174
|
return params.value;
|
|
158
175
|
},
|
|
159
176
|
filterParams: _objectSpread(_objectSpread({}, col.filterParams || {}), {}, {
|
|
@@ -161,7 +178,7 @@ export function processEnumColumn(col, dataType) {
|
|
|
161
178
|
}),
|
|
162
179
|
searchComponent: Select,
|
|
163
180
|
searchComponentProps: {
|
|
164
|
-
options:
|
|
181
|
+
options: valueEnum.map(function (item) {
|
|
165
182
|
return {
|
|
166
183
|
label: item.label,
|
|
167
184
|
value: item.value
|