liufumingren bd2363bf00 chore: 初始化仓库(backend / frontend / extension 三块)
- backend/:Egg 3 纯 JSON 接口服务(MySQL 8 + Redis),全部走 header 令牌鉴权;
  已彻底去掉服务端渲染(删除 page 控制器 / app/view / nunjucks / session / CSRF),
  开发时把页面请求反代到前端 dev server,生产托管 frontend/dist(SPA 回退)。
  单测 91 个通过(不需要本机数据库)。
- frontend/:Vite + Vue3 + TypeScript 的 SPA(登录 / 注册 / 找回密码 / 扫码登录与确认 /
  首页统计 / 设备管理 / 扫码记录 / 个人中心 / 测试页),vue-tsc 类型检查与构建通过。
- extension/:MV3 浏览器扩展(零构建),注入第三方 WMS 页面识别运单号并打开溯源页。
- 忽略规则统一放根 .gitignore:node_modules、dist、logs / logs-*、run、typings、
  .env*、config.local.js(含本机数据库与 Redis 密码,绝不入库)。
2026-10-17 08:50:32 +08:00

49 lines
1.6 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

'use strict';
const { Controller } = require('egg');
/**
* web 用户端:**我自己设备的扫码记录**(`/api/web/records`)
*
* 鉴权:`middleware.apiAuth()`;范围限定为「当前用户名下的设备」——
* 先取我的设备 id 列表,再拿它去过滤记录(`service.scan.listRecords({ scannerIds })`)。
*/
class WebRecordController extends Controller {
/**
* GET /api/web/records
* query: `?page=&pageSize=&deviceId=&channelId=&barcode=&startTime=&endTime=`
* - `deviceId` 只能填自己名下的设备(否则 404);不填 = 所有设备
* - `startTime` / `endTime` 支持 `2026-10-16 12:00:00`、10/13 位时间戳
*/
async index() {
const { ctx } = this;
const { page, pageSize, deviceId, channelId, barcode, startTime, endTime } = ctx.query;
const ids = await ctx.service.scanner.idsOfUser(ctx.state.user.id);
let scannerIds = ids;
if (deviceId) {
const id = Number(deviceId);
if (!ids.includes(id)) ctx.throw(404, '设备不存在或不属于当前账号');
scannerIds = [ id ];
}
const data = await ctx.service.scan.listRecords({
page, pageSize, scannerIds, channelId, barcode, startTime, endTime,
});
ctx.body = {
ok: true,
data: Object.assign({}, data, {
// 拍平所属设备(前端表格直接显示),免得前端再查一次
list: data.list.map(row => Object.assign({}, row, {
deviceSn: row.scanner ? row.scanner.sn : null,
deviceName: row.scanner ? row.scanner.name : null,
scanner: undefined,
})),
}),
};
}
}
module.exports = WebRecordController;