refactor: 优化问卷列表和详情功能
1. 添加 formatTime 工具函数,支持日期格式化 2. 重命名搜索处理函数 blurs 为 handleSearchClick,提高可读性 3. 更新问卷项数据字段,使用 answer_num_h5 和 recycle_progress_h5 4. 优化问卷场景名称处理逻辑,增加默认值 5. 完善 SurveyItem 类型定义,添加缺失的字段类型
This commit is contained in:
@@ -1,3 +1,13 @@
|
|||||||
|
/**
|
||||||
|
* 格式化时间
|
||||||
|
* @param time 格式化时间
|
||||||
|
* @param split 分割符
|
||||||
|
* @param join 连接符
|
||||||
|
* @returns 格式化后的时间
|
||||||
|
*/
|
||||||
export function formatTime(time: string, split = ' ', join = ' '){
|
export function formatTime(time: string, split = ' ', join = ' '){
|
||||||
|
// 如果时间不存在,返回自身的值
|
||||||
|
if (!time) return time;
|
||||||
|
|
||||||
return time.split(split).join(join)
|
return time.split(split).join(join)
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="survey-search">
|
<div class="survey-search">
|
||||||
<nav-search v-model:value="searchValue" @search="blurs" />
|
<nav-search v-model:value="searchValue" @search="handleSearchClick" />
|
||||||
<!-- <nav-search
|
<!-- <nav-search
|
||||||
placeholder="请输入关键词"
|
placeholder="请输入关键词"
|
||||||
v-model:value="searchValue"
|
v-model:value="searchValue"
|
||||||
@@ -64,7 +64,7 @@ watch(searchValue, () => {
|
|||||||
form.value.page = 1;
|
form.value.page = 1;
|
||||||
});
|
});
|
||||||
|
|
||||||
const blurs = () => {
|
const handleSearchClick = () => {
|
||||||
form.value.page = 1;
|
form.value.page = 1;
|
||||||
form.value.project_name = searchValue.value;
|
form.value.project_name = searchValue.value;
|
||||||
survey.value = [];
|
survey.value = [];
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ import {
|
|||||||
currentSurvey
|
currentSurvey
|
||||||
} from '@/views/Survey/hooks/useSurveyData';
|
} from '@/views/Survey/hooks/useSurveyData';
|
||||||
import ai from '@/assets/img/analysis/ai.svg';
|
import ai from '@/assets/img/analysis/ai.svg';
|
||||||
import { ref } from 'vue';
|
import { nextTick, ref } from 'vue';
|
||||||
import { formatTime } from '@/utils/date';
|
import { formatTime } from '@/utils/date';
|
||||||
|
|
||||||
const form = ref({
|
const form = ref({
|
||||||
@@ -122,16 +122,17 @@ function copyItem(item: SurveyItem) {
|
|||||||
showCancelButton: true,
|
showCancelButton: true,
|
||||||
confirmButtonColor: '#03B03C'
|
confirmButtonColor: '#03B03C'
|
||||||
})
|
})
|
||||||
.then(async () => {
|
.then(() => {
|
||||||
const res = await copySurveys(item.sn);
|
copySurveys(item.sn).then((res) => {
|
||||||
if (res.data.code === 200 || res.data.code === 201) {
|
if (res.data.code === 200 || res.data.code === 201) {
|
||||||
showSuccessToast('复制成功');
|
showSuccessToast('复制成功');
|
||||||
form.value.page = 1;
|
form.value.page = 1;
|
||||||
survey.value = [];
|
survey.value = [] as any;
|
||||||
await fetchSurveys(form.value);
|
fetchSurveys(form.value);
|
||||||
} else {
|
} else {
|
||||||
showFailToast(res.data);
|
showFailToast(res.data);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
// on cancel
|
// on cancel
|
||||||
@@ -149,7 +150,9 @@ function copyItem(item: SurveyItem) {
|
|||||||
<el-text style="max-width: 100px">
|
<el-text style="max-width: 100px">
|
||||||
<b v-html="survey.project_name"></b>
|
<b v-html="survey.project_name"></b>
|
||||||
</el-text>
|
</el-text>
|
||||||
<el-text class="wrap">{{ survey.answer_num }}份</el-text>
|
<el-text class="wrap" v-if="survey.publish_number"
|
||||||
|
>{{ survey.publish_number }}份</el-text
|
||||||
|
>
|
||||||
<el-text class="wrap" v-if="survey.is_time" style="text-wrap: nowrap">
|
<el-text class="wrap" v-if="survey.is_time" style="text-wrap: nowrap">
|
||||||
{{ `${survey.start_time} 至 ${survey.end_time ?? '无限期'}` }}
|
{{ `${survey.start_time} 至 ${survey.end_time ?? '无限期'}` }}
|
||||||
</el-text>
|
</el-text>
|
||||||
@@ -201,11 +204,11 @@ function copyItem(item: SurveyItem) {
|
|||||||
<el-space class="survey_item_info_desc" spacer="|">
|
<el-space class="survey_item_info_desc" spacer="|">
|
||||||
<section>
|
<section>
|
||||||
<el-text size="small">回收数量</el-text>
|
<el-text size="small">回收数量</el-text>
|
||||||
<el-text> {{ survey.answer_num }}</el-text>
|
<el-text> {{ survey.answer_num_h5 }}</el-text>
|
||||||
</section>
|
</section>
|
||||||
<section>
|
<section>
|
||||||
<el-text size="small">回收数量进度</el-text>
|
<el-text size="small">回收数量进度</el-text>
|
||||||
<el-text>{{ survey.recycle_progress }}</el-text>
|
<el-text>{{ survey.recycle_progress_h5 }}</el-text>
|
||||||
</section>
|
</section>
|
||||||
<section>
|
<section>
|
||||||
<el-text size="small">投放时间进度</el-text>
|
<el-text size="small">投放时间进度</el-text>
|
||||||
|
|||||||
@@ -35,8 +35,8 @@ async function fetchSurveys(form: any) {
|
|||||||
total.value = res.data.meta.total;
|
total.value = res.data.meta.total;
|
||||||
survey.value.forEach((item) => {
|
survey.value.forEach((item) => {
|
||||||
const sceneName = JSON.parse(JSON.stringify(item.scene_name));
|
const sceneName = JSON.parse(JSON.stringify(item.scene_name));
|
||||||
|
const nameList = sceneName ? sceneName?.split('-') : ['其他', '未知问卷'];
|
||||||
|
|
||||||
const nameList = sceneName ? sceneName.split('-') : [];
|
|
||||||
if (nameList.length > 0) {
|
if (nameList.length > 0) {
|
||||||
item.scene_name = nameList[1] ? nameList[1] : nameList[0];
|
item.scene_name = nameList[1] ? nameList[1] : nameList[0];
|
||||||
}
|
}
|
||||||
@@ -51,7 +51,6 @@ async function fetchSurveys(form: any) {
|
|||||||
if (survey.value.length >= total.value) {
|
if (survey.value.length >= total.value) {
|
||||||
finished.value = true;
|
finished.value = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// Toast()
|
// Toast()
|
||||||
}
|
}
|
||||||
|
|||||||
3
src/views/Survey/types/survey.d.ts
vendored
3
src/views/Survey/types/survey.d.ts
vendored
@@ -1,4 +1,7 @@
|
|||||||
type SurveyItem = {
|
type SurveyItem = {
|
||||||
|
publish_number: string | number
|
||||||
|
answer_num_h5: number
|
||||||
|
recycle_progress_h5: number
|
||||||
scene_name: string
|
scene_name: string
|
||||||
project_name: string
|
project_name: string
|
||||||
created_at: string
|
created_at: string
|
||||||
|
|||||||
Reference in New Issue
Block a user