门户修改静态文字

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()

相关推荐
阿珊和她的猫2 分钟前
React Hooks:革新组件开发的优势与实践
前端·react.js·状态模式
全栈技术负责人3 分钟前
AI时代前端工程师的转型之路
前端·人工智能
花归去21 分钟前
echarts 柱状图曲线图
开发语言·前端·javascript
喝拿铁写前端21 分钟前
当 AI 会写代码之后,我们应该怎么“管”它?
前端·人工智能
老前端的功夫24 分钟前
TypeScript 类型魔术:模板字面量类型的深层解密与工程实践
前端·javascript·ubuntu·架构·typescript·前端框架
Nan_Shu_6141 小时前
学习: Threejs (2)
前端·javascript·学习
G_G#1 小时前
纯前端js插件实现同一浏览器控制只允许打开一个标签,处理session变更问题
前端·javascript·浏览器标签页通信·只允许一个标签页
@大迁世界1 小时前
TypeScript 的本质并非类型,而是信任
开发语言·前端·javascript·typescript·ecmascript
GIS之路1 小时前
GDAL 实现矢量裁剪
前端·python·信息可视化
是一个Bug1 小时前
后端开发者视角的前端开发面试题清单(50道)
前端