Skip to content

Commit

Permalink
📝 修改创建项目的帮助文档
Browse files Browse the repository at this point in the history
  • Loading branch information
kongnet committed Aug 27, 2019
1 parent 8ff7e6a commit 73154d8
Show file tree
Hide file tree
Showing 6 changed files with 166 additions and 18 deletions.
23 changes: 12 additions & 11 deletions README_demo9.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,18 @@
3. 运行demo9,npm run demo9,启动数据库探针
4. 最终效果
![最终效果](demo_img/treemap.gif)
- 方式二

1. 项目地址: [skyjt](https://github.com/kongnet/sky)
2. 安装 npm i -g skyjt
3. 创建新的文件夹,cd 进入,执行
- jt init -f
![init](demo_img/init.gif)
4. cd 进test,执行 npm i,
5. 安装全局nodemon,npm i -g nodemon.
6. 执行 node index
7. 最终效果同方法一
- 方式二(推荐方式)
* 1. 使用skyjt安装skybase,项目地址: [skyjt](https://github.com/kongnet/sky)
* 2. 安装 npm i -g skyjt
* 3. 创建新的文件夹,cd 进入,执行
* 4. jt init -f // 强制初始化

![init](demo_img/init.gif)

* 5. cd进创建的目录,执行 **npm i** or **yarn** or **cnpm i**// 安装依赖包
* 6. 安装全局nodemon, npm i -g nodemon.
* 7. 执行 **nodemon** or **npm start** or **node index**
* 8. 最终效果同方法一 // 数据库探针需要修改 **./config/config.default.js****mysql** 的配置
- 注意

请确认数据库链接正常,且有一定的数据.
Expand Down
21 changes: 20 additions & 1 deletion demo/9-mysql-chart/model/api/skyapi/probe.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,26 @@ module.exports = {
name: 'mysql探针数据',
desc: 'mysql探针数据',
method: 'get',
controller: 'mysqlProbe.getTableColumn',
controller: 'mysqlProbe.getDbTable',
param: {
outputType: {
name: '输出类型',
desc: '接口输出html或者json',
def: 'html',
type: 'string'
}
},
'token': false,
'needSign': false,
'err_code': {},
'test': {},
'front': true
},
'mysqlGrid': {
name: 'mysql探针数据',
desc: 'mysql探针数据',
method: 'get',
controller: 'mysqlProbe.getDbTableColumn',
param: {
outputType: {
name: '输出类型',
Expand Down
29 changes: 27 additions & 2 deletions demo/9-mysql-chart/router/mysqlProbe.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ module.exports = {
ctx.throwCode(r.code, r.msg)
}
},
async getTableColumn (ctx) {
async getDbTable (ctx) {
let { outputType } = ctx.checkedData.data
const r = await mysqlProbe.getTableColumn(ctx.checkedData.data)
const r = await mysqlProbe.getDbTable(ctx.checkedData.data)
if (r && r.code === 0) {
// outputType = 'json' // 先写死
if (outputType === 'html') {
Expand All @@ -49,5 +49,30 @@ module.exports = {
} else {
ctx.throwCode(r.code, r.msg)
}
},
async getDbTableColumn (ctx) {
let { outputType } = ctx.checkedData.data
const r = await mysqlProbe.getDbTableColumn(ctx.checkedData.data)
if (r && r.code === 0) {
if (outputType === 'html') {
let f = fs.readFileSync(path.join(__dirname, '../template/grid-mysql.html'))
let packObj = $.tools.jsonPack(r.data)
packObj.shift()
let obj = {
table_id: 'grid_mysql',
table_title: 'Mysql数据库-表-字段',
table_head: ['数据库', '表', '列', '列类型', '列注解'],
table_col: [0, 1, 2, 3, 4],
// table_col: ['dbName', 'tableName', 'columnName', 'columnKey', 'columnComment'],
table_list: packObj
}
ctx.type = 'html'
ctx.body = $.tpl(f.toString()).render(obj)
} else {
ctx.ok(r)
}
} else {
ctx.throwCode(r.code, r.msg)
}
}
}
51 changes: 47 additions & 4 deletions demo/9-mysql-chart/service/mysqlProbe.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,26 @@ let sql = `select
table_comment as 'tableComment'
from information_schema.tables
order by data_length desc, index_length desc;`

let tableSql = `SELECT
table_schema as db,
table_name as table_name,
table_comment as table_comment
FROM
information_schema.\`TABLES\`
WHERE
table_schema NOT IN ( 'information_schema', 'performance_schema', 'mysql', 'sys' );`
let columnSql = `SELECT
table_schema AS db_name,
table_name AS table_name,
column_name AS column_name,
column_type AS column_type,
column_key AS column_key,
column_comment AS column_comment
FROM
information_schema.\`COLUMNS\`
WHERE
table_schema NOT IN ( 'information_schema', 'performance_schema', 'mysql', 'sys' )
ORDER BY table_schema;`
async function getTableColumnSize () {
let r = await db.cmd(sql).run()
let arr = []
Expand All @@ -35,7 +54,7 @@ async function getTableColumnSize () {
data: { tableRow: arr, tableSize: arrSize }
}
}
async function getTableColumn () {
async function getDbTable () {
let r = await db.cmd(sql).run()
let arr = []
let obj = {}
Expand All @@ -50,13 +69,37 @@ async function getTableColumn () {
}
})
arr.shift()
// console.log(arr)
return {
code: 0,
data: { tableColumn: arr, len: r.length }
}
}
async function getDbTableColumn () {
let r = await db.cmd(tableSql).run()
let dbTableCommentMap = {}
r.map(it => {
dbTableCommentMap[[it.db, it.table_name].join('$$')] = it.table_comment.trim().replaceAll('\r\n', '')
})
r = await db.cmd(columnSql).run()
r = r.map(it => {
// console.log(dbTableCommentMap[it.db_name + '$$' + it.table_name])
return {
dbName: it.db_name,
tableName: it.table_name + ' ' + dbTableCommentMap[it.db_name + '$$' + it.table_name],
columnName: it.column_name,
columnKey: it.column_key, // PRI->UNI->MUL
columnComment: it.column_comment
}
})
return {
code: 0,
data: r
}
}

getDbTableColumn()
module.exports = {
getTableColumnSize,
getTableColumn
getDbTable,
getDbTableColumn
}
59 changes: 59 additions & 0 deletions demo/9-mysql-chart/template/grid-mysql.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<style type="text/css">
table.gridtable {
font-family: verdana,arial,sans-serif;
font-size:11px;
color:#333333;
border-width: 1px;
border-color: #666666;
border-collapse: collapse;
width:50%;
}
table.gridtable th {
border-width: 1px;
padding: 8px;
border-style: solid;
border-color: #666666;
background-color: #dedede;
}
table.gridtable td {
text-align: left;
border-width: 1px;
padding: 8px;
border-style: solid;
border-color: #666666;
background-color: #ffffff;
}
</style>
<h3>{{ d.table_title }}</h3>
<table id="{{d.table_id}}" class="gridtable">
{{# let headLen}}
{{# if(d.table_head){ headLen=d.table_head.length;}}
<thead>
<tr>
<th>序号</th>
{{# for(let i = 0, len = d.table_head.length; i < len; i++){ }}
<th>{{ d.table_head[i] }}</th>
{{# } }}
</tr>
</thead>
{{# } else { headLen=d.table_col.length; }}
<thead>
<tr>
<th>序号</th>
{{# for(let i = 0, len = d.table_col.length; i < len; i++){ }}
<th>{{ d.table_col[i] }}</th>
{{# } }}
</tr>
</thead>
{{# } }}
<tbody>
{{# for(let i = 0, len = d.table_list.length; i < len; i++){ }}
<tr>
<td>{{i+1}}</td>
{{# for(let k = 0, len1 = headLen; k < len1; k++){ }}
<td>{{ d.table_list[i][d.table_col[k]]||'' }}</td>
{{# } }}
</tr>
{{# } }}
</tbody>
</table>
1 change: 1 addition & 0 deletions output-template/package.json.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"description": "{{d.proDesc}}",
"main": "index.js",
"scripts": {
"start": "nodemon index.js",
"test": "echo \"Error: no test specified\" && exit 1",
"cz": "git add . && git status && git cz"
},
Expand Down

0 comments on commit 73154d8

Please sign in to comment.