Authored by shijian

save

/**
*
* @author: jiangfeng<jeff.jiang@yoho.cn>
* @date: 16/8/22
* @author: shijian<jian.shi@yoho.cn>
* @date: 17/5/31
*/
'use strict';
const Router = require('koa-router');
const moment = require('moment');
const redisStore = require('koa-redis');
const redis = require("redis");
const client = redis.createClient();
const multi = client.multi();
client.on("error", function (err) {
console.log("Error " + err);
});
const {
OperationLogger
... ... @@ -15,46 +23,46 @@ const {
const r = new Router();
r.get('/', async(ctx) => {
await ctx.render('action/keywords');
});
// r.post('/log/query', async(ctx) => {
const setData = ()=>{
client.set('keywords_mana:aaa', 'aaa');
client.set('keywords_mana:bbb', 'bbb');
let arr = ['keywords_mana:aaa', 'keywords_mana:bbb'];
// let q = ctx.request.body;
for (var i=0; i<arr.length; i++) {
multi.sadd('keywords_mana_list', arr[i]);
}
// let start = parseInt(q.start || 0, 10);
// let length = parseInt(q.length || 10, 10);
// let draw = parseInt(q.draw, 10);
multi.exec(function(errors, results) {
// let sort = {time: -1};
// if (q.order && q.order.length > 0) {
// let col = q.order[0].column;
// let dir = q.order[0].dir === 'desc' ? -1 : 1;
});
}
// col = parseInt(col, 10);
// if (q.columns && q.columns.length > col) {
// sort = {};
// sort[q.columns[col].data] = dir;
// }
// }
const getData = async(key)=>{
multi.smembers(key);
return new Promise(function (resolve, reject) {
multi.exec(function(errors, results) {
resolve(results);
});
});
}
// let logs = await OperationLogger.cfind({}).sort(sort).skip(start).limit(length).exec();
// let total = await OperationLogger.count();
r.get('/', async(ctx) => {
await ctx.render('action/keywords');
});
// logs.forEach(l => {
// l.username = l.user.username;
// l.time = moment(l.time).format('YYYY-MM-DD HH:mm:ss.sss');
// l.meta = JSON.stringify(l.meta || {});
// });
r.get('/getKeywords', async(ctx) => {
// ctx.body = {
// draw: draw,
// recordsTotal: total,
// recordsFiltered: total,
// data: logs
// };
let q = ctx.request.query;
let r = await getData("keywords_mana_list");
ctx.body = {
code: 200,
message: 'success',
data: r[0]
};
// });
});
module.exports = r;
... ...
... ... @@ -14,41 +14,25 @@
<!-- media -->
</div>
<div class="contentpanel project-index-page">
<div class="contentpanel project-index-page" style="padding-bottom: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>操作用户</th>
<th>时间</th>
<th>动作</th>
<th>描述</th>
<th>数据</th>
</tr>
</thead>
</table>
<label style="margin-right:20px;"><input type="checkbox" style="margin-right:5px;">全选</label>
<button class="btn btn-default" type="submit" style="margin-right:10px;">增加</button>
<button class="btn btn-default" type="submit">删除</button>
</div>
</div>
</div>
<div class="contentpanel project-index-page">
<div class="contentpanel project-index-page" style="padding-top:0;">
<div class="panel panel-default">
<div class="panel-heading">
<div class="pull-right">
<a href="" class="tooltips panel-minimize"><i class="fa fa-minus"></i></a>
</div>
<h4 class="panel-title">操作日志</h4>
</div>
<div class="panel-body">
<table id="table-oper-log" class="table table-striped table-bordered building-table">
<thead>
<tr>
<th>操作用户</th>
<th>时间</th>
<th>动作</th>
<th>描述</th>
<th>数据</th>
<th>ID</th>
<th>关键词</th>
<th>操作</th>
</tr>
</thead>
</table>
... ... @@ -59,24 +43,30 @@
<script>
$(document).on('ready pjax:success', function() {
$("#table-oper-log").DataTable({
/**$("#table-oper-log").DataTable({
pageLength: 25,
retrieve: true,
responsive: true,
processing: true,
serverSide: true,
ajax: {
url: '/operation/log/query',
type: "POST"
url: '/keywords/getKeywords',
type: "GET"
},
columns: [
{data: "username"},
{data: "time"},
{data: "action"},
{data: "description"},
{data: "meta"}
{data: "datas"},
{data: "datas"},
{data: "datas"}
],
order: [[1, 'desc']]
});**/
$.get('/keywords/getKeywords', function(data){console.log(data);
var html='';
let datas=data.data;
datas.forEach(function(item, index){
html+='<tr><td>'+index+'</td><td>'+item+'</td><td><button class="btn btn-default" type="submit">编辑</button><button class="btn btn-default" type="submit">删除</button></td></tr>';
});
$('#table-oper-log').html($('#table-oper-log').html()+html);
});
});
</script>
\ No newline at end of file
... ...
This diff could not be displayed because it is too large.
... ... @@ -39,6 +39,7 @@
"koa-body": "^1.4.0",
"koa-convert": "^1.2.0",
"koa-mount": "^2.0.0",
"koa-redis": "^3.0.0",
"koa-router": "^7.0.1",
"koa-session": "^3.3.1",
"koa-static": "^3.0.0",
... ... @@ -57,6 +58,7 @@
"qcloudapi-sdk": "^0.1.5",
"qn": "^1.3.0",
"qs": "^6.2.0",
"redis": "^2.7.1",
"request-promise": "^4.1.1",
"shelljs": "^0.7.0",
"socket.io": "^1.4.6",
... ... @@ -64,4 +66,4 @@
"tar": "^2.2.1",
"utility": "^1.8.0"
}
}
}
\ No newline at end of file
... ...