Authored by yyq

Merge branch 'feature/keywords' of git.yoho.cn:OPENTECH/yoho-node-ci into feature/keywords

... ... @@ -17,10 +17,6 @@ client.on("error", function (err) {
console.log("Error " + err);
});
const {
OperationLogger
} = require('../../models');
const r = new Router();
const multiAsync=()=>{
... ... @@ -34,8 +30,11 @@ const multiAsync=()=>{
}
//查看
const getDataList = async(key)=>{
multi.lrange("keywords_mana_list", 0, -1);
const getDataList = async(key, page)=>{
let start = (page-1)*10;
let end = (page)*10-1;
multi.lrange(key, start, end);
multi.LLEN(key);
return multiAsync();
}
... ... @@ -58,12 +57,13 @@ const delDataValues = async(arr)=>{
const addDataValues = async(value)=>{
let key=`keywords_mana:${value}`;
multi.set(key, value);
multi.lrem('keywords_mana_list', 1, key);
multi.lpush('keywords_mana_list', key);
return multiAsync();
}
//编辑
const editDataValues = async(value, oldValue)=>{console.log(value, oldValue);
const editDataValues = async(value, oldValue)=>{
try{
await delDataValues([oldValue]);
await addDataValues(value);
... ... @@ -73,6 +73,12 @@ const editDataValues = async(value, oldValue)=>{console.log(value, oldValue);
}
}
//搜索
const searchDataValues = async(value)=>{
let key=`keywords_mana:*${value}*`;
multi.KEYS(key);
return multiAsync();
}
r.get('/', async(ctx) => {
await ctx.render('action/keywords');
... ... @@ -80,12 +86,14 @@ r.get('/', async(ctx) => {
r.get('/getKeywords', async(ctx) => {
let q = ctx.request.query;
let r = await getDataList("keywords_mana_list");console.log(r);
let result = await getDataValues(r);
let r = await getDataList("keywords_mana_list", q.currentPage, q.pageCount);
let result = [];
if(r[0].length)result = await getDataValues(r[0]);
ctx.body = {
code: 200,
message: 'success',
data: result
data: result,
total:r[1]
};
});
... ... @@ -145,4 +153,18 @@ r.get('/editKeywords', async(ctx) => {
};
}
});
r.get('/searchKeywords', async(ctx) => {
let q = ctx.request.query;
let key = q['association'];
let r = await searchDataValues(key);
let result = [];
if(r[0].length)result = await getDataValues(r[0]);
ctx.body = {
code: 200,
message: 'success',
data: result,
total:1
};
});
module.exports = r;
... ...
... ... @@ -17,9 +17,13 @@
<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 type="checkbox" style="margin-right:5px;">全选</label>
<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>
<button class="btn btn-default" type="submit">删除</button>
<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>
... ... @@ -41,17 +45,15 @@
<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>
</table>
</div>
</div>
</div>
<ul class="pager">
<li><a class="privious pages">上一页</a></li>
<li><a class="next pages">下一页</a></li>
</ul>
<style>
.nostyle{
background: transparent;
... ... @@ -74,21 +76,62 @@
bottom: 0;
margin:auto;
}
.pager{
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', function(data){
$.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);
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+='<tr><td><label><input type="checkbox">'+index+'</label></td><td><input value="'+item+'" disabled></td><td><button class="btn btn-default nostyle edit">编辑</button><button class="btn btn-default nostyle delete">删除</button></td></tr>';
html+=tableHtml(item, index);
});
$('#table-oper-log').html($('#table-oper-log').html()+html);
$('#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');
... ... @@ -108,7 +151,14 @@
var val=input.val();
$.get('/keywords/editKeywords', {keywords:JSON.stringify([val, oldValue])}, function(data){
if(data.code===200){
input.attr('disabled',true);
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);
}
});
});
... ... @@ -122,4 +172,42 @@
}
});
});
//全选
$('#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);
pageTotal=Math.ceil(data.total/pageCount);
}
});
});
</script>
\ No newline at end of file
... ...