|
@@ -1,14 +1,18 @@
|
|
-import { ref, unref, onMounted, computed } from "vue";
|
|
|
|
|
|
+import { ref, unref, onMounted, computed, watch } from "vue";
|
|
import { chatApi } from '@/api/chat';
|
|
import { chatApi } from '@/api/chat';
|
|
|
|
|
|
export const useInfinite = (path, props) => {
|
|
export const useInfinite = (path, props) => {
|
|
|
|
+
|
|
const pageParams = ref({ pageNum: 1, pageSize: 20 });
|
|
const pageParams = ref({ pageNum: 1, pageSize: 20 });
|
|
|
|
+ const queryParams = ref(props);
|
|
|
|
|
|
const recordList = ref([]);
|
|
const recordList = ref([]);
|
|
const isFetching = ref(false);
|
|
const isFetching = ref(false);
|
|
const counter = ref(0);
|
|
const counter = ref(0);
|
|
const noMore = ref(false);
|
|
const noMore = ref(false);
|
|
|
|
|
|
|
|
+ // let isSwitchStatus = false;
|
|
|
|
+
|
|
const isMore = computed(() => pageParams.value.pageNum * pageParams.value.pageSize < counter.value);
|
|
const isMore = computed(() => pageParams.value.pageNum * pageParams.value.pageSize < counter.value);
|
|
|
|
|
|
const addHistoryRecord = record => {
|
|
const addHistoryRecord = record => {
|
|
@@ -16,8 +20,7 @@ export const useInfinite = (path, props) => {
|
|
}
|
|
}
|
|
|
|
|
|
const onScrolltolower = async () => {
|
|
const onScrolltolower = async () => {
|
|
-
|
|
|
|
- if(unref(isFetching) || unref(noMore)) return;
|
|
|
|
|
|
+ if(unref(isFetching) || unref(noMore) ) return;
|
|
|
|
|
|
isFetching.value = true;
|
|
isFetching.value = true;
|
|
|
|
|
|
@@ -26,7 +29,7 @@ export const useInfinite = (path, props) => {
|
|
recordList.value.push(...rows);
|
|
recordList.value.push(...rows);
|
|
|
|
|
|
counter.value = total;
|
|
counter.value = total;
|
|
-
|
|
|
|
|
|
+
|
|
if (unref(isMore)) {
|
|
if (unref(isMore)) {
|
|
pageParams.value.pageNum ++;
|
|
pageParams.value.pageNum ++;
|
|
} else {
|
|
} else {
|
|
@@ -38,23 +41,33 @@ export const useInfinite = (path, props) => {
|
|
|
|
|
|
const onReset = async () => {
|
|
const onReset = async () => {
|
|
const { rows, total } = await initRecordData({pageNum:1, pageSize: (pageParams.value.pageNum * pageParams.value.pageSize) + 1});
|
|
const { rows, total } = await initRecordData({pageNum:1, pageSize: (pageParams.value.pageNum * pageParams.value.pageSize) + 1});
|
|
-
|
|
|
|
recordList.value = rows;
|
|
recordList.value = rows;
|
|
counter.value = total;
|
|
counter.value = total;
|
|
- noMore.value = !unref(isMore);
|
|
|
|
|
|
+
|
|
|
|
+ noMore.value = !unref(isMore)
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ // 重置请求
|
|
const onRestore = async (params) => {
|
|
const onRestore = async (params) => {
|
|
pageParams.value = { pageNum: 1, pageSize: 20 };
|
|
pageParams.value = { pageNum: 1, pageSize: 20 };
|
|
- const { rows, total } = await initRecordData(params);
|
|
|
|
|
|
+ queryParams.value = { ...unref(queryParams), ...params };
|
|
|
|
+
|
|
|
|
+ const { rows, total } = await initRecordData();
|
|
|
|
+
|
|
|
|
+ // isSwitchStatus = true;
|
|
|
|
+
|
|
recordList.value = rows;
|
|
recordList.value = rows;
|
|
counter.value = total;
|
|
counter.value = total;
|
|
|
|
+
|
|
|
|
+ // setTimeout(() => isSwitchStatus = false, 100);
|
|
|
|
+
|
|
|
|
+ noMore.value = !isMore.value;
|
|
}
|
|
}
|
|
|
|
|
|
const initRecordData = async (params = {}) => {
|
|
const initRecordData = async (params = {}) => {
|
|
const reqParams = {
|
|
const reqParams = {
|
|
- ...pageParams.value,
|
|
|
|
- ...props,
|
|
|
|
|
|
+ ...unref(pageParams),
|
|
|
|
+ ...unref(queryParams),
|
|
...params
|
|
...params
|
|
}
|
|
}
|
|
return await chatApi.getRecordFetch(path, reqParams);
|
|
return await chatApi.getRecordFetch(path, reqParams);
|