1.修复了xnPageSelector只能加载前两页的bug

2.将回显查询的结果移动到最前方防止滑动监听出现问题
3.initParams应该包含原始的param参数以适应条件查询需求
pull/157/head
gao 2023-08-28 11:47:29 +08:00
parent 3f493de7bf
commit 2dcff6f5c5
1 changed files with 122 additions and 123 deletions

View File

@ -14,11 +14,9 @@
</a-spin>
</template>
<script setup name="xnPageSelector">
import { cloneDeep } from 'lodash-es'
<script setup>
import { watch } from 'vue'
const current = ref(1) //
const total = ref(0) //
const initParams = ref({})
const options = ref([])
@ -60,24 +58,23 @@
//
const onPage = (param = {}) => {
if (props.pageFunction) {
initParams.value = param
initParams.value.size = props.pageSize
initParams.value = { ...initParams.value, ...param, size: props.pageSize };
// API
spinning.value = true
props
.pageFunction(initParams.value)
spinning.value = true;
props.pageFunction(initParams.value)
.then((data) => {
initParams.value.current = data.current
//
initParams.value.current = data.current;
//
total.value = data.total
options.value = data.records
queryEcho()
total.value = data.total;
options.value = data.records;
queryEcho();
})
.finally(() => {
spinning.value = false
})
}
spinning.value = false;
});
}
};
const queryEcho = () => {
//
if (props.echoFunction) {
@ -90,7 +87,7 @@
}
props.echoFunction(param).then((data) => {
if (data[0]){
options.value.push(data[0])
options.value.unshift(data[0])
}
})
}
@ -119,27 +116,29 @@
const handlePagination = () => {
//
if (options.value.length < total.value) {
const param = cloneDeep(initParams.value)
param.current = initParams.value.current + 1
spinning.value = true
props
.pageFunction(param)
const param = { ...initParams.value, current: initParams.value.current + 1 };
spinning.value = true;
props.pageFunction(param)
.then((data) => {
if (data.records.length > 0) {
options.value = [...cloneDeep(options.value), ...data.records].filter((item, index, self) => {
return (
self.findIndex((f) => {
return f.id === item.id
}) === index
)
})
//
initParams.value.current = data.current;
//
const newOptions = [...options.value, ...data.records];
// 使 id
const uniqueOptions = newOptions.reduce((acc, cur) => {
acc[cur.id] = cur;
return acc;
}, {});
options.value = Object.values(uniqueOptions);
}
})
.finally(() => {
spinning.value = false
})
}
spinning.value = false;
});
}
};
defineExpose({
onPage
})