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

43 lines
2.0 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';
/**
* 扫描器(设备)表模型(scanners)
*
* 设备身份只有一种:`GET /api/device/login` 扫码登录换来的长期 JWT
* (建记录/绑定都发生在「手机确认登录」那一刻),库里只存当前令牌的 `jti`(重签即失效)。
* `user_id` 为空表示尚未绑定账号。
*/
module.exports = (app) => {
const { BIGINT, STRING, TINYINT, DATE } = app.Sequelize;
const Scanner = app.model.define('scanner', {
id: { type: BIGINT.UNSIGNED, primaryKey: true, autoIncrement: true, comment: '主键' },
userId: { type: BIGINT.UNSIGNED, comment: '绑定的用户 id' },
sn: { type: STRING(64), allowNull: false, comment: '扫描器 SN(唯一标识)' },
name: { type: STRING(64), allowNull: false, defaultValue: '', comment: '名称 / 别名' },
vendor: { type: STRING(64), comment: '厂商' },
model: { type: STRING(64), comment: '型号' },
firmware: { type: STRING(32), comment: '固件 / 客户端版本' },
ip: { type: STRING(45), comment: '最近登录 IP' },
// ⚠️ 历史字段:早期「sn + secret 注册/登录」用的密钥哈希,现在已不再写入/校验(列保留)
secretHash: { type: STRING(100), comment: '历史字段:扫描器密钥哈希(已废弃)' },
// 库里不存 JWT 本体,只存当前令牌的 jti:重签令牌会让旧令牌立即失效
tokenJti: { type: STRING(64), comment: '当前 JWT 的 jti' },
tokenExpiresAt: { type: DATE, comment: '令牌过期时间' },
status: { type: TINYINT.UNSIGNED, allowNull: false, defaultValue: 1, comment: '状态:1正常 0禁用' },
lastRegisterAt: { type: DATE, comment: '最近注册时间' },
lastLoginAt: { type: DATE, comment: '最近登录时间' },
lastSeenAt: { type: DATE, comment: '最近心跳时间' },
}, {
tableName: 'scanners',
paranoid: true,
comment: '扫描器表',
});
Scanner.associate = function() {
app.model.Scanner.belongsTo(app.model.User, { foreignKey: 'user_id', as: 'user' });
};
return Scanner;
};