response js_code

This commit is contained in:
2025-02-26 16:37:17 +08:00
parent 78d13ece36
commit 446210ea4c
5 changed files with 24 additions and 5 deletions

BIN
data.db

Binary file not shown.

BIN
data.xlsx

Binary file not shown.

View File

@ -1,3 +1,6 @@
body {
background-color: azure;
}
main { main {
text-align: center; text-align: center;
vertical-align: middle; vertical-align: middle;

View File

@ -7,8 +7,9 @@
<a href="/"><button type="button">返回</button></a> <a href="/"><button type="button">返回</button></a>
<div></div><div></div> <div></div><div></div>
</div> </div>
<hr>
<form method=post enctype=multipart/form-data action="/import"> <form method=post enctype=multipart/form-data action="/import">
<div><input style="width:300px;" type=file name=选择></div> <div><input style="width:300px;" type=file name=file></div>
<div class="handler"><div></div><input style="width:100px;"type=submit value=上传></div> <div class="handler"><div></div><input style="width:100px;"type=submit value=上传></div>
</form> </form>
<div> <div>

View File

@ -21,9 +21,16 @@ def index():
@app.route('/check', methods=['GET']) @app.route('/check', methods=['GET'])
def check(): def check():
inventory = Inventory.query.filter_by(checked=False).first() inventory = Inventory.query.filter_by(checked=False).first()
print(inventory)
if not inventory: if not inventory:
return "All checked" js_code = '''
<script>
alert("未导入Excel或已完成!");
location.href="https://a.yum2.cc";
</script>
'''
response = make_response(js_code)
response.headers['Content-Type'] = 'application/javascript'
return response
return render_template('check.html',inventory=inventory) return render_template('check.html',inventory=inventory)
@app.route('/get_inventory', methods=['POST']) @app.route('/get_inventory', methods=['POST'])
@ -90,7 +97,15 @@ def import_file():
file_path = 'data.xlsx' file_path = 'data.xlsx'
file.save(file_path) file.save(file_path)
import_from_xlsx(file_path) import_from_xlsx(file_path)
return '<script>alert("文件导入成功!");location.href="https://a.yum2.cc";</script>' js_code = '''
<script>
alert("文件导入成功!");
location.href="https://a.yum2.cc";
</script>
'''
response = make_response(js_code)
response.headers['Content-Type'] = 'application/javascript'
return response
return redirect(url_for('upload_form')) return redirect(url_for('upload_form'))
@ -108,7 +123,7 @@ def download_xlsx():
# 设置工作表名称 # 设置工作表名称
ws.title = "Inventory" ws.title = "Inventory"
# 设置工作表列名 # 设置工作表列名
ws.append(["sort", "location", "tag", "amount", "checked"]) ws.append(["序号", "位置", "标签", "数量", "已确认"])
# 写入数据 # 写入数据
for inventory in inventorys: for inventory in inventorys:
ws.append([inventory.sort, inventory.location, inventory.tag, inventory.amount, inventory.checked]) ws.append([inventory.sort, inventory.location, inventory.tag, inventory.amount, inventory.checked])