-
Notifications
You must be signed in to change notification settings - Fork 284
/
Copy pathvue.ts
154 lines (147 loc) · 5.19 KB
/
vue.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
import type {
IPagerApi,
IPagerProps,
IPagerState,
ISharedRenderlessParamHooks,
IPagerRenderlessParamUtils
} from '@/types'
import {
computedShowPager,
computedInternalLayout,
computedTotalText,
computedInternalPageCount,
computedSimplestPagerOption,
computedSimplestPagerWidth,
handleJumperFocus,
handleSizeChange,
handleJumperInput,
handleJumperChange,
handleJumperClick,
isValueNumber,
parseValueNumber,
handleSizeShowPopover,
handleSizeHidePopover,
canJumperGo,
beforeSizeChangeHandler,
beforePagerChangeHandler,
copyEmit,
beforeChangeHandler,
handleCurrentChange,
prev,
next,
buildBeforePageChangeParam,
getValidCurrentPage,
emitChange,
setTotal,
clickSizes,
watchInternalCurrentPage,
watchPageSizes,
watchCurrentPage,
watchInternalPageCount,
watchPageSize,
watchTotal,
watchShowSizes
} from './index'
export const api = [
'state',
'handleJumperFocus',
'handleSizeChange',
'handleJumperInput',
'handleJumperChange',
'handleJumperClick',
'isValueNumber',
'parseValueNumber',
'handleSizeShowPopover',
'handleSizeHidePopover',
'canJumperGo',
'beforeSizeChangeHandler',
'beforePagerChangeHandler',
'beforeJumperChangeHandler',
'beforeChangeHandler',
'handleCurrentChange',
'prev',
'next',
'buildBeforePageChangeParam',
'getValidCurrentPage',
'emitChange',
'setTotal',
'clickSizes'
]
export const renderless = (
props: IPagerProps,
{ reactive, computed, watch }: ISharedRenderlessParamHooks,
{ emit, vm, nextTick, t, designConfig }: IPagerRenderlessParamUtils
): IPagerApi => {
const api = {} as IPagerApi
const state: IPagerState = reactive({
showSizes: false,
internalCurrentPage: 1,
internalPageSize: props.pageSize,
lastEmittedPage: -1,
userChangePageSize: false,
internalTotal: props.total,
jumperValue: '1',
jumperBackup: '1',
simplestPagerOption: computed(() => api.computedSimplestPagerOption()),
simplestPagerWidth: computed(() => api.computedSimplestPagerWidth()),
showPager: computed(() => api.computedShowPager()),
internalLayout: computed(() => api.computedInternalLayout()),
totalText: computed(() => api.computedTotalText()),
internalPageCount: computed(() => api.computedInternalPageCount()),
showJumperSufix: designConfig?.state?.showJumperSufix ?? true,
align: props.align || designConfig?.state?.align || 'left',
totalI18n: designConfig?.state?.totalI18n || 'totals',
totalFixedLeft: computed(
() => props.totalFixedLeft ?? designConfig?.state?.totalFixedLeft ?? props.mode !== 'simplest' ?? true
),
pageSizeText: props.pageSizeText ?? designConfig?.state?.pageSizeText
})
Object.assign(api, {
state,
computedShowPager: computedShowPager({ props, state }),
computedInternalLayout: computedInternalLayout({ props }),
computedTotalText: computedTotalText({ props, t }),
computedInternalPageCount: computedInternalPageCount({ props, state }),
computedSimplestPagerOption: computedSimplestPagerOption({ props, state }),
computedSimplestPagerWidth: computedSimplestPagerWidth({ state }),
getValidCurrentPage: getValidCurrentPage({ state }),
handleJumperFocus: handleJumperFocus({ state }),
handleSizeChange: handleSizeChange({ props, state, api, emit, vm }),
handleJumperInput: handleJumperInput({ state }),
handleJumperChange: handleJumperChange({ props, state, api }),
handleJumperClick: handleJumperClick({ props, state, api }),
isValueNumber: isValueNumber({ state }),
parseValueNumber: parseValueNumber({ state }),
handleSizeShowPopover: handleSizeShowPopover({ state, props }),
handleSizeHidePopover: handleSizeHidePopover({ state }),
canJumperGo: canJumperGo({ props, state, vm }),
beforeSizeChangeHandler: beforeSizeChangeHandler({ state, emit }),
beforePagerChangeHandler: beforePagerChangeHandler({ state, emit }),
copyEmit: copyEmit({ emit }),
beforeChangeHandler: beforeChangeHandler({ state, api }),
handleCurrentChange: handleCurrentChange({ state, api }),
prev: prev({ state, props, api, emit }),
next: next({ props, state, api, emit }),
buildBeforePageChangeParam: buildBeforePageChangeParam({ state }),
emitChange: emitChange({ state, nextTick, emit }),
setTotal: setTotal({ state }),
clickSizes: clickSizes(),
// watch
watchInternalCurrentPage: watchInternalCurrentPage({ state, emit }),
watchPageSizes: watchPageSizes({ state, props }),
watchCurrentPage: watchCurrentPage({ state, api }),
watchInternalPageCount: watchInternalPageCount({ state, api }),
watchPageSize: watchPageSize({ state }),
watchTotal: watchTotal({ state }),
watchShowSizes: watchShowSizes({ nextTick, vm })
})
state.internalCurrentPage = api.getValidCurrentPage(props.currentPage)
watch(() => state.internalCurrentPage, api.watchInternalCurrentPage)
watch(() => props.pageSizes, api.watchPageSizes, { immediate: true })
watch(() => props.currentPage, api.watchCurrentPage)
watch(() => state.internalPageCount, api.watchInternalPageCount)
watch(() => props.pageSize, api.watchPageSize, { immediate: true })
watch(() => props.total, api.watchTotal)
watch(() => state.showSizes, api.watchShowSizes)
return api
}