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

View File

@ -1,21 +1,19 @@
<script setup lang="ts">
import { ref, nextTick, unref } from "vue";
import { HTMLElementPlus } from "./types";
// import { formatDate } from "@vueuse/core";
import { ref, onMounted, unref } from "vue";
import { formatDate } from "@/utils/formatDate";
import Flippers from "./Flippers.vue";
// defineOptions({
// name: "Countdown"
// });
const flipObjs = ref<(HTMLElementPlus | null)[]>([]);
const flipObjs = ref([]);
const flipperHour1 = ref<HTMLElementPlus | null>(null);
const flipperHour2 = ref<HTMLElementPlus | null>(null);
const flipperMinute1 = ref<HTMLElementPlus | null>(null);
const flipperMinute2 = ref<HTMLElementPlus | null>(null);
const flipperSecond1 = ref<HTMLElementPlus | null>(null);
const flipperSecond2 = ref<HTMLElementPlus | null>(null);
const flipperHour1 = ref(null);
const flipperHour2 = ref(null);
const flipperMinute1 = ref(null);
const flipperMinute2 = ref(null);
const flipperSecond1 = ref(null);
const flipperSecond2 = ref(null);
//
const init = () => {
@ -25,8 +23,17 @@ const init = () => {
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 = [
unref(flipperHour1),
unref(flipperHour2),
@ -36,6 +43,7 @@ nextTick(() => {
unref(flipperSecond2)
];
init();
start();
});
</script>

View File

@ -1,11 +1,30 @@
<script setup lang="ts">
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 {
frontTextFromData.value = text;
}
function setBack(text: number): void {
backTextFromData.value = text;
}
const textClass = (number: number) => {
return "number" + number;
};
@ -14,12 +33,15 @@ const styleName = computed(() => {
return {
mainClass: `m-flipper down go`,
font: `digital front ${textClass(frontTextFromData.value)}`,
back: `digital back ${textClass(frontTextFromData.value)}`
back: `digital back ${textClass(backTextFromData.value)}`
};
});
// promise
defineExpose({
setFront
setFront,
setBack
});
</script>