jobsys-newbie 2.2.1 → 2.2.2
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/components/pagination/NewbiePagination.jsx +272 -0
- package/components/pagination/index.js +5 -0
- package/components/pagination/index.less +0 -0
- package/components/provider/NewbieProvider.jsx +1 -0
- package/components/table/NewbieTable.jsx +1 -1
- package/dist/jobsys-newbie.cjs +1 -1
- package/dist/jobsys-newbie.cjs.map +1 -1
- package/dist/jobsys-newbie.js +1 -1
- package/dist/jobsys-newbie.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
import { defineComponent, inject, reactive, ref } from "vue"
|
|
2
|
+
import { isBoolean, isUndefined } from "lodash-es"
|
|
3
|
+
import { useCache, useFetch, useProcessStatusSuccess, useSm3 } from "../../hooks"
|
|
4
|
+
|
|
5
|
+
import "./index.less"
|
|
6
|
+
import NewbieSearch from "../search/NewbieSearch.jsx"
|
|
7
|
+
import { Divider } from "ant-design-vue"
|
|
8
|
+
import { NEWBIE_PAGINATION } from "../provider/NewbieProvider.jsx"
|
|
9
|
+
/**
|
|
10
|
+
* 分页组件
|
|
11
|
+
*
|
|
12
|
+
*
|
|
13
|
+
* @version 2.1.0
|
|
14
|
+
*/
|
|
15
|
+
export default defineComponent({
|
|
16
|
+
name: "NewbiePagination",
|
|
17
|
+
props: {
|
|
18
|
+
/**
|
|
19
|
+
* 是否使用分页,为 Object 时时使用自定义分页
|
|
20
|
+
*/
|
|
21
|
+
pagination: { type: [Boolean, Object], default: true },
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* 原生翻页事件
|
|
25
|
+
*/
|
|
26
|
+
pageEvents: { type: Object, default: () => ({}) },
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* 是否使用表单搜索
|
|
30
|
+
*/
|
|
31
|
+
filterable: { type: Boolean, default: true },
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* 请求数据URL
|
|
35
|
+
*
|
|
36
|
+
*/
|
|
37
|
+
url: { type: String, default: "" },
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* 请求方式,默认为 GET
|
|
41
|
+
*
|
|
42
|
+
* @values get, post
|
|
43
|
+
*/
|
|
44
|
+
method: { type: String, default: "get" },
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* 请求数据时额外提交的参数
|
|
48
|
+
*/
|
|
49
|
+
extraData: { type: Object, default: () => ({}) },
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* 加载后数据的回调函数
|
|
53
|
+
*/
|
|
54
|
+
afterFetched: { type: Function, default: null },
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* 数据为空文案
|
|
58
|
+
*/
|
|
59
|
+
emptyText: { type: String, default: "暂无内容" },
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* 加载错误文案
|
|
63
|
+
*/
|
|
64
|
+
errorText: { type: String, default: "加载失败,点击重新加载" },
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* 持久化,传入 localStorage 的 key,如果为 true, 将会以 URL Hash 为 key
|
|
68
|
+
*/
|
|
69
|
+
persistence: { type: [Boolean, String], default: false },
|
|
70
|
+
},
|
|
71
|
+
emits: [
|
|
72
|
+
/**
|
|
73
|
+
* 未传入 `url` 时的手动请求方法
|
|
74
|
+
*/
|
|
75
|
+
"fetch",
|
|
76
|
+
],
|
|
77
|
+
|
|
78
|
+
setup(props, { slots, emit, expose }) {
|
|
79
|
+
const searchRef = ref()
|
|
80
|
+
const footerElemRef = ref()
|
|
81
|
+
|
|
82
|
+
const paginationProvider = inject(NEWBIE_PAGINATION, () => {})
|
|
83
|
+
|
|
84
|
+
const genPersistenceKey = (prefix) => {
|
|
85
|
+
if (!props.persistence) {
|
|
86
|
+
return null
|
|
87
|
+
}
|
|
88
|
+
prefix = prefix || ""
|
|
89
|
+
if (isBoolean(props.persistence)) {
|
|
90
|
+
return `newbiePagination_${prefix}` + useSm3(location.href)
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return `newbiePagination_${prefix}` + useSm3(location.pathname + "_" + props.persistence)
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
let persistencePagination = props.persistence ? useCache(genPersistenceKey()).get({}) : {}
|
|
97
|
+
|
|
98
|
+
const state = reactive({
|
|
99
|
+
pagination: {
|
|
100
|
+
// 翻页数据
|
|
101
|
+
totalSize: 0,
|
|
102
|
+
currentPage: persistencePagination.currentPage || 1,
|
|
103
|
+
pageSize: persistencePagination.pageSize || props.pagination?.pageSize || 10,
|
|
104
|
+
},
|
|
105
|
+
|
|
106
|
+
isLoading: { loading: false }, // 翻页Loading
|
|
107
|
+
|
|
108
|
+
items: [], // 页面数据
|
|
109
|
+
searchFormData: {}, // 搜索表单数据
|
|
110
|
+
})
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* 持久化翻页与滚动
|
|
114
|
+
*/
|
|
115
|
+
const onPersistence = () => {
|
|
116
|
+
if (!props.persistence) {
|
|
117
|
+
return
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const data = {
|
|
121
|
+
...state.pagination,
|
|
122
|
+
}
|
|
123
|
+
useCache(genPersistenceKey()).set(data)
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const getQueryData = () => {
|
|
127
|
+
let params = { ...state.searchFormData, ...props.extraData }
|
|
128
|
+
if (props.pagination) {
|
|
129
|
+
if (state.pagination.pageSize) {
|
|
130
|
+
params[NEWBIE_PAGINATION.pageSizeKey] = state.pagination.pageSize
|
|
131
|
+
}
|
|
132
|
+
params[NEWBIE_PAGINATION.pageKey] = state.pagination.currentPage
|
|
133
|
+
}
|
|
134
|
+
return params
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const setQueryData = (fields) => {
|
|
138
|
+
if (searchRef.value) {
|
|
139
|
+
searchRef.value?.setQueryForm(fields)
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const fetchItems = async () => {
|
|
144
|
+
let data = {},
|
|
145
|
+
params = getQueryData()
|
|
146
|
+
|
|
147
|
+
const method = props.method
|
|
148
|
+
|
|
149
|
+
if (method === "get") {
|
|
150
|
+
data = { params }
|
|
151
|
+
} else if (method === "post") {
|
|
152
|
+
data = { ...params }
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
const res = await useFetch(state.isLoading)[method](props.url, data)
|
|
156
|
+
useProcessStatusSuccess(res, () => {
|
|
157
|
+
const fetched = props.afterFetched || paginationProvider.afterFetched
|
|
158
|
+
const result = fetched(res)
|
|
159
|
+
if (props.pagination) {
|
|
160
|
+
state.pagination.totalSize = result.totalSize
|
|
161
|
+
}
|
|
162
|
+
state.items = result.items
|
|
163
|
+
})
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* 执行获取数据
|
|
168
|
+
* @param {boolean} refresh 是否刷新
|
|
169
|
+
* @return {*}
|
|
170
|
+
*/
|
|
171
|
+
const doFetch = async (refresh) => {
|
|
172
|
+
if (refresh === true) {
|
|
173
|
+
state.pagination.currentPage = 1
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
if (props.url) {
|
|
177
|
+
await fetchItems()
|
|
178
|
+
} else {
|
|
179
|
+
emit("fetch")
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
onPersistence()
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
const onSearch = (searchData) => {
|
|
186
|
+
state.searchFormData = searchData
|
|
187
|
+
doFetch(!searchData.persistence)
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* 获取当前页的数据
|
|
191
|
+
* @returns {*[]}
|
|
192
|
+
*/
|
|
193
|
+
const getData = () => {
|
|
194
|
+
return [].concat(state.items)
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* 设置数据
|
|
199
|
+
* @param items
|
|
200
|
+
*/
|
|
201
|
+
const setData = (items) => {
|
|
202
|
+
state.items = items
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* 设置翻页数据
|
|
207
|
+
* @param {int} total
|
|
208
|
+
* @param {int} currentPage
|
|
209
|
+
* @param {int} pageSize
|
|
210
|
+
*/
|
|
211
|
+
const setPagination = (total, currentPage, pageSize) => {
|
|
212
|
+
if (!isUndefined(total)) {
|
|
213
|
+
state.pagination.totalSize = total
|
|
214
|
+
}
|
|
215
|
+
if (!isUndefined(currentPage)) {
|
|
216
|
+
state.pagination.currentPage = currentPage
|
|
217
|
+
}
|
|
218
|
+
if (!isUndefined(pageSize)) {
|
|
219
|
+
state.pagination.pageSize = pageSize
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* 获取翻页数据
|
|
225
|
+
* @returns {*}
|
|
226
|
+
*/
|
|
227
|
+
const getPagination = () => state.pagination
|
|
228
|
+
|
|
229
|
+
expose({
|
|
230
|
+
getData,
|
|
231
|
+
setData,
|
|
232
|
+
setPagination,
|
|
233
|
+
getPagination,
|
|
234
|
+
getQueryData,
|
|
235
|
+
setQueryData,
|
|
236
|
+
doFetch,
|
|
237
|
+
})
|
|
238
|
+
/********** render **********/
|
|
239
|
+
|
|
240
|
+
const prependElem = () => (slots.prepend ? <div class={"newbie-pagination-prepend-wrapper"}>{slots.prepend()}</div> : null)
|
|
241
|
+
|
|
242
|
+
const filterElem = () =>
|
|
243
|
+
props.filterable
|
|
244
|
+
? [
|
|
245
|
+
<NewbieSearch
|
|
246
|
+
ref={searchRef}
|
|
247
|
+
persistence={props.persistence}
|
|
248
|
+
filterableColumns={state.filterableColumns}
|
|
249
|
+
sortableColumns={state.sortableColumns}
|
|
250
|
+
onSearch={onSearch}
|
|
251
|
+
>
|
|
252
|
+
{{
|
|
253
|
+
...props.searchSlots,
|
|
254
|
+
}}
|
|
255
|
+
</NewbieSearch>,
|
|
256
|
+
<Divider></Divider>,
|
|
257
|
+
]
|
|
258
|
+
: null
|
|
259
|
+
|
|
260
|
+
const footerElem = () =>
|
|
261
|
+
slots.append || props.pagination ? (
|
|
262
|
+
<div ref={footerElemRef} class={`newbie-pagination-footer`}>
|
|
263
|
+
<div class={"newbie-pagination-append-wrapper"}>{slots.append ? slots.append() : null}</div>
|
|
264
|
+
<div class={"newbie-pagination-pagination-wrapper"}></div>
|
|
265
|
+
</div>
|
|
266
|
+
) : null
|
|
267
|
+
|
|
268
|
+
const contentElem = () => <div class={"newbie-pagination-content-wrapper"}>{slots.default?.()}</div>
|
|
269
|
+
|
|
270
|
+
return () => <div class={"newbie-pagination"}>{[prependElem(), filterElem(), contentElem(), footerElem()]}</div>
|
|
271
|
+
},
|
|
272
|
+
})
|
|
File without changes
|
|
@@ -7,6 +7,7 @@ export const NEWBIE_TABLE = Symbol("NEWBIE_TABLE")
|
|
|
7
7
|
export const NEWBIE_UPLOADER = Symbol("NEWBIE_UPLOADER")
|
|
8
8
|
export const NEWBIE_FORM = Symbol("NEWBIE_FORM")
|
|
9
9
|
export const NEWBIE_SEARCH = Symbol("NEWBIE_SEARCH")
|
|
10
|
+
export const NEWBIE_PAGINATION = Symbol("NEWBIE_PAGINATION")
|
|
10
11
|
|
|
11
12
|
/**
|
|
12
13
|
* Newbie 配置组件
|
|
@@ -747,7 +747,7 @@ export default defineComponent({
|
|
|
747
747
|
showQuickJumper: true,
|
|
748
748
|
showSizeChanger: true,
|
|
749
749
|
showTotal: (total) => useT("table.total", { total }),
|
|
750
|
-
pageSizeOptions: ["10", "30", "50", "100"],
|
|
750
|
+
pageSizeOptions: ["10", "30", "50", "100", "300", "500"],
|
|
751
751
|
total: state.pagination.totalSize,
|
|
752
752
|
pageSize: state.pagination.pageSize,
|
|
753
753
|
current: state.pagination.currentPage,
|