This commit is contained in:
2025-02-26 05:09:27 +00:00
parent 330f8d3b8c
commit 57ade9911d
8 changed files with 18 additions and 184 deletions

View File

@ -18,7 +18,6 @@ class Inventory(db.Model):
tag = db.Column(db.Text) tag = db.Column(db.Text)
amount = db.Column(db.Integer) amount = db.Column(db.Integer)
checked = db.Column(db.Boolean, default=False) checked = db.Column(db.Boolean, default=False)
name = db.Column(db.Text)
# mtime = db.Column(db.Date) # mtime = db.Column(db.Date)

View File

@ -16,8 +16,8 @@ function checknext() {
var id = parseInt(idelement.innerText, 10); // 第二个参数10表示解析的基数这里是十进制 var id = parseInt(idelement.innerText, 10); // 第二个参数10表示解析的基数这里是十进制
var tagelement = document.getElementById("inventory-tag"); var tagelement = document.getElementById("inventory-tag");
var tag = tagelement.innerText; var tag = tagelement.innerText;
var name = "A"
var msg = document.getElementById("flash-msg"); var msg = document.getElementById("flash-msg");
var location = document.getElementById("inventory-location");
// var params = new URLSearchParams({ // var params = new URLSearchParams({
// checked: 1, // checked: 1,
// id: id, // id: id,
@ -29,7 +29,7 @@ function checknext() {
headers: { headers: {
'Content-Type': 'application/json' '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(response => response.json())
.then(data => { .then(data => {
@ -38,57 +38,9 @@ function checknext() {
tagelement.innerText = data.tag; tagelement.innerText = data.tag;
idelement.innerText = data.id; idelement.innerText = data.id;
msg.innerText = data.checkedone + " 盘点数 " + data.checkedamount; msg.innerText = data.checkedone + " 盘点数 " + data.checkedamount;
location.innerText = data.location;
}) })
.catch(error => console.error('Error:', error)); .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();

View File

@ -16,9 +16,8 @@
{% block content %}{% endblock %} {% block content %}{% endblock %}
<footer> <footer>
{% block footer %} {% block footer %}
<small id="username"> luff <small> 2025 &copy; SDHLMH
</small> </small>
<!-- <p><a id="bottom" href="#" title="Go Top">&uarr;</a></p> -->
{% endblock %} {% endblock %}
</footer> </footer>
</main> </main>

View File

@ -7,7 +7,7 @@
<div> <div>
<div class="handler"> <div class="handler">
<a href="/"><button type="button">返回</button></a> <a href="/"><button type="button">返回</button></a>
<div></div><div><p id="inventory-id" hidden>{{ inventory.id }}</p></div> <div id="inventory-location"></div><div><p id="inventory-id" hidden>{{ inventory.id }}</p></div>
</div> </div>
<h1 id="inventory-tag">{{ inventory.tag }}</h1> <h1 id="inventory-tag">{{ inventory.tag }}</h1>
<hr> <hr>

View File

@ -5,9 +5,6 @@
<form method=get action="/upload"> <form method=get action="/upload">
<input style="width:150px;" type=submit value=上传XLSX> <input style="width:150px;" type=submit value=上传XLSX>
</form> </form>
<form method=get action="/list">
<input style="width:150px;" type=submit value=显示列表>
</form>
<form method=get action="/check"> <form method=get action="/check">
<input style="width:150px;" type=submit value=继续盘点> <input style="width:150px;" type=submit value=继续盘点>
</form> </form>

View File

@ -1,62 +0,0 @@
{% extends 'base.html' %}
{% block content %}
<div id="flash-msg">
开始盘点>>>
</div>
<div>
<div class="handler">
<a href="/"><button type="button">返回</button></a>
<div></div><div><p id="inventory-id" hidden>0</p></div>
</div>
<div class="handler">
<button onclick="previousPage()" type="button">上页</button>
<div></div>
<button onclick="nextPage()" type="button">下页</button>
</div>
<table style="width:100%">
<tr>
<th>标签</th>
<th>数量</th>
<th>已盘</th>
</tr>
<tr>
<td id="tag1">一月</td>
<td id="amount1">¥3400</td>
<td id="checked1">¥3400</td>
</tr>
<tr>
<td id="tag2">一月</td>
<td id="amount2">¥3400</td>
<td id="checked2">¥3400</td>
</tr>
<tr>
<td id="tag3">一月</td>
<td id="amount3">¥3400</td>
<td id="checked3">¥3400</td>
</tr>
<tr>
<td id="tag4">一月</td>
<td id="amount4">¥3400</td>
<td id="checked4">¥3400</td>
</tr>
<tr>
<td id="tag5">一月</td>
<td id="amount5">¥3400</td>
<td id="checked5">¥3400</td>
</tr>
<tr>
<td id="tag6">一月</td>
<td id="amount6">¥3400</td>
<td id="checked6">¥3400</td>
</tr>
</table>
<div class="handler">
<button onclick="previousPage()" type="button">上页</button>
<div></div>
<button onclick="nextPage()" type="button">下页</button>
</div>
</div>
{% endblock %}

View File

@ -3,9 +3,10 @@
{% block content %} {% block content %}
<h1>上传Excel XLSX文件</h1> <h1>上传Excel XLSX文件</h1>
<form method=get action="/"> <div class="handler">
<input style="width:150px;" type=submit value=返回> <a href="/"><button type="button">返回</button></a>
</form> <div></div><div></div>
</div>
<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=选择></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>

View File

@ -5,8 +5,9 @@
:copyright: © 2025 luffmims <luffmims@hotmaill.com> :copyright: © 2025 luffmims <luffmims@hotmaill.com>
:license: MIT, see LICENSE for more details. :license: MIT, see LICENSE for more details.
""" """
import time
from flask import jsonify, redirect, request, url_for, render_template, send_file 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 io import BytesIO
from openpyxl import Workbook from openpyxl import Workbook
from inventory_check import app, db from inventory_check import app, db
@ -17,10 +18,6 @@ from werkzeug.exceptions import BadRequest
def index(): def index():
return render_template('index.html') return render_template('index.html')
@app.route('/list')
def list():
return render_template('list.html')
@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()
@ -36,7 +33,6 @@ def update_inventory():
data = request.get_json() data = request.get_json()
inventory_id = data['id'] inventory_id = data['id']
amount = data['amount'] amount = data['amount']
name = data['name']
if not inventory_id or not amount: if not inventory_id or not amount:
raise BadRequest('Missing inventory id or amount') raise BadRequest('Missing inventory id or amount')
@ -47,7 +43,6 @@ def update_inventory():
raise BadRequest('Inventory not found') raise BadRequest('Inventory not found')
checkedone = inventory.tag checkedone = inventory.tag
inventory.amount = amount inventory.amount = amount
inventory.name = name
inventory.checked = True inventory.checked = True
# 提交更改 # 提交更改
@ -63,6 +58,7 @@ def update_inventory():
return jsonify({ return jsonify({
'id': inventory.id, 'id': inventory.id,
'tag': inventory.tag, 'tag': inventory.tag,
'location': inventory.location,
'amount': inventory.amount, 'amount': inventory.amount,
'checkedone': checkedone, 'checkedone': checkedone,
'checkedamount': amount 'checkedamount': amount
@ -94,7 +90,7 @@ 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 '文件导入成功! <a href="/">返回</a>' return '<script>alert("文件导入成功!");location.href="https://a.yum2.cc";</script>'
return redirect(url_for('upload_form')) return redirect(url_for('upload_form'))
@ -102,6 +98,7 @@ def import_file():
@app.route('/download-xlsx') @app.route('/download-xlsx')
def download_xlsx(): def download_xlsx():
filename = time.strftime("%Y%m%d.xlsx", time.localtime())
# 创建一个 Excel 工作簿 # 创建一个 Excel 工作簿
inventorys = Inventory.query.all() # 查询所有数据, and sort data by sort inventorys = Inventory.query.all() # 查询所有数据, and sort data by sort
# 创建一个工作簿 # 创建一个工作簿
@ -111,65 +108,16 @@ def download_xlsx():
# 设置工作表名称 # 设置工作表名称
ws.title = "Inventory" ws.title = "Inventory"
# 设置工作表列名 # 设置工作表列名
ws.append(["sort", "location", "tag", "amount", "checked", "name"]) ws.append(["sort", "location", "tag", "amount", "checked"])
# 写入数据 # 写入数据
for inventory in inventorys: 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() output = BytesIO()
wb.save(output) wb.save(output)
output.seek(0) # 移动到字节流的开头 output.seek(0) # 移动到字节流的开头
# 设置响应头,提供下载功能 # 设置响应头,提供下载功能
response = make_response(send_file(output, mimetype='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', as_attachment=True, download_name='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=example.xlsx" response.headers["Content-Disposition"] = "attachment; filename=" + filename
return response 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)