feat: 优化问卷分析图表展示功能
- 修复饼图组件显示问题,取消注释使图表正常显示 - 优化数据处理逻辑,支持问题索引1和2的数据处理 - 移除不必要的响应式包装,直接使用JSON对象提高性能 - 清理未使用的导入和函数,如showToast、surveys等 - 添加对空选项数组的条件判断,避免渲染空数据 - 移除控制台日志输出,提高代码整洁度 - 更新IDE图标主题为material-icon-theme - 优化图表配置结构,简化代码
This commit is contained in:
@@ -1,117 +1,109 @@
|
||||
import {
|
||||
getSurveysPage, deleteSurveys,
|
||||
saveTemplates
|
||||
} from '@/api/home';
|
||||
import { ref } from 'vue';
|
||||
import {
|
||||
showDialog,
|
||||
showConfirmDialog,
|
||||
showFailToast,
|
||||
showToast
|
||||
} from 'vant';
|
||||
import { getSurveysDetail } from '@/api/design';
|
||||
|
||||
const form = ref({
|
||||
page: 0,
|
||||
pageSize: 10,
|
||||
project_name: ''
|
||||
});
|
||||
|
||||
const searchValue = ref('');
|
||||
const survey = ref<SurveyItem[]>([]);
|
||||
const total = ref(0);
|
||||
const loading = ref(false);
|
||||
const finished = ref(false);
|
||||
const currentSurvey = ref<SurveyItem>();
|
||||
|
||||
async function fetchSingleSurvey(sn: string) {
|
||||
const res = await getSurveysDetail(sn);
|
||||
// console.log(res);
|
||||
if (res.data.code === 0) {
|
||||
currentSurvey.value = res.data.data;
|
||||
}
|
||||
}
|
||||
|
||||
async function fetchSurveys() {
|
||||
const params = {
|
||||
page: form.value.page,
|
||||
per_page: form.value.pageSize,
|
||||
group_id: 0,
|
||||
project_name: searchValue.value
|
||||
};
|
||||
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.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) {
|
||||
finished.value = true;
|
||||
}
|
||||
} else {
|
||||
// Toast()
|
||||
}
|
||||
}
|
||||
|
||||
function deleteItem(item: SurveyItem) {
|
||||
showDialog({
|
||||
title: `确认删除问卷${item.project_name} ?`,
|
||||
showCancelButton: true,
|
||||
confirmButtonColor: '#03B03C'
|
||||
})
|
||||
.then(async () => {
|
||||
const res = await deleteSurveys(item.sn);
|
||||
if (res.data.message) {
|
||||
showToast(res.data.message);
|
||||
} else {
|
||||
showToast('删除成功!');
|
||||
}
|
||||
form.value.page = 1;
|
||||
survey.value = [];
|
||||
await fetchSurveys();
|
||||
})
|
||||
.catch(() => {
|
||||
// on cancel
|
||||
});
|
||||
};
|
||||
|
||||
// 保存为模板
|
||||
async function saveTemplate(item: SurveyItem) {
|
||||
const data = JSON.parse(JSON.stringify(item));
|
||||
const res = await saveTemplates(item.sn, data);
|
||||
if (res.data.code === 200 || res.data.code === 201) {
|
||||
showConfirmDialog({
|
||||
message: '模板保存成功,请前往模板市场查看!',
|
||||
showCancelButton: false
|
||||
});
|
||||
} else {
|
||||
showFailToast(res.data);
|
||||
}
|
||||
}
|
||||
|
||||
export {
|
||||
form,
|
||||
fetchSurveys,
|
||||
loading,
|
||||
finished,
|
||||
survey,
|
||||
total,
|
||||
searchValue,
|
||||
deleteItem,
|
||||
saveTemplate,
|
||||
currentSurvey,
|
||||
fetchSingleSurvey
|
||||
}
|
||||
;
|
||||
import { getSurveysPage, deleteSurveys, saveTemplates } from '@/api/home';
|
||||
import { ref } from 'vue';
|
||||
import { showDialog, showConfirmDialog, showFailToast, showToast } from 'vant';
|
||||
import { getSurveysDetail } from '@/api/design';
|
||||
|
||||
const form = ref({
|
||||
page: 0,
|
||||
pageSize: 10,
|
||||
project_name: ''
|
||||
});
|
||||
|
||||
const searchValue = ref('');
|
||||
const survey = ref<SurveyItem[]>([]);
|
||||
const total = ref(0);
|
||||
const loading = ref(false);
|
||||
const finished = ref(false);
|
||||
const currentSurvey = ref<SurveyItem>();
|
||||
|
||||
async function fetchSingleSurvey(sn: string) {
|
||||
const res = await getSurveysDetail(sn);
|
||||
// console.log(res);
|
||||
if (res.data.code === 0) {
|
||||
currentSurvey.value = res.data.data;
|
||||
}
|
||||
}
|
||||
|
||||
async function fetchSurveys() {
|
||||
const params = {
|
||||
page: form.value.page,
|
||||
per_page: form.value.pageSize,
|
||||
group_id: 0,
|
||||
project_name: searchValue.value
|
||||
};
|
||||
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) {
|
||||
finished.value = true;
|
||||
}
|
||||
} else {
|
||||
// Toast()
|
||||
}
|
||||
}
|
||||
|
||||
function deleteItem(item: SurveyItem) {
|
||||
showDialog({
|
||||
title: `确认删除问卷${item.project_name} ?`,
|
||||
showCancelButton: true,
|
||||
confirmButtonColor: '#03B03C'
|
||||
})
|
||||
.then(async () => {
|
||||
const res = await deleteSurveys(item.sn);
|
||||
if (res.data.message) {
|
||||
showToast(res.data.message);
|
||||
} else {
|
||||
showToast('删除成功!');
|
||||
}
|
||||
form.value.page = 1;
|
||||
survey.value = [];
|
||||
await fetchSurveys();
|
||||
})
|
||||
.catch(() => {
|
||||
// on cancel
|
||||
});
|
||||
}
|
||||
|
||||
// 保存为模板
|
||||
async function saveTemplate(item: SurveyItem) {
|
||||
const data = JSON.parse(JSON.stringify(item));
|
||||
const res = await saveTemplates(item.sn, data);
|
||||
if (res.data.code === 200 || res.data.code === 201) {
|
||||
showConfirmDialog({
|
||||
message: '模板保存成功,请前往模板市场查看!',
|
||||
showCancelButton: false
|
||||
});
|
||||
} else {
|
||||
showFailToast(res.data);
|
||||
}
|
||||
}
|
||||
|
||||
export {
|
||||
form,
|
||||
fetchSurveys,
|
||||
loading,
|
||||
finished,
|
||||
survey,
|
||||
total,
|
||||
searchValue,
|
||||
deleteItem,
|
||||
saveTemplate,
|
||||
currentSurvey,
|
||||
fetchSingleSurvey
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user