keywords.hbs
7.92 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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
<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="/keywords">关键词管理</a></li>
</ul>
<h4>关键词管理</h4>
</div>
</div>
<!-- media -->
</div>
<div class="contentpanel project-index-page" style="padding-bottom:0;">
<div class="panel panel-default">
<div class="panel-body">
<label style="margin-right:20px;"><input id="allSelected" type="checkbox" style="margin-right:5px;">全选</label>
<a data-toggle="modal" href="#pop" class="btn btn-default" style="margin-right:10px;">增加</a>
<a class="btn btn-default deleteAll">删除</a>
<button class="btn btn-default search" style="float:right;">搜索</button>
<div class="col-sm-3" style="float:right;">
<input type="text" class="form-control" id="firstname" placeholder="请输入关键词">
</div>
</div>
</div>
</div>
<div id="pop" class="modal fade in" style="display: none; ">
<div class="modal-header">
<a class="close" data-dismiss="modal">×</a>
<h3>添加关键词</h3>
</div>
<div class="modal-body">
<input type="text" style="height:50px;width:400px;" id="addDatas">
</div>
<div class="modal-footer">
<a class="btn btn-success addKeywords">确定</a>
</div>
</div>
<div class="contentpanel project-index-page" style="padding-top:0;">
<div class="panel panel-default">
<div class="panel-body">
<table id="table-oper-log" class="table table-striped table-bordered building-table">
<thead><tr><th>ID</th><th>关键词</th><th>操作</th></tr></thead>
{{# tabs}}
<tr><td><label><input type="checkbox">{{@index}}</label></td><td><input class="values" value="{{.}}" disabled></td><td><button class="btn btn-default nostyle edit">编辑</button><button class="btn btn-default nostyle delete">删除</button></td></tr>
{{/ tabs}}
</table>
</div>
</div>
</div>
{{# pager}}
<div class="text-right">
<ul class="pagination">
{{# prePage}}
<li><a href="{{url}}">上一页</a></li>
{{/ prePage}}
{{# pages}}
<li class="{{#unless url}}disabled {{/unless}}{{#if cur}}active{{/if}}"><a {{#if url}}href="{{url}}"{{^}}href="javascript:;"{{/if}}>{{num}}</a></li>
{{/ pages}}
{{# nextPage}}
<li><a href="{{url}}">下一页</a></li>
{{/ nextPage}}
</ul>
</div>
{{/ pager}}
<style>
.nostyle{
background: transparent;
}
input[type=checkbox]{
vertical-align: sub;
margin-right: 5px;
}
input[disabled]{
background: transparent;
border: none;
}
#pop{
width:500px;
height:250px;
background: #fff;
left: 0;
right: 0;
top: 0;
bottom: 0;
margin:auto;
}
.text-right{
float: right;
margin-right: 20px;
margin-top:0;
}
.pages{
cursor: pointer;
}
</style>
<script>
var currentPage=1,pageCount=10,pageTotal;
var tabHead='<thead><tr><th>ID</th><th>关键词</th><th>操作</th></tr></thead>';
//展示列表
/**$(document).on('ready pjax:success', function() {
$.get('/keywords/getKeywords', {page:currentPage, limit:pageCount}, function(data){
var html='';
let datas=data.data;
if(datas){
datas.forEach(function(item, index){
html+=tableHtml(item, index);
});
$('#table-oper-log').html(tabHead+html);
pageTotal=Math.ceil(data.total/pageCount);
}
});
});
$('.privious').on('click', function() {
if(currentPage==1)return;
$.get('/keywords/getKeywords?',{currentPage:--currentPage, pageCount:pageCount}, function(data){
var html='';
let datas=data.data;
if(datas){
datas.forEach(function(item, index){
html+=tableHtml(item, index);
});
$('#table-oper-log').html(tabHead+html);
}
});
});
$('.next').on('click', function() {
if(currentPage>=pageTotal)return;
$.get('/keywords/getKeywords?',{currentPage:++currentPage, pageCount:pageCount}, function(data){
var html='';
let datas=data.data;
if(datas){
datas.forEach(function(item, index){
html+=tableHtml(item, index);
});
$('#table-oper-log').html(tabHead+html);
}
});
});**/
//删除
$(document).on('click', '.delete', function(){
var val=$($(this).parents('tr').find('input')[1]).val();
var parent=$(this).parents('tr');
$.get('/keywords/delKeywords', {keywords:JSON.stringify([val])}, function(data){
if(data.code===200){
parent.replaceWith('');
}
});
});
//编辑
$(document).on('click', '.edit', function(){
let input=$($(this).parents('tr').find('input')[1]);
input.attr('disabled',false);
let oldValue=input.val();
input.attr('oldValue',oldValue);
input.on('blur', function(){
var val=input.val();
$.get('/keywords/editKeywords', {keywords:JSON.stringify([val, oldValue])}, function(data){
if(data.code===200){
var isSame=false;
$('table .values').each(function(){
if($(this)!=input){
if($(this).val()==input.val())isSame=true;
}
});
if(isSame) location.reload();
else input.attr('disabled',true);
}
});
});
});
//添加
$(document).on('click', '.addKeywords', function(){
var val=$('#addDatas').val();
$.get('/keywords/addKeywords', {keywords:val}, function(data){
if(data.code===200){
location.reload();
}
});
});
//全选
$('#allSelected').on('click', function(){
var check=false;
if($(this).attr('checked')){
check=true;
}
$("table :checkbox").attr("checked", check);
});
$('.deleteAll').on('click',function(){
let arr=[];
$("table :checkbox:checked").each(function(item){
arr.push($($(this).parents('tr').find('input')[1]).val());
});
if(!arr.length)return;
$.get('/keywords/delKeywords', {keywords:JSON.stringify(arr)}, function(data){
if(data.code===200){
location.reload();
}
});
});
function tableHtml(item, index){
return '<tr><td><label><input type="checkbox">'+index+'</label></td><td><input class="values" value="'+item+'" disabled></td><td><button class="btn btn-default nostyle edit">编辑</button><button class="btn btn-default nostyle delete">删除</button></td></tr>';
}
//搜索
$('.search').on('click',function(){
if(!$('#firstname').val())return;
$.get('/keywords/searchKeywords', {association:$('#firstname').val()}, function(data){
var html='';
let datas=data.data;
if(data.code===200){
datas.forEach(function(item, index){
html+=tableHtml(item, index);
});
$('#table-oper-log').html(tabHead+html);
$('.text-right').hide();
}
});
});
</script>