前端利用layui:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Layui</title> <meta name="renderer" content="webkit"> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"> <link rel="stylesheet" href="../static/CSS/layui/css/layui.css" media="all"> <!-- 注意:如果你直接复制所有代码到本地,上述css路径需要改成你本地的 --> </head> <body> <div class="layui-layout layui-layout-admin"> <div class="layui-header"> <div class="layui-logo layui-hide-xs layui-bg-black">智能数据库系统</div> <!-- 头部区域(可配合layui 已有的水平导航) --> <ul class="layui-nav layui-layout-left"> <!-- 移动端显示 --> <li class="layui-nav-item layui-show-xs-inline-block layui-hide-sm" lay-header-event="menuLeft"> <i class="layui-icon layui-icon-spread-left"></i> </li> <li class="layui-nav-item layui-hide-xs"><a href="index">导入</a></li> <li class="layui-nav-item layui-hide-xs"><a href="table_list">数据字典</a></li> <li class="layui-nav-item layui-hide-xs"><a href="tolook">可视化</a></li> </ul> <ul class="layui-nav layui-layout-right"> <li class="layui-nav-item layui-hide layui-show-md-inline-block"> <a href="javascript:;"> <img src="//tva1.sinaimg.cn/crop.0.0.118.118.180/5db11ff4gw1e77d3nqrv8j203b03cweg.jpg" class="layui-nav-img"> tester </a> <dl class="layui-nav-child"> <dd><a href="">Your Profile</a></dd> <dd><a href="">Settings</a></dd> <dd><a href="">Sign out</a></dd> </dl> </li> <li class="layui-nav-item" lay-header-event="menuRight" lay-unselect> <a href="javascript:;"> <i class="layui-icon layui-icon-more-vertical"></i> </a> </li> </ul> </div> <div class="layui-side layui-bg-black"> <div class="layui-side-scroll"> <!-- 左侧导航区域(可配合layui已有的垂直导航) --> <ul class="layui-nav layui-nav-tree" lay-filter="test"> <li class="layui-nav-item"><a href="/index">导入数据</a></li> <li class="layui-nav-item"><a href="/table_list">已导入数据</a></li> </ul> </div> </div> <div class="layui-body"> <!-- 内容主体区域 --> <div style="padding: 15px;"> <table class="layui-table" id="idTest" lay-data="{ 1300, height:690, url:'/get_look_dictionary',where:{table_name:'{{ table_name }}',database_name:'{{ database_name }}'}, page:false, id:'idTest'}" lay-filter="demo"> <thead> <tr> <th lay-data="{field:'key_english', 220, fixed: true}">英文名</th> <th lay-data="{field:'key_china', 220}">中文名</th> <th lay-data="{field:'key_type', 180}">字段类型</th> <th lay-data="{field:'key_long', 180}">字段长度</th> <th lay-data="{field:'key_null', 180}">字段缺省值</th> <th lay-data="{field:'key_unit', 180}">单位</th> <th lay-data="{fixed: 'right', 220, align:'center', toolbar: '#barDemo'}"></th> </tr> </thead> </table> <script type="text/html" id="barDemo"> <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="add">添加</a> <a class="layui-btn layui-btn-xs" lay-event="dictionary">修改</a> <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a> </script> </div> </div> <div class="layui-footer"> <!-- 底部固定区域 --> 寒蝉鸣泣之时 </div> </div> <script src="../static/CSS/layui/layui.js"> </script> <script> //JS layui.use(['element', 'layer', 'util'], function(){ var element = layui.element ,layer = layui.layer ,util = layui.util ,$ = layui.$; //头部事件 util.event('lay-header-event', { //左侧菜单事件 menuLeft: function(othis){ layer.msg('展开左侧菜单的操作', {icon: 0}); } ,menuRight: function(){ layer.open({ type: 1 ,content: '<div style="padding: 15px;">处理右侧面板的操作</div>' ,area: ['260px', '100%'] ,offset: 'rt' //右上角 ,anim: 5 ,shadeClose: true }); } }); }); var table = layui.table; table.on('tool(demo)', function(obj){ var data = obj.data; if(obj.event === 'add'){ layer.msg('ID:'+ data.a_id + ' 的查看操作'); } else if(obj.event === 'del'){ layer.confirm('真的删除行么', function(index){ obj.del(); layer.close(index); }); } else if(obj.event === 'dictionary'){ window.location.href="/look_dictionary" + "?table_name="+data.table_name+"&database_name="+data.database_name; // layer.alert('编辑行:<br>'+ JSON.stringify(data)) } }); </script> </body> </html>
@app.route('/get_look_dictionary') def get_look_dictionary(): table_name=request.values.get("table_name") database_name=request.values.get("database_name") table_data,table_unit=dictionary.get_dictionary(table_name,database_name) data_re=[] count=len(table_data) for index in range(len(table_data)): data_re.append({"key_english":table_data[index][0],"key_china":table_data[index][1],"key_type":table_data[index][2], "key_long":table_data[index][3],"key_null":table_data[index][4],"key_unit":table_unit[index]}) print("数据字典:(table_name="+table_name+",database_name="+database_name+")") print(data_re) return jsonify({"code": 0, "msg": "", "count": count, "data": data_re})
#获取表的数据字典 def get_dictionary(name_table,database_name): #中文名,英文名,数据类型,单位 # select column_name,column_comment ,data_type,CHARACTER_MAXIMUM_LENGTH,COLUMN_DEFAULT # from information_schema.columns # where table_name='表名' and table_schema='bigwork_data' #英文名,中文名,字段类型,字段长度,缺省值,单位在数据的第一行 sql="select column_name,column_comment ,data_type,CHARACTER_MAXIMUM_LENGTH,COLUMN_DEFAULT " \ "from information_schema.columns " \ "where table_name='"+name_table+"' and table_schema='"+database_name+"'" res = query_mysql(sql) sql="select * from "+name_table+" limit 1" res2=query_mysql(sql) return res,res2[0] pass