refactor(Survey): 优化问卷列表加载和搜索功能
- 添加 requestSingle 标志以控制单次请求 - 优化 fetchSurveys 函数,避免重复请求- 调整 Index.vue 中的搜索逻辑,提高用户体验 - 移除不必要的数据处理,简化代码结构
This commit is contained in:
@@ -11,6 +11,8 @@ const requestLoading = ref(false);
|
||||
const finished = ref(false);
|
||||
const currentSurvey = ref<SurveyItem>();
|
||||
|
||||
const requestSingle = ref(true);
|
||||
|
||||
async function fetchSingleSurvey(sn: string) {
|
||||
const res = await getSurveysDetail(sn);
|
||||
// const res = await getSetting({sn})
|
||||
@@ -21,31 +23,20 @@ async function fetchSingleSurvey(sn: string) {
|
||||
}
|
||||
|
||||
async function fetchSurveys(form: any) {
|
||||
if (!requestSingle.value) return;
|
||||
requestSingle.value = false;
|
||||
requestLoading.value = true;
|
||||
const params = {
|
||||
page: form.page,
|
||||
per_page: form.pageSize,
|
||||
group_id: 0,
|
||||
// project_name: searchValue.value
|
||||
key_word: searchValue.value
|
||||
key_word: form.key_word
|
||||
};
|
||||
const res = await getSurveysPage(params);
|
||||
if (res.data.code === 0) {
|
||||
survey.value = survey.value.concat(res.data.data);
|
||||
total.value = res.data.meta.total;
|
||||
survey.value.forEach((item) => {
|
||||
const sceneName = JSON.parse(JSON.stringify(item.scene_name));
|
||||
const nameList = sceneName ? sceneName?.split('-') : ['其他', '未知问卷'];
|
||||
|
||||
if (nameList.length > 0) {
|
||||
item.scene_name = nameList[1] ? nameList[1] : nameList[0];
|
||||
}
|
||||
|
||||
const timeList = item.created_at.split(' ');
|
||||
if (nameList.length) {
|
||||
item.created_at = timeList[0];
|
||||
}
|
||||
});
|
||||
loading.value = false;
|
||||
// 数据全部加载完成
|
||||
if (survey.value.length >= total.value) {
|
||||
@@ -55,6 +46,7 @@ async function fetchSurveys(form: any) {
|
||||
// Toast()
|
||||
}
|
||||
requestLoading.value = false;
|
||||
requestSingle.value = true;
|
||||
}
|
||||
|
||||
function deleteItem(item: SurveyItem, form: any) {
|
||||
@@ -63,7 +55,7 @@ function deleteItem(item: SurveyItem, form: any) {
|
||||
showCancelButton: true,
|
||||
confirmButtonColor: '#03B03C'
|
||||
})
|
||||
.then(async () => {
|
||||
.then(async() => {
|
||||
const res = await deleteSurveys(item.sn);
|
||||
if (res.data.message) {
|
||||
showToast(res.data.message);
|
||||
|
||||
Reference in New Issue
Block a user