feat: 添加页面刷新功能
This commit is contained in:
@@ -158,7 +158,7 @@
|
||||
|
||||
<script setup>
|
||||
import { computed, ref, watch } from 'vue';
|
||||
import { onShow } from '@dcloudio/uni-app';
|
||||
import { onPullDownRefresh, onShow } from '@dcloudio/uni-app';
|
||||
import modeSwitch from '@/components/mode_switch/mode_switch.vue';
|
||||
import sheep from '@/sheep';
|
||||
import OrderStoreApi from '@/sheep/api/trade/orderStore';
|
||||
@@ -236,7 +236,7 @@
|
||||
return storeIds;
|
||||
};
|
||||
|
||||
const ensureStoreList = async () => {
|
||||
const ensureStoreList = async (force = false) => {
|
||||
const storeIds = await getUserStoreIds();
|
||||
if (!storeIds) {
|
||||
storeList.value = [];
|
||||
@@ -245,7 +245,7 @@
|
||||
return '';
|
||||
}
|
||||
if (storeLoading.value) return storeIds;
|
||||
if (storeIdsKey.value === storeIds && storeList.value.length) return storeIds;
|
||||
if (!force && storeIdsKey.value === storeIds && storeList.value.length) return storeIds;
|
||||
storeLoading.value = true;
|
||||
try {
|
||||
const { code, data } = await StoreApi.getStoreListByStoreIds(storeIds);
|
||||
@@ -281,7 +281,10 @@
|
||||
return params;
|
||||
};
|
||||
|
||||
const getList = async () => {
|
||||
const getList = async (force = false) => {
|
||||
while (force && loading.value) {
|
||||
await new Promise((resolve) => setTimeout(resolve, 50));
|
||||
}
|
||||
if (loading.value) return;
|
||||
const storeId = await ensurePickUpStoreId();
|
||||
if (!(storeId > 0)) {
|
||||
@@ -318,6 +321,18 @@
|
||||
await getList();
|
||||
});
|
||||
|
||||
onPullDownRefresh(async () => {
|
||||
try {
|
||||
expandedMap.value = {};
|
||||
await ensureStoreList(true);
|
||||
const current = Number(selectedStoreId.value || 0);
|
||||
if (current > 0) uni.setStorageSync(STORE_SELECTED_KEY, current);
|
||||
await getList(true);
|
||||
} finally {
|
||||
uni.stopPullDownRefresh();
|
||||
}
|
||||
});
|
||||
|
||||
let searchTimer = null;
|
||||
watch(
|
||||
[currentTab, keyword, selectedStoreId],
|
||||
|
||||
Reference in New Issue
Block a user