refactor: 重构逻辑配额相关代码
1. 将逻辑配额相关逻辑从组件中抽离到useSurvey hook 2. 修复LogicInfo组件中visibleQuestionConfig的判断逻辑 3. 更新响应类型定义,添加randomProgress和cycle_progress字段 4. 修改'历史记录'为'搜索历史',提升用户体验 5. 删除不再使用的useLogicInfo.ts文件
This commit is contained in:
2
src/api/types/response.d.ts
vendored
2
src/api/types/response.d.ts
vendored
@@ -20,6 +20,8 @@ export interface MetaData {
|
||||
* 通用API响应接口
|
||||
*/
|
||||
export interface ApiResponse<T> {
|
||||
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 */
|
||||
|
||||
@@ -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<any[]>([]);
|
||||
const cycle = ref<any[]>([]);
|
||||
const random = ref<any[]>([]);
|
||||
|
||||
// 获取逻辑配额相关数据
|
||||
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 };
|
||||
|
||||
@@ -29,7 +29,7 @@ useFetchRecommon();
|
||||
<layout>
|
||||
<template #title>
|
||||
<section class="history-title">
|
||||
<el-text class="title">历史记录</el-text>
|
||||
<el-text class="title">搜索历史</el-text>
|
||||
<div>
|
||||
<el-icon @click="delHistory"><Delete /></el-icon>
|
||||
</div>
|
||||
|
||||
@@ -1,14 +1,8 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, ref } from 'vue';
|
||||
import {
|
||||
updateDate,
|
||||
cycle,
|
||||
loading,
|
||||
quota,
|
||||
random
|
||||
} from '@/views/Survey/views/Analysis/components/LogicInfo/hooks/useLogicInfo';
|
||||
import { useRoute } from 'vue-router';
|
||||
import YlTable from '@/components/YlTable/Index.vue';
|
||||
import { fetchLogicInfo } from '@/hooks/request/useSurvey';
|
||||
|
||||
const route = useRoute();
|
||||
|
||||
@@ -16,6 +10,8 @@ const route = useRoute();
|
||||
const sn = defineModel<string>('sn');
|
||||
// sn 的获取方式,默认优先从上级传递的,如果没有尝试从 router 获取
|
||||
sn.value = sn.value ?? (route.query.sn as string);
|
||||
// 逻辑的相关信息数据
|
||||
const { quota, random, cycle, loading } = fetchLogicInfo(sn.value);
|
||||
|
||||
const activeTab = ref(0);
|
||||
const tabs = ref<LogicInfoTab[]>([
|
||||
@@ -27,7 +23,7 @@ const tabs = ref<LogicInfoTab[]>([
|
||||
{ prop: 'sample_number', label: '样本量', width: 90 },
|
||||
{ prop: 'percent', label: '进度', width: 90 }
|
||||
],
|
||||
data: quota as any
|
||||
data: quota.value as any
|
||||
},
|
||||
{
|
||||
title: '随机题组配额',
|
||||
@@ -37,7 +33,7 @@ const tabs = ref<LogicInfoTab[]>([
|
||||
{ prop: 'sample_num', label: '样本量', width: 120 },
|
||||
{ prop: 'precent', label: '进度', width: 120 }
|
||||
],
|
||||
data: random as any
|
||||
data: random.value as any
|
||||
},
|
||||
{
|
||||
title: '循环题组配额',
|
||||
@@ -47,7 +43,7 @@ const tabs = ref<LogicInfoTab[]>([
|
||||
{ prop: 'sample_num', label: '样本量', width: 80 },
|
||||
{ prop: 'precent', label: '进度', width: 120 }
|
||||
],
|
||||
data: cycle as any
|
||||
data: cycle.value as any
|
||||
}
|
||||
]);
|
||||
const currentTabs = computed(() => {
|
||||
@@ -65,7 +61,7 @@ const visibleQuestionConfig = computed(() => {
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<van-cell class="logic-info" v-if="visibleQuestionConfig">
|
||||
<van-cell class="logic-info" v-if="visibleQuestionConfig.length > 0">
|
||||
<template #extra>
|
||||
<section style="width: 86vw" v-loading="loading">
|
||||
<!-- tabs 选项列表 -->
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
import { cycleProgress, randomProgress, quotaProgress } from '@/api/anslysis';
|
||||
import { ref } from 'vue';
|
||||
import type { CycleProgressItem } from '../types/cycleProgress';
|
||||
|
||||
const loading = ref(false);
|
||||
|
||||
// 循环逻辑配额列表
|
||||
const cycle = ref<CycleProgressItem[]>([]);
|
||||
// 随机题组配额列表
|
||||
const random = ref([]);
|
||||
// 逻辑配额
|
||||
const quota = ref<any>([]);
|
||||
|
||||
async function updateDate(sn: string) {
|
||||
loading.value = false;
|
||||
// 获取逻辑配额相关数据
|
||||
let response = await quotaProgress(sn);
|
||||
// console.log(response.data.data);
|
||||
quota.value = response.data.data;
|
||||
|
||||
|
||||
// 获取循环配额相关数据
|
||||
response = await cycleProgress(sn);
|
||||
// console.log(response.data.data.cycle_progress);
|
||||
cycle.value = response.data.data.cycle_progress;
|
||||
|
||||
response = await randomProgress(sn);
|
||||
// console.log(response.data.data.randomProgress);
|
||||
random.value = response.data.data.randomProgress;
|
||||
|
||||
loading.value = false;
|
||||
}
|
||||
|
||||
export { updateDate, cycle, loading, quota, random };
|
||||
Reference in New Issue
Block a user