You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
97 lines
2.8 KiB
97 lines
2.8 KiB
6 months ago
|
'''
|
||
|
前端业务
|
||
|
'''
|
||
|
from flask import Blueprint,request,render_template,jsonify,redirect,session
|
||
|
import adminProcess
|
||
|
from Controller.Data2DB import mylog
|
||
|
|
||
|
user = Blueprint("user",__name__)
|
||
|
log0=mylog()
|
||
|
# 前端首页
|
||
|
@user.route("/")
|
||
|
def front():
|
||
|
data = {}
|
||
|
data['timeinfo'],data['temp'] = adminProcess.getTemp()
|
||
|
log0.info("获取天气成功")
|
||
|
return render_template("index.html", data=data)
|
||
|
|
||
|
#疫情展示路由
|
||
|
@user.route("/yqShow")
|
||
|
def yq():
|
||
|
data = {}
|
||
|
data['timeinfo'], data['temp'] = adminProcess.getTemp()
|
||
|
return render_template("front/yq.html", data=data)
|
||
|
|
||
|
#疫情展示路由
|
||
|
@user.route("/yqData")
|
||
|
def yqdata():
|
||
|
data = adminProcess.getDataList("yq")
|
||
|
if len(data) > 0:
|
||
|
date = [item[2] for item in data]
|
||
|
qznum = [item[3] for item in data]
|
||
|
zynum = [item[4] for item in data]
|
||
|
log0.info("获取疫情数据成功")
|
||
|
return jsonify({"code": 200, "date": date,"qznum":qznum,"zynum":zynum})
|
||
|
else:
|
||
|
log0.info("获取疫情数据不成功")
|
||
|
return jsonify({"code": 404})
|
||
|
|
||
|
|
||
|
#美图展示路由
|
||
|
@user.route("/mtShow")
|
||
|
def mt():
|
||
|
data = {}
|
||
|
data['mt'] = adminProcess.getDataList("mtData")
|
||
|
return render_template("front/mt.html", data=data)
|
||
|
|
||
|
# 进入新闻首页
|
||
|
@user.route("/news")
|
||
|
def index():
|
||
|
# 获取来源的参数
|
||
|
page = request.args.get('page')
|
||
|
if page is None: page = 1
|
||
|
# 增加获取一共多少页的代码
|
||
|
data = {}
|
||
|
data['totalPage']=adminProcess.getDataListPage(tableName='news')
|
||
|
data['currentPage'] = int(page)
|
||
|
data['news']=adminProcess.getDataListByPage(tableName='news',page=int(page))
|
||
|
data['timeinfo'], data['temp'] = adminProcess.getTemp()
|
||
|
log0.info("进入新闻页面成功")
|
||
|
return render_template("front/news.html",data=data)
|
||
|
|
||
|
''' 后台登录处理'''
|
||
|
@user.route("/admin/login",methods=['POST'])
|
||
|
def adminlogin():
|
||
|
username = request.form['name']
|
||
|
userpwd = request.form['password']
|
||
|
if adminProcess.login(username,userpwd):
|
||
|
session['username']=username
|
||
|
return redirect("/admin/index")
|
||
|
else:
|
||
|
return redirect('/admin')
|
||
|
|
||
|
'''搜索请求'''
|
||
|
@user.route("/search",methods=['POST'])
|
||
|
def search():
|
||
|
kw = request.form['keyword']
|
||
|
# 组转自己的搜索引擎
|
||
|
data={}
|
||
|
data['result']=adminProcess.searchdata(kw)
|
||
|
log0.info("搜索关键词"+kw)
|
||
|
return render_template("front/search.html",data=data)
|
||
|
|
||
|
''' 后台登录注销'''
|
||
|
@user.route("/admin/logout")
|
||
|
def adminlogout():
|
||
|
session.clear()
|
||
|
return jsonify({'code':200,'msg':'注销成功!'})
|
||
|
|
||
|
# 进入系统后台路由,要求登录
|
||
|
@user.route("/admin")
|
||
|
def admin():
|
||
|
return render_template("admin.html")
|
||
|
|
||
|
# 登录成果后进入系统管理首页
|
||
|
@user.route("/admin/index")
|
||
|
def admin_index():
|
||
|
return render_template("admin/index.html")
|