add_risk.hbs
5.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
{{#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>