@@ -275,10 +275,11 @@ const default_list = {
],
};
const list = ref([]);
-onBeforeMount(() => {
- SeckillAPI.getSeckillList((res: any) => {
+onMounted(() => {
+ console.log('aaaa');
+ SeckillAPI.getSeckillList({}).then((res: any) => {
const data = res.data;
- console.log(data);
+ console.log(res.data);
if (!isEmpty(data.current)) {
list.value = data.current.goods;
} else {
From b5e20337a108f6e4f414ff991afe64ca0498d8c6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E4=BA=8E=E8=82=96=E7=A3=8A?= <18851179580@163.com>
Date: Wed, 4 Sep 2024 17:31:52 +0800
Subject: [PATCH 2/5] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=A1=B5=E9=9D=A2?=
=?UTF-8?q?=E6=98=BE=E7=A4=BA1?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/components/model-seckill/index.vue | 1 -
src/components/model-seckill/model-seckill-content.vue | 9 +++------
2 files changed, 3 insertions(+), 7 deletions(-)
diff --git a/src/components/model-seckill/index.vue b/src/components/model-seckill/index.vue
index 1db8a060..3d543562 100644
--- a/src/components/model-seckill/index.vue
+++ b/src/components/model-seckill/index.vue
@@ -276,7 +276,6 @@ const default_list = {
};
const list = ref([]);
onMounted(() => {
- console.log('aaaa');
SeckillAPI.getSeckillList({}).then((res: any) => {
const data = res.data;
console.log(res.data);
diff --git a/src/components/model-seckill/model-seckill-content.vue b/src/components/model-seckill/model-seckill-content.vue
index bb772b07..75ab6de7 100644
--- a/src/components/model-seckill/model-seckill-content.vue
+++ b/src/components/model-seckill/model-seckill-content.vue
@@ -120,12 +120,9 @@ const props = defineProps({
}),
},
});
-const state = reactive({
- form: props.value,
- data: props.styles,
-});
-// 如果需要解构,确保使用toRefs
-const { form, data } = toRefs(state);
+
+const form = ref(props.value);
+const data = ref(props.styles);
watchEffect(() => {
form.value = props.value;
From 8bc4fa31dfb3da2819d93a34398d7da9fb8a6045 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E4=BA=8E=E8=82=96=E7=A3=8A?= <18851179580@163.com>
Date: Wed, 4 Sep 2024 18:04:55 +0800
Subject: [PATCH 3/5] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=A7=92=E6=9D=80?=
=?UTF-8?q?=E6=97=B6=E9=97=B4=E6=98=BE=E7=A4=BA?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/components/model-seckill/index.vue | 44 +++++++++++++++++++++-----
1 file changed, 36 insertions(+), 8 deletions(-)
diff --git a/src/components/model-seckill/index.vue b/src/components/model-seckill/index.vue
index 3d543562..ac022ba9 100644
--- a/src/components/model-seckill/index.vue
+++ b/src/components/model-seckill/index.vue
@@ -8,7 +8,7 @@
{{ form.topic_text }}
|
-
+
距离结束
![]()
@@ -24,6 +24,9 @@
+
+ 活动已结束
+
{{ form.button_text }}
@@ -181,14 +184,8 @@ onBeforeMount(async () => {
const url = await online_url('/static/plugins/seckill/images/diy/').then(res => res);
new_url.value = url + 'time.png';
})
-
const form = computed(() => props.value?.content || {});
const new_style = computed(() => props.value?.style || {});
-const time_config = [
- { key: 'hour', value: 12 },
- { key: 'minute', value: 30 },
- { key: 'second', value: 52 },
-]
const time_bg = computed(() => {
const { countdown_bg_color_list, countdown_direction } = new_style.value;
// 渐变
@@ -275,12 +272,43 @@ const default_list = {
],
};
const list = ref([]);
+const time_config = reactive([
+ { key: 'hour', value: '12' },
+ { key: 'minute', value: '30' },
+ { key: 'second', value: '52' },
+]);
+const endTime = ref('2024-09-07 12:30:52');
+const intervalId = ref(undefined);
+const updateCountdown = () => {
+ const now = new Date();
+ const distance = new Date(endTime.value).getTime() - now.getTime();
+ // 如果倒计时结束,显示结束信息
+ if (distance < 0) {
+ clearInterval(intervalId.value);
+ return;
+ }
+ // 计算时间
+ const hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
+ const minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
+ const seconds = Math.floor((distance % (1000 * 60)) / 1000);
+ time_config.forEach((item) => {
+ if (item.key == 'hour') {
+ item.value = hours < 10 ? '0' + hours : hours.toString();
+ } else if (item.key == 'minute') {
+ item.value = minutes < 10 ? '0' + minutes : minutes.toString();
+ } else if (item.key == 'second') {
+ item.value = seconds < 10 ? '0' + seconds : seconds.toString();
+ }
+ });
+}
+// 更新倒计时函数
onMounted(() => {
SeckillAPI.getSeckillList({}).then((res: any) => {
const data = res.data;
- console.log(res.data);
if (!isEmpty(data.current)) {
list.value = data.current.goods;
+ endTime.value = data.current.time_end;
+ intervalId.value = setInterval(updateCountdown, 1000);
} else {
list.value = Array(4).fill(default_list);
}
From e28627cd3c8c1c83978537da1986faa4ca9a098b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E4=BA=8E=E8=82=96=E7=A3=8A?= <18851179580@163.com>
Date: Wed, 4 Sep 2024 18:57:56 +0800
Subject: [PATCH 4/5] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=97=B6=E9=97=B4?=
=?UTF-8?q?=E6=9B=B4=E6=96=B0?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/components/model-seckill/index.vue | 48 +++++++++++++++++++-------
1 file changed, 36 insertions(+), 12 deletions(-)
diff --git a/src/components/model-seckill/index.vue b/src/components/model-seckill/index.vue
index ac022ba9..d6d7235a 100644
--- a/src/components/model-seckill/index.vue
+++ b/src/components/model-seckill/index.vue
@@ -8,8 +8,8 @@
{{ form.topic_text }}
|
-
-
距离结束
+
+
{{ seckill_time.time_first_text }}
@@ -25,7 +25,7 @@
- 活动已结束
+ 已结束
@@ -273,18 +273,33 @@ const default_list = {
};
const list = ref([]);
const time_config = reactive([
- { key: 'hour', value: '12' },
- { key: 'minute', value: '30' },
- { key: 'second', value: '52' },
+ { key: 'hour', value: '00' },
+ { key: 'minute', value: '00' },
+ { key: 'second', value: '00' },
]);
-const endTime = ref('2024-09-07 12:30:52');
const intervalId = ref(undefined);
+const seckill_time = ref({
+ endTime: '2024-09-04 18:51:00',
+ startTime: '2024-09-04 18:51:00',
+ status: 0,
+ time_first_text: '距结束'
+});
const updateCountdown = () => {
const now = new Date();
- const distance = new Date(endTime.value).getTime() - now.getTime();
+ let endTime = seckill_time.value.endTime;
+ if (seckill_time.value.status === 0) {
+ endTime = seckill_time.value.startTime;
+ }
+ const distance = new Date(endTime).getTime() - now.getTime();
// 如果倒计时结束,显示结束信息
if (distance < 0) {
clearInterval(intervalId.value);
+ // 如果是待开始状态,则显示开始倒计时,并且在结束的时候根据结束时候再执行一个定时器
+ if (seckill_time.value.status === 0) {
+ seckill_time.value.status = 1;
+ seckill_time.value.time_first_text = '距结束';
+ intervalId.value = setInterval(updateCountdown, 1000);
+ }
return;
}
// 计算时间
@@ -302,12 +317,22 @@ const updateCountdown = () => {
});
}
// 更新倒计时函数
-onMounted(() => {
+onBeforeMount(() => {
SeckillAPI.getSeckillList({}).then((res: any) => {
const data = res.data;
if (!isEmpty(data.current)) {
- list.value = data.current.goods;
- endTime.value = data.current.time_end;
+ if (!isEmpty(data.current.goods)) {
+ list.value = data.current.goods;
+ } else {
+ list.value = Array(4).fill(default_list);
+ }
+ const { status, time_first_text } = data.current.time;
+ seckill_time.value = {
+ endTime: data.current.time_end,
+ startTime: data.current.time_start,
+ status: status,
+ time_first_text: time_first_text
+ }
intervalId.value = setInterval(updateCountdown, 1000);
} else {
list.value = Array(4).fill(default_list);
@@ -392,7 +417,6 @@ const autoplay = ref(false);
const slides_per_group = ref(1);
// 内容参数的集合
watchEffect(() => {
-
// 是否滚动
if (new_style.value.is_roll) {
autoplay.value = {
From f4f0780827cd0eaed04afd4a5b778f08bbb28d03 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E4=BA=8E=E8=82=96=E7=A3=8A?= <18851179580@163.com>
Date: Thu, 5 Sep 2024 09:33:45 +0800
Subject: [PATCH 5/5] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=80=92=E8=AE=A1?=
=?UTF-8?q?=E6=97=B6=E9=80=BB=E8=BE=91=E6=9B=B4=E6=96=B0?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/components/model-seckill/index.vue | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/src/components/model-seckill/index.vue b/src/components/model-seckill/index.vue
index d6d7235a..e43b7752 100644
--- a/src/components/model-seckill/index.vue
+++ b/src/components/model-seckill/index.vue
@@ -292,12 +292,14 @@ const updateCountdown = () => {
}
const distance = new Date(endTime).getTime() - now.getTime();
// 如果倒计时结束,显示结束信息
- if (distance < 0) {
+ if (distance <= 1000) {
clearInterval(intervalId.value);
// 如果是待开始状态,则显示开始倒计时,并且在结束的时候根据结束时候再执行一个定时器
if (seckill_time.value.status === 0) {
seckill_time.value.status = 1;
seckill_time.value.time_first_text = '距结束';
+ // 先执行一次倒计时,后续的等待倒计时执行
+ setTimeout(() => { updateCountdown();}, 0);
intervalId.value = setInterval(updateCountdown, 1000);
}
return;
@@ -328,11 +330,13 @@ onBeforeMount(() => {
}
const { status, time_first_text } = data.current.time;
seckill_time.value = {
- endTime: data.current.time_end,
- startTime: data.current.time_start,
- status: status,
+ endTime: '2024-09-05 09:36:00',
+ startTime: '2024-09-05 09:33:00',
+ status: 0,
time_first_text: time_first_text
}
+ // 先执行一次倒计时,后续的等待倒计时执行
+ setTimeout(() => { updateCountdown();}, 0);
intervalId.value = setInterval(updateCountdown, 1000);
} else {
list.value = Array(4).fill(default_list);