mirror of https://gitee.com/xiaonuobase/snowy
代码格式化
parent
2dcff6f5c5
commit
d28af316a8
|
@ -58,23 +58,24 @@ watch(props, (newValue) => {
|
||||||
// 请求数据
|
// 请求数据
|
||||||
const onPage = (param = {}) => {
|
const onPage = (param = {}) => {
|
||||||
if (props.pageFunction) {
|
if (props.pageFunction) {
|
||||||
initParams.value = { ...initParams.value, ...param, size: props.pageSize };
|
initParams.value = { ...initParams.value, ...param, size: props.pageSize }
|
||||||
// 加载API
|
// 加载API
|
||||||
spinning.value = true;
|
spinning.value = true
|
||||||
props.pageFunction(initParams.value)
|
props
|
||||||
|
.pageFunction(initParams.value)
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
// 更新当前页码
|
// 更新当前页码
|
||||||
initParams.value.current = data.current;
|
initParams.value.current = data.current
|
||||||
// 加载完后设置总数
|
// 加载完后设置总数
|
||||||
total.value = data.total;
|
total.value = data.total
|
||||||
options.value = data.records;
|
options.value = data.records
|
||||||
queryEcho();
|
queryEcho()
|
||||||
})
|
})
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
spinning.value = false;
|
spinning.value = false
|
||||||
});
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
|
||||||
const queryEcho = () => {
|
const queryEcho = () => {
|
||||||
// 如果带有查询的方法,那么我们去给查询回显
|
// 如果带有查询的方法,那么我们去给查询回显
|
||||||
if (props.echoFunction) {
|
if (props.echoFunction) {
|
||||||
|
@ -116,28 +117,29 @@ const handlePopupScroll = (e) => {
|
||||||
const handlePagination = () => {
|
const handlePagination = () => {
|
||||||
// 判断已有数量是否小于总量
|
// 判断已有数量是否小于总量
|
||||||
if (options.value.length < total.value) {
|
if (options.value.length < total.value) {
|
||||||
const param = { ...initParams.value, current: initParams.value.current + 1 };
|
const param = { ...initParams.value, current: initParams.value.current + 1 }
|
||||||
spinning.value = true;
|
spinning.value = true
|
||||||
props.pageFunction(param)
|
props
|
||||||
|
.pageFunction(param)
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
if (data.records.length > 0) {
|
if (data.records.length > 0) {
|
||||||
// 更新当前页码
|
// 更新当前页码
|
||||||
initParams.value.current = data.current;
|
initParams.value.current = data.current
|
||||||
// 合并新旧数据
|
// 合并新旧数据
|
||||||
const newOptions = [...options.value, ...data.records];
|
const newOptions = [...options.value, ...data.records]
|
||||||
// 使用 id 去重
|
// 使用 id 去重
|
||||||
const uniqueOptions = newOptions.reduce((acc, cur) => {
|
const uniqueOptions = newOptions.reduce((acc, cur) => {
|
||||||
acc[cur.id] = cur;
|
acc[cur.id] = cur
|
||||||
return acc;
|
return acc
|
||||||
}, {});
|
}, {})
|
||||||
options.value = Object.values(uniqueOptions);
|
options.value = Object.values(uniqueOptions)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
spinning.value = false;
|
spinning.value = false
|
||||||
});
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
defineExpose({
|
defineExpose({
|
||||||
onPage
|
onPage
|
||||||
|
|
Loading…
Reference in New Issue