add_risk.hbs 5.34 KB
{{#data}}
<div class="pageheader">
    <div class="media">
        <div class="pageicon pull-left">
            <i class="fa fa-th-list"></i>
        </div>
        <div class="media-body">
            <ul class="breadcrumb">
                <li><a href="/"><i class="glyphicon glyphicon-home"></i></a></li>
                <li><a href="/risk_management/risk_management">风险控制</a></li>
                <li>{{#if route}}编辑配置{{else}}新增配置{{/if}}</li>
            </ul>
            <h4>{{#if route}}编辑配置{{else}}新增配置{{/if}}</h4>
        </div>
    </div>
    <!-- media -->
</div>
<!-- pageheader -->

<div class="contentpanel servers-page form-horizontal"> 
    <div class="form-group">
        <label for="app" class="col-sm-2 control-label text-center">应用名称:</label>
        <div class="col-sm-6">
            <select class="form-control" style="height: 40px; line-height: 40px;" id="app">
                {{#each ../apps}}
                    <option value="{{name}}" data-app="{{app}}" {{#if selected}}selected{{/if}}>{{name}}</option>
                {{/each}}
            </select>
        </div>
    </div>
    <div class="form-group">
        <label for="router" class="col-sm-2 control-label text-center">路由路径:</label>
        <div class="col-sm-6">
            <input type="text" class="form-control" id="router" placeholder="请输入路由路径" value="{{route}}">
        </div>
    </div>
    <div class="form-group">
        <label for="exampleFormControlInput1" class="col-sm-2 control-label text-center">时间间隔:</label>
        <div class="col-sm-6">
            <input type="text" class="form-control" id="interval" placeholder="请输入时间间隔" value="{{interval}}">
        </div>
        <div class="col-sm-2" style="line-height: 40px;"></div>
    </div>
    <div class="form-group">
        <label for="exampleFormControlInput1" class="col-sm-2 control-label text-center">请求次数:</label>
        <div class="col-sm-6">
            <input type="text" class="form-control" id="requests" placeholder="请输入请求次数" value="{{requests}}">
        </div>
        <div class="col-sm-2" style="line-height: 40px;"></div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label text-center">状  态:</label>
        <div class="col-sm-10">
            <label class="radio-inline">
                <input type="radio" name="status" id="status-on" value="on" {{#unless state}}checked{{/unless}}>开启
            </label>
            <label class="radio-inline">
                <input type="radio" name="status" id="status-off" value="off"{{#if state}}checked{{/if}}>关闭
            </label>
        </div>
    </div>
    <div class="row">
        <label class="col-sm-2"></label>
        <div class="col-sm-10">
            {{#if route}}
                <button type="button" class="btn btn-success edit">保存</button>
            {{else}}
                <button type="button" class="btn btn-success save">保存</button>
            {{/if}}            
            <button type="button" class="btn btn-default cancel">取消</button>
        </div>
    </div>
</div>
{{/data}}
<script>
    let $app = $('#app'),
        $router = $('#router'),
        $interval = $('#interval'),
        $requests = $('#requests');

    function check() {
        if ($.trim($router.val()) === '') {
            alert('请输入路由路径!');
            return true;
        }

        if ($.trim($interval.val()) === '') {
            alert('请输入时间间隔!');
            return true;
        }

        if (isNaN($interval.val())) {
            alert('时间间隔必须为数字!');
            return true;
        }

        if ($.trim($requests.val()) === '') {
            alert('请输入请求次数!');
            return true;
        }

        if (isNaN($requests.val())) {
            alert('请求次数必须为数字!');
            return true;
        }
    }
    $('.save').on('click', function() {
        if (check()) {
            return;
        }

        $.post('/risk_management/setter', {
            app: $app.val(),
            route: $router.val(),
            interval: $interval.val(),
            requests: $requests.val(),
            state: $('input[type=radio]:checked').val()
        }, function(ret) {
            if (ret.code === 200) {
                alert('添加成功!');
                location.href = '/risk_management/risk_management';
            } else {
                alert('添加失败!');
            }
        });
    });

    $('.edit').on('click', function() {
        if (check()) {
            return;
        }

        $.post('/risk_management/edit', {
            param: {
                app: $app.val(),
                route: $router.val(),
                interval: $interval.val(),
                requests: $requests.val(),
                state: $('input[type=radio]:checked').val()
            },
            edit: location.href.split('?')[1]
        }, function(ret) {
            if (ret.code === 200) {
                alert('编辑成功!');
                location.href = '/risk_management/risk_management';
            } else {
                alert('编辑失败!');
            }
        });
    });

    $('.cancel').on('click', function() {
        location.href = '/risk_management/risk_management';
    });
    </script>