From 9bfefd635c549afbd18c5bd85ee4d2a903a55aa5 Mon Sep 17 00:00:00 2001 From: houhuan Date: Sun, 7 Dec 2025 16:06:51 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dbug=EF=BC=8C=E5=BD=92?= =?UTF-8?q?=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vercel/project.json | 1 - .vercelignore | 7 ------ README.md | 55 +++++++++++++++++++++++++++++--------------- static/index.html | 4 ++-- vercel.json | 1 - 5 files changed, 39 insertions(+), 29 deletions(-) delete mode 100644 .vercel/project.json delete mode 100644 .vercelignore delete mode 100644 vercel.json diff --git a/.vercel/project.json b/.vercel/project.json deleted file mode 100644 index bdfcecc..0000000 --- a/.vercel/project.json +++ /dev/null @@ -1 +0,0 @@ -{"projectId":"prj_d4Snf7Qo4GMchiUVyezwVqJieNi6","orgId":"team_hyS3Eg5TitOtyQ1YVgGLzKUz","projectName":"trae_table_ls74","neverMindDeployCard":true} \ No newline at end of file diff --git a/.vercelignore b/.vercelignore deleted file mode 100644 index a48e5d3..0000000 --- a/.vercelignore +++ /dev/null @@ -1,7 +0,0 @@ -node_modules -build -dist -.git -.trae -.log -.figma \ No newline at end of file diff --git a/README.md b/README.md index d31a134..ebcaead 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,15 @@ -# 商品查询系统 +# 益选便利店商品查询 -## 功能 -- 导入Excel为数据库(以条码为主键Upsert) -- 查询商品:条码精确查、名称模糊查 -- 响应式前端,手机/电脑可用 +## 概述 +- 基于 FastAPI + SQLite 的轻量查询系统,适配手机和桌面 +- 支持导入 Excel,条码为主键自动插入/更新(Upsert) +- 支持条码部分匹配(前缀/后缀/任意包含)与名称关键词搜索 +- 内置扫码入口:支持浏览器原生条码识别与拍照识别兜底 -## 运行 -1. 安装依赖:`python -m pip install fastapi "uvicorn[standard]" pandas openpyxl python-multipart` -2. 启动服务:`python -m uvicorn app.main:app --host 0.0.0.0 --port 57777`(或设置环境变量 `PORT=57777`) -3. 打开页面:`http://localhost:57777/` +## 本地运行 +- 安装依赖:`python -m pip install fastapi "uvicorn[standard]" pandas openpyxl python-multipart` +- 启动服务:`python -m uvicorn app.main:app --host 0.0.0.0 --port 57777` +- 访问页面:`http://localhost:57777/` ## 导入 - 页面“导入Excel”选择文件并提交 @@ -16,22 +17,40 @@ ## 接口 - `POST /import` 表单上传`file` -- `GET /products/{barcode}` 返回名称、进价、卖价、条码 -- `GET /products?q=关键词&limit=20` 名称模糊查询 +- `GET /products/{barcode}` 精确条码查询 +- `GET /products?q=关键词&limit=20&page=1&sort=name&order=asc` 列表查询 + - 当 `q` 为数字时:支持条码前缀、后缀与任意包含匹配;同时匹配名称包含 + - 当 `q` 为文本时:按名称包含匹配 - `GET /health` 健康检查 ## 数据库 - SQLite 文件:`data/products.db` - 表:`products(barcode primary key, name, purchase_price, sale_price, category, created_at, source_file)` - 索引:`idx_products_name(name)` + - 性能:启用 WAL 与适度同步,提升并发读取 -## 注意 -- Excel中文列名需一致 -- 非数字价格会被跳过或置为空 -- 条码为空的行跳过 ## Docker(推荐部署) - 构建并启动:`docker compose up --build -d` -- 端口:宿主机映射 `57777:57777` -- 数据与静态资源挂载: +- 端口映射:`57777:57777`(保持不变) +- 卷挂载: - `./data:/app/data`(SQLite 持久化) - - `./static:/app/static:ro`(前端文件,无需重建镜像即可更新) + - `./static:/app/static:ro`(前端文件可直接更新,无需重建) +- 宝塔/Nginx(可选):反代到 `http://127.0.0.1:57777` 并启用 HTTPS +- 详见《部署文档.md》 + +## 前端扫码 +- 优先使用浏览器原生 `BarcodeDetector` 实时识别 +- 非安全上下文或不支持时,自动切换为“拍照识别”方式 +- 识别成功自动填充并触发查询 + +## 项目结构 +- `app/` 后端 FastAPI +- `static/` 前端页面与脚本、样式 +- `data/` 运行时生成的 SQLite 数据库 +- `Dockerfile`、`docker-compose.yml` 部署配置 +- `部署文档.md` 服务器部署说明 + +## 常见问题 +- 无法唤起相机:请通过 HTTPS 域名访问或使用支持的浏览器;HTTP 下自动切换为拍照识别 +- 构建缓存问题:使用 `docker compose build --no-cache && docker compose up -d` +- 中文命令行乱码:页面显示正常;确保浏览器为 UTF-8 编码 diff --git a/static/index.html b/static/index.html index 3897922..c496def 100644 --- a/static/index.html +++ b/static/index.html @@ -3,7 +3,7 @@ - 商品查询 + 益选便利店商品查询 @@ -14,7 +14,7 @@
-

商品查询

+

益选便利店商品查询