From 57ade9911dff634adba7a029cc300c4ee5e14d1b Mon Sep 17 00:00:00 2001 From: luff Date: Wed, 26 Feb 2025 05:09:27 +0000 Subject: [PATCH] simplify --- inventory_check/models.py | 1 - inventory_check/static/js/script.js | 54 ++------------------- inventory_check/templates/base.html | 3 +- inventory_check/templates/check.html | 2 +- inventory_check/templates/index.html | 3 -- inventory_check/templates/list.html | 62 ------------------------ inventory_check/templates/upload.html | 7 +-- inventory_check/views.py | 70 ++++----------------------- 8 files changed, 18 insertions(+), 184 deletions(-) delete mode 100644 inventory_check/templates/list.html diff --git a/inventory_check/models.py b/inventory_check/models.py index 759a269..bdf8206 100644 --- a/inventory_check/models.py +++ b/inventory_check/models.py @@ -18,7 +18,6 @@ class Inventory(db.Model): tag = db.Column(db.Text) amount = db.Column(db.Integer) checked = db.Column(db.Boolean, default=False) - name = db.Column(db.Text) # mtime = db.Column(db.Date) diff --git a/inventory_check/static/js/script.js b/inventory_check/static/js/script.js index 6a33d2b..18ab8c7 100644 --- a/inventory_check/static/js/script.js +++ b/inventory_check/static/js/script.js @@ -16,8 +16,8 @@ function checknext() { var id = parseInt(idelement.innerText, 10); // 第二个参数10表示解析的基数,这里是十进制 var tagelement = document.getElementById("inventory-tag"); var tag = tagelement.innerText; - var name = "A" var msg = document.getElementById("flash-msg"); + var location = document.getElementById("inventory-location"); // var params = new URLSearchParams({ // checked: 1, // id: id, @@ -29,7 +29,7 @@ function checknext() { headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({id: id, amount: amount.value, name: name}) + body: JSON.stringify({id: id, amount: amount.value}) }) .then(response => response.json()) .then(data => { @@ -38,57 +38,9 @@ function checknext() { tagelement.innerText = data.tag; idelement.innerText = data.id; msg.innerText = data.checkedone + " 盘点数 " + data.checkedamount; + location.innerText = data.location; }) .catch(error => console.error('Error:', error)); } -// function apiAuth() { -// if (!window.h5sdk) { -// alert("请在飞书客户端中打开"); -// return; -// } - -// window.h5sdk.ready(() => { -// tt.requestAccess({ -// appID: "your_app_id", -// scopeList: [], -// success(res) { -// // 将 code 发送到服务端 -// fetch(`/callback?code=${res.code}`) -// .then(response => response.json()) -// .then(data => { -// console.log("用户信息:", data); -// // 在页面上展示用户姓名 -// document.getElementById("username").innerText = data.name; -// }); -// }, -// fail(err) { -// console.error("获取授权码失败:", err); -// } -// }); -// }); -// } -// apiAuth(); - -function apiAuth() { - tt.requestAccess({ - appID: "cli_a70da4f71bf1d00c", - scopeList: [], - success(res) { - // 将 code 发送到服务端 - fetch(`/callback?code=${res.code}`) - .then(response => response.json()) - .then(data => { - // console.log("用户信息:", data); - // 在页面上展示用户姓名 - document.getElementById("username").innerText = data.name; - }); - }, - fail(err) { - console.error("获取授权码失败:", err); - } - }); - }; - -apiAuth(); \ No newline at end of file diff --git a/inventory_check/templates/base.html b/inventory_check/templates/base.html index 77704a1..378e79d 100644 --- a/inventory_check/templates/base.html +++ b/inventory_check/templates/base.html @@ -16,9 +16,8 @@ {% block content %}{% endblock %} diff --git a/inventory_check/templates/check.html b/inventory_check/templates/check.html index 1e7c2eb..4d2adfc 100644 --- a/inventory_check/templates/check.html +++ b/inventory_check/templates/check.html @@ -7,7 +7,7 @@
-
+

{{ inventory.tag }}


diff --git a/inventory_check/templates/index.html b/inventory_check/templates/index.html index daa21de..ea232fb 100644 --- a/inventory_check/templates/index.html +++ b/inventory_check/templates/index.html @@ -5,9 +5,6 @@
-
- -
diff --git a/inventory_check/templates/list.html b/inventory_check/templates/list.html deleted file mode 100644 index 1509df8..0000000 --- a/inventory_check/templates/list.html +++ /dev/null @@ -1,62 +0,0 @@ -{% extends 'base.html' %} - -{% block content %} -
- 开始盘点>>> -
-
- -
- -
-
-
- -
- -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
标签数量已盘
一月¥3400¥3400
一月¥3400¥3400
一月¥3400¥3400
一月¥3400¥3400
一月¥3400¥3400
一月¥3400¥3400
-
- -
- -
-
-{% endblock %} - diff --git a/inventory_check/templates/upload.html b/inventory_check/templates/upload.html index 68786e6..b6822af 100644 --- a/inventory_check/templates/upload.html +++ b/inventory_check/templates/upload.html @@ -3,9 +3,10 @@ {% block content %}

上传Excel XLSX文件

-
- -
+
+ +
+
diff --git a/inventory_check/views.py b/inventory_check/views.py index fe404d0..2982634 100644 --- a/inventory_check/views.py +++ b/inventory_check/views.py @@ -5,8 +5,9 @@ :copyright: © 2025 luffmims :license: MIT, see LICENSE for more details. """ +import time from flask import jsonify, redirect, request, url_for, render_template, send_file -from flask import make_response, session +from flask import make_response from io import BytesIO from openpyxl import Workbook from inventory_check import app, db @@ -17,10 +18,6 @@ from werkzeug.exceptions import BadRequest def index(): return render_template('index.html') -@app.route('/list') -def list(): - return render_template('list.html') - @app.route('/check', methods=['GET']) def check(): inventory = Inventory.query.filter_by(checked=False).first() @@ -36,7 +33,6 @@ def update_inventory(): data = request.get_json() inventory_id = data['id'] amount = data['amount'] - name = data['name'] if not inventory_id or not amount: raise BadRequest('Missing inventory id or amount') @@ -47,7 +43,6 @@ def update_inventory(): raise BadRequest('Inventory not found') checkedone = inventory.tag inventory.amount = amount - inventory.name = name inventory.checked = True # 提交更改 @@ -63,6 +58,7 @@ def update_inventory(): return jsonify({ 'id': inventory.id, 'tag': inventory.tag, + 'location': inventory.location, 'amount': inventory.amount, 'checkedone': checkedone, 'checkedamount': amount @@ -94,7 +90,7 @@ def import_file(): file_path = 'data.xlsx' file.save(file_path) import_from_xlsx(file_path) - return '文件导入成功! 返回' + return '' return redirect(url_for('upload_form')) @@ -102,6 +98,7 @@ def import_file(): @app.route('/download-xlsx') def download_xlsx(): + filename = time.strftime("%Y%m%d.xlsx", time.localtime()) # 创建一个 Excel 工作簿 inventorys = Inventory.query.all() # 查询所有数据, and sort data by sort # 创建一个工作簿 @@ -111,65 +108,16 @@ def download_xlsx(): # 设置工作表名称 ws.title = "Inventory" # 设置工作表列名 - ws.append(["sort", "location", "tag", "amount", "checked", "name"]) + ws.append(["sort", "location", "tag", "amount", "checked"]) # 写入数据 for inventory in inventorys: - ws.append([inventory.sort, inventory.location, inventory.tag, inventory.amount, inventory.checked, inventory.name]) + ws.append([inventory.sort, inventory.location, inventory.tag, inventory.amount, inventory.checked]) output = BytesIO() wb.save(output) output.seek(0) # 移动到字节流的开头 # 设置响应头,提供下载功能 - response = make_response(send_file(output, mimetype='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', as_attachment=True, download_name='example.xlsx')) - response.headers["Content-Disposition"] = "attachment; filename=example.xlsx" + response = make_response(send_file(output, mimetype='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', as_attachment=True, download_name=filename)) + response.headers["Content-Disposition"] = "attachment; filename=" + filename return response - -# 应用凭证信息 -APP_ID = "cli_a70da4f71bf1d00c" -APP_SECRET = "4zV9xcunWUE8E4kKS4hw5e3m6pgjoduz" - -# 获取 app_access_token -def get_app_access_token(): - url = "https://open.feishu.cn/open-apis/auth/v3/app_access_token/internal/" - payload = { - "app_id": APP_ID, - "app_secret": APP_SECRET - } - response = request.post(url, json=payload) - return response.json().get("app_access_token") - -# 获取 user_access_token -def get_user_access_token(app_access_token, code): - url = "https://open.feishu.cn/open-apis/authen/v1/access_token" - headers = {"Authorization": f"Bearer {app_access_token}"} - payload = {"grant_type": "authorization_code", "code": code} - response = request.post(url, headers=headers, json=payload) - return response.json().get("data", {}).get("access_token") - -# 获取用户信息 -def get_user_info(user_access_token): - url = "https://open.feishu.cn/open-apis/authen/v1/user_info" - headers = {"Authorization": f"Bearer {user_access_token}"} - response = request.get(url, headers=headers) - return response.json().get("data") - -@app.route("/callback", methods=["GET"]) -def callback(): - code = request.args.get("code") - if not code: - return jsonify({"error": "Missing code parameter"}), 400 - - # 获取 app_access_token - app_access_token = get_app_access_token() - - # 获取 user_access_token - user_access_token = get_user_access_token(app_access_token, code) - - # 获取用户信息 - user_info = get_user_info(user_access_token) - - # 存储用户信息到 session - session["user_info"] = user_info - - return jsonify(user_info) \ No newline at end of file