@kyfe/ks-query-table 0.0.2 → 0.0.3
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/index.js +35386 -7
- package/package.json +7 -5
- package/query-table.common.js.map +1 -0
- package/query-table.css +1 -0
- package/query-table.umd.js +35396 -0
- package/query-table.umd.js.map +1 -0
- package/query-table.umd.min.js +11 -0
- package/query-table.umd.min.js.map +1 -0
- package/README.md +0 -45
- package/api/index.js +0 -12
- package/assets/horizontal-back.svg +0 -1
- package/components/pe-table/cell.js +0 -184
- package/components/pe-table/collapse.js +0 -334
- package/components/pe-table/empty.vue +0 -48
- package/components/pe-table/header.js +0 -328
- package/components/pe-table/images/abnormal.png +0 -0
- package/components/pe-table/images/empty.png +0 -0
- package/components/pe-table/images/fold.svg +0 -1
- package/components/pe-table/images/sort.svg +0 -1
- package/components/pe-table/images/sorting.svg +0 -1
- package/components/pe-table/images/unfold.svg +0 -1
- package/components/pe-table/index.vue +0 -837
- package/components/pe-table/load-more.js +0 -46
- package/components/pe-table/props/index.js +0 -183
- package/components/pe-table/row.vue +0 -118
- package/components/pe-table/scrollbar.js +0 -424
- package/components/pe-table/stretch-damping.js +0 -112
- package/components/pe-table/style/cell.less +0 -89
- package/components/pe-table/style/empty.less +0 -48
- package/components/pe-table/style/header.less +0 -141
- package/components/pe-table/style/index.less +0 -88
- package/components/pe-table/style/load-more.less +0 -61
- package/components/pe-table/style/row.less +0 -6
- package/components/pe-table/table-loading.vue +0 -119
- package/components/pe-table/table-total.vue +0 -53
- package/components/pe-table/utils/animate.js +0 -80
- package/components/pe-table/utils/columns.js +0 -290
- package/components/pe-table/utils/data.js +0 -12
- package/components/pe-table/utils/fixed.js +0 -69
- package/components/pe-table/utils/formatter.js +0 -327
- package/components/pe-table/utils/render-cells.js +0 -424
- package/components/pe-table/utils/slot.js +0 -28
- package/components/pe-table/utils/tools.js +0 -84
- package/components/pe-table/utils/touch-scroll.js +0 -417
- package/components/query-table/index.vue +0 -492
- package/components/query-table/mixins/column-mixin.js +0 -102
- package/components/query-table/mixins/column-setting.js +0 -143
- package/components/query-table/mixins/data-mixin.js +0 -502
- package/components/query-table/mixins/pagination-mixin.js +0 -25
- package/components/query-table/mixins/table-fixed.js +0 -111
- package/components/query-table/mixins/table-horizontal.js +0 -119
- package/components/table-horizontal.vue +0 -99
- package/components/table-pagination.vue +0 -32
- package/components/table-settings/assets/arrpw-up.svg +0 -1
- package/components/table-settings/assets/disabled-down.svg +0 -1
- package/components/table-settings/assets/disabled-up.svg +0 -1
- package/components/table-settings/assets/down.svg +0 -1
- package/components/table-settings/assets/up.svg +0 -1
- package/components/table-settings/index.less +0 -294
- package/components/table-settings/index.vue +0 -260
- package/components/table-settings/settings.vue +0 -479
- package/components/table-settings/test.js +0 -626
- package/components/table-settings//344/270/252/346/200/247/350/256/276/347/275/256.md +0 -0
- package/components/tooltip.js +0 -124
- package/hooks/use-cache-promise.js +0 -27
- package/hooks/use-column-config.js +0 -186
- package/hooks/use-encryption.js +0 -0
- package/hooks/use-generic-search.js +0 -95
- package/store/column-store.js +0 -0
- package/styles/table.less +0 -24
- package/utils/column.js +0 -36
- package/utils/config.js +0 -12
- package/utils/encryption.js +0 -32
- package/utils/http.js +0 -1
- package/utils/localStorage.js +0 -35
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
.pe-table-header_cell {
|
|
2
|
-
position: absolute;
|
|
3
|
-
left: 0;
|
|
4
|
-
display: flex;
|
|
5
|
-
align-items: center;
|
|
6
|
-
box-sizing: border-box;
|
|
7
|
-
font-size: 12PX;
|
|
8
|
-
padding: 0 8PX;
|
|
9
|
-
height: 100%;
|
|
10
|
-
overflow: hidden;
|
|
11
|
-
background-color: #f7f8fa;
|
|
12
|
-
color: #575555;
|
|
13
|
-
// border-bottom: 1PX solid #D9DEE2;
|
|
14
|
-
// border-right: 0.5PX solid #DEDEDE;
|
|
15
|
-
}
|
|
16
|
-
.ks-multi-screen .pe-table-header_cell {
|
|
17
|
-
font-size: 13PX !important;
|
|
18
|
-
}
|
|
19
|
-
.pe-table-header_cell::after {
|
|
20
|
-
content: '';
|
|
21
|
-
position: absolute;
|
|
22
|
-
top: 0;
|
|
23
|
-
right: 0;
|
|
24
|
-
width: 1px;
|
|
25
|
-
height: 100%;
|
|
26
|
-
background-color: #DEDEDE;
|
|
27
|
-
transform-origin: right;
|
|
28
|
-
transform: scaleX(0.5);
|
|
29
|
-
}
|
|
30
|
-
.pe-table-header_cell.center {
|
|
31
|
-
justify-content: center;
|
|
32
|
-
}
|
|
33
|
-
.pe-table-header_cell.right {
|
|
34
|
-
justify-content: flex-end
|
|
35
|
-
}
|
|
36
|
-
.pe-table-header_cell.left {
|
|
37
|
-
justify-content: flex-start
|
|
38
|
-
}
|
|
39
|
-
// .pe-table-header_cell::before {
|
|
40
|
-
// position: absolute;
|
|
41
|
-
// content: '';
|
|
42
|
-
// display: block;
|
|
43
|
-
// padding: 8px 0;
|
|
44
|
-
// right: 0;
|
|
45
|
-
// width: 1px;
|
|
46
|
-
// background: #d9dee2;
|
|
47
|
-
// }
|
|
48
|
-
.pe-table-header_cell.overflow span {
|
|
49
|
-
overflow: hidden;
|
|
50
|
-
white-space: nowrap;
|
|
51
|
-
text-overflow: ellipsis;
|
|
52
|
-
}
|
|
53
|
-
.pe-table-header_cell-label {
|
|
54
|
-
overflow: hidden;
|
|
55
|
-
white-space: nowrap;
|
|
56
|
-
text-overflow: ellipsis;
|
|
57
|
-
}
|
|
58
|
-
.pe-table-header_cell-sort {
|
|
59
|
-
margin-left: 3PX;
|
|
60
|
-
display: flex;
|
|
61
|
-
align-items: center;
|
|
62
|
-
justify-content: center;
|
|
63
|
-
flex-direction: column;
|
|
64
|
-
width: 8PX;
|
|
65
|
-
height: 14PX;
|
|
66
|
-
}
|
|
67
|
-
.pe-table-header_cell-sort .sort-caret {
|
|
68
|
-
background: url('../images/sort.svg');
|
|
69
|
-
background-repeat: no-repeat;
|
|
70
|
-
background-size: 8PX 4PX;
|
|
71
|
-
width: 8PX;
|
|
72
|
-
height: 4PX;
|
|
73
|
-
}
|
|
74
|
-
.pe-table-header_cell-sort .descending {
|
|
75
|
-
margin-top: 2PX;
|
|
76
|
-
transform: rotate(180deg);
|
|
77
|
-
}
|
|
78
|
-
.pe-table-header_cell-sort.ascending .sort-caret.ascending {
|
|
79
|
-
background: url('../images/sorting.svg');
|
|
80
|
-
background-repeat: no-repeat;
|
|
81
|
-
background-size: 8PX 4PX;
|
|
82
|
-
}
|
|
83
|
-
.pe-table-header_cell-sort.descending .sort-caret.descending {
|
|
84
|
-
background: url('../images/sorting.svg');
|
|
85
|
-
background-repeat: no-repeat;
|
|
86
|
-
background-size: 8PX 4PX;
|
|
87
|
-
}
|
|
88
|
-
.pe-table-header_cell-collapse {
|
|
89
|
-
position: relative;
|
|
90
|
-
box-sizing: border-box;
|
|
91
|
-
display: inline-block;
|
|
92
|
-
width: 12PX;
|
|
93
|
-
height: 20PX;
|
|
94
|
-
margin-left: 6PX;
|
|
95
|
-
margin-right: -2PX;
|
|
96
|
-
padding: 4PX 0;
|
|
97
|
-
}
|
|
98
|
-
.pe-table-header_cell-collapse::after {
|
|
99
|
-
content: '';
|
|
100
|
-
position: absolute;
|
|
101
|
-
top: 0;
|
|
102
|
-
right: -8PX;
|
|
103
|
-
width: 8PX;
|
|
104
|
-
height: 100%;
|
|
105
|
-
background-color: transparent;
|
|
106
|
-
}
|
|
107
|
-
.pe-table-header_cell-collapse::before {
|
|
108
|
-
content: '';
|
|
109
|
-
position: absolute;
|
|
110
|
-
top: 0;
|
|
111
|
-
left: -8PX;
|
|
112
|
-
width: 8PX;
|
|
113
|
-
height: 100%;
|
|
114
|
-
background-color: transparent;
|
|
115
|
-
}
|
|
116
|
-
.pe-table-header_cell-collapse.unfold {
|
|
117
|
-
background: url('../images/unfold.svg');
|
|
118
|
-
background-size: 12PX 12PX;
|
|
119
|
-
background-position: center;
|
|
120
|
-
background-repeat: no-repeat;
|
|
121
|
-
background-clip: content-box;
|
|
122
|
-
}
|
|
123
|
-
.pe-table-header_cell-collapse.fold {
|
|
124
|
-
background: url('../images/fold.svg');
|
|
125
|
-
background-size: 12PX 12PX;
|
|
126
|
-
background-position: center;
|
|
127
|
-
background-repeat: no-repeat;
|
|
128
|
-
background-clip: content-box;
|
|
129
|
-
}
|
|
130
|
-
.pe-table-header_cell.collapse-bg {
|
|
131
|
-
background-color: #F0F3F8 !important;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
.pe-table-scrolling__x {
|
|
135
|
-
.pe-table-header_cell__last-fixed {
|
|
136
|
-
box-shadow: 4px 0 6px -4px rgba(28, 32, 35, 0.1);
|
|
137
|
-
}
|
|
138
|
-
.pe-table-header_cell__last-fixed.pe-table-header_cell::after {
|
|
139
|
-
display: none;
|
|
140
|
-
}
|
|
141
|
-
}
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
.pe-table-wrap {
|
|
2
|
-
height: 100%;
|
|
3
|
-
overflow: hidden;
|
|
4
|
-
}
|
|
5
|
-
.pe-table-container {
|
|
6
|
-
position: relative;
|
|
7
|
-
height: 100%;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
.pe-table-scrollbar_horizontal-track {
|
|
11
|
-
position: absolute;
|
|
12
|
-
bottom: 0;
|
|
13
|
-
z-index: 10;
|
|
14
|
-
// height: 4PX;
|
|
15
|
-
height: var(--peHScrollbarSize);
|
|
16
|
-
width: 100%;
|
|
17
|
-
// cursor: pointer;
|
|
18
|
-
}
|
|
19
|
-
.pe-table-scrollbar_horizontal-thumb {
|
|
20
|
-
background-color: transparent;
|
|
21
|
-
height: 100%;
|
|
22
|
-
// cursor: pointer;
|
|
23
|
-
border-radius: 0.25rem;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
.pe-table-scrollbar_vertical-track {
|
|
27
|
-
position: absolute;
|
|
28
|
-
right: 0;
|
|
29
|
-
height: 100%;
|
|
30
|
-
// width: 4PX;
|
|
31
|
-
width: var(--peVScrollbarSize);
|
|
32
|
-
z-index: 10;
|
|
33
|
-
// cursor: pointer;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
.pe-table-scrollbar_vertical-thumb {
|
|
37
|
-
border-radius: 0.25rem;
|
|
38
|
-
width: 100%;
|
|
39
|
-
// cursor: pointer;
|
|
40
|
-
background-color: transparent;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
.pe-table-wrap .hidden {
|
|
44
|
-
transition: opacity 0.3s ease-in-out;
|
|
45
|
-
opacity: 0;
|
|
46
|
-
}
|
|
47
|
-
.pe-table-wrap .visible {
|
|
48
|
-
transition: opacity 0.3s ease-in-out;
|
|
49
|
-
opacity: 1;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
.pe-table-resize_line {
|
|
53
|
-
position: absolute;
|
|
54
|
-
top: 0;
|
|
55
|
-
width: 2PX;
|
|
56
|
-
height: 100%;
|
|
57
|
-
z-index: 10;
|
|
58
|
-
background-color: #e66868;
|
|
59
|
-
display: none;
|
|
60
|
-
}
|
|
61
|
-
.pe-table-resize_line-thumb {
|
|
62
|
-
position: absolute;
|
|
63
|
-
top: 0;
|
|
64
|
-
right: 0;
|
|
65
|
-
width: 4PX;
|
|
66
|
-
background-color: #e66868;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
.load-more {
|
|
70
|
-
position: relative;
|
|
71
|
-
will-change: transform;
|
|
72
|
-
transform: translateY(-9999px);
|
|
73
|
-
height: 180PX;
|
|
74
|
-
width: 100%;
|
|
75
|
-
// opacity: 0;
|
|
76
|
-
// z-index: -1;
|
|
77
|
-
}
|
|
78
|
-
.stretch {
|
|
79
|
-
position: relative;
|
|
80
|
-
will-change: transform;
|
|
81
|
-
transform: translateY(-9999px);
|
|
82
|
-
height: 44PX;
|
|
83
|
-
line-height: 44PX;
|
|
84
|
-
font-size: 13PX;
|
|
85
|
-
color: #7B7878;
|
|
86
|
-
width: 100%;
|
|
87
|
-
text-align: center;
|
|
88
|
-
}
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
.pe-table-load-more {
|
|
2
|
-
display: flex;
|
|
3
|
-
width: 100%;
|
|
4
|
-
height: 44PX;
|
|
5
|
-
justify-content: center;
|
|
6
|
-
align-items: center;
|
|
7
|
-
.loading {
|
|
8
|
-
width: 14PX;
|
|
9
|
-
height: 14PX;
|
|
10
|
-
border: 1PX solid transparent;
|
|
11
|
-
border-top-color: #03050D;
|
|
12
|
-
border-left-color: #03050D;
|
|
13
|
-
border-bottom-color: #03050D;
|
|
14
|
-
border-radius: 50%;
|
|
15
|
-
animation: spin 1s ease-in-out infinite;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
@keyframes spin {
|
|
19
|
-
to {
|
|
20
|
-
transform: rotate(360deg);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
.loading-container {
|
|
24
|
-
display: inline-block;
|
|
25
|
-
font-size: 13PX;
|
|
26
|
-
color: #C2C0C0;
|
|
27
|
-
}
|
|
28
|
-
.loading-color {
|
|
29
|
-
padding-left: 8PX;
|
|
30
|
-
color: #03050D !important;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
.dots {
|
|
34
|
-
display: inline-block;
|
|
35
|
-
width: 0;
|
|
36
|
-
overflow: hidden;
|
|
37
|
-
vertical-align: bottom;
|
|
38
|
-
animation: dotAnimation 2s infinite;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
@keyframes dotAnimation {
|
|
42
|
-
0% {
|
|
43
|
-
width: 0;
|
|
44
|
-
}
|
|
45
|
-
20% {
|
|
46
|
-
width: 0.4em;
|
|
47
|
-
}
|
|
48
|
-
40% {
|
|
49
|
-
width: 0.8em;
|
|
50
|
-
}
|
|
51
|
-
60% {
|
|
52
|
-
width: 1.2em;
|
|
53
|
-
}
|
|
54
|
-
80% {
|
|
55
|
-
width: 1.2em;
|
|
56
|
-
}
|
|
57
|
-
100% {
|
|
58
|
-
width: 0;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
<script>
|
|
2
|
-
function sleep(timestamp) {
|
|
3
|
-
return new Promise(resolve => setTimeout(resolve, timestamp))
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
export default {
|
|
7
|
-
props: {
|
|
8
|
-
delayLoading: { type: Number, default: 0 },
|
|
9
|
-
|
|
10
|
-
top: {
|
|
11
|
-
type: [Number, String],
|
|
12
|
-
default: 0,
|
|
13
|
-
},
|
|
14
|
-
headerTotalHeight: {
|
|
15
|
-
type: [Number, String],
|
|
16
|
-
default: 0,
|
|
17
|
-
},
|
|
18
|
-
},
|
|
19
|
-
data() {
|
|
20
|
-
return { endDelay: false }
|
|
21
|
-
},
|
|
22
|
-
mounted() {
|
|
23
|
-
this.delayLoading && sleep(this.delayLoading).finally(() => (this.endDelay = true))
|
|
24
|
-
},
|
|
25
|
-
render() {
|
|
26
|
-
const $props = this.$props
|
|
27
|
-
const top = $props.top ? $props.top : $props.headerTotalHeight + 30
|
|
28
|
-
const style = {
|
|
29
|
-
top: top + 'PX',
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
if (this.delayLoading && !this.endDelay) return null
|
|
33
|
-
|
|
34
|
-
return (
|
|
35
|
-
<div class="table-loading">
|
|
36
|
-
<div class="loading-wrap" style={style}>
|
|
37
|
-
<div class="loading"></div>
|
|
38
|
-
</div>
|
|
39
|
-
</div>
|
|
40
|
-
)
|
|
41
|
-
},
|
|
42
|
-
methods: {
|
|
43
|
-
handleMaskClick(event) {
|
|
44
|
-
event.stopPropagation()
|
|
45
|
-
event.preventDefault()
|
|
46
|
-
},
|
|
47
|
-
},
|
|
48
|
-
}
|
|
49
|
-
</script>
|
|
50
|
-
<style lang="less" scoped>
|
|
51
|
-
.table-loading {
|
|
52
|
-
z-index: 999;
|
|
53
|
-
position: absolute;
|
|
54
|
-
top: 0;
|
|
55
|
-
left: 0;
|
|
56
|
-
bottom: 0;
|
|
57
|
-
right: 0;
|
|
58
|
-
.loading-wrap {
|
|
59
|
-
position: absolute;
|
|
60
|
-
left: 50%;
|
|
61
|
-
transform: translateX(-50%);
|
|
62
|
-
color: #03050d;
|
|
63
|
-
display: flex;
|
|
64
|
-
width: 16px;
|
|
65
|
-
height: 30px;
|
|
66
|
-
align-items: center;
|
|
67
|
-
.loading {
|
|
68
|
-
width: 14px;
|
|
69
|
-
height: 14px;
|
|
70
|
-
border: 1px solid transparent;
|
|
71
|
-
border-top-color: #03050d;
|
|
72
|
-
border-left-color: #03050d;
|
|
73
|
-
border-bottom-color: #03050d;
|
|
74
|
-
border-radius: 50%;
|
|
75
|
-
animation: spin 1s ease-in-out infinite;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
@keyframes spin {
|
|
79
|
-
to {
|
|
80
|
-
transform: rotate(360deg);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
// .loading-container {
|
|
84
|
-
// padding-left: 8PX;
|
|
85
|
-
// display: inline-block;
|
|
86
|
-
// font-size: 14PX;
|
|
87
|
-
// }
|
|
88
|
-
|
|
89
|
-
// .dots {
|
|
90
|
-
// display: inline-block;
|
|
91
|
-
// width: 0;
|
|
92
|
-
// overflow: hidden;
|
|
93
|
-
// vertical-align: bottom;
|
|
94
|
-
// animation: dotAnimation 2s infinite;
|
|
95
|
-
// }
|
|
96
|
-
|
|
97
|
-
@keyframes dotAnimation {
|
|
98
|
-
0% {
|
|
99
|
-
width: 0;
|
|
100
|
-
}
|
|
101
|
-
20% {
|
|
102
|
-
width: 0.4em;
|
|
103
|
-
}
|
|
104
|
-
40% {
|
|
105
|
-
width: 0.8em;
|
|
106
|
-
}
|
|
107
|
-
60% {
|
|
108
|
-
width: 1.2em;
|
|
109
|
-
}
|
|
110
|
-
80% {
|
|
111
|
-
width: 1.2em;
|
|
112
|
-
}
|
|
113
|
-
100% {
|
|
114
|
-
width: 0;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
</style>
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
<script>
|
|
2
|
-
export default {
|
|
3
|
-
props: {
|
|
4
|
-
show: {
|
|
5
|
-
type: Boolean,
|
|
6
|
-
default: false
|
|
7
|
-
},
|
|
8
|
-
endRow: {
|
|
9
|
-
type: [Number, String],
|
|
10
|
-
default: 0
|
|
11
|
-
},
|
|
12
|
-
total: {
|
|
13
|
-
type: [Number, String],
|
|
14
|
-
default: 0
|
|
15
|
-
}
|
|
16
|
-
},
|
|
17
|
-
render () {
|
|
18
|
-
const style = {
|
|
19
|
-
display: this.show ? 'block' : 'none',
|
|
20
|
-
}
|
|
21
|
-
return (
|
|
22
|
-
<div class="table-total" style={style}>
|
|
23
|
-
<span class="total-end">{ `${this.endRow}` }</span><span>/</span><span>{ `${this.total}` }</span>
|
|
24
|
-
</div>
|
|
25
|
-
)
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
</script>
|
|
29
|
-
<style lang="less" scoped>
|
|
30
|
-
.table-total {
|
|
31
|
-
z-index: 999;
|
|
32
|
-
position: absolute;
|
|
33
|
-
bottom: 16PX;
|
|
34
|
-
left: 50%;
|
|
35
|
-
transform: translate(-50%, -50%);
|
|
36
|
-
width: 64PX;
|
|
37
|
-
height: 20PX;
|
|
38
|
-
line-height: 20PX;
|
|
39
|
-
font-size: 12PX;
|
|
40
|
-
color: #1D1919;
|
|
41
|
-
text-align: center;
|
|
42
|
-
border-radius: 100PX;
|
|
43
|
-
background: rgba(255, 255, 255, 0.9);
|
|
44
|
-
box-shadow: 0px 0px 6px 0px rgba(28, 32, 35, 0.12);
|
|
45
|
-
.total-end {
|
|
46
|
-
color: #F2412F;
|
|
47
|
-
}
|
|
48
|
-
.popup-content {
|
|
49
|
-
padding-bottom: constant(safe-area-inset-bottom);
|
|
50
|
-
padding-bottom: env(safe-area-inset-bottom)
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
</style>
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
export function smoothEaseOut(t) {
|
|
2
|
-
return t < 0.5 ? 4 * t * t * t : 1 - Math.pow(-2 * t + 2, 3) / 2;
|
|
3
|
-
}
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* 平滑滚动到指定位置
|
|
7
|
-
* @param {Object} options 滚动配置
|
|
8
|
-
* @param {Number} options.from 起始位置
|
|
9
|
-
* @param {Number} options.to 目标位置
|
|
10
|
-
* @param {Number} options.duration 动画持续时间(毫秒)
|
|
11
|
-
* @param {Function} options.onUpdate 位置更新回调
|
|
12
|
-
* @param {Function} [options.onComplete] 动画完成回调
|
|
13
|
-
* @param {Function} [options.easing=easeOutCubic] 缓动函数
|
|
14
|
-
*/
|
|
15
|
-
export function animateScroll(options) {
|
|
16
|
-
const {
|
|
17
|
-
from,
|
|
18
|
-
to,
|
|
19
|
-
duration,
|
|
20
|
-
onUpdate,
|
|
21
|
-
onComplete,
|
|
22
|
-
easing = smoothEaseOut
|
|
23
|
-
} = options
|
|
24
|
-
|
|
25
|
-
const startTime = performance.now()
|
|
26
|
-
const distance = to - from
|
|
27
|
-
let animationId = null
|
|
28
|
-
let lastPos = from
|
|
29
|
-
|
|
30
|
-
const animate = (currentTime = performance.now()) => {
|
|
31
|
-
const elapsed = currentTime - startTime
|
|
32
|
-
const progress = Math.min(elapsed / duration, 1)
|
|
33
|
-
|
|
34
|
-
// 时间补偿
|
|
35
|
-
if (progress < 1) {
|
|
36
|
-
animationId = requestAnimationFrame(animate)
|
|
37
|
-
const nextFrameTime = performance.now()
|
|
38
|
-
const frameDuration = nextFrameTime - currentTime
|
|
39
|
-
|
|
40
|
-
if (frameDuration > 16.7) {
|
|
41
|
-
const compensation = frameDuration / 16.7
|
|
42
|
-
const compensatedProgress = Math.min(progress * compensation, 1)
|
|
43
|
-
const easedProgress = easing(compensatedProgress)
|
|
44
|
-
const currentPos = from + (distance * easedProgress)
|
|
45
|
-
if (Math.abs(currentPos - lastPos) >= 1) {
|
|
46
|
-
onUpdate(currentPos)
|
|
47
|
-
lastPos = currentPos
|
|
48
|
-
}
|
|
49
|
-
return
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
// 正常计算
|
|
54
|
-
const easedProgress = easing(progress)
|
|
55
|
-
const currentPos = from + (distance * easedProgress)
|
|
56
|
-
|
|
57
|
-
if (Math.abs(currentPos - lastPos) >= 1) {
|
|
58
|
-
onUpdate(currentPos)
|
|
59
|
-
lastPos = currentPos
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
if (progress >= 1) {
|
|
63
|
-
onUpdate(to) // 确保到达终点
|
|
64
|
-
if (onComplete) onComplete()
|
|
65
|
-
animationId = null
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
animationId = requestAnimationFrame(animate)
|
|
70
|
-
|
|
71
|
-
// 返回取消函数
|
|
72
|
-
return {
|
|
73
|
-
cancel: () => {
|
|
74
|
-
if (animationId) {
|
|
75
|
-
cancelAnimationFrame(animationId)
|
|
76
|
-
animationId = null
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
}
|