- 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 密码,绝不入库)。
45 lines
1.3 KiB
JavaScript
45 lines
1.3 KiB
JavaScript
'use strict';
|
||
|
||
const { Controller } = require('egg');
|
||
|
||
/**
|
||
* web 用户端:首页统计(`/api/web/stats`)
|
||
*
|
||
* 只统计**当前用户名下**的数据(设备数 / 通道数 / 扫码记录数 + 最近一条扫码记录),
|
||
* 与运维视角的统计(`service.user.count()` 那种全站数字)区分开。
|
||
*/
|
||
class WebStatsController extends Controller {
|
||
/** GET /api/web/stats */
|
||
async index() {
|
||
const { ctx } = this;
|
||
const userId = ctx.state.user.id;
|
||
const ids = await ctx.service.scanner.idsOfUser(userId);
|
||
|
||
const [ deviceCount, channelCount, recordCount, latest ] = await Promise.all([
|
||
ctx.service.scanner.count({ userId }),
|
||
ctx.service.scan.countChannels({ scannerIds: ids }),
|
||
ctx.service.scan.countRecords({ scannerIds: ids }),
|
||
ctx.service.scan.listRecords({ scannerIds: ids, page: 1, pageSize: 1 }),
|
||
]);
|
||
|
||
const row = latest.list[0] || null;
|
||
ctx.body = {
|
||
ok: true,
|
||
data: {
|
||
deviceCount,
|
||
channelCount,
|
||
recordCount,
|
||
latestRecord: row ? {
|
||
id: row.id,
|
||
barcode: row.barcode,
|
||
channelId: row.channelId,
|
||
deviceSn: row.scanner ? row.scanner.sn : null,
|
||
scanTime: row.scanTime,
|
||
} : null,
|
||
},
|
||
};
|
||
}
|
||
}
|
||
|
||
module.exports = WebStatsController;
|