重构学习任务

This commit is contained in:
田岩
2025-09-12 14:27:18 +08:00
parent 3e2f81bbda
commit ca7f9a09a1
61 changed files with 11150 additions and 305 deletions
+33
View File
@@ -0,0 +1,33 @@
import {
computed,
reactive,
nextTick,
ref
} from 'vue';
export default function useIndexList() {
const tabAct = ref(0);
const listItemRefs = ref([]);
const tabChange = (item) => {
tabAct.value = item.index;
};
const swiperChange = (item) => {
tabAct.value = item.detail.current;
};
const search = (value) => {
console.log('search', value);
listItemRefs.value.forEach((item, index) => {
item?.search(value, tabAct.value === index);
});
};
return {
tabAct,
listItemRefs,
tabChange,
swiperChange,
search,
};
}
+63
View File
@@ -0,0 +1,63 @@
import {
computed,
reactive,
nextTick,
ref
} from 'vue';
export default function useZpaging({
pagingRef, // 必传:z-paging组件的ref
fetchFunction, // 必传:接口请求函数
searchKey = '' // 可选:搜索参数名,默认'searchText'
}) {
const total = ref(-1);
const data_list = ref([]);
const searchText = ref('');
const queryList = async (pageNo, pageSize) => {
try {
const requestParams = {
page: pageNo,
limit: pageSize
};
// 只有当searchKey有效(非空字符串/非undefined)且searchText有值时,才添加搜索参数
if (searchKey && searchKey.trim() && searchText.value) {
requestParams[searchKey] = searchText.value;
}
const res = await fetchFunction(requestParams);
total.value = res.total??res.body.length
pagingRef.value.completeByTotal(res.body, res.total);
} catch (err) {
console.error('分页查询失败:', err);
pagingRef.value?.complete(false);
}
};
//刷新列表要求
const reload = () => {
pagingRef.value?.reload()
};
// 清空分页数据,pageNo恢复为默认值。
const clear = () => {
total.value = -1
pagingRef.value?.clear();
}
// 搜索
const search = (value, state) => {
searchText.value = value;
if (state) {
reload()
} else {
clear()
}
};
return {
queryList,
reload,
search,
clear,
searchText,
total,
data_list
};
}