test: tsx

This commit is contained in:
Composure 2023-02-24 20:50:45 +08:00
parent 33c0ee8f4f
commit f318cbaa9b
3 changed files with 47 additions and 18 deletions

View File

@ -1,6 +1,6 @@
export default { export default {
path: "/test", path: "/test",
redirect: "/test/403", redirect: "/test/countdown",
meta: { meta: {
icon: "material-symbols:import-contacts-outline", icon: "material-symbols:import-contacts-outline",
title: "测试页面" title: "测试页面"
@ -11,8 +11,7 @@ export default {
name: "Countdown", name: "Countdown",
component: () => import("@/views/testPage/Countdown.vue"), component: () => import("@/views/testPage/Countdown.vue"),
meta: { meta: {
title: "倒计时", title: "倒计时"
keepAlive: false
} }
} }
] ]

View File

@ -1,21 +1,19 @@
<script setup lang="ts"> <script setup lang="ts">
import { ref, nextTick, unref } from "vue"; import { ref, onMounted, unref } from "vue";
import { HTMLElementPlus } from "./types";
// import { formatDate } from "@vueuse/core";
import { formatDate } from "@/utils/formatDate"; import { formatDate } from "@/utils/formatDate";
import Flippers from "./Flippers.vue"; import Flippers from "./Flippers.vue";
// defineOptions({ // defineOptions({
// name: "Countdown" // name: "Countdown"
// }); // });
const flipObjs = ref<(HTMLElementPlus | null)[]>([]); const flipObjs = ref([]);
const flipperHour1 = ref<HTMLElementPlus | null>(null); const flipperHour1 = ref(null);
const flipperHour2 = ref<HTMLElementPlus | null>(null); const flipperHour2 = ref(null);
const flipperMinute1 = ref<HTMLElementPlus | null>(null); const flipperMinute1 = ref(null);
const flipperMinute2 = ref<HTMLElementPlus | null>(null); const flipperMinute2 = ref(null);
const flipperSecond1 = ref<HTMLElementPlus | null>(null); const flipperSecond1 = ref(null);
const flipperSecond2 = ref<HTMLElementPlus | null>(null); const flipperSecond2 = ref(null);
// //
const init = () => { const init = () => {
@ -25,8 +23,17 @@ const init = () => {
flipObjs?.value[i]?.setFront(nowTimeStr[i]); flipObjs?.value[i]?.setFront(nowTimeStr[i]);
} }
}; };
//
nextTick(() => { const start = () => {
const now = new Date();
const nowTimeStr = formatDate(new Date(now.getTime()), "hhiiss");
setInterval(() => {
for (let i = 0; i < flipObjs.value.length; i++) {
flipObjs?.value[i]?.setBack(nowTimeStr[i]);
}
}, 1000);
};
onMounted(() => {
flipObjs.value = [ flipObjs.value = [
unref(flipperHour1), unref(flipperHour1),
unref(flipperHour2), unref(flipperHour2),
@ -36,6 +43,7 @@ nextTick(() => {
unref(flipperSecond2) unref(flipperSecond2)
]; ];
init(); init();
start();
}); });
</script> </script>

View File

@ -1,11 +1,30 @@
<script setup lang="ts"> <script setup lang="ts">
import { ref, defineExpose, computed } from "vue"; import { ref, defineExpose, computed } from "vue";
const props = defineProps({
frontText: {
type: Number,
default: 0
},
backText: {
type: Number,
default: 1
}
});
// //
const frontTextFromData = ref(0); const frontTextFromData = ref(props.frontText);
//
const backTextFromData = ref(props.backText);
function setFront(text: number): void { function setFront(text: number): void {
frontTextFromData.value = text; frontTextFromData.value = text;
} }
function setBack(text: number): void {
backTextFromData.value = text;
}
const textClass = (number: number) => { const textClass = (number: number) => {
return "number" + number; return "number" + number;
}; };
@ -14,12 +33,15 @@ const styleName = computed(() => {
return { return {
mainClass: `m-flipper down go`, mainClass: `m-flipper down go`,
font: `digital front ${textClass(frontTextFromData.value)}`, font: `digital front ${textClass(frontTextFromData.value)}`,
back: `digital back ${textClass(frontTextFromData.value)}` back: `digital back ${textClass(backTextFromData.value)}`
}; };
}); });
// promise
defineExpose({ defineExpose({
setFront setFront,
setBack
}); });
</script> </script>