惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

爱范儿
爱范儿
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
WordPress大学
WordPress大学
Y
Y Combinator Blog
I
InfoQ
美团技术团队
罗磊的独立博客
B
Blog RSS Feed
GbyAI
GbyAI
小众软件
小众软件
IT之家
IT之家
Engineering at Meta
Engineering at Meta
Blog — PlanetScale
Blog — PlanetScale
V
V2EX
Last Week in AI
Last Week in AI
酷 壳 – CoolShell
酷 壳 – CoolShell
Jina AI
Jina AI
MyScale Blog
MyScale Blog
博客园 - 聂微东
Microsoft Security Blog
Microsoft Security Blog
博客园 - 【当耐特】
Apple Machine Learning Research
Apple Machine Learning Research
The GitHub Blog
The GitHub Blog
T
The Blog of Author Tim Ferriss

Hyde Blog

Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog
Hyde Blog
Hyde · 2025-10-05 · via Hyde Blog

vue

// 全局问候提示
<script setup lang="ts" name="GlobalGreet">
import { TkMessage } from "vitepress-theme-teek";
import { ref, watch, onMounted } from "vue";
import { useRoute } from "vitepress";

const route = useRoute();

const hasGreet = ref(false);
const duration = 4000;

const greet = () => {
  console.log(1);
  if (hasGreet.value) return;

  hasGreet.value = true;
  setTimeout(() => {
    hasGreet.value = false;
  }, duration);

  const now = new Date();
  let hours = now.getHours();
  let minutes = now.getMinutes();
  let seconds = now.getSeconds();

  const timeStr = `${String(hours).padStart(2, "0")}:${String(minutes).padStart(
    2,
    "0"
  )}:${String(seconds).padStart(2, "0")}`;
  const message = getGreetingMessage(hours, timeStr);

  TkMessage.primary({
    showClose: true,
    message,
    duration,
    plain: true,
    offset: 80,
  });
};

const getGreetingMessage = (hours: number, timeStr: string) => {
  if (hours >= 6 && hours < 9) {
    return `早上好呀~,现在是 ${timeStr},吃早餐了吗?😊🤭`;
  }
  if (hours >= 9 && hours < 12) {
    return `上午好呀~,现在是 ${timeStr},该准备吃饭啦🥗🍖~`;
  }

  if (hours >= 12 && hours < 16) {
    return `下午好呀~,现在是 ${timeStr},繁忙的下午也要适当休息哦🥤🏀~`;
  }

  if (hours >= 16 && hours < 19) {
    return `到黄昏了~,现在是 ${timeStr},该准备吃饭啦🥗🍖~`;
  }

  if (hours >= 19 && hours < 22) {
    return `晚上好呀~,现在是 ${timeStr},该准备洗漱睡觉啦🥱😪~`;
  }

  if (hours >= 22 || hours < 6) {
    return `别再熬夜了~,现在是 ${timeStr},早点睡吧,让我们一起欣赏早上的太阳~😇🛏`;
  }

  return `你好呀!现在是 ${timeStr}。`;
};

onMounted(() => {
  watch(route, greet, { immediate: true });
});
</script>

<template></template>

vue

<script setup lang="ts" name="TeekLayoutProvider">
// @ts-ignore
import GlobalGreet from "./GlobalGreet.vue"; //导入全局问候组件
</script>

<template>
  <Teek.Layout>
    <template #layout-top>
      <!-- 全局问候组件 -->
      <GlobalGreet />
    </template>
    其他组件...
  </Teek.Layout>
</template>