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

68 lines
2.0 KiB
JavaScript
Raw Permalink 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');
/**
* 运维/内部:系统配置(sys_config)读写
*
* 挂在 `middleware.internalAuth()` 后面;读接口带 Redis 缓存,写接口自动失效。
*/
class InternalConfigController extends Controller {
/** GET /api/configs?group=wechat —— 列表(管理用,含禁用项) */
async index() {
const { ctx } = this;
const list = await ctx.service.config.list({ groupName: ctx.query.group });
ctx.body = { ok: true, data: { list, total: list.length } };
}
/** GET /api/configs/:group/:key —— 取单个配置值(带 Redis 缓存) */
async show() {
const { ctx } = this;
const { group, key } = ctx.params;
const value = await ctx.service.config.get(group, key);
if (value === null) {
ctx.status = 404;
ctx.body = { ok: false, message: '配置不存在' };
return;
}
ctx.body = { ok: true, data: { group, key, value } };
}
/** GET /api/configs/:group —— 取一个分组的所有启用配置 */
async showGroup() {
const { ctx } = this;
const { group } = ctx.params;
const data = await ctx.service.config.getGroup(group);
ctx.body = { ok: true, data };
}
/** PUT /api/configs —— 新增或更新(幂等) */
async upsert() {
const { ctx } = this;
const { configKey } = ctx.request.body || {};
if (!configKey) {
ctx.status = 422;
ctx.body = { ok: false, message: 'configKey 不能为空' };
return;
}
const data = await ctx.service.config.set(ctx.request.body);
ctx.body = { ok: true, data };
}
/** DELETE /api/configs/:group/:key —— 软删除 */
async destroy() {
const { ctx } = this;
const { group, key } = ctx.params;
const removed = await ctx.service.config.remove(group, key);
if (!removed) {
ctx.status = 404;
ctx.body = { ok: false, message: '配置不存在' };
return;
}
ctx.body = { ok: true, data: { group, key } };
}
}
module.exports = InternalConfigController;