From 3b0c71989b7463427f8051167767a84d1d64f46f Mon Sep 17 00:00:00 2001 From: Huangzhe Date: Mon, 19 May 2025 15:59:24 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E9=87=8D=E6=9E=84=E9=80=BB?= =?UTF-8?q?=E8=BE=91=E9=85=8D=E9=A2=9D=E7=9B=B8=E5=85=B3=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. 将逻辑配额相关逻辑从组件中抽离到useSurvey hook 2. 修复LogicInfo组件中visibleQuestionConfig的判断逻辑 3. 更新响应类型定义,添加randomProgress和cycle_progress字段 4. 修改'历史记录'为'搜索历史',提升用户体验 5. 删除不再使用的useLogicInfo.ts文件 --- src/api/types/response.d.ts | 2 ++ src/hooks/request/useSurvey.ts | 34 ++++++++++++++++++- .../HomeSearch/components/Recommend/Index.vue | 2 +- .../Analysis/components/LogicInfo/Index.vue | 18 ++++------ .../LogicInfo/hooks/useLogicInfo.ts | 34 ------------------- 5 files changed, 43 insertions(+), 47 deletions(-) delete mode 100644 src/views/Survey/views/Analysis/components/LogicInfo/hooks/useLogicInfo.ts diff --git a/src/api/types/response.d.ts b/src/api/types/response.d.ts index 486293e..7f05a8d 100644 --- a/src/api/types/response.d.ts +++ b/src/api/types/response.d.ts @@ -20,6 +20,8 @@ export interface MetaData { * 通用API响应接口 */ export interface ApiResponse { + randomProgress: never[]; + cycle_progress: import("d:/code/ebiz/code/ylst-survey-h5/src/views/Survey/views/Analysis/components/LogicInfo/types/cycleProgress").CycleProgressItem[] | { title: string; num: number; option: string; start: number; end: number; precent: string; question_index: number; question_title: string; relation_type: number; is_fixed: number; is_fixed_select: number; quota_num: number; sample_num: number; group_info: string; }[]; /** 响应状态码,0表示成功 */ code: number; /** 响应消息,成功时为null */ diff --git a/src/hooks/request/useSurvey.ts b/src/hooks/request/useSurvey.ts index 7da5c8a..09bfd89 100644 --- a/src/hooks/request/useSurvey.ts +++ b/src/hooks/request/useSurvey.ts @@ -1,3 +1,4 @@ +import { cycleProgress, quotaProgress, randomProgress } from '@/api/anslysis'; import { getSurveysDetail } from '@/api/design'; import { getSurveysPage } from '@/api/home'; import { surveyAnalysis } from '@/api/survey'; @@ -50,4 +51,35 @@ function useFetchAnalysis(sn: string) { }; } -export { fetchSurveys, fetchSingleSurvey, useFetchAnalysis }; +function fetchLogicInfo(sn: string) { + // 用于控制 loading 状态 + const loading = ref(false); + const quota = ref([]); + const cycle = ref([]); + const random = ref([]); + + // 获取逻辑配额相关数据 + let response = quotaProgress(sn).then(({ data }) => { + quota.value = data.data; + }); + + // 获取循环配额相关数据 + response = cycleProgress(sn).then(({ data }) => { + cycle.value = data.data.cycle_progress; + }); + + response = randomProgress(sn).then(({ data }) => { + random.value = data.data.randomProgress; + }); + + loading.value = false; + + return { + loading, + quota, + cycle, + random + }; +} + +export { fetchSurveys, fetchSingleSurvey, useFetchAnalysis, fetchLogicInfo }; diff --git a/src/views/HomeSearch/components/Recommend/Index.vue b/src/views/HomeSearch/components/Recommend/Index.vue index f68a296..9162126 100644 --- a/src/views/HomeSearch/components/Recommend/Index.vue +++ b/src/views/HomeSearch/components/Recommend/Index.vue @@ -29,7 +29,7 @@ useFetchRecommon();