simplify
This commit is contained in:
@ -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)
|
||||
|
||||
|
||||
|
@ -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();
|
@ -16,9 +16,8 @@
|
||||
{% block content %}{% endblock %}
|
||||
<footer>
|
||||
{% block footer %}
|
||||
<small id="username"> luff
|
||||
<small> 2025 © SDHLMH
|
||||
</small>
|
||||
<!-- <p><a id="bottom" href="#" title="Go Top">↑</a></p> -->
|
||||
{% endblock %}
|
||||
</footer>
|
||||
</main>
|
||||
|
@ -7,7 +7,7 @@
|
||||
<div>
|
||||
<div class="handler">
|
||||
<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>
|
||||
<h1 id="inventory-tag">{{ inventory.tag }}</h1>
|
||||
<hr>
|
||||
|
@ -5,9 +5,6 @@
|
||||
<form method=get action="/upload">
|
||||
<input style="width:150px;" type=submit value=上传XLSX>
|
||||
</form>
|
||||
<form method=get action="/list">
|
||||
<input style="width:150px;" type=submit value=显示列表>
|
||||
</form>
|
||||
<form method=get action="/check">
|
||||
<input style="width:150px;" type=submit value=继续盘点>
|
||||
</form>
|
||||
|
@ -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 %}
|
||||
|
@ -3,9 +3,10 @@
|
||||
|
||||
{% block content %}
|
||||
<h1>上传Excel XLSX文件</h1>
|
||||
<form method=get action="/">
|
||||
<input style="width:150px;" type=submit value=返回>
|
||||
</form>
|
||||
<div class="handler">
|
||||
<a href="/"><button type="button">返回</button></a>
|
||||
<div></div><div></div>
|
||||
</div>
|
||||
<form method=post enctype=multipart/form-data action="/import">
|
||||
<div><input style="width:300px;" type=file name=选择></div>
|
||||
<div class="handler"><div></div><input style="width:100px;"type=submit value=上传></div>
|
||||
|
@ -5,8 +5,9 @@
|
||||
:copyright: © 2025 luffmims <luffmims@hotmaill.com>
|
||||
: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 '文件导入成功! <a href="/">返回</a>'
|
||||
return '<script>alert("文件导入成功!");location.href="https://a.yum2.cc";</script>'
|
||||
|
||||
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)
|
Reference in New Issue
Block a user