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 @@ - @@ -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 }} 个
-
- -
+
+
Preview