页面树结构
转至元数据结尾
转至元数据起始

问题描述:

仪盘表日期组件,禁止选择指定日期之前的所有日期,如下图所示:

解决方案:

通过宏代码的方式实现如下:

// 日期参数必须大于某个日期
// 对象:日期参数,事件onBeforRender
function main(page: IPage, portlet: IFilterPortlet) {
    portlet.setFilterValueChangeHandler(function (value: Array) {
        //获取参数的日期
        let c_date = new Date(value[0])
        // 设置比较日期
        const compare_date = new Date("2024-5-1")
        // 对比日期,如果小于2024-5-1,则将值设置未2024-5-1
        if (c_date < compare_date) { 
            alert("日期应大于2024-5-1")
            value[0]="2024-05-01"
           // console.log(c_date)
         }
        return value

    });
}


实现效果:

选择日期小于2034-5-1号的提示如下:

  • 无标签

评论

  1. 陈艳 发表:

    年月类型参考:

    function main(page: IPage, portlet: IFilterPortlet) {
    portlet.setFilterValueChangeHandler(function (value: Array) {
    debugger
    //获取参数的日期
    let c_date = new Date(value[0])
    // 设置比较日期
    const compare_date = new Date("2024-1-1")
    // 对比日期,如果小于2024-5-1,则将值设置未2024-5-1
    const result =compareYearMonth(c_date,compare_date)
    if (result===1) {
    alert("年月应大于2024-01")
    value[0]="2024-01"
    // console.log(c_date)
    }
    return value

    });
    }

    function compareYearMonth(date1:Date, date2:Date) {
    // 格式化为年份和月份
    const yearMonth1 = `${date1.getFullYear()}-${date1.getMonth() + 1}`;
    const yearMonth2 = `${date2.getFullYear()}-${date2.getMonth() + 1}`;
    // 比较字符串
    return yearMonth1 > yearMonth2 ? -1 : 1;
    }