• 项目Js源码整合


    整合一下目前做的项目中JS中用到的相关源码等,留待记录和使用。

    一、ajaxgrid源码部分


    1、初始化


    2、查询

    var code = $('#city option:selected').val();//Jquery获取选中的值  
    var radius = $('#radius option:selected').val();//Jquery获取选中的值
    

    3、删除

    ①:

        function deleteData(obj) {
            //获取当前行对象
            var row = ajaxgrid.getEventRecord(obj);
            //根据row获取当前行的相关数据
            var province = row.data.province;
            var year = row.data.year;
            var stage = row.data.stage;
            //向后台action发起request请求
            $.request({
                action:"delete",
                //附加参数传递方法:params中传递附加的参数
                params:{'uuid':row.data.uuid},
                success:onsavecomplete
            }) ;
        }
    
        function onsavecomplete(response){
            setRM('success', response.getMessage(), retrieve());
        }

    4、保存

    5、根据id获取值,时间值等

    JSP:

    <td align="center" width="80">月报年份</td>
    <td>
    <hy:date width="100px" id="yearId" editor="year" name="year" upload="true" startyear="2018" endyear="${test}"/></td>
    <td align="center" width="80">月份</td>
    <td>
    <hy:drop width="100px" id="stageId" list="stageList" listKey="value" listValue="label" name="stage" upload="true" />
    </td>

    JS:根据日期id获取日期的相关数据

    function checkIsHave() {
            var year = yearId.getValue();
            var stage = stageId.getSelectedValue();
            if (year == null || year == "") {
                setRM('error', "请选择年份!");
                return false;
            }
            if (stage == null || stage == "") {
                setRM('error', "请选择期数!");
                return false;
            }
            $.request({
                action:"checkIsHave",
                params:{'yearStr':year, 'stageStr':stage},
                success:function (response) {
                    var isHave = response.getParameter("isHave");
                    var nohave=response.getParameter("message");
                    if (nohave) {
                        alert("尚未报送该月数据,无法生成月报")
                        }else{
                    if (isHave) {
                        $.confirm("提示", "已经生成过本月月报是否要重新生成?", function() {
                            createMonthReport();
                        }, function() {
                        });
                    } else {
                        createMonthReport();
                    }
                        }
                }
            }) ;
        }

    6、详情、跳转链接 : a 标签

    JSP:

    <hy:gridcustom title="操作" width="200" customstylefunc="setLink()">                  
        <!-- <a href="javascript:void(0)" onclick="edit(this)">详情</a>&nbsp;     
        <a href="javascript:void(0)" id="rid" onclick="rid(this)" >解除注销</a>&nbsp;  -->      
    </hy:gridcustom>

    JS方法:

    function setLink(record){
        var htmlstr="";
        var status = record.get("busStatus");
        if (status == "2") {
            htmlstr += "<a href="javascript:void(0)" onclick="edit(this)">详情</a>&nbsp";
            htmlstr += "<a href="javascript:void(0)" onclick="rid(this)">解除注销</a>";     
        }else{
            htmlstr += "<a href="javascript:void(0)" onclick="edit(this)">详情</a>";
        }
        return htmlstr;
    }




    二、ajaxform源码部分

    1、获取ajaxform中的某个对象

    var city = ajaxform.getColumnValue("city");
    
    var jtyktVal = response.getParameter("jtykt");
    ajaxform.setValue("jtykt",jtyktVal);


    三、源码片段

    1、界面取值、赋值计算等

    function lineDrop1(){
            var code = $('#city option:selected').val();//Jquery获取选中的值
            var lineDrop1 = $('#lineDrop1 option:selected').val();
            var upMiler1 = $('input[name=upMiler][type=text]');
            var downMiler1 = $('input[name=downMiler][type=text]');
            var upDownMiler1 = $('input[name=upDownMiler][type=text]');
            $.post('/gj/gj/application/gjOnlineApplication.do?action=getBusLineUp',{'lineDrop1':lineDrop1,'code':code},function(result){
                upMiler1.val((Number(result.BusLineUp)/1000).toFixed(2));
                downMiler1.val((Number(result.BusLineDown)/1000).toFixed(2));
                upDownMiler1.val((Number(upMiler1.val())+Number(downMiler1.val())).toFixed(2));
                $('input[name=yyxlcd][type=text]').val(((Number(upMiler1.val())+Number(downMiler1.val())+Number(upDownMiler1.val()))/2).toFixed(2));
        })
    }

    2、级联下拉部分

    JSP:

    <td align="center" width="80">城市</td>
    <td>
        <hy:drop width="103px" list="cityList" listKey="value" listValue="label"
            name="city" upload="true" nullable="false" id="cityId" onchange="refreshDrop()"/>
    </td>
    <td align="center" width="80">企业</td>
    <td>
        <hy:drop width="103px" id="unitDrop" list="unitWorkList" listKey="value" listValue="label" listFilter="filter"  name="unit" upload="true" />
    </td>
    <td align="center" width="80">线路</td>
    <td>
        <hy:drop width="103px" id="lineDrop"  name="lineUuid" list="lineList" listKey="value" listValue="label" listFilter="filter" upload="true" ></hy:drop>
    </td>

    JS:级联下拉

    function refreshDrop() {
            var city = cityId.getSelectedValue();
            unitDrop.refreshByFilter(city);
            lineDrop.refreshByFilter(city);
        }

    3、0-100的数字校验,小数校验、整数校验

        function vaild3 (title,column) {
            var columnObj = ajaxform.getColumnComponent(column);
            //0——100的数字校验
            var patrn = /^(((d|[1-9]d)(.d{1,2})?)|100|100.0|100.00)$/;  
            //2为小数校验
            var patrn = /^(([0-9][0-9]*)|(([0].d{1,2}|[1-9][0-9]*.d{1,2})))$/;
            //正则整数校验
            var patrn = /^[0-9]*$/;
            var columnValue = ajaxform.getColumnValue(column);
            if (columnValue!=null && columnValue!="" && !patrn.test(columnValue)) {
                notPassMsg = title + ':只能输入0-100,小数点后两位的数字!';
                notPassArray[column]=notPassMsg;
                columnObj.css({"background-color":"#FDC8CC"});
                $.alert('提示信息', notPassMsg, function(){});
            } else {
                delete notPassArray[column];
                columnObj.css({"background-color":""});
            }
    
        }

    4、后台response,前台得到值

    Action:

        private String planBeginYear;
        private Long city;
        //添加set和get方法
    
        responseData.setParameter("planBeginYear", planBeginYear);
        responseData.setParameter("city", city);

    JS:

    var year = response.getParameter("planBeginYear");
    var city = response.getParameter("city");
  • 相关阅读:
    JAVA设计模式之单例模式
    JAVA设计模式之单例模式
    数据库连接池
    数据库连接池
    DbUtils操作数据库
    DbUtils操作数据库
    Hadoop 问题之 Linux服务器jps报process information unavailable
    echarts ——纵坐标赋值
    echarts ——div没有设置样式图表就展示不出来!
    Elasticsearch+spring boot(一)
  • 原文地址:https://www.cnblogs.com/aixing/p/13327534.html
Copyright © 2020-2023  润新知