refactor(survey): 重构问卷数据管理逻辑
- 新增 clearSurveys 函数用于清空问卷数据 - 在复制问卷和删除问卷后调用 clearSurveys函数 - 在组件卸载和重置搜索时调用 clearSurveys 函数 - 优化了问卷数据的更新逻辑,解决了内容不更新的问题 - 重新添加了 .prettierrc 文件,规范代码格式
This commit is contained in:
@@ -34,7 +34,7 @@
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { onUnmounted, ref, watch } from 'vue';
|
||||
import { onMounted, onUnmounted, ref, watch } from 'vue';
|
||||
import NavSearch from '@/components/Search/Index.vue';
|
||||
import NewSurvey from '@/views/Home/components/NewSurvey/index.vue';
|
||||
import EmptyContainer from '@/views/Survey/components/EmptyContainer.vue';
|
||||
@@ -45,7 +45,8 @@ import {
|
||||
finished,
|
||||
survey,
|
||||
requestLoading,
|
||||
searchValue
|
||||
searchValue,
|
||||
clearSurveys
|
||||
} from '@/views/Survey/hooks/useSurveyData';
|
||||
import emptyImg from '@/assets/img/emptyImg.png';
|
||||
|
||||
@@ -69,7 +70,7 @@ const handleSearchClick = () => {
|
||||
form.page = 1;
|
||||
form.key_word = searchValue.value;
|
||||
// 重置 survey 数据
|
||||
survey.value = [];
|
||||
clearSurveys();
|
||||
// 重置 finished 状态
|
||||
finished.value = false;
|
||||
|
||||
@@ -78,11 +79,16 @@ const handleSearchClick = () => {
|
||||
|
||||
onUnmounted(() => {
|
||||
// 当组件卸载的时候,清空 survey 数据
|
||||
survey.value = [];
|
||||
clearSurveys();
|
||||
// 清空搜索的字符
|
||||
searchValue.value = '';
|
||||
});
|
||||
|
||||
onMounted(() => {
|
||||
// 解决当没有问卷的时候,里面的内容不更新的问题
|
||||
fetchSurveys(form);
|
||||
});
|
||||
|
||||
async function handleLoadSurveys() {
|
||||
await fetchSurveys(form);
|
||||
form.page = form.page + 1;
|
||||
|
||||
@@ -15,7 +15,8 @@ import {
|
||||
fetchSurveys,
|
||||
deleteItem,
|
||||
saveTemplate,
|
||||
currentSurvey
|
||||
currentSurvey,
|
||||
clearSurveys
|
||||
} from '@/views/Survey/hooks/useSurveyData';
|
||||
import ai from '@/assets/img/analysis/ai.svg';
|
||||
import { ref } from 'vue';
|
||||
@@ -127,7 +128,7 @@ function copyItem(item: SurveyItem) {
|
||||
if (res.data.code === 200 || res.data.code === 201) {
|
||||
showSuccessToast('复制成功');
|
||||
form.value.page = 1;
|
||||
survey.value = [] as any;
|
||||
clearSurveys();
|
||||
fetchSurveys(form.value);
|
||||
} else {
|
||||
showFailToast(res.data);
|
||||
@@ -150,10 +151,10 @@ function copyItem(item: SurveyItem) {
|
||||
<el-text style="max-width: 100px">
|
||||
<b v-html="survey.project_name"></b>
|
||||
</el-text>
|
||||
<el-text class="wrap" v-if="survey.publish_number">
|
||||
<el-text v-if="survey.publish_number" class="wrap">
|
||||
{{ survey.publish_number }}份
|
||||
</el-text>
|
||||
<el-text class="wrap" v-if="survey.is_time" style="text-wrap: nowrap">
|
||||
<el-text v-if="survey.is_time" class="wrap" style="text-wrap: nowrap">
|
||||
{{ `${survey.start_time}${survey.end_time ? ' 至 ' + survey.end_time : ''}` }}
|
||||
</el-text>
|
||||
</div>
|
||||
|
||||
@@ -63,7 +63,7 @@ function deleteItem(item: SurveyItem, form: any) {
|
||||
showToast('删除成功!');
|
||||
}
|
||||
form.page = 1;
|
||||
survey.value = [];
|
||||
clearSurveys();
|
||||
await fetchSurveys(form);
|
||||
})
|
||||
.catch(() => {
|
||||
@@ -85,6 +85,10 @@ async function saveTemplate(item: SurveyItem) {
|
||||
}
|
||||
}
|
||||
|
||||
function clearSurveys() {
|
||||
survey.value = [];
|
||||
}
|
||||
|
||||
export {
|
||||
fetchSurveys,
|
||||
loading,
|
||||
@@ -96,5 +100,6 @@ export {
|
||||
saveTemplate,
|
||||
currentSurvey,
|
||||
requestLoading,
|
||||
fetchSingleSurvey
|
||||
fetchSingleSurvey,
|
||||
clearSurveys
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user