| 123456789101112131415161718192021222324252627282930313233343536 |
- import { GetNotice } from '@/api/public'
- export function timeFix() {
- const time = new Date()
- const hour = time.getHours()
- return hour < 9 ? '早上好' : hour <= 11 ? '上午好' : hour <= 13 ? '中午好' : hour < 20 ? '下午好' : '晚上好'
- }
- /**
- * 学期判断
- * 返回 [学期开始时间戳, 明日时间戳]
- */
- export function getSemesterTimestamps() {
- const now = new Date()
- const year = now.getFullYear()
- const feb1ThisYear = new Date(year, 1, 1, 0, 0, 0, 0) // 当年 2-01
- const aug31ThisYear = new Date(year, 7, 31, 0, 0, 0, 0) // 当年 8-31
- // 下学期:2 月 1 日 ~ 8 月 31 日
- // 上学期:8 月 31 日 ~ 次年 2 月 1 日
- // 1 月属于上一年的上学期
- return [(now >= feb1ThisYear && now < aug31ThisYear) ? feb1ThisYear.getTime() : new Date(now < feb1ThisYear ? year - 1 : year, 7, 31, 0, 0, 0, 0).getTime(), now.getTime() + 86400000]
- }
- export async function getNotice(key) {
- try {
- const res = await GetNotice({ key })
- if (!res || res.code !== 0) {
- console.log(`获取公告失败:${res?.msg ?? ''}`)
- return ''
- }
- return res.msg ?? ''
- } catch (error) {
- console.log('获取公告失败:', error)
- return ''
- }
- }
|