mirror of
https://codeup.aliyun.com/67762337eccfc218f6110e0e/vue/fe-manage.git
synced 2025-12-09 10:56:46 +08:00
fix bug
This commit is contained in:
@@ -292,6 +292,41 @@ export function usePage(_url, params, init = true,listing = false) {
|
||||
reset,
|
||||
};
|
||||
}
|
||||
export function useThrottlePage(_url, params = {}, init = true) {
|
||||
|
||||
const state = reactive({
|
||||
data: [],
|
||||
loading: false,
|
||||
total: 0,
|
||||
totalPage: 0,
|
||||
page: 1,
|
||||
...params
|
||||
});
|
||||
|
||||
watch(() => params.keyword, throttle(fetch, 600));
|
||||
watch(() => params.page, fetch);
|
||||
|
||||
function fetch() {
|
||||
state.loading = true;
|
||||
if (!params.keyword) {
|
||||
state.loading = false;
|
||||
return;
|
||||
}
|
||||
return request(_url, params).then(r => {
|
||||
state.data = params.page === 1 ? r.data.records : [...state.data, ...r.data.records];
|
||||
state.totalPage = r.data.pages;
|
||||
state.total = r.data.total;
|
||||
state.loading = false;
|
||||
});
|
||||
}
|
||||
|
||||
init && fetch();
|
||||
return {
|
||||
...toRefs(state),
|
||||
fetch,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
export function useRequest(_url, params, init = true) {
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
</template>
|
||||
<script setup>
|
||||
import {computed, defineEmits, defineProps, onMounted, ref, watch} from "vue";
|
||||
import {usePage} from "@/api/request";
|
||||
import {useThrottlePage} from "@/api/request";
|
||||
import {USER_LIST} from "@/api/apis";
|
||||
|
||||
const props = defineProps({
|
||||
@@ -58,7 +58,7 @@ const isOpen = ref(false)
|
||||
|
||||
const memberParam = ref({keyword: '', page: 1, pageSize: 20})
|
||||
|
||||
const {data: userList, loading} = usePage(USER_LIST, memberParam.value, false)
|
||||
const {data: userList, loading} = useThrottlePage(USER_LIST, memberParam.value, false)
|
||||
|
||||
const options = computed(() => userList.value.filter(e => !(props.value + '').includes(e.id)).map(e => ({
|
||||
label: e.realName + e.userNo,
|
||||
@@ -94,6 +94,7 @@ const searchMember = (keyword) => {
|
||||
userList.value = []
|
||||
memberParam.value.page = 1
|
||||
memberParam.value.keyword = keyword
|
||||
console.log('searchMember', memberParam.value)
|
||||
};
|
||||
|
||||
function blur() {
|
||||
|
||||
Reference in New Issue
Block a user