main
caizhizhong 6 months ago
parent b15ebfacfe
commit c6d7523791

124
app.py

@ -0,0 +1,124 @@
from flask import Flask, render_template, request, jsonify
import webbrowser
import sqldb
app = Flask(__name__)
#进入首页
@app.route('/')
# def hei():
# return render_template('test.html')
#
#进入'index'页面
@app.route('/index/')
#进入后自动运行下面函数
def index():
return render_template('goods.html')
@app.route('/other/')
def other():
return render_template('records.html')
@app.route('/count/')
def count():
return render_template('count.html')
@app.route('/data/goods/')
def getgoods():
#data数据要以这种方式命名是为了LAYUI的数据要求
data = {"code": 0, "msg": ""}
name = request.args.get('search_name') or ''
model = request.args.get('search_model') or ''
process = request.args.get('search_process') or ''
lst = sqldb.select_goods(name, model, process)
for i in lst:
i['needbuy'] = int(i['safenumber']) - int(i['number'])
data['count'] = len(lst)
data['data'] = lst
return data
@app.route('/data/records/')
def getrecords():
data = {"code": 0, "msg": ""}
lst = sqldb.select_records()
data['count'] = len(lst)
data['data'] = lst
return data
@app.route('/data/counts/')
def getcounts():
process = request.args.get('process')
inorout = request.args.get('inorout')
date1 = request.args.get('date1')
date2 = request.args.get('date2') + " 23:59:59"
data = {"code": 0, "msg": ""}
lst = sqldb.count_goods(process, inorout, date1, date2)
data['count'] = len(lst)
data['data'] = lst
return data
@app.route('/op/<kind>')
def op(kind):
if kind == 'in':
id = request.args.get('in_id')
change = request.args.get('in_change')
people = request.args.get('in_people');
sqldb.insert_records(id, 1, change, people)
elif kind == 'out':
id = request.args.get('out_id')
change = request.args.get('out_change')
people = request.args.get('out_people');
sqldb.insert_records(id, 0, change, people)
elif kind == 'add':
name = request.args.get('add_name')
model = request.args.get('add_model')
factory = request.args.get('add_factory') or ''
process = request.args.get('add_process')
price = request.args.get('add_price') or 0
sqldb.insert_goods(name, model, factory, process, price)
elif kind == 'del':
id = request.args.get('del_id')
sqldb.del_goods(id)
elif kind == 'edit':
# 更新物品信息
id = request.args.get('edit_id')
name = request.args.get('edit_name')
model = request.args.get('edit_model')
process = request.args.get('edit_process')
factory = request.args.get('edit_factory') or ''
price = request.args.get('edit_price') or 0
safe_number = request.args.get('edit_safenumber') or 0
sqldb.update_goods(id, name, model, process, factory, price,safe_number)
return jsonify()
@app.route('/data/<kind>')
def get_names(kind):
data = {"code": 0, "msg": ""}
lst = sqldb.get_names(kind)
# print(lst)
for i in list(lst):
if i[kind] is None:
lst.pop(lst.index(i))
data['count'] = len(lst)
data['data'] = lst
return data
@app.route('/error/')
def error():
return "500"
if __name__ == '__main__':
webbrowser.open("http://127.0.0.1:5000/")
app.run()
Loading…
Cancel
Save