门户修改静态文字

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

相关推荐
Ares-Wang15 分钟前
Vue2 》》Vue3》》 Render函数 h
javascript
葡萄城技术团队27 分钟前
SpreadJS 纯前端表格控件:破解中国式复杂报表技术文档
前端
Humbunklung28 分钟前
C# 压缩解压文件的常用方法
前端·c#·压缩解压
通往曙光的路上33 分钟前
时隔一天第二阶段他来了 html!!!!!!!!!!!
前端·html
爱吃甜品的糯米团子1 小时前
CSS图片背景属性
前端·css
雮尘1 小时前
一文读懂Android Fragment栈管理
android·前端
Aoda1 小时前
浏览器字体设置引发的Bug:从一次调查到前端字体策略的深度思考
前端·css
朝与暮1 小时前
《javascript进阶-类(class):构造函数的语法糖》
前端·javascript
入秋1 小时前
Three.js 实战之电子围栏可根据模型自动生成
前端·前端框架·three.js
用户6120414922131 小时前
jsp+servlet做的咖啡品牌管理后台
java·前端·后端