ssr_degrade_edit.hbs
4.8 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
{{#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="/ssr_degrade/index">SSR自适应降级</a></li>
<li>编辑配置</li>
</ul>
<h4>编辑配置</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">
<input type="text" class="form-control" id="app" placeholder="应用名称" value="{{app}}" {{#if app}}readonly{{/if}}>
</div>
</div>
<div class="form-group">
<label for="router" class="col-sm-2 control-label text-center">降级条件:</label>
<div class="col-sm-10">
<div id="degrades">
{{#degrades}}
<div class="form-inline degrade" style="margin-top: 10px;">
<input type="text" class="form-control data-time" style="width: 50px" placeholder="" value="{{time}}">秒内平均qps大于
<input type="text" class="form-control data-tick" style="width: 50px" placeholder="" value="{{tick}}">,
<input type="text" class="form-control data-delay" style="width: 50px" placeholder="" value="{{delay}}">分钟内未触发则恢复
<a href="javascript:;" class="delete">删除</a>
</div>
{{/degrades}}
</div>
<div style="padding-top: 20px;">
<a href="javascript:;" id="add" class="">新增</a>
</div>
</div>
</div>
<div class="row">
<label class="col-sm-2"></label>
<div class="col-sm-10">
<button type="button" class="btn btn-success save">保存</button>
<button type="button" class="btn btn-default cancel">取消</button>
</div>
</div>
</div>
<div style="display: none;" id="template">
<div class="form-inline degrade" style="margin-top: 10px;">
<input type="text" class="form-control data-time" style="width: 50px" placeholder="秒" value="">秒内平均qps大于
<input type="text" class="form-control data-tick" style="width: 50px" placeholder="qps" value="">,
<input type="text" class="form-control data-delay" style="width: 50px" placeholder="qps" value="">分钟内未触发则恢复
<a href="javascript:;" class="delete">删除</a>
</div>
</div>
{{/data}}
<script>
let $app = $('#app'),
$router = $('#router'),
$interval = $('#interval'),
$requests = $('#requests');
function getData() {
const app = $('#app').val();
if (!app) {
alert('请输入应用名称');
return false;
}
const $degrades = $('#degrades').find('.degrade');
const data = $degrades.map((index, el) => {
const $el = $(el);
const time = +$el.find('.data-time').val();
const tick = +$el.find('.data-tick').val();
const delay = +$el.find('.data-delay').val();
return {
time,
tick,
delay
};
}).toArray();
let valid = true;
data.forEach(degrade => {
if (!degrade.time || !Number.isInteger(+degrade.time)) {
alert('请输入时间!');
valid = false;
return false;
}
if (!degrade.tick || !Number.isInteger(+degrade.tick)) {
alert('请输入qps!');
valid = false;
return false;
}
if (!degrade.delay || !Number.isInteger(+degrade.delay)) {
alert('请输入恢复时间!');
valid = false;
return false;
}
});
if (!valid) {
return false;
}
return {
app,
degrades: data
};
}
$('#add').on('click', function() {
var template = $('#template').html();
var $degrade = $(template);
$degrade.find('.delete').on('click', function () {
$(this).parent().remove();
});
$('#degrades').append($degrade);
});
$('.delete').on('click', function() {
$(this).parent().remove();
});
$('.save').on('click', function() {
const data = getData();
if (!data) {
return;
}
$.post('/ssr_degrade/edit', data, function(ret) {
if (ret.code === 200) {
alert('添加成功!');
location.href = '/ssr_degrade/index';
} else {
alert('添加失败!');
}
});
});
$('.cancel').on('click', function() {
location.href = '/ssr_degrade/index';
});
</script>