一次尝试:用户自定义不同类型报表

1.创建插件
npm包管理:
npm install -g yo

npm install -g generator-kibana-plugin

mkdir echartdashboard-plugin

cd echartdashboard-plugin

yo kibana-plugin

 

2.测试插件步骤:
在插件目录下执行 npm install 安装相关的插件
创建一个名叫 kibana 的文件夹,将这个 echartdashboard-plugin 整个目录都拷贝到 kibana 目录下。(kibana/echartdashboard-plugin)
将这个kibana目录保存或压缩为一个zip文件
使用 kibana-plugins 的local方法安装这个zip文件


3.开发插件
index.jskibana的控制器在启动的时候,会逐个加载安装了的插件。插件是以对象(kibana.Plugin)的方式存在。这个对象是在index.js文件中定义的。其中:

app -> main 属性定义的是启动的js
app -> icon 属性定义的是侧边栏的图标
config属性,定义的是从 kinbana.yml 里面的属性和默认值(注意:在kibana.yml,参数必须放在plugins名字下面,比如这里是echart_dashboard)
init(server, options) ,是初始化函数,里面传入了server对象,这是kibana启动的http server (HAPI) 对象,在函数中,我设置了路由,即一开始就加载做好的vue + echart的dashboard。


import { resolve } from 'path';
import apiRoute from './server/routes/redirect';
import cacheData from './server/cache/cachedata'
export default function (kibana) {
return new kibana.Plugin({
require: ['elasticsearch'],

uiExports: {

app: {
title: '',
description: 'a independent dashboard based on echarts',
main: 'plugins/echart_dashboard/app.js',
icon: 'plugins/echart_dashboard/echarts.svg'
}
},

config(Joi) {
return Joi.object({
enabled: Joi.boolean().default(true),
interval: Joi.string().default( "now/w"),
index: Joi.string().default("app*")
}).default();
},


init(server, options) {
// Add server routes and initalize the plugin here
cacheData.setCacheData(server);
apiRoute(server);
}

});
};


4.redirect.js
/app/echart_dashboard, 这个path是plugin的访问目录,返回../plugins/echart_dashboard,,这里返回目录,其实是默认会返回该目录下的index.html文件,所有,public目录下必须有index.html文件
其他定义的路由,实际上就是通过rest接口提供dashboard的数据
import cacheData from "../cache/cachedata"
export default function (server) {
server.route({
path: '/app/echart_dashboard',
method: 'GET',
handler(req, reply) {
reply.redirect('../plugins/echart_dashboard')
}
});

server.route({
path: '/api/echart_dashboard/ModuleInstance',
method: ['POST', 'GET'],config: {cors : true},
handler: function (req, reply) {
reply(cacheData.getCacheData('ModuleInstance'));
}
});

server.route({
path: '/api/echart_dashboard/jsondata',
method: ['POST', 'GET'],config: {cors : true},
handler: function (req, reply) {
reply(cacheData.getCacheData('jsondata'));
}
});

server.route({
path: '/api/echart_dashboard/arraydata',
method: ['POST', 'GET'],config: {cors : true},
handler: function (req, reply) {
reply(cacheData.getCacheData('arraydata'));
}
});

server.route({
path: '/api/echart_dashboard/errjdata',
method: ['POST', 'GET'],config: {cors : true},
handler: function (req, reply) {
reply(cacheData.getCacheData('errjdata'));
}
});

server.route({
path: '/api/echart_dashboard/timestampData',
method: ['POST', 'GET'],config: {cors : true},
handler: function (req, reply) {
reply(cacheData.getCacheData('timestampData'));
}
});
}

 

5.public 目录
这里public目录就是我们的echart dashboard插件了。用vue开发一个dashboard.参考:https://github.com/zce/dashboard。

开发完之后,用vue脚手架提供的build命令 (npm run build)。会生成一个dist目录

 


6.要修改build.js assetsPath

require('./check-versions')()
require('shelljs/global')
env.NODE_ENV = 'production'

var path = require('path')
var config = require('../config')
var ora = require('ora')
var webpack = require('webpack')
var webpackConfig = require('./webpack.prod.conf')

console.log(
' Tip:\n' +
' Built files are meant to be served over an HTTP server.\n' +
' Opening index.html over file:// won\'t work.\n'
)

var spinner = ora('building for production...')
spinner.start()

var assetsPath = path.join(config.build.assetsRoot, config.build.assetsSubDirectory)
rm('-rf', assetsPath)
mkdir('-p', assetsPath)
cp('-R', 'plugins/echart_dashboard/*', assetsPath)

webpack(webpackConfig, function (err, stats) {
spinner.stop()
if (err) throw err
process.stdout.write(stats.toString({
colors: true,
modules: false,
children: false,
chunks: false,
chunkModules: false
}) + '\n')
})


6.修改index.js 修改 assetsSubDirectory
var path = require('path')

module.exports = {
build: {
env: require('./prod.env'),
index: path.resolve(__dirname, '../dist/index.html'),
assetsRoot: path.resolve(__dirname, '../dist'),
assetsSubDirectory: 'plugins/echart_dashboard',
assetsPublicPath: '/',
productionSourceMap: false,
// Gzip off by default as many popular static hosts such as
// Surge or Netlify already gzip all static assets for you.
// Before setting to `true`, make sure to:
// npm install --save-dev compression-webpack-plugin
productionGzip: false,
productionGzipExtensions: ['js', 'css']
},
dev: {
env: require('./dev.env'),
port: 8081,
assetsSubDirectory: 'plugins/echart_dashboard',
assetsPublicPath: '/',
proxyTable: {},
// CSS Sourcemaps off by default because relative paths are "buggy"
// with this option, according to the CSS-Loader README
// (https://github.com/webpack/css-loader#sourcemaps)
// In our experience, they generally work as expected,
// just be aware of this issue when enabling this option.
cssSourceMap: false
}
}

 

转载于:https://www.cnblogs.com/Yanss/p/10678849.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
-功能简介-   (1)任意增加、修改、删除报表,而无须改动源程序。   (2)自动生成功能,选择项目后快速生成表格式或自由式等常用报表。   (3)手动设计功能,可以设计出复杂的中国式报表及套打单据。   (4)直线、文本、表达式等对象的位置、大小、字体、颜色可以任意改变。   (5)具有中英翻译功能,表达式可以采用中文,适合中国人使用。   (6)表达式非常灵活,可以是字段、函数、变量组成的复杂表达式。如:取小数位(数量*单价*折扣/100,2)。   (7)表达式具有校验功能,如表达式有错误系统会立即提示。   (8)所有界面完全汉化,直观明了,可交付最终用户使用。   (9)采用动态数据窗口处理,无须调用PB之外的资源。   (10)表头和表体之间的格线,不会出现“裂缝”,改进了PB本身的缺陷。   (11)打印纸张、比例、横向、纵向打印等可以设置。   (12)数据源可以是后台数据库表或共享前台数据窗口数据,满足不同的需要。   (13)自动识别并适应显示分辨率。   (14)调用简便,与其它PB开发系统之接口简单。   (15)可以直接在Orcal,Sybase,Ms-sql等大型数据库下使用而无需任何改动。 (16)调用本系统之前已经设计好的报表,可以选择“原数据窗口格式”生成到本系统,把“死报表”变成“活报表”。 (17)对于下拉数据窗口的数据,可以采用本系统的“后台取数()”函数来实现取数。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值