api_cache.hbs
4.82 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
<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>缓存管理</li>
</ul>
<h4>Api缓存清理</h4>
</div>
</div>
<!-- media -->
</div>
<!-- pageheader -->
<div class="contentpanel">
<div class="row">
<div class="col-sm-4 col-md-3">
<div>
<button class="btn btn-danger" id="flush-btn">Flush All</button>
</div>
<h4 class="md-title mb5">memcached列表</h4>
<div class="host-list">
{{#each hosts}}
<p><span>{{host}}</span><span class="fa fa-times pull-right host-remove" style="color: red; cursor: pointer;" data-id="{{_id}}" data-host="{{host}}"></span></p>
{{/each}}
</div>
<div class="mb20"></div>
<div>
<button class="btn btn-success" id="add-btn">添加</button>
</div>
<br>
</div><!-- col-sm-4 -->
<div class="col-sm-8 col-md-9">
<div class="panel">
<div class="panel-heading">
<div class="pull-right">
<a class="btn btn-success btn-rounded mr20 api-clean-btn">删除缓存</a>
</div>
<div class="panel-title">
缓存key前缀:
<input type="text" style="width: 33%; height: 40px;" id="api-key">
</div>
</div><!-- panel-heading -->
<div class="panel-body yoho-log-dark">
<div class="results-list" id="api-cache-log">
</div><!-- results-list -->
</div><!-- panel-body -->
</div><!-- panel -->
</div><!-- col-sm-8 -->
</div><!-- row -->
</div>
<script>
$(document).on('ready pjax:success', function() {
$('#add-btn').click(function(){
var i = layer.prompt({
title: '请输入host,例如 127.0.0.1:11211'
}, function(host) {
$.post('/api_cache/host/add', {host: host}, function(ret) {
if (ret.code == 200) {
$('.host-list').append('<p>' + host + '</p>');
layer.close(i);
}
});
});
});
$('.api-clean-btn').click(function() {
var key = $('#api-key').val();
if (key) {
$.post('/api_cache/clean', {key: key}, function(ret) {
if (ret.code == 200) {
layer.msg('正在清理中');
}
});
} else {
layer.msg('请输入key');
}
});
$('.host-remove').click(function(){
var id = $(this).data('id');
var host = $(this).data('host');
var parent = $(this).parent();
var i = layer.confirm('确定删除host:<code>' + host + '</code>吗?', {
btn: ['确定', '取消']
}, function() {
$.post('/api_cache/host/del', {id: id}, function(ret) {
if (ret.code === 200) {
$(parent).remove();
layer.close(i);
}
});
});
});
$('#flush-btn').click(function(){
var i = layer.confirm('确定清楚所有缓存吗?', {
btn: ['确定', '取消']
}, function() {
$.post('/api_cache/flush', function(ret) {
if (ret.code === 200) {
layer.close(i);
}
});
});
});
function layoutResize() {
$('.yoho-log-dark').height($('body').height() - 340);
}
$(window).resize(function() {
layoutResize();
});
layoutResize();
var $logWrap = $('.yoho-log-dark');
var timer = 0;
var ws = io();
ws.on('connect', function() {
ws.on('/api_cache/log', function(data) {
$('#api-cache-log').append('<p><span class="host">'+data.host+'</span><span class="message">'+data.msg+'</span></p>');
if (timer == 0) {
timer = setTimeout(function(){
$logWrap.scrollTop($logWrap[0].scrollHeight);
timer = 0;
}, 1000);
}
});
});
ws.on('error', function() {
console.log('connect fail');
});
});
</script>