@lx-frontend/wrap-element-ui 0.4.6-beta.1 → 1.0.0-beta
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/AddMembers/index.vue.d.ts +31 -0
- package/dist/AuditSteps/index.vue.d.ts +46 -0
- package/dist/DemoComponent/index.vue.d.ts +2 -0
- package/dist/EditableTable/index.vue.d.ts +186 -0
- package/dist/EditableTable/types.d.ts +123 -0
- package/dist/EditableTable/useCellHover.d.ts +11 -0
- package/dist/EditableTable/useColumnHeaderOperation.d.ts +106 -0
- package/dist/EditableTable/useDefaultOperation.d.ts +22 -0
- package/dist/EditableTable/useDragSort.d.ts +15 -0
- package/dist/EditableTable/usePagination.d.ts +13 -0
- package/dist/EditableTable/useRowBgColor.d.ts +16 -0
- package/dist/EditableTable/useViewSetting.d.ts +58 -0
- package/dist/Ellipsis/MultilineEllipsis.vue.d.ts +91 -0
- package/dist/Ellipsis/index.vue.d.ts +89 -0
- package/dist/LxTable/index.vue.d.ts +2 -0
- package/dist/PopoverForm/index.vue.d.ts +50 -0
- package/dist/SearchForm/index.vue.d.ts +105 -0
- package/dist/SearchSelect/index.vue.d.ts +53 -0
- package/dist/index.css +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.mjs +40808 -0
- package/dist/singleMessage/index.d.ts +4 -0
- package/package.json +57 -33
- package/{packages/AddMembers/src/AddMembers.vue → src/components/AddMembers/index.vue} +35 -13
- package/{packages/AuditSteps/src/AuditSteps.vue → src/components/AuditSteps/index.vue} +55 -0
- package/{packages/DemoComponent/src/DemoComponent.vue → src/components/DemoComponent/index.vue} +11 -0
- package/src/components/EditableTable/README.md +147 -0
- package/src/components/EditableTable/index.less +716 -0
- package/src/components/EditableTable/index.vue +842 -0
- package/src/components/EditableTable/pin-top.png +0 -0
- package/src/components/EditableTable/types.ts +94 -0
- package/src/components/EditableTable/useCellHover.ts +72 -0
- package/src/components/EditableTable/useColumnHeaderOperation.ts +188 -0
- package/src/components/EditableTable/useDefaultOperation.ts +96 -0
- package/src/components/EditableTable/useDragSort.ts +292 -0
- package/src/components/EditableTable/usePagination.ts +34 -0
- package/src/components/EditableTable/useRowBgColor.ts +51 -0
- package/src/components/EditableTable/useViewSetting.ts +67 -0
- package/{packages/Ellipsis/src → src/components/Ellipsis}/MultilineEllipsis.vue +1 -1
- package/{packages/Ellipsis/src/Ellipsis.vue → src/components/Ellipsis/index.vue} +5 -5
- package/src/components/LxTable/index.vue +296 -0
- package/{packages/SearchForm/src/SearchForm.vue → src/components/SearchForm/index.vue} +47 -21
- package/{packages/SearchSelect/src/SearchSelect.vue → src/components/SearchSelect/index.vue} +7 -4
- package/src/components/index.ts +22 -0
- package/babel.config.js +0 -5
- package/global.d.ts +0 -23
- package/packages/AddMembers/index.js +0 -11
- package/packages/AuditSteps/index.js +0 -7
- package/packages/DemoComponent/index.js +0 -7
- package/packages/Ellipsis/index.js +0 -7
- package/packages/LxTable/index.js +0 -11
- package/packages/LxTable/src/LxTable.vue +0 -296
- package/packages/PopoverForm/index.js +0 -7
- package/packages/SearchForm/index.js +0 -7
- package/packages/SearchSelect/index.js +0 -7
- package/packages/index.js +0 -59
- package/packages/theme-default/gulpfile.js +0 -25
- package/packages/theme-default/lib/AuditSteps.css +0 -1
- package/packages/theme-default/lib/DemoComponent.css +0 -1
- package/packages/theme-default/lib/index.css +0 -1
- package/packages/theme-default/package.json +0 -23
- package/packages/theme-default/src/AuditSteps.scss +0 -52
- package/packages/theme-default/src/DemoComponent.scss +0 -9
- package/packages/theme-default/src/common/var.scss +0 -0
- package/packages/theme-default/src/fonts/.gitkeep +0 -0
- package/packages/theme-default/src/index.css +0 -11
- package/packages/theme-default/src/index.scss +0 -2
- package/packages/utils/.gitkeep +0 -0
- package/plugins/wrap.js +0 -22
- package/postcss.config.js +0 -5
- package/tsconfig.json +0 -41
- /package/{packages/PopoverForm/src/PopoverForm.vue → src/components/PopoverForm/index.vue} +0 -0
- /package/{packages → src/components}/singleMessage/index.ts +0 -0
|
Binary file
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
export enum IEditType {
|
|
2
|
+
INPUT = 'input',
|
|
3
|
+
SELECT = 'select',
|
|
4
|
+
DATE_ONLY = 'date'
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export interface IColumnConfigRequired {
|
|
8
|
+
prop: string;
|
|
9
|
+
label: string;
|
|
10
|
+
editType?: IEditType; // 编辑格式
|
|
11
|
+
sortable?: boolean; // 该列是否允许排序,ture则表头弹窗会显示升降序按钮
|
|
12
|
+
slotName?: string; // 如果要自定义,传入 slotName
|
|
13
|
+
isAlwaysShow?: boolean; // 不可隐藏,显示设置中,该列不允许隐藏
|
|
14
|
+
isColumnSearchAble?: boolean; // 列是否允许搜索,true则表头弹窗会多一个搜索框
|
|
15
|
+
summary?: boolean; // 是否可以显示该列的统计
|
|
16
|
+
summaryMethod?: (values: any[]) => string | number; // 这一列的统计方法,values为该列的所有值
|
|
17
|
+
// filters?: {value: string | number; text: string; [key: string]: any}[];
|
|
18
|
+
// 透传el-table column有的属性, https://element.eleme.cn/#/en-US/component/table#table-column-attributes
|
|
19
|
+
[key: string]: any;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
type IInputColumn = IColumnConfigRequired & {
|
|
23
|
+
inputType: string | number;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
type ISelectColumn = IColumnConfigRequired & {
|
|
27
|
+
options: {key: string; value: string | number; [key: string]: any}[];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
type IDateOnlyColumn = IColumnConfigRequired & {}
|
|
31
|
+
type IDateTimeColumn = IColumnConfigRequired & {}
|
|
32
|
+
|
|
33
|
+
export type IColumnConfig = IInputColumn | ISelectColumn | IDateOnlyColumn | IDateTimeColumn
|
|
34
|
+
|
|
35
|
+
export type IColorList = {
|
|
36
|
+
name: string; // 颜色名称
|
|
37
|
+
textColor: string; // 颜色弹窗中文本颜色
|
|
38
|
+
sampleColor: string; // 颜色弹窗中样例的颜色
|
|
39
|
+
bgColor: string; // 选中颜色后,行背景色
|
|
40
|
+
id: number; // 颜色id
|
|
41
|
+
default?: boolean // 是否是默认色,默认色需要显示颜色图标
|
|
42
|
+
}[]
|
|
43
|
+
|
|
44
|
+
type IPointLoc = {
|
|
45
|
+
x: number;
|
|
46
|
+
y: number;
|
|
47
|
+
}
|
|
48
|
+
export type IDraggingData = {
|
|
49
|
+
isDragging?: boolean
|
|
50
|
+
startPosition?: IPointLoc
|
|
51
|
+
draggingRow?: HTMLElement | HTMLElement[]
|
|
52
|
+
draggingIndex?: number
|
|
53
|
+
dropIndex?: number
|
|
54
|
+
rowDoms?: Record<number, HTMLElement[]>
|
|
55
|
+
rowHeight?: number
|
|
56
|
+
rowsRange?: ([number, number] | undefined)[]
|
|
57
|
+
hiddenTds?: HTMLElement[]
|
|
58
|
+
fullScreenDiv?: HTMLElement
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export type IDefaultOperationType = 'edit' | 'delete' | 'top'
|
|
62
|
+
|
|
63
|
+
export type ITableDataItem = {
|
|
64
|
+
colorId?: number;
|
|
65
|
+
isPinned?: boolean;
|
|
66
|
+
[k: string]: any;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export interface IProps {
|
|
70
|
+
dataList: ITableDataItem[];
|
|
71
|
+
columnConfig: IColumnConfig[];
|
|
72
|
+
hasExpandRow?: boolean;
|
|
73
|
+
hasIndexColumn?: boolean;
|
|
74
|
+
hasSelectionColumn?: boolean;
|
|
75
|
+
rowDragAble?: boolean;
|
|
76
|
+
total: number;
|
|
77
|
+
defaultOperations?: IDefaultOperationType[];
|
|
78
|
+
colorList?: IColorList;
|
|
79
|
+
leftFixedCount?: number;
|
|
80
|
+
dragSemiRange?: number;
|
|
81
|
+
loading?: boolean;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export interface IEmits {
|
|
85
|
+
(e: 'selection-change', selection: any): void
|
|
86
|
+
(e: 'row-bg-change', param: {colorId: number; row: ITableDataItem; rowIndex: number}): void
|
|
87
|
+
(e: 'row-drag-drop', param: { row: any; fromIndex: number; toIndex: number; page: number; size: number;}): void
|
|
88
|
+
(e: 'row-delete', param: { row: any; index: number; page: number; size: number; }): void
|
|
89
|
+
(e: 'row-edit', param: { row: any, index: number; page: number; size: number;}): void
|
|
90
|
+
(e: 'row-pin-to-top', param: { row: any, rawIndex: number; page: number; size: number;}): void
|
|
91
|
+
(e: 'row-edit-save', param: { page: number; size: number; row: any; changedData: Record<string, any>; }): void
|
|
92
|
+
(e: 'row-edit-cancel', param: { row: any; page: number; size: number;}): void
|
|
93
|
+
(e: 'page-change', param: { page: number, size: number }): void
|
|
94
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import debounce from 'lodash/debounce';
|
|
2
|
+
import throttle from 'lodash/throttle';
|
|
3
|
+
import { onBeforeUnmount, onMounted, ref } from 'vue'
|
|
4
|
+
|
|
5
|
+
export default function useCellHover(tableDomRef) {
|
|
6
|
+
|
|
7
|
+
// 鼠标悬浮的行
|
|
8
|
+
const hoveringCellInfo = ref<{
|
|
9
|
+
rowIndex: number;
|
|
10
|
+
columnProperty: string;
|
|
11
|
+
}>({ rowIndex: -1, columnProperty: ''});
|
|
12
|
+
|
|
13
|
+
const isMouseWheeling = ref(false);
|
|
14
|
+
|
|
15
|
+
onMounted(() => {
|
|
16
|
+
tableDomRef.value.$el.addEventListener('mouseleave', resetHoveringCellInfo);
|
|
17
|
+
document.addEventListener('wheel', throttledHandleMouseWheel);
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
onBeforeUnmount(() => {
|
|
21
|
+
tableDomRef.value.$el.removeEventListener('mouseleave', resetHoveringCellInfo);
|
|
22
|
+
document.removeEventListener('wheel', throttledHandleMouseWheel);
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
const setCellClassName = ({ column, rowIndex }) => {
|
|
26
|
+
// hoving-cell-[name]-[rowIndex]
|
|
27
|
+
if (!column.property) return '';
|
|
28
|
+
return `hoving-cell-(${column.property})-(${rowIndex})`;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const resetHoveringCellInfo = () => {
|
|
32
|
+
hoveringCellInfo.value = {
|
|
33
|
+
rowIndex: -1,
|
|
34
|
+
columnProperty: ''
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
let timerHandler: any = null
|
|
39
|
+
// 性能考虑,在鼠标滚动时,停止处理cell的hover事件
|
|
40
|
+
const handleMouseWheel = () => {
|
|
41
|
+
isMouseWheeling.value = true;
|
|
42
|
+
clearTimeout(timerHandler);
|
|
43
|
+
// 停止滚动后,恢复hover事件
|
|
44
|
+
timerHandler = setTimeout(() => {
|
|
45
|
+
isMouseWheeling.value = false;
|
|
46
|
+
}, 100)
|
|
47
|
+
}
|
|
48
|
+
const throttledHandleMouseWheel = throttle(handleMouseWheel, 50);
|
|
49
|
+
|
|
50
|
+
const handleCellMouseEnter = (row, column, cell, event) => {
|
|
51
|
+
// 性能考虑,表格滚动时会不断触发该事件,导致滚动性能变差
|
|
52
|
+
if (isMouseWheeling.value) return
|
|
53
|
+
|
|
54
|
+
const className = [...event.target.classList].find(c => /hoving-cell-\(\w+\)-\(\d+\)/.test(c))
|
|
55
|
+
if (!className) return;
|
|
56
|
+
// 正则匹配括号中的内容
|
|
57
|
+
const matchArr = className.match(/hoving-cell-\((\w+)\)-\((\d+)\)/);
|
|
58
|
+
|
|
59
|
+
hoveringCellInfo.value = {
|
|
60
|
+
rowIndex: +matchArr?.[2],
|
|
61
|
+
columnProperty: matchArr?.[1]
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const debouncedHoverHandler = debounce(handleCellMouseEnter, 10);
|
|
66
|
+
|
|
67
|
+
return {
|
|
68
|
+
hoveringCellInfo,
|
|
69
|
+
setCellClassName,
|
|
70
|
+
debouncedHoverHandler
|
|
71
|
+
}
|
|
72
|
+
}
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import { computed, ref, watch, nextTick } from "vue"
|
|
2
|
+
import { IColumnConfig, IProps } from './types';
|
|
3
|
+
|
|
4
|
+
interface IUseColumnHeaderOperationParams {
|
|
5
|
+
props: IProps
|
|
6
|
+
tableDomRef: any
|
|
7
|
+
sortFilterPopoverRef: any
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export default function useColumnHeaderOperation({props, tableDomRef, sortFilterPopoverRef}: IUseColumnHeaderOperationParams) {
|
|
11
|
+
|
|
12
|
+
// column如果有sortable属性,点击列头部,会直接触发排序,为了在弹窗点确定时再触发排序,需要阻止点击立即排序
|
|
13
|
+
// 所以,初始渲染时,将sortable设置为false,在触发排序逻辑时再设置成真实的值,再利用el-table自身的排序逻辑触发排序
|
|
14
|
+
const inSorting = ref(false);
|
|
15
|
+
|
|
16
|
+
// 生效中的排序配置
|
|
17
|
+
const sortType = ref<'ascending' | 'descending' | null>(null);
|
|
18
|
+
const sortingColumn = ref<IColumnConfig | null>(null);
|
|
19
|
+
|
|
20
|
+
// 临时的排序配置
|
|
21
|
+
const tempSortType = ref<'ascending' | 'descending' | null>(null);
|
|
22
|
+
const tempSortingColumn = ref<IColumnConfig | null>(null);
|
|
23
|
+
|
|
24
|
+
// 生效中的过滤配置 和 临时过滤配置
|
|
25
|
+
const filteredValue = ref<Record<string, string[]>>({});
|
|
26
|
+
const tempFilteredValue = ref<Record<string, string[]>>({});
|
|
27
|
+
|
|
28
|
+
// 生效中的统计配置 和 临时统计配置
|
|
29
|
+
const tempSummaryList = ref<string[]>([]);
|
|
30
|
+
const summaryList = ref<string[]>([]);
|
|
31
|
+
|
|
32
|
+
// 生效中的搜索配置 和 临时搜索配置
|
|
33
|
+
const searchValue = ref<Record<string, string>>({});
|
|
34
|
+
const tempSearchValue = ref<Record<string, string>>({});
|
|
35
|
+
|
|
36
|
+
const isColumnFiltering = computed(() => Object.keys(tempFilteredValue.value).some(k => tempFilteredValue.value[k]?.length));
|
|
37
|
+
|
|
38
|
+
const showColumnHeadSortIcon = (column: IColumnConfig) => column.filters || column.isColumnSortable || column.isColumnSearchAble || column.summary;
|
|
39
|
+
|
|
40
|
+
watch(
|
|
41
|
+
() => props.columnConfig,
|
|
42
|
+
(val) => {
|
|
43
|
+
filteredValue.value = val.reduce((prev, curr) => ({...prev, [curr.prop]: []}), {});
|
|
44
|
+
tempFilteredValue.value = { ...filteredValue.value };
|
|
45
|
+
},
|
|
46
|
+
{ immediate: true }
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
const tableSummaryMethod = (param) => {
|
|
50
|
+
const { columns, data } = param;
|
|
51
|
+
const sums: (string | number)[] = []
|
|
52
|
+
columns.forEach((column, index) => {
|
|
53
|
+
if (index === 0) {
|
|
54
|
+
sums[index] = '合计';
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
if (!summaryList.value.includes(column.property)) {
|
|
58
|
+
sums[index] = '';
|
|
59
|
+
} else {
|
|
60
|
+
const values = data.map(item => item[column.property]);
|
|
61
|
+
// 找到对应列的summaryMethod函数
|
|
62
|
+
const summaryMethod = props.columnConfig.find(c => c.prop === column.property)?.summaryMethod ?? (() => '');
|
|
63
|
+
sums[index] = summaryMethod(values);
|
|
64
|
+
}
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
return sums
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const isColumnHeadActive = (column: IColumnConfig) => {
|
|
71
|
+
return filteredValue.value[column.prop]?.length ||
|
|
72
|
+
sortingColumn.value?.prop === column.prop ||
|
|
73
|
+
searchValue.value[column.prop] ||
|
|
74
|
+
summaryList.value.includes(column.prop);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const handleHeaderPopoverShow = (column) => {
|
|
78
|
+
// 关闭其他的排序和筛选弹窗(理论上不写也能关闭其他,但是就是有些列会出现两个弹窗同时出现的情况)
|
|
79
|
+
closeSortAndFilterPopover(column.prop);
|
|
80
|
+
tempFilteredValue.value = { ...filteredValue.value };
|
|
81
|
+
tempSearchValue.value = { ...searchValue.value };
|
|
82
|
+
tempSortType.value = sortType.value;
|
|
83
|
+
tempSortingColumn.value = sortingColumn.value ? { ...sortingColumn.value } as IColumnConfig : null;
|
|
84
|
+
// 临时合计项设置成实际的合计项
|
|
85
|
+
tempSummaryList.value = [ ...summaryList.value ];
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const closeSortAndFilterPopover = (exceptProp?: string) => {
|
|
89
|
+
sortFilterPopoverRef.value?.forEach((item: any) => {
|
|
90
|
+
if (!exceptProp || exceptProp !== item.$el.dataset.prop) {
|
|
91
|
+
item.doClose();
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const handleSort = (type: 'ascending' | 'descending', column) => {
|
|
97
|
+
tempSortType.value = type;
|
|
98
|
+
tempSortingColumn.value = column;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const handleHeaderOperationConfirm = async (scope) => {
|
|
102
|
+
summaryList.value = [ ...tempSummaryList.value ];
|
|
103
|
+
sortingColumn.value = tempSortingColumn.value ? {...tempSortingColumn.value} : null;
|
|
104
|
+
sortType.value = tempSortType.value;
|
|
105
|
+
if (sortingColumn.value) {
|
|
106
|
+
// 恢复列配置的sortable属性,只有列配置的sortable为true,才能用下面的sort方法
|
|
107
|
+
inSorting.value = true;
|
|
108
|
+
await nextTick();
|
|
109
|
+
tableDomRef.value?.sort(sortingColumn.value.prop, sortType.value);
|
|
110
|
+
inSorting.value = false
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
filteredValue.value = { ...tempFilteredValue.value };
|
|
114
|
+
searchValue.value = { ...tempSearchValue.value };
|
|
115
|
+
|
|
116
|
+
filterColumns(scope.store);
|
|
117
|
+
|
|
118
|
+
closeSortAndFilterPopover();
|
|
119
|
+
await nextTick()
|
|
120
|
+
tableDomRef.value?.doLayout();
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const handleHeaderOperationReset = async (column, scope) => {
|
|
124
|
+
if (sortingColumn.value && sortingColumn.value.prop === column.prop) {
|
|
125
|
+
tableDomRef.value?.clearSort();
|
|
126
|
+
sortingColumn.value = null;
|
|
127
|
+
sortType.value = null;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// 合计
|
|
131
|
+
summaryList.value = summaryList.value.filter(item => item !== column.prop);
|
|
132
|
+
|
|
133
|
+
filteredValue.value[column.prop] = [];
|
|
134
|
+
searchValue.value[column.prop] = '';
|
|
135
|
+
filterColumns(scope.store);
|
|
136
|
+
|
|
137
|
+
closeSortAndFilterPopover();
|
|
138
|
+
await nextTick();
|
|
139
|
+
tableDomRef.value?.doLayout();
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const filterColumns = (store) => {
|
|
143
|
+
store.states.columns.forEach(column => {
|
|
144
|
+
if (filteredValue.value[column.property]) {
|
|
145
|
+
store.commit('filterChange', {
|
|
146
|
+
column,
|
|
147
|
+
values: filteredValue.value[column.property],
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
// 根据searchValue过滤数据
|
|
153
|
+
const data = store.states.data.filter(item => {
|
|
154
|
+
const flag = Object.keys(searchValue.value)
|
|
155
|
+
.filter(key => searchValue.value[key])
|
|
156
|
+
.reduce((pre, key) => {
|
|
157
|
+
const value = searchValue.value[key];
|
|
158
|
+
|
|
159
|
+
return pre && item[key] && `${item[key]}`.indexOf(value) > -1;
|
|
160
|
+
}, true);
|
|
161
|
+
|
|
162
|
+
return flag;
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
store.states.data = data;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
return {
|
|
169
|
+
isColumnHeadActive,
|
|
170
|
+
handleHeaderPopoverShow,
|
|
171
|
+
handleSort,
|
|
172
|
+
handleHeaderOperationConfirm,
|
|
173
|
+
handleHeaderOperationReset,
|
|
174
|
+
summaryList,
|
|
175
|
+
tableSummaryMethod,
|
|
176
|
+
filteredValue,
|
|
177
|
+
showColumnHeadSortIcon,
|
|
178
|
+
tempSortingColumn,
|
|
179
|
+
tempSearchValue,
|
|
180
|
+
tempFilteredValue,
|
|
181
|
+
tempSummaryList,
|
|
182
|
+
tempSortType,
|
|
183
|
+
sortingColumn,
|
|
184
|
+
isColumnFiltering,
|
|
185
|
+
searchValue,
|
|
186
|
+
inSorting
|
|
187
|
+
}
|
|
188
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { Ref, ref } from "vue"
|
|
2
|
+
import { IEmits } from "./types"
|
|
3
|
+
|
|
4
|
+
interface IParams {
|
|
5
|
+
emit: IEmits;
|
|
6
|
+
pageSize: Ref<number>;
|
|
7
|
+
currentPage: Ref<number>;
|
|
8
|
+
tableDomRef: Ref<any>;
|
|
9
|
+
hasExpandRow: boolean
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export default function useDefaultOperation({emit, pageSize, currentPage, tableDomRef, hasExpandRow}: IParams) {
|
|
13
|
+
const operationPopoverRef = ref<any>(null);
|
|
14
|
+
const editingRowData = ref<Record<string, any>>({});
|
|
15
|
+
const editingRowIndex = ref<number>(-1);
|
|
16
|
+
|
|
17
|
+
const handleDelete = (row, index) => {
|
|
18
|
+
emit('row-delete', {
|
|
19
|
+
row,
|
|
20
|
+
index,
|
|
21
|
+
page: currentPage.value,
|
|
22
|
+
size: pageSize.value
|
|
23
|
+
})
|
|
24
|
+
closeOperationPopover();
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const closeOperationPopover = () => {
|
|
28
|
+
operationPopoverRef.value?.forEach((item) => item?.doClose());
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const closeAllExpandedRows = () => {
|
|
32
|
+
if (!hasExpandRow) return
|
|
33
|
+
tableDomRef.value?.data.forEach((item) => {
|
|
34
|
+
tableDomRef.value?.toggleRowExpansion(item, false)
|
|
35
|
+
})
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const handleEdit = (scope) => {
|
|
39
|
+
// 折叠所有展开的行
|
|
40
|
+
closeAllExpandedRows();
|
|
41
|
+
const { row, $index: index } = scope;
|
|
42
|
+
editingRowData.value = {...row};
|
|
43
|
+
editingRowIndex.value = index;
|
|
44
|
+
emit('row-edit', { row, index, page: currentPage.value, size: pageSize.value});
|
|
45
|
+
closeOperationPopover();
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const handleRowPinToTop = (scope) => {
|
|
49
|
+
const { row, $index: index, store } = scope;
|
|
50
|
+
const dataList = store.states.data;
|
|
51
|
+
const newList = [
|
|
52
|
+
...dataList.slice(0, index),
|
|
53
|
+
...dataList.slice(index + 1)
|
|
54
|
+
];
|
|
55
|
+
newList.unshift({...row, isPinned: true});
|
|
56
|
+
store.states.data = newList;
|
|
57
|
+
emit('row-pin-to-top', { row, rawIndex: index, page: currentPage.value, size: pageSize.value});
|
|
58
|
+
closeOperationPopover();
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const handleEditSave = (row) => {
|
|
62
|
+
editingRowIndex.value = -1;
|
|
63
|
+
const changedData = {}
|
|
64
|
+
for (const key of Object.keys(row)) {
|
|
65
|
+
if (row[key] !== editingRowData.value[key]) {
|
|
66
|
+
changedData[key] = editingRowData.value[key]
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
emit('row-edit-save', {
|
|
71
|
+
page: currentPage.value,
|
|
72
|
+
size: pageSize.value,
|
|
73
|
+
row,
|
|
74
|
+
changedData
|
|
75
|
+
});
|
|
76
|
+
editingRowData.value = {};
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const handleEditCancel = (row) => {
|
|
80
|
+
editingRowIndex.value = -1;
|
|
81
|
+
editingRowData.value = {};
|
|
82
|
+
emit('row-edit-cancel', { row, page: currentPage.value, size: pageSize.value});
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return {
|
|
86
|
+
operationPopoverRef,
|
|
87
|
+
editingRowData,
|
|
88
|
+
editingRowIndex,
|
|
89
|
+
handleDelete,
|
|
90
|
+
closeAllExpandedRows,
|
|
91
|
+
handleEdit,
|
|
92
|
+
handleEditSave,
|
|
93
|
+
handleEditCancel,
|
|
94
|
+
handleRowPinToTop
|
|
95
|
+
}
|
|
96
|
+
}
|