前端页面展示MySQL数据并实现前后端互动
前端页面使用H-ui框架 后端使用flask框架 数据库使用mysql 连接数据库通过pymysql实现
前端代码如下
- <html lang="en">
- <head>
- <meta charset="utf-8">
- <meta name="renderer" content="webkit|ie-comp|ie-stand">
- <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
- <meta name="viewport"
- content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
- <meta http-equiv="Cache-Control" content="no-siteapp"/>
- <title>风险预警系统</title>
- <link rel="stylesheet" type="text/css" href="../static/ui/static/h-ui/css/H-ui.min.css"/>
- <link rel="stylesheet" type="text/css" href="../static/ui/static/h-ui.admin/css/H-ui.admin.css"/>
- <link rel="stylesheet" type="text/css" href="../static/ui/lib/Hui-iconfont/1.0.8/iconfont.css"/>
- <link rel="stylesheet" type="text/css" href="../static/ui/static/h-ui.admin/skin/default/skin.css" id="skin"/>
- <link rel="stylesheet" type="text/css" href="../static/ui/static/h-ui.admin/css/style.css"/>
- <link rel="stylesheet" type="text/css" href="../static/css/out.css"/>
- <style>
- .hide {
- display: none;
- }
- </style>
- <script type="text/javascript">
- var region = {
- "反洗钱":
- {
- "": [""],
- "黑名单": ["", "黑名单一致性", "黑名单实时监控"],
- "客户风险等级": ["", "首次评估", "定期评估", "客户风险等级唯一性", ""],
- "可疑交易": ["", "可疑交易定性意见留痕", "可疑交易上报及时性"],
- "法人客户": ["", "身份要素信息完整性"],
- "个人客户": ["", "身份证件有效期"]
- },
- "财务":
- {
- "": [""],
- "赔付差异": ["", "财务支付金额与业务金额不一致", "核赔不通过,财务表显示已支付成功", "财务表显示已支付,理赔端无对应数据", "理赔业务表中未包含公估费", "财务支出时间比理赔业务表时间提前", "理赔主表中的总支付金额小于理赔业务表中的总支付金额"]
- }
- }
- </script>
- </head>
- <body>
- <nav class="breadcrumb"><i id="logo"></i> <a class="btn btn-success radius r"
- style="line-height:1.6em;margin-top:3px"
- href="javascript:location.replace(location.href);"
- title="刷新"><i
- class="Hui-iconfont"></i></a></nav>
- <div class="page-container">
- <div class="text-c">
- <select id="province" onchange="change(this.value);" class="select-box" style="width:200px;">
- <option>请选择一级指标</option>
- </select>
- <select id="city" onchange="countyChange(this.value);" class="select-box" style="width:200px;">
- <option>请选择二级指标</option>
- </select>
- <select id="county" class="select-box" style="width:200px;">
- <option>请选择三级指标</option>
- </select>
- <span> 查询数据范围</span>
- <input type="text"
- onfocus="WdatePicker({ maxDate:'#F{$dp.$D(\'datemax\')||\'%y-%M-%d\'}',dateFmt:'yyyy-MM-dd',isShowToday:false,isShowClear:false })"
- id="datemin"
- class="input-text Wdate" style="width:300px;">
- -
- <input type="text"
- onfocus="WdatePicker({ minDate:'#F{$dp.$D(\'datemin\')}',maxDate:'%y-%M-%d',dateFmt:'yyyy-MM-dd',isShowToday:false,isShowClear:false })"
- id="datemax"
- class="input-text Wdate" style="width:300px;">
- <button type="button" class="btn btn-success radius" id="tijiao" name=""><i class="Hui-iconfont"></i> 搜索
- </button>
- </div>
- <div class="mt-20">
- <table class="table table-border table-bordered table-hover table-bg thisTable">
- <thead>
- <tr class="text-c">
- <th>序号</th>
- <th>指标名称</th>
- <th>指标日期</th>
- <th>监控状态</th>
- <th>下载</th>
- </tr>
- </thead>
- <tbody id="tbody" class="text-c">
- </tbody>
- </table>
- <div id="page1" class="r pager" style="margin-top: 10px"></div>
- <div style="font-size: 18px; font-family: 宋体; margin-top: 5px">监控状态:1--预警 0--正常</div>
- </div>
- </div>
- <!--_footer-->
- <script type="text/javascript" src="../static/ui/lib/jquery/1.9.1/jquery.min.js"></script>
- <script type="text/javascript" src="../static/ui/lib/layer/2.4/layer.js"></script>
- <script type="text/javascript" src="../static/ui/static/h-ui/js/H-ui.min.js"></script>
- <script type="text/javascript" src="../static/ui/static/h-ui.admin/js/H-ui.admin.js"></script> <!--/_footer-->
- <script src='../static/js/threelevellinkpage.js'></script>
- <!--业务代码-->
- <script type="text/javascript" src="../static/ui/lib/My97DatePicker/4.8/WdatePicker.js"></script>
- <script type="text/javascript" src="../static/ui/lib/datatables/1.10.0/jquery.dataTables.min.js"></script>
- <script type="text/javascript" src="../static/ui/lib/laypage/1.2/laypage.js"></script>
- <script type="text/javascript">
- $(function () {
- $('#DataTables_Table_0_length').hide();
- $('#DataTables_Table_0_filter').hide();
- $('#DataTables_Table_0_previous').hide();
- $('#DataTables_Table_0_next').hide();
- $('#DataTables_Table_0_info').hide();
- core.getUserListByPage();
- $("#tijiao").click(function () {
- var datemin = $("#datemin").val();
- var datemax = $("#datemax").val();
- var province = $("#province").val();
- var city = $("#city").val();
- var county = $("#county").val();
- core.getUserListByPage(datemin, datemax, province, city, county);
- });
- });
- var core = (function ($$) {
- var getRootPath = function () {
- var curWwwPath = window.document.location.href;
- var pathName = window.document.location.pathname;
- var pos = curWwwPath.indexOf(pathName);
- var localhostPath = curWwwPath.substring(0, pos);
- var projectName = pathName.substring(0, pathName.substr(1).indexOf('/') + 1);
- return (localhostPath + projectName);
- };
- var getPage = function (url, config, content) {
- $.getJSON(url, config, function (res) {
- $('#theme-count').html(res.totalPeo)
- laypage({
- cont: 'page1',
- pages: Math.ceil(res.total / config.pageSize),
- curr: config.page || 1,
- group: 10,
- skip: true,
- jump: function (obj, first) {
- if (!first) {
- config.page = obj.curr;
- getPage(url, config, content)
- }
- }
- });
- $('tbody').html(content(res, config.page))
- });
- };
- function parseUserList(res, currPage) {
- var content = "";
- if (res.total > 0) {
- var i = 1;
- $.each(res.rows, function (i, o) {
- content += "<tr class=\"text-c\">";
- content += "<td width=\"10\" title='" + o.id + "'>" + o.curr_page + "</td>";
- content += "<td width=\"10\" title='" + o.target + "'>" + o.target + "</td>";
- content += "<td width=\"10\" title='" + o.monitor_date + "'>" + o.monitor_date + "</td>";
- content += "<td width=\"10\" title='" + o.monitir_status + "'>" + o.monitir_status + "</td>";
- {#content += "<td width=\"10\"" + "id='" +o.target+ o.monitor_date+ ".xls" + "'" + "title='" + o.monitor_dpwnload + "'>" + "<button type=\"button\" class=\"btn btn-secondary radius loadExcel\" id=\"loadExcel\" name=\"\" href=\"\"><i class=\"Hui-iconfont\"></i>导出EXCEL\n" + "</button>" + o.monitor_dpwnload + "</td>";#}
- content += "<td width=\"10\"" + "id='" + o.target + o.monitor_date + ".xls" + "'" + "title='" + o.monitor_dpwnload + "'>" + "<a href=\"http://127.0.0.1:5000/download_xls?code_n=" + o.monitor_dpwnload + "\"><button type=\"button\" class=\"btn btn-secondary radius loadExcel " + o.hide_h + "\" id=\"loadExcel\" ><i class=\"Hui-iconfont\"></i>导出EXCEL\n" + "</button></a>" + "</td>";
- content += "</tr>";
- });
- $('.laypage_main ').show();
- return content;
- } else {
- content += "<tr class='odd'>"
- content += "<td valign=\"top\" colspan=\"12\" class=\"dataTables_empty\">没有数据</td>"
- content += "</tr>"
- $('.laypage_main ').hide();
- return content;
- }
- }
- var getUserListByPage = function (datemin, datemax, province, city, county, curr) {
- core.getPage(core.getRootPath() + '/log_mysql_data?', {
- page: curr || 1,
- pageSize: 10,
- datemin: datemin,
- datemax: datemax,
- province: province,
- city: city,
- county: county,
- }, parseUserList);
- };
- return {
- getRootPath: getRootPath,
- getPage: getPage,
- getUserListByPage: getUserListByPage
- }
- })(jQuery);
- </script>
- </body>
- </html>
后端代码
- # 获取mysql存的日志信息
- @BLACKLIST_blu.route('/log_mysql_data', methods=["GET"])
- def Log_mysql():
- # code = '1________'
- start_date = request.args.get("datemin", None)
- end_date = request.args.get("datemax", None)
- # 编码
- province = request.args.get("province", None)
- city = request.args.get("city", None)
- county = request.args.get("county", None)
- # print(county, 'county')
- # 编码
- code = targetcode(province, city, county)
- # print(code, 'code')
- if start_date is None:
- start_date = '1970-01-01'
- if end_date is None:
- end_date = '9999-12-31'
- if start_date is '':
- start_date = '1970-01-01'
- if end_date is '':
- end_date = '9999-12-31'
- curr = int(request.args.get("page"))
- pageSize = int(request.args.get("pageSize"))
- curr = (curr - 1) * pageSize
- sql = "SELECT * FROM inner_factors_summary_display where " + "'" + str(
- start_date) + "' <= FactorsDate and FactorsDate <= " + "'" + str(
- end_date) + "'" + " and ThirdFactorCode like '" + str(code) + "'" + " limit " + str(
- pageSize) + " offset " + str(curr) + " ;"
- # print(sql, 'sql')
- cc = bd_db.cursor()
- cn_list = []
- # count = "select count(id) from inner_factors_summary_display"
- count = "SELECT count(id) FROM inner_factors_summary_display where " + "'" + str(
- start_date) + "' <= FactorsDate and FactorsDate <= " + "'" + str(
- end_date) + "'" + " and ThirdFactorCode like '" + str(code) + "'"
- # cc.execute(sql, {"datemin": start_date, "datemax": end_date, "pageSize": pageSize, "curr": curr})
- cc.execute(sql)
- content = cc.fetchall()
- n = 0
- for i in content:
- n += 1
- # print(i,"i")
- if i[4] == '1':
- hide = ''
- else:
- hide = 'hide'
- curr_page = curr + n
- cn_list.append(
- {'id': i[0], 'target': i[1], 'monitor_date': i[2], 'monitir_status': i[4], 'monitor_dpwnload': i[7],
- 'hide_h': hide, 'curr_page': curr_page})
- cc.execute(count)
- count1 = cc.fetchall()[0][0]
- data = {"rows": cn_list, "total": count1}
- return json.dumps(data)
- # 获取前端页面 风险预警系统
- @BLACKLIST_blu.route('/earlywarningsystem', methods=["GET", "POST"])
- def Narlywarningsystem():
- if request.method == "GET":
- return render_template('translate.html')
给个编码代码
- from inner_ctrl01.common.utils import bd_db
- def targetcode(province, city, county):
- province_code = None
- city_code = None
- county_code = None
- code_str = "_________"
- if province == '请选择一级指标' or province == None:
- province_code = '___'
- else:
- if province == '':
- province_code = "___"
- if province != "" and province != None:
- sql = "SELECT FactorsCode FROM inner_frist_level_factors where FactorsCName = " + "'" + str(province) + "'"
- cc = bd_db.cursor()
- cc.execute(sql)
- content = cc.fetchall()
- province_code = str(content[0][0])
- if city == '请选择二级指标'or city == None:
- city_code = '___'
- else:
- if city == '':
- city_code = '___'
- if city != '' and city != None:
- sql = "SELECT FactorsCode FROM inner_second_level_factors where FactorsCName = " + "'" + str(city) + "';"
- cc = bd_db.cursor()
- cc.execute(sql)
- content = cc.fetchall()
- province_code = ''
- city_code = str(content[0][0])
- if county == '请选择三级指标' or county == None:
- county_code = '___'
- else:
- if county == '':
- county_code = '___'
- if county != "" and county != None:
- sql = "SELECT FactorsCode FROM inner_third_level_factors where FactorsCName = " + "'" + str(county) + "';"
- cc = bd_db.cursor()
- cc.execute(sql)
- content = cc.fetchall()
- province_code = ''
- city_code = ''
- county_code = str(content[0][0])
- if province == None:
- province_code = "___"
- city_code = "___"
- county_code = "___"
- code_str = str(province_code) + str(city_code) + str(county_code)
- return code_str
数据库结构
- # inner_frist_level_factors
- id 自增 主键 不能为空
- FactorsCname varchar
- FactorsCode varchar null unique
- # inner_second_level_factors
- id 自增 主键 不能为空
- FactorsCname varchar
- FactorsCode varchar null unique
- FatherCode varchar null
- # inner_third_level_factors
- id 自增 主键 不能为空
- FactorsCname varchar
- FactorsCode varchar null unique
FatherCode varchar null
FactorsEname varchar
- # inner_factors_summary_display
FactorsCname varchar
FactorsDate varchar
FactorsStatus varchar
FactorsFlag varchar
thirdFactorsCode varchar
FactorsDownloadUrl varchar
FactorsEname varchar
以上四张表可以根据自己需求设计。我们将第四张表的数据传到前端页面。
其他部门在前几篇博客里面。
本篇博客不适合新人,结束!
前端页面展示MySQL数据并实现前后端互动的更多相关文章
- base64编码后的pdf文件前端页面展示--pdf.js的应用
最近在整理项目中用到的插件或者使用心得,感觉还是写成博客,能加深新一层的理解. 我先说一下我的需求:由于java后台编译的文件流在手机端加载速度太慢,所以想着可以在前端解析,放在页面展示给用户. 所以 ...
- Saiku控制页面展示的数据过长自动换行(二十四)
Saiku控制页面展示的数据过长自动换行 目前用到saiku来展示数据,发现数据文本过长也不会自动换行,然而用户那边又需要换行(会好看些),所以就来改一改源码啦 首先我们使用谷歌浏览器 inspect ...
- 【FAQ】分析服务导出的事件数据和概览页面展示的数据不一致该如何解决?
华为分析服务面向开发者提供两种数据展现方式:(1)事件数据下载,开发者可以将事件数据下载后导入到自有的分析系统中:(2)直接在AGC概览页面查看用户数和事件数. 问题描述 某开发者想将事件数据导入到自 ...
- vue+mockjs 模拟数据,实现前后端分离开发
在项目中尝试了mockjs,mock数据,实现前后端分离开发. 关于mockjs,官网描述的是 1.前后端分离 2.不需要修改既有代码,就可以拦截 Ajax 请求,返回模拟的响应数据. 3.数据类型丰 ...
- Python Django CMDB项目实战之-2创建APP、建模(models.py)、数据库同步、高级URL、前端页面展示数据库中数据
基于之前的项目代码来编写 Python Django CMDB项目实战之-1如何开启一个Django-并设置base页index页文章页面 现在我们修改一个文章列表是从数据库中获取数据, 下面我们就需 ...
- ECharts, PHP, MySQL, Ajax, JQuery 实现前后端数据可视化
ECharts 下载js代码 工作原理浅析 在项目中引入ECharts 后台处理 数据库端MySQL PHP端 JQuery Ajax处理 ECharts 端处理 前端全部代码 演示结果 总结 最近要 ...
- 在前端页面展示Markdown文件
常我们都会在GitHub上浏览很多的readme文件,这些都是Markdown语法写成的Markdown文件,HTML中并没有用于展示Markdown文件的元素,那么为什么可以在前端展示呢? 有别于G ...
- django--如何将数据结果集序列化传给前端页面展示
示例为一对多的表关系,学生为多,老师为一,设置外键字段可以为空,也就是说关联的老师被删除该学生依然存在,只是相应字段留空 class Teacher(models.Model): name = mod ...
- servlet自动获取前端页面提交数据
servlet自动获取前端页面jsp提交数据 以下是本人在学习过程中,因前端页面提交参数过多,后台servlet封装实体类过于麻烦而写的一个工具类,应用于jsp/servlet数据提交后,基于MVC+ ...
随机推荐
- GMA Round 1 相交
传送门 相交 在实数范围内,设抛物线$C_1:y^2=2x$,双曲线:$C_2:\frac{y^2}{b^2}-\frac{x^2}{a^2}=1$(a,b为参数). 假如a和b都在(0,16)这个区 ...
- pygame-KidsCanCode系列jumpy-part10-角色动画(上)
上一节学习如何利用spritesheet加载图片,但是player仍然是一张静态的图片,比较枯燥,我们要让它动起来! Player类,先把各种状态的图片加载起来: # 加载各种状态的图片序列 def ...
- Dockerfile的 RUN和CMD
在创建Dockerfile的时候,RUN和CMD都是很重要的命令.它们各自的作用分别如下: RUNRUN命令是创建Docker镜像(image)的步骤,RUN命令对Docker容器( containe ...
- 将 Smart 构件发布到 Maven 中央仓库
https://my.oschina.net/huangyong/blog/226738
- 卷积神经网络(CNN)代码实现(MNIST)解析
在http://blog.csdn.net/fengbingchun/article/details/50814710中给出了CNN的简单实现,这里对每一步的实现作个说明: 共7层:依次为输入层.C1 ...
- angularjs自定义filter
angular.Module API Overview Methods info([info]); provider(name, providerType); factory(name, provid ...
- curl 模拟表单post文件
网上查询出来的几乎都是错误的,正确的应该是: $data = array( 'pic'=>new CURLFile($path) // 如果无效可以这样 // 'pic'=>curl_fi ...
- APP微信支付Java后台的实现(springmvc)
第一次做微信支付,阅读完开发文档后,下了个官方demo,摸索了好久,期间也出现了好多问题,终于是实现生成预支付订单以及支付成功后接收微信服务器通知,不多说了,直接上代码: 一.工具类 Constant ...
- XSS跨站脚本小结(转)
原文链接:http://www.cnblogs.com/xiaozi/p/5588099.html#undefined XSS漏洞验证经常遇到一些过滤,如何进行有效验证和绕过过滤呢,这里小结一下常见的 ...
- Gorm使用详解
1.什么是Gorm go语言编写的orm框架 特点: 1)全功能ORM 2)关联(包含一个,包含多个,属于,多对多) 3)Callbacks(创建/保存/更新/删除/查找前后回调) 4)预加载 5)事 ...