Authored by 毕凯

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

... ... @@ -4,33 +4,50 @@
// SecretKey: 'Mhuw11qY5KPK5fBYxDHAsQnzzpU4Xqzx',
// serviceType: 'logset'
// });
const _ = require('lodash');
const moment = require('moment');
const rp = require('request-promise');
const Model = require('./model');
const qcloud = require('../../lib/qcloud');
let _convert = res => {
res = JSON.parse(res);
let message;
_.each(res.results, (item, idx) => {
message = JSON.parse(JSON.parse(item.content)['__CONTENT__'].message);
res.results[idx].message = message.message;
res.results[idx].level = message.level;
// res.results[idx].t = moment(message.timestamp).format('YYYY-MM-DD HH:mm:ss');
delete res.results[idx].content;
});
return res;
};
class Logs extends Model {
constructor() {
super('logs');
}
async init(query = 'yoho') {
const result = await rp(qcloud.sign({
async init({query = '', limit = 10}) {
const res = await rp(qcloud.sign({
method: 'get',
baseUrl: 'http://ap-beijing.cls.myqcloud.com',
uri: '/searchlog',
qs: {
logset_id: '3a292186-9241-4d2c-98de-a13896ed7b25',
topic_ids: '3cb90ed6-0f92-40cb-b064-42f36d13b11a',
start_time: moment(Date.now() - 3600 * 1000).format('YYYY-MM-DD HH:mm:ss'),
start_time: moment(Date.now() - 3600 * 1000 * 48).format('YYYY-MM-DD HH:mm:ss'),
end_time: moment().format('YYYY-MM-DD HH:mm:ss'),
query,
limit: '10'
limit
},
headers: {}
}))
return result
}, {query, limit}));
return _convert(res)
}
}
... ...
... ... @@ -6,7 +6,7 @@ const r = new Router;
const logs = {
async query(ctx) {
let logs = await Logs.init();
let logs = await Logs.init(ctx.query);
ctx.body = logs
}
... ...
... ... @@ -76,6 +76,7 @@
},
"devDependencies": {
"ada": "^0.2.7",
"axios": "^0.18.0",
"iview": "^2.13.0",
"nodemon": "^1.11.0",
"vue": "^2.5.16",
... ...
import LogService from './log-service';
export {
LogService
};
... ...
import Service from '../service';
let apiUrl = {
query: '/logs/query'
};
class Logs extends Service {
getLogs(params) {
return this.get(apiUrl.query, {params});
}
}
export default Logs;
... ...
import axios from 'axios';
class Service {
get(url, options) {
return axios.get(url, options).then(res => {
if (res.status === 200) {
return res.data;
}
return {};
});
}
post(url, data) {
return axios.post(url, data).then(res => {
if (res.status === 200) {
return res.data;
}
return {};
});
}
}
export default Service;
... ...
<template>
<div>
Node logs
<div class="filter">
<Input v-model="value" placeholder="日志集" style="width: 300px"></Input>
<Input v-model="value" placeholder="日志主题" style="width: 300px"></Input>
<Input v-model="value" placeholder="检索关键词多个以空格分隔" style="width: 300px"></Input>
<Select v-model="model1" style="width:200px">
<Option v-for="item in cityList" :value="item.value" :key="item.value">{{ item.label }}</Option>
</Select>
</div>
<Table highlight-row ref="currentRowTable" :columns="columns" :data="logs"></Table>
</div>
</template>
<script>
import {LogService} from '../../js/services/logs';
export default {
data() {
return {
columns: [
{
title: 'topic_name',
key: 'topic_name'
},
{
title: 'topic_id',
key: 'topic_id'
},
{
title: '级别',
key: 'level'
},
{
title: '内容',
key: 'message'
},
{
title: '时间',
key: 'timestamp'
}
],
logs: []
}
},
methods: {
searchLog() {
this.logService.getLogs({limit: 20}).then(res => {
this.logs = res.results;
});
}
},
created() {
this.logService = new LogService();
this.searchLog();
}
}
</script>
\ No newline at end of file
</script>
... ...