stk-table-vue 1.2.4 → 1.2.6

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.
Files changed (68) hide show
  1. package/README.md +194 -194
  2. package/lib/{Dropdown-D_9cB0rD.js → Dropdown-BAANgg_5.js} +2 -2
  3. package/lib/{StkTable-CVcmlZi9.js → StkTable-CGcxwpdb.js} +22 -6
  4. package/lib/src/StkTable/StkTable.vue.d.ts +18 -4
  5. package/lib/src/StkTable/types/index.d.ts +4 -1
  6. package/lib/src/StkTable/useVirtualScroll.d.ts +6 -1
  7. package/lib/stk-table-vue.js +3 -3
  8. package/lib/style.css +1 -1
  9. package/package.json +93 -93
  10. package/src/StkTable/StkTable.vue +2362 -2338
  11. package/src/StkTable/components/DragHandle.vue +9 -9
  12. package/src/StkTable/components/SortIcon.vue +6 -6
  13. package/src/StkTable/components/TreeNodeCell.vue +19 -19
  14. package/src/StkTable/components/TriangleIcon.vue +3 -3
  15. package/src/StkTable/const.ts +50 -50
  16. package/src/StkTable/custom-cells/ChangeCell/ChangeCell.less +34 -34
  17. package/src/StkTable/custom-cells/ChangeCell/createChangeCell.ts +90 -90
  18. package/src/StkTable/custom-cells/ChangeCell/index.ts +4 -4
  19. package/src/StkTable/custom-cells/CheckboxCell/CheckboxCell.less +14 -14
  20. package/src/StkTable/custom-cells/CheckboxCell/CheckboxCell.vue +56 -56
  21. package/src/StkTable/custom-cells/CheckboxCell/createCheckboxCell.ts +146 -146
  22. package/src/StkTable/custom-cells/CheckboxCell/index.ts +5 -5
  23. package/src/StkTable/custom-cells/FilterCell/Dropdown/index.ts +16 -16
  24. package/src/StkTable/custom-cells/FilterCell/Dropdown/index.vue +186 -186
  25. package/src/StkTable/custom-cells/FilterCell/Filter.less +118 -118
  26. package/src/StkTable/custom-cells/FilterCell/Filter.vue +66 -66
  27. package/src/StkTable/custom-cells/FilterCell/createFilterCell.ts +120 -120
  28. package/src/StkTable/custom-cells/FilterCell/index.ts +6 -6
  29. package/src/StkTable/custom-cells/FilterCell/types.ts +43 -43
  30. package/src/StkTable/custom-cells/NumberCell/createNumberCell.ts +43 -43
  31. package/src/StkTable/custom-cells/NumberCell/index.ts +2 -2
  32. package/src/StkTable/custom-cells/utils/formatNumber.ts +137 -137
  33. package/src/StkTable/features/const.ts +1 -1
  34. package/src/StkTable/features/index.ts +1 -1
  35. package/src/StkTable/features/useAreaSelection.ts +1240 -1239
  36. package/src/StkTable/index.ts +20 -20
  37. package/src/StkTable/mergeCellsCache.ts +69 -69
  38. package/src/StkTable/registerFeature.ts +40 -40
  39. package/src/StkTable/style.less +791 -791
  40. package/src/StkTable/types/highlightDimOptions.ts +28 -28
  41. package/src/StkTable/types/index.ts +503 -500
  42. package/src/StkTable/useAutoResize.ts +87 -87
  43. package/src/StkTable/useColResize.ts +202 -202
  44. package/src/StkTable/useFixedCol.ts +168 -168
  45. package/src/StkTable/useFixedStyle.ts +75 -75
  46. package/src/StkTable/useGetFixedColPosition.ts +63 -63
  47. package/src/StkTable/useHighlight.ts +270 -270
  48. package/src/StkTable/useIndexResolver.ts +29 -29
  49. package/src/StkTable/useKeyboardArrowScroll.ts +114 -114
  50. package/src/StkTable/useMaxRowSpan.ts +60 -60
  51. package/src/StkTable/useMergeCells.ts +541 -541
  52. package/src/StkTable/useRowExpand.ts +81 -81
  53. package/src/StkTable/useScrollRowByRow.ts +96 -96
  54. package/src/StkTable/useScrollbar.ts +177 -177
  55. package/src/StkTable/useSorter.ts +267 -267
  56. package/src/StkTable/useTableColumns.ts +142 -142
  57. package/src/StkTable/useThDrag.ts +94 -94
  58. package/src/StkTable/useTrDrag.ts +100 -100
  59. package/src/StkTable/useTree.ts +253 -253
  60. package/src/StkTable/useVirtualScroll.ts +1032 -1025
  61. package/src/StkTable/useWheeling.ts +23 -23
  62. package/src/StkTable/utils/constRefUtils.ts +29 -29
  63. package/src/StkTable/utils/index.ts +331 -331
  64. package/src/StkTable/utils/rowHeightFenwickTree.ts +74 -74
  65. package/src/StkTable/utils/useTriggerRef.ts +33 -33
  66. package/src/VirtualTree.vue +622 -622
  67. package/src/VirtualTreeSelect.vue +367 -367
  68. package/src/vite-env.d.ts +10 -10
@@ -1,66 +1,66 @@
1
- <script setup lang="ts">
2
- import { CustomHeaderCellProps } from '../../types';
3
- import { computed } from 'vue';
4
- import { getDropdownIns } from './Dropdown/index';
5
- import { FilterOption } from './types';
6
-
7
- const props = defineProps<
8
- CustomHeaderCellProps<any> & {
9
- theme?: 'light' | 'dark';
10
- active?: boolean; // 是否激活筛选
11
- getOptions: () => FilterOption[]; // 懒获取筛选选项,仅在下拉打开时调用
12
- }
13
- >();
14
-
15
- // 从父组件继承 theme,默认为 'light'
16
- const theme = computed(() => props.theme || 'light');
17
-
18
- const emit = defineEmits<{
19
- (e: 'change', value: FilterOption['value'][]): void;
20
- }>();
21
-
22
- function handleIconClick(e: MouseEvent) {
23
- e.stopPropagation();
24
- const target = e.target as HTMLElement;
25
- const rect = target.getBoundingClientRect();
26
-
27
- // 计算相对于文档的位置(考虑滚动偏移)
28
- const scrollTop = window.pageYOffset || document.documentElement.scrollTop;
29
- const scrollLeft = window.pageXOffset || document.documentElement.scrollLeft;
30
-
31
- getDropdownIns().then(ins => {
32
- if (ins.visible) {
33
- ins.hide();
34
- return;
35
- }
36
- ins.setTheme(theme.value);
37
- ins.show(
38
- {
39
- x: rect.left + scrollLeft,
40
- y: rect.bottom + scrollTop,
41
- height: rect.height,
42
- },
43
- props.getOptions(),
44
- handleConfirm,
45
- );
46
- });
47
- }
48
-
49
- function handleConfirm(value: FilterOption['value'][]) {
50
- emit('change', value);
51
- }
52
- </script>
53
-
54
- <template>
55
- <div class="stk-filter" :class="[{ 'stk-filter--active': props.active }, `stk-filter--${theme}`]">
56
- <slot>
57
- <span>{{ props.col.title }}</span>
58
- </slot>
59
- <svg class="stk-filter-icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1024 1024" @click="handleIconClick">
60
- <path
61
- fill="currentColor"
62
- d="M950.58 0 l-894.06 0 q-91.93 17.17 -34.34 119.21 l293.97 251.54 l6.06 9.1 q16.17 20.2 16.17 47.48 l0 468.74 l1.01 8.08 q3.03 10.11 9.09 19.2 q2.02 2.02 5.05 7.07 q36.37 33.34 84.86 4.04 l216.19 -124.26 q21.21 -22.22 18.18 -50.51 l0 -332.36 l1.01 -11.12 q4.04 -26.26 22.23 -45.46 l292.96 -251.54 l9.1 -10.11 q43.44 -54.55 14.14 -81.82 q-28.29 -27.28 -61.62 -27.28 ZM832.38 119.21 l-277.81 235.38 l0 377.82 l-96.98 55.57 l0 -433.39 l-275.8 -235.38 l650.59 0 Z"
63
- />
64
- </svg>
65
- </div>
66
- </template>
1
+ <script setup lang="ts">
2
+ import { CustomHeaderCellProps } from '../../types';
3
+ import { computed } from 'vue';
4
+ import { getDropdownIns } from './Dropdown/index';
5
+ import { FilterOption } from './types';
6
+
7
+ const props = defineProps<
8
+ CustomHeaderCellProps<any> & {
9
+ theme?: 'light' | 'dark';
10
+ active?: boolean; // 是否激活筛选
11
+ getOptions: () => FilterOption[]; // 懒获取筛选选项,仅在下拉打开时调用
12
+ }
13
+ >();
14
+
15
+ // 从父组件继承 theme,默认为 'light'
16
+ const theme = computed(() => props.theme || 'light');
17
+
18
+ const emit = defineEmits<{
19
+ (e: 'change', value: FilterOption['value'][]): void;
20
+ }>();
21
+
22
+ function handleIconClick(e: MouseEvent) {
23
+ e.stopPropagation();
24
+ const target = e.target as HTMLElement;
25
+ const rect = target.getBoundingClientRect();
26
+
27
+ // 计算相对于文档的位置(考虑滚动偏移)
28
+ const scrollTop = window.pageYOffset || document.documentElement.scrollTop;
29
+ const scrollLeft = window.pageXOffset || document.documentElement.scrollLeft;
30
+
31
+ getDropdownIns().then(ins => {
32
+ if (ins.visible) {
33
+ ins.hide();
34
+ return;
35
+ }
36
+ ins.setTheme(theme.value);
37
+ ins.show(
38
+ {
39
+ x: rect.left + scrollLeft,
40
+ y: rect.bottom + scrollTop,
41
+ height: rect.height,
42
+ },
43
+ props.getOptions(),
44
+ handleConfirm,
45
+ );
46
+ });
47
+ }
48
+
49
+ function handleConfirm(value: FilterOption['value'][]) {
50
+ emit('change', value);
51
+ }
52
+ </script>
53
+
54
+ <template>
55
+ <div class="stk-filter" :class="[{ 'stk-filter--active': props.active }, `stk-filter--${theme}`]">
56
+ <slot>
57
+ <span>{{ props.col.title }}</span>
58
+ </slot>
59
+ <svg class="stk-filter-icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1024 1024" @click="handleIconClick">
60
+ <path
61
+ fill="currentColor"
62
+ d="M950.58 0 l-894.06 0 q-91.93 17.17 -34.34 119.21 l293.97 251.54 l6.06 9.1 q16.17 20.2 16.17 47.48 l0 468.74 l1.01 8.08 q3.03 10.11 9.09 19.2 q2.02 2.02 5.05 7.07 q36.37 33.34 84.86 4.04 l216.19 -124.26 q21.21 -22.22 18.18 -50.51 l0 -332.36 l1.01 -11.12 q4.04 -26.26 22.23 -45.46 l292.96 -251.54 l9.1 -10.11 q43.44 -54.55 14.14 -81.82 q-28.29 -27.28 -61.62 -27.28 ZM832.38 119.21 l-277.81 235.38 l0 377.82 l-96.98 55.57 l0 -433.39 l-275.8 -235.38 l650.59 0 Z"
63
+ />
64
+ </svg>
65
+ </div>
66
+ </template>
@@ -1,120 +1,120 @@
1
- import { CustomHeaderCellProps, UniqKey } from '@/StkTable/types';
2
- import { computed, defineComponent, getCurrentInstance, h, markRaw, ref, VNode, watch } from 'vue';
3
- import Filter from './Filter.vue';
4
- import type { CreateFilterCellOption, FilterComponentConfig, FilterOption, FilterStatus } from './types.js';
5
-
6
- /**
7
- * 从数据源提取筛选选项
8
- *
9
- * @param dataSource 数据源
10
- * @param columnKey 列名
11
- * @returns 筛选选项数组
12
- */
13
- function extractFilterOptions(dataSource: any[], columnKey: string): FilterOption[] {
14
- const uniqueValues = new Set<any>();
15
-
16
- dataSource.forEach(row => {
17
- const val = row[columnKey];
18
- if (val !== undefined && val !== null) {
19
- uniqueValues.add(val);
20
- }
21
- });
22
-
23
- return Array.from(uniqueValues).map(value => ({
24
- label: String(value),
25
- value,
26
- }));
27
- }
28
-
29
- /**
30
- * 表格筛选功能工厂函数 (BETA)
31
- *
32
- * Q: 为什么要通过 stkTableInstance 来设置筛选状态,而不是直接在 createFilterCell 中传入dataSource。
33
- * A: 因为 createFilterCell 不一定有 dataSource的上下文,它可能在独立的js/ts 中使用,而非Vue SFC。而通过 stkTableInstance 可以获取到 dataSource
34
- * @beta
35
- * @returns
36
- */
37
- export function createFilterCell(option?: CreateFilterCellOption) {
38
- const filterStatus = ref<Record<UniqKey, FilterStatus>>({});
39
-
40
- function FilterComponent(config?: FilterComponentConfig, component?: VNode | ((props: CustomHeaderCellProps<any>) => VNode)) {
41
- return markRaw(
42
- defineComponent({
43
- // eslint-disable-next-line vue/require-prop-types
44
- props: ['col', 'colIndex'],
45
- setup(props: CustomHeaderCellProps<any>) {
46
- const colKey = props.col.dataIndex;
47
-
48
- const currentInstance = getCurrentInstance();
49
- /**
50
- * 查找最近的StkTable组件实例
51
- * @returns
52
- */
53
- function findStkTableInstance(curIns: any) {
54
- let current = curIns;
55
- while ((current = current.parent)) {
56
- if (current.type?.name === 'StkTable') {
57
- return current;
58
- }
59
- }
60
- return null;
61
- }
62
- const stkTableInstance = findStkTableInstance(currentInstance);
63
- // 从 StkTable 实例获取 theme
64
- const theme = computed(() => stkTableInstance?.props?.theme || 'light');
65
- const filterNumber = computed(() => {
66
- return filterStatus.value[colKey]?.value.length || 0;
67
- });
68
-
69
- // 自动从数据中提取筛选选项(懒计算,仅在下拉打开时触发)
70
- let cachedAutoOptions: FilterOption[] | null = null;
71
- // 数据源变化时清除缓存,下次打开下拉时重新计算
72
- watch(
73
- () => stkTableInstance?.props?.dataSource,
74
- () => {
75
- cachedAutoOptions = null;
76
- },
77
- );
78
- function getAutoOptions(): FilterOption[] {
79
- if (!config?.autoOptions) return [];
80
- if (cachedAutoOptions) return cachedAutoOptions;
81
- const dataSource: any[] = stkTableInstance?.props?.dataSource || [];
82
- cachedAutoOptions = extractFilterOptions(dataSource, colKey);
83
- return cachedAutoOptions;
84
- }
85
-
86
- // 优先使用 FilterComponent 传入的 options,其次使用自动提取的选项
87
- function getResolvedOptions(): FilterOption[] {
88
- return config?.options ?? getAutoOptions();
89
- }
90
-
91
- function handleChange(value: FilterOption['value'][]) {
92
- filterStatus.value[colKey] = {
93
- value,
94
- filter: config?.filter ?? filterStatus.value[colKey]?.filter,
95
- };
96
- option?.onChange?.({ colKey, status: filterStatus.value[colKey] });
97
- stkTableInstance?.exposed?.setFilter(filterStatus.value, option);
98
- }
99
- return () =>
100
- h(
101
- Filter,
102
- {
103
- ...props,
104
- theme: theme.value,
105
- active: filterNumber.value > 0,
106
- getOptions: getResolvedOptions,
107
- onChange: handleChange,
108
- },
109
- component ? { default: () => [h(component, props)] } : undefined,
110
- );
111
- },
112
- }),
113
- );
114
- }
115
-
116
- return {
117
- Filter: FilterComponent,
118
- filterStatus,
119
- };
120
- }
1
+ import { CustomHeaderCellProps, UniqKey } from '@/StkTable/types';
2
+ import { computed, defineComponent, getCurrentInstance, h, markRaw, ref, VNode, watch } from 'vue';
3
+ import Filter from './Filter.vue';
4
+ import type { CreateFilterCellOption, FilterComponentConfig, FilterOption, FilterStatus } from './types.js';
5
+
6
+ /**
7
+ * 从数据源提取筛选选项
8
+ *
9
+ * @param dataSource 数据源
10
+ * @param columnKey 列名
11
+ * @returns 筛选选项数组
12
+ */
13
+ function extractFilterOptions(dataSource: any[], columnKey: string): FilterOption[] {
14
+ const uniqueValues = new Set<any>();
15
+
16
+ dataSource.forEach(row => {
17
+ const val = row[columnKey];
18
+ if (val !== undefined && val !== null) {
19
+ uniqueValues.add(val);
20
+ }
21
+ });
22
+
23
+ return Array.from(uniqueValues).map(value => ({
24
+ label: String(value),
25
+ value,
26
+ }));
27
+ }
28
+
29
+ /**
30
+ * 表格筛选功能工厂函数 (BETA)
31
+ *
32
+ * Q: 为什么要通过 stkTableInstance 来设置筛选状态,而不是直接在 createFilterCell 中传入dataSource。
33
+ * A: 因为 createFilterCell 不一定有 dataSource的上下文,它可能在独立的js/ts 中使用,而非Vue SFC。而通过 stkTableInstance 可以获取到 dataSource
34
+ * @beta
35
+ * @returns
36
+ */
37
+ export function createFilterCell(option?: CreateFilterCellOption) {
38
+ const filterStatus = ref<Record<UniqKey, FilterStatus>>({});
39
+
40
+ function FilterComponent(config?: FilterComponentConfig, component?: VNode | ((props: CustomHeaderCellProps<any>) => VNode)) {
41
+ return markRaw(
42
+ defineComponent({
43
+ // eslint-disable-next-line vue/require-prop-types
44
+ props: ['col', 'colIndex'],
45
+ setup(props: CustomHeaderCellProps<any>) {
46
+ const colKey = props.col.dataIndex;
47
+
48
+ const currentInstance = getCurrentInstance();
49
+ /**
50
+ * 查找最近的StkTable组件实例
51
+ * @returns
52
+ */
53
+ function findStkTableInstance(curIns: any) {
54
+ let current = curIns;
55
+ while ((current = current.parent)) {
56
+ if (current.type?.name === 'StkTable') {
57
+ return current;
58
+ }
59
+ }
60
+ return null;
61
+ }
62
+ const stkTableInstance = findStkTableInstance(currentInstance);
63
+ // 从 StkTable 实例获取 theme
64
+ const theme = computed(() => stkTableInstance?.props?.theme || 'light');
65
+ const filterNumber = computed(() => {
66
+ return filterStatus.value[colKey]?.value.length || 0;
67
+ });
68
+
69
+ // 自动从数据中提取筛选选项(懒计算,仅在下拉打开时触发)
70
+ let cachedAutoOptions: FilterOption[] | null = null;
71
+ // 数据源变化时清除缓存,下次打开下拉时重新计算
72
+ watch(
73
+ () => stkTableInstance?.props?.dataSource,
74
+ () => {
75
+ cachedAutoOptions = null;
76
+ },
77
+ );
78
+ function getAutoOptions(): FilterOption[] {
79
+ if (!config?.autoOptions) return [];
80
+ if (cachedAutoOptions) return cachedAutoOptions;
81
+ const dataSource: any[] = stkTableInstance?.props?.dataSource || [];
82
+ cachedAutoOptions = extractFilterOptions(dataSource, colKey);
83
+ return cachedAutoOptions;
84
+ }
85
+
86
+ // 优先使用 FilterComponent 传入的 options,其次使用自动提取的选项
87
+ function getResolvedOptions(): FilterOption[] {
88
+ return config?.options ?? getAutoOptions();
89
+ }
90
+
91
+ function handleChange(value: FilterOption['value'][]) {
92
+ filterStatus.value[colKey] = {
93
+ value,
94
+ filter: config?.filter ?? filterStatus.value[colKey]?.filter,
95
+ };
96
+ option?.onChange?.({ colKey, status: filterStatus.value[colKey] });
97
+ stkTableInstance?.exposed?.setFilter(filterStatus.value, option);
98
+ }
99
+ return () =>
100
+ h(
101
+ Filter,
102
+ {
103
+ ...props,
104
+ theme: theme.value,
105
+ active: filterNumber.value > 0,
106
+ getOptions: getResolvedOptions,
107
+ onChange: handleChange,
108
+ },
109
+ component ? { default: () => [h(component, props)] } : undefined,
110
+ );
111
+ },
112
+ }),
113
+ );
114
+ }
115
+
116
+ return {
117
+ Filter: FilterComponent,
118
+ filterStatus,
119
+ };
120
+ }
@@ -1,6 +1,6 @@
1
- // 导出Filter组件相关模块
2
- export { createFilterCell } from './createFilterCell';
3
- export type { FilterStatus, CreateFilterCellOption } from './types';
4
- // export { default as Filter } from './Filter.vue';
5
-
6
- import './Filter.less';
1
+ // 导出Filter组件相关模块
2
+ export { createFilterCell } from './createFilterCell';
3
+ export type { FilterStatus, CreateFilterCellOption } from './types';
4
+ // export { default as Filter } from './Filter.vue';
5
+
6
+ import './Filter.less';
@@ -1,43 +1,43 @@
1
- // Filter组件相关类型定义
2
-
3
- import { UniqKey } from '@/StkTable/types';
4
-
5
- /** 筛选选项接口 */
6
- export interface FilterOption {
7
- label: string;
8
- value: any;
9
- selected?: boolean;
10
- }
11
-
12
- /** 筛选状态接口 */
13
- export interface FilterStatus {
14
- value: FilterOption['value'][];
15
- /**
16
- * 自定义筛选逻辑函数。
17
- * 当选中筛选条件时,根据此函数的返回值决定记录是否保留。
18
- * @param row 当前行数据
19
- * @param cellValue 当前单元格的值(即 row[columnKey])
20
- * @param filterValues 当前选中的筛选值数组
21
- * @returns 返回 true 保留记录,false 过滤掉
22
- */
23
- filter?: (args: { row: any; cellValue: any; filterValues: FilterOption['value'][] }) => boolean;
24
- }
25
-
26
- /** FilterComponent 配置接口 */
27
- export interface FilterComponentConfig {
28
- options?: FilterOption[];
29
- filter?: FilterStatus['filter'];
30
- /**
31
- * 是否自动从数据中提取筛选选项,默认 false
32
- * en: Whether to automatically extract filter options from the data source
33
- */
34
- autoOptions?: boolean;
35
- }
36
-
37
- /** createFilter选项接口 */
38
- export interface CreateFilterCellOption {
39
- /** 是否远程筛选 */
40
- remote?: boolean;
41
- /** 筛选状态改变时触发 */
42
- onChange?: (data: { colKey: UniqKey; status: FilterStatus }) => void;
43
- }
1
+ // Filter组件相关类型定义
2
+
3
+ import { UniqKey } from '@/StkTable/types';
4
+
5
+ /** 筛选选项接口 */
6
+ export interface FilterOption {
7
+ label: string;
8
+ value: any;
9
+ selected?: boolean;
10
+ }
11
+
12
+ /** 筛选状态接口 */
13
+ export interface FilterStatus {
14
+ value: FilterOption['value'][];
15
+ /**
16
+ * 自定义筛选逻辑函数。
17
+ * 当选中筛选条件时,根据此函数的返回值决定记录是否保留。
18
+ * @param row 当前行数据
19
+ * @param cellValue 当前单元格的值(即 row[columnKey])
20
+ * @param filterValues 当前选中的筛选值数组
21
+ * @returns 返回 true 保留记录,false 过滤掉
22
+ */
23
+ filter?: (args: { row: any; cellValue: any; filterValues: FilterOption['value'][] }) => boolean;
24
+ }
25
+
26
+ /** FilterComponent 配置接口 */
27
+ export interface FilterComponentConfig {
28
+ options?: FilterOption[];
29
+ filter?: FilterStatus['filter'];
30
+ /**
31
+ * 是否自动从数据中提取筛选选项,默认 false
32
+ * en: Whether to automatically extract filter options from the data source
33
+ */
34
+ autoOptions?: boolean;
35
+ }
36
+
37
+ /** createFilter选项接口 */
38
+ export interface CreateFilterCellOption {
39
+ /** 是否远程筛选 */
40
+ remote?: boolean;
41
+ /** 筛选状态改变时触发 */
42
+ onChange?: (data: { colKey: UniqKey; status: FilterStatus }) => void;
43
+ }
@@ -1,43 +1,43 @@
1
- import type { CustomCellProps } from '../../types';
2
- import { defineComponent, h, markRaw } from 'vue';
3
- import { formatNumber, type FormatNumberOptions } from '../utils/formatNumber';
4
-
5
- /** createNumberCell 配置选项(等同于格式化选项) */
6
- export interface CreateNumberCellOptions extends FormatNumberOptions {}
7
-
8
- /**
9
- * 数字格式化单元格工厂函数
10
- *
11
- * 纯展示型单元格:将 `cellValue` 经 {@link formatNumber} 格式化为文本。
12
- * 数字对齐请在列配置上设置 `align: 'right'`。
13
- *
14
- * @param options 格式化选项
15
- * @returns `NumberCell` 组件构造函数,使用时需调用一次:`customCell: NumberCell()`
16
- *
17
- * @example
18
- * ```ts
19
- * const { NumberCell } = createNumberCell({ decimals: 2 });
20
- * const NumberCellComp = NumberCell();
21
- * const columns = [
22
- * { title: '现价', dataIndex: 'price', align: 'right', customCell: NumberCellComp },
23
- * ];
24
- * ```
25
- */
26
- export function createNumberCell(options?: CreateNumberCellOptions) {
27
- /** 单元格组件 - 用于 customCell */
28
- function NumberCell() {
29
- return markRaw(
30
- defineComponent({
31
- // eslint-disable-next-line vue/require-prop-types
32
- props: ['row', 'col', 'cellValue', 'rowIndex', 'colIndex', 'expanded', 'treeExpanded'],
33
- setup(props: CustomCellProps<any>) {
34
- return () => h('span', { class: 'stk-number-cell' }, formatNumber(props.cellValue, options));
35
- },
36
- }),
37
- );
38
- }
39
-
40
- return {
41
- NumberCell,
42
- };
43
- }
1
+ import type { CustomCellProps } from '../../types';
2
+ import { defineComponent, h, markRaw } from 'vue';
3
+ import { formatNumber, type FormatNumberOptions } from '../utils/formatNumber';
4
+
5
+ /** createNumberCell 配置选项(等同于格式化选项) */
6
+ export interface CreateNumberCellOptions extends FormatNumberOptions {}
7
+
8
+ /**
9
+ * 数字格式化单元格工厂函数
10
+ *
11
+ * 纯展示型单元格:将 `cellValue` 经 {@link formatNumber} 格式化为文本。
12
+ * 数字对齐请在列配置上设置 `align: 'right'`。
13
+ *
14
+ * @param options 格式化选项
15
+ * @returns `NumberCell` 组件构造函数,使用时需调用一次:`customCell: NumberCell()`
16
+ *
17
+ * @example
18
+ * ```ts
19
+ * const { NumberCell } = createNumberCell({ decimals: 2 });
20
+ * const NumberCellComp = NumberCell();
21
+ * const columns = [
22
+ * { title: '现价', dataIndex: 'price', align: 'right', customCell: NumberCellComp },
23
+ * ];
24
+ * ```
25
+ */
26
+ export function createNumberCell(options?: CreateNumberCellOptions) {
27
+ /** 单元格组件 - 用于 customCell */
28
+ function NumberCell() {
29
+ return markRaw(
30
+ defineComponent({
31
+ // eslint-disable-next-line vue/require-prop-types
32
+ props: ['row', 'col', 'cellValue', 'rowIndex', 'colIndex', 'expanded', 'treeExpanded'],
33
+ setup(props: CustomCellProps<any>) {
34
+ return () => h('span', { class: 'stk-number-cell' }, formatNumber(props.cellValue, options));
35
+ },
36
+ }),
37
+ );
38
+ }
39
+
40
+ return {
41
+ NumberCell,
42
+ };
43
+ }
@@ -1,2 +1,2 @@
1
- export { createNumberCell } from './createNumberCell';
2
- export type { CreateNumberCellOptions } from './createNumberCell';
1
+ export { createNumberCell } from './createNumberCell';
2
+ export type { CreateNumberCellOptions } from './createNumberCell';