门户修改静态文字

function getCurrentDateFormatted(){ const now = new Date(); const year = now.getFullYear(); const month = now.getMonth() + 1;

ini 复制代码
// 获取当月第一天
const firstDay = new Date(year, now.getMonth(), 1);
const firstDayOfWeek = firstDay.getDay();

// 调整周起始:将周日视为第7天,周一为第1天
const adjustedFirstDay = firstDayOfWeek === 0 ? 7 : firstDayOfWeek;

// 计算当前日期是当月的第几天
const dayOfMonth = now.getDate();

// 计算当前日期是第几周
let weekNumber;
if (dayOfMonth <= (8 - adjustedFirstDay)) {
  weekNumber = 1;
} else {
  const remainingDays = dayOfMonth - (8 - adjustedFirstDay);
  weekNumber = Math.ceil(remainingDays / 7) + 1;
}

return `${year}年${month}月第${weekNumber}周`;

} function getCurrentFestival(){ const now = new Date(); const year = now.getFullYear(); const month = now.getMonth() + 1; const date = now.getDate();

javascript 复制代码
// 计算春节日期(农历正月初一,使用近似公历日期)
// 春节通常在1月21日至2月20日之间
const springFestival = new Date(year, 0, 1);
const springFestivalDate = new Date(year, 0,
  (springFestival.getDay() >= 4 ? 22 : 15) - springFestival.getDay());

// 节日日期配置
const festivals = [
  { name: '元旦', date: new Date(year, 0, 1) },
  { name: '春节', date: springFestivalDate },
  { name: '清明节', date: new Date(year, 3, 4) }, // 通常是4月4日或5日
  { name: '劳动节', date: new Date(year, 4, 1) },
  { name: '端午节', date: new Date(year, 4, 5) }, // 农历五月初五,近似公历6月
  { name: '中秋节', date: new Date(year, 8, 15) }, // 农历八月十五,近似公历9月
  { name: '国庆节', date: new Date(year, 9, 1) }
];

// 检查当前日期是否是某个节日
for (const festival of festivals) {
  if (month === festival.date.getMonth() + 1 &&
    date === festival.date.getDate()) {
    return festival.name;
  }
}

return null; // 如果不是节日返回null

}

// 使用示例 const festival = getCurrentFestival();

this.getWidgetRef('static-text10923').$el.firstChild.lastChild.innerText = getCurrentDateFormatted()

this.getWidgetRef('static-text49065').$el.firstChild.lastChild.innerText = getCurrentFestival()

相关推荐
用户4445543654265 小时前
在Android开发中阅读源码的指导思路
前端
用户54277848515405 小时前
ESM 模块(ECMAScript Module)详解
前端
全栈前端老曹6 小时前
【ReactNative】核心组件与 JSX 语法
前端·javascript·react native·react.js·跨平台·jsx·移动端开发
用户54277848515406 小时前
JavaScript 闭包详解:由浅入深掌握作用域与内存管理的艺术
前端
小小黑0076 小时前
快手小程序-实现插屏广告的功能
前端·javascript·小程序
用户54277848515406 小时前
闭包在 Vue 项目中的应用
前端
TG:@yunlaoda360 云老大6 小时前
配置华为云国际站代理商OBS跨区域复制时,如何编辑委托信任策略?
java·前端·华为云
dlhto6 小时前
前端登录验证码组件
前端
@万里挑一6 小时前
vue中使用虚拟列表,封装虚拟列表
前端·javascript·vue.js
黑臂麒麟6 小时前
Electron for OpenHarmony 跨平台实战开发:Electron 文件系统操作实战
前端·javascript·electron·openharmony