Ver código fonte

优化:每答完一题就存到本地

htc 1 dia atrás
pai
commit
82ba5b9eea
4 arquivos alterados com 57 adições e 30 exclusões
  1. 6 0
      pages.json
  2. 34 0
      pages/launch.vue
  3. 0 7
      pages/login.vue
  4. 17 23
      pages/questionnaireFill.vue

+ 6 - 0
pages.json

@@ -1,5 +1,11 @@
 {
 	"pages": [
+		{
+			"path": "pages/launch",
+			"style": {
+				"navigationStyle": "custom"
+			}
+		},
 		{
 			"path": "pages/login",
 			"style": {

+ 34 - 0
pages/launch.vue

@@ -0,0 +1,34 @@
+<template>
+	<view class="launch-container"></view>
+</template>
+
+<script>
+	export default {
+		data(){
+			return {
+				
+			}
+		},
+		onLoad() {
+			if(uni.getStorageSync('userInfo')){
+				uni.reLaunch({ url:'/pages/home' })
+			}else{
+				uni.reLaunch({ url:'/pages/login' })
+			}
+		},
+		methods:{
+			
+		}
+	}
+</script>
+
+<style scoped lang="less">
+	.launch-container {
+		display: flex;
+		align-items: center;
+		justify-content: center;
+		height: 100vh;
+		width: 100vw;
+		background-color: #FFFFFF; 
+	}
+</style>

+ 0 - 7
pages/login.vue

@@ -32,13 +32,6 @@
 				
 			}
 		},
-		onReady() {
-			if(uni.getStorageSync('userInfo')){
-				uni.reLaunch({
-					url:'/pages/home'
-				})
-			}
-		},
 		methods:{
 			decryptPhoneNumber(e){
 				if(uni.getStorageSync('token')){

+ 17 - 23
pages/questionnaireFill.vue

@@ -34,8 +34,8 @@
 				teamQuestionnaireId:'',
 				list:[],
 				questionnaire:null,
-				isLoading: true, // 新增加载状态
-				isSubmitting: false // 新增提交状态
+				isLoading: true,
+				isSubmitting: false
 			}
 		},
 		onLoad(option) {
@@ -56,7 +56,9 @@
 					if (item.warn) {
 						this.$set(item, 'warn', false);
 					}
-				}
+				}
+				
+				this.setQuestionnaireCache();
 			},
 			getList(){
 				let questionnaire = null;
@@ -103,7 +105,6 @@
 			    });
 			
 			    if (firstUnansweredIndex > -1) {
-			        // 使用 uni.showModal 以提供更好的用户体验
 			        return uni.showModal({
 			            title: '提示',
 			            content: `第 ${firstUnansweredIndex + 1} 项未选择答案,请选择。`,
@@ -111,49 +112,42 @@
 			        });
 			    }
 			
-			    // 使用更清晰的逻辑构建提交数据
 			    const submitList = this.list.map(question => {
-			        // 映射 userAnswer 数组,并添加一个清晰的 `isSelected` 字段
 			        const formattedUserAnswer = question.userAnswer.map(option => ({
 			            ...option,
-			            // 假设后端需要一个布尔值来表示是否选中
 			            isSelected: option.questionOption === question.answer
 			        }));
 			
-			        // 剔除前端专用的字段(answer, warn),保持提交数据纯净
 			        const { answer, warn, ...restOfQuestion } = question;
 			
 			        return {
 			            ...restOfQuestion,
-			            isAnswer: '1', // 标记为已作答
-			            userAnswer: formattedUserAnswer // 使用格式化后的数组
+			            isAnswer: '1',
+			            userAnswer: formattedUserAnswer
 			        };
 			    });
 			
 			    this.isSubmitting = true;
 			    this.$api.post('/core/team/member/answer/submit', submitList).then(res => {
 			        if (res.data.code !== 0) {
-			            // 在失败时也应该重置提交状态
 			            this.isSubmitting = false; 
 			            return this.$showToast(res.data.msg);
 			        }
 			        uni.removeStorageSync('questionnaire');
-			        // 提交成功后建议使用 redirectTo 或 reLaunch,防止用户返回到填写页
 			        uni.redirectTo({
 			            url: '/pages/questionnaireResult'
 			        });
 			    }).catch(err => {
-			        // this.isSubmitting = false; // .finally() 中已经处理
 			        this.$showToast('网络异常,请稍后重试');
 			    })
 			    .finally(() => {
-			        this.isSubmitting = false; // 确保无论成功或失败,提交状态都会被重置
+			        this.isSubmitting = false;
 			    });
 			},
 			setQuestionnaireCache(){
 				const answeredList = this.list
-					.filter(l => l.answer) // 过滤出已回答的
-					.map(l => ({ id: l.id, answer: l.answer })); // 转换成需要的格式
+					.filter(l => l.answer)
+					.map(l => ({ id: l.id, answer: l.answer }));
 				
 				if (answeredList.length === 0) {
 					uni.removeStorageSync('questionnaire');
@@ -167,13 +161,13 @@
 				uni.setStorageSync('questionnaire', JSON.stringify(qinfo));
 			}
 		},
-		onUnload() {
-			this.setQuestionnaireCache();
-		},
-		onBackPress() {
-			this.setQuestionnaireCache();
-			return false; 
-		}
+		// onUnload() {
+		// 	this.setQuestionnaireCache();
+		// },
+		// onBackPress() {
+		// 	this.setQuestionnaireCache();
+		// 	return false; 
+		// }
 	}
 </script>