From 5e0e76d88269cbc30e2ef97324f90cbc1e52aa4c Mon Sep 17 00:00:00 2001
From: xixiibn5100 <1584914306@qq.com>
Date: Tue, 10 Dec 2024 01:59:14 +0800
Subject: [PATCH 1/3] feat: add vote limit on number of options
---
src/pages/View/view.vue | 30 +++++++++++++++++++-----------
1 file changed, 19 insertions(+), 11 deletions(-)
diff --git a/src/pages/View/view.vue b/src/pages/View/view.vue
index 2e0cf0e..b63db38 100644
--- a/src/pages/View/view.vue
+++ b/src/pages/View/view.vue
@@ -123,7 +123,7 @@
提交问卷
-
+
你确认要提交问卷吗?
@@ -138,7 +138,7 @@
-
+
@@ -192,7 +192,8 @@
})
const optionStore = useMainStore().useOptionStore()
const questionnaireStore = useMainStore().useQuetionnaireStore()
- onMounted(() => {
+ onMounted(async () => {
+
loginStore.setShowHeader(false);
let idParam = route.query.id as string | undefined;
if (idParam) {
@@ -206,22 +207,22 @@
}
}
getQuestionnaireView();
+ try{
+ const res = await getStatistic({id: Number(decryptedId.value)})
+ resultData.value = res.data.statistics[0].options
+ } catch (e) {
+ ElNotification.error(e)
+ }
});
const tokenOutDate = computed(() => {
const lastDate = localStorage.getItem('timestamp');
-
// 如果没有存储时间戳(首次请求或过期),调用 verifyAPI
- if (!lastDate || Date.now() - parseInt(lastDate) > 7 * 24 * 60 * 60 * 1000){
- return true
- } else {
- return false
- }
+ return !(!lastDate || Date.now() - parseInt(lastDate) > 7 * 24 * 60 * 60 * 1000);
});
const verify = () => {
const lastDate = localStorage.getItem('timestamp');
-
// 如果没有存储时间戳(首次请求或过期),调用 verifyAPI
if (!lastDate || Date.now() - parseInt(lastDate) > 7 * 24 * 60 * 60 * 1000) {
// 调用 verifyAPI 获取新的 token
@@ -313,6 +314,14 @@
ElNotification.error('您有多选题未完成作答.')
return true;
}
+ if(q.question_type === 2 && q.answer.split('┋').length > q.maximum_option || q.answer.split('┋').length < q.minimum_option) {
+ if(q.answer.split('┋').length > q.maximum_option) {
+ ElNotification.error(`该投票最多只能选择${q.maximum_option}个选项`)
+ } else if(q.answer.split('┋').length < q.minimum_option) {
+ ElNotification.error(`该投票最少需要选择${q.maximum_option}个选项`)
+ }
+ return true;
+ }
if (q.question_type === 3 && q.answer!== '' && q.reg && !new RegExp(q.reg).test(q.answer)) {
ElNotification.error(`第${q.serial_num}题的回答不符合要求.`);
@@ -353,7 +362,6 @@
try{
const res = await getStatistic({id: Number(decryptedId.value)})
resultData.value = res.data.statistics[0].options
- console.log(resultData.value)
} catch (e) {
ElNotification.error(e)
}
From d8d8a74d2c89db850c3e3b2680f05fab5f26ee4a Mon Sep 17 00:00:00 2001
From: xixiibn5100 <1584914306@qq.com>
Date: Tue, 10 Dec 2024 10:43:52 +0800
Subject: [PATCH 2/3] feat: add temporary time limit
---
src/pages/View/view.vue | 20 ++++++++++++++------
1 file changed, 14 insertions(+), 6 deletions(-)
diff --git a/src/pages/View/view.vue b/src/pages/View/view.vue
index b63db38..8ab3e2b 100644
--- a/src/pages/View/view.vue
+++ b/src/pages/View/view.vue
@@ -206,12 +206,20 @@
ElNotification.error("无效的问卷id")
}
}
- getQuestionnaireView();
- try{
- const res = await getStatistic({id: Number(decryptedId.value)})
- resultData.value = res.data.statistics[0].options
- } catch (e) {
- ElNotification.error(e)
+ //TODO: 支持设置问卷开始时间
+ const now = new Date(); // 当前时间
+ const targetDate = new Date(2024, 12, 10, 0, 0, 0);
+
+ if (now > targetDate) {
+ getQuestionnaireView();
+ try{
+ const res = await getStatistic({id: Number(decryptedId.value)})
+ resultData.value = res.data.statistics[0].options
+ } catch (e) {
+ ElNotification.error(e)
+ }
+ } else if (now < targetDate) {
+ ElNotification.error("投票未开放")
}
});
From 399e07485b0577e23a684038b398244f71afc975 Mon Sep 17 00:00:00 2001
From: xixiibn5100 <1584914306@qq.com>
Date: Tue, 10 Dec 2024 21:29:23 +0800
Subject: [PATCH 3/3] feat: add start time setting
---
src/pages/DetailInfo/index.vue | 11 +++++++++++
src/pages/View/view.vue | 24 ++++++++++++++----------
src/pages/View/vote.vue | 5 ++---
3 files changed, 27 insertions(+), 13 deletions(-)
diff --git a/src/pages/DetailInfo/index.vue b/src/pages/DetailInfo/index.vue
index 5582306..6838bdd 100644
--- a/src/pages/DetailInfo/index.vue
+++ b/src/pages/DetailInfo/index.vue
@@ -92,6 +92,15 @@
每日最多提交是否统一登录
+
+ 问卷开始时间
+
+
问卷截止时间
{
return futureDate;
};
+const startTime = ref(Date.now())
// 用于获取问卷部分的容器元素
const questionnaireContainer = ref();
@@ -404,6 +414,7 @@ const dataReverse = () => {
const submit = (state:number) => {
submitData.value.time = time.value
+ submitData.value.start_time = new Date(startTime.value).toISOString()
submitData.value.questions = question.value;
console.log(question.value);
if(isNew === 'false') {
diff --git a/src/pages/View/view.vue b/src/pages/View/view.vue
index 8ab3e2b..04acaf6 100644
--- a/src/pages/View/view.vue
+++ b/src/pages/View/view.vue
@@ -116,7 +116,7 @@
-
+
@@ -133,7 +133,7 @@
学号
- 密码
+ 密码
@@ -179,6 +179,7 @@
id: null,
questions_list: [],
});
+ const startTime = ref()
const resultData = ref(undefined)
const route = useRoute();
const loginStore = useMainStore().useLoginStore();
@@ -206,11 +207,6 @@
ElNotification.error("无效的问卷id")
}
}
- //TODO: 支持设置问卷开始时间
- const now = new Date(); // 当前时间
- const targetDate = new Date(2024, 12, 10, 0, 0, 0);
-
- if (now > targetDate) {
getQuestionnaireView();
try{
const res = await getStatistic({id: Number(decryptedId.value)})
@@ -218,9 +214,6 @@
} catch (e) {
ElNotification.error(e)
}
- } else if (now < targetDate) {
- ElNotification.error("投票未开放")
- }
});
const tokenOutDate = computed(() => {
@@ -270,6 +263,16 @@
}
};
+ const handleSubmit = () => {
+ const nowDate = Date.now()
+ const startTimestamp = new Date(startTime.value).getTime()
+ const showTime = startTime.value.replace("T", " ").split("+")[0].split(".")[0]
+ if(nowDate - startTimestamp < 0){
+ ElNotification.error(`问卷开始时间为 ${showTime}`)
+ } else {
+ showModal('QuestionnaireSubmit')
+ }
+ }
const getQuestionnaireView = () => {
if(decryptedId.value){
useRequest(() => getUserAPI({id: decryptedId.value as number}),{
@@ -280,6 +283,7 @@
question.value = formData.value.questions;
time.value = formData.value.time.replace("T", " ").split("+")[0].split(".")[0]
submitData.value.id = res.data.id;
+ startTime.value = res.data.start_time
// console.log("问卷id:"+submitData.value.id)
question.value.forEach(q => {
//获取已存储的答案
diff --git a/src/pages/View/vote.vue b/src/pages/View/vote.vue
index 19b2f82..ea080b8 100644
--- a/src/pages/View/vote.vue
+++ b/src/pages/View/vote.vue
@@ -21,9 +21,8 @@
最少选 {{ props.minimum_option }} 个
最多选 {{ props.maximum_option }} 个