feat(frontend): 管理端改用 Gi Admin Pro 框架 + 腾讯云主题
前端此前只有本地实现、从未入库,本次首次纳入版本管理。
框架切换
· 以 Gi Admin Pro(Vue3 + Vite + TS + Arco Design Vue + Pinia)为底
· 剥离 14 个演示页面目录 / 121 个文件(demo 28、file 20、form 19、system 18…)
· 依赖 dependencies 35 → 19,devDependencies 31 → 27
· 保留框架核心:layout、Gi* 组件库、hooks、权限指令、错误页、登录页
主题:腾讯云 / TDesign 官方色板
· 主色 #0052D9(腾讯蓝)、成功 #00A870、警告 #ED7B2F、危险 #E34D59
· 页面底色 #f3f3f3、文字 rgba(0,0,0,90/60/40/26%)
· 覆盖 Arco 底层色板 + 显式语义别名(primary/success/warning/danger/link/neutral)
· 三个改了不生效也不报错的坑已记入注释:
1) Arco 色值是逗号分隔 RGB 三元组,不是 #RRGGBB
2) Arco 把色板定义在 body 而非 :root,必须写 `:root, body`
3) setting.json 的 themeColor 会以内联样式写进 body,优先级高于样式表
对接后端(三处契约差异在 @/utils/http 统一适配)
· 响应信封 {code,msg,data} → {code,success,message,data}
· Token 头 token → Authorization: Bearer
· 分页 {list,total} → 补一份 records,list 原样保留
· 40101 → 登录页;登录密码 RSA 加密(公钥走 /auth/public-key,轮换无需重建前端)
· 路由:后端只下发菜单键,前端在本地路由表上过滤(有哪些页面归代码,谁能看归后端)
已实现页面(浏览器实测通过)
· 登录:RSA 加密 + 自适应验证码/租户码 + 账号锁定提示
· 工作台:真实数据(组织 6 个 / 角色 1 个 / 权限 25 项)
· 组织架构:三级树 + CRUD + 占用校验
· 租户管理:开通租户 + 初始密码只显示一次的强确认
· 待建页:未实现菜单显示所属里程碑
· 权限菜单:学校管理员看不到「租户管理」
视觉资产按腾讯云主题重做
· logo.svg(渐变圆角方 + 填)、favicon.svg(小尺寸做减法)、login-hero.svg(材料归集)
· 登录页点阵纹理走主题变量,换主色自动跟随
· 文案改为产品实际能力:自动改名 / 强制压缩 / 隐私保护
清理模板遗留(约 17MB + 三处外部依赖)
· 百度统计脚本(上报到 gi-demo 作者的统计账号)
· 用户菜单「项目地址」(跳转模板作者的 Gitee 仓库)
· 两份 8.8MB mp3、388KB favicon.ico、57KB 模板插画、未引用字体与 loading.gif
· 「个人中心」指向已删除的 /system/account(点了 404)
· 头部头像在无 avatarUrl 时渲染成裂图 → 改为姓名首字兜底
后端修复
· 新增 GET /auth/public-key(前端加密登录密码用)
· DataSeeder.ancestor_path 生成错误:子节点本该是 /16/17/ 却写成 /17/
该字段是「按院系统计」的索引,错了会漏人/多人且不报错 —— 改为从库里读父节点路径
· seedDemoOrgs 曾放在租户作用域外 + admin 早退分支之后,导致启动失败 / 永不执行
· 示范租户补一套三级组织树(1 学校 / 2 院系 / 3 班级),供界面演示
This commit is contained in:
@@ -4,7 +4,10 @@ import javax.crypto.Cipher;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.KeyFactory;
|
||||
import java.security.PrivateKey;
|
||||
import java.security.interfaces.RSAPrivateCrtKey;
|
||||
import java.security.interfaces.RSAPublicKey;
|
||||
import java.security.spec.PKCS8EncodedKeySpec;
|
||||
import java.security.spec.RSAPublicKeySpec;
|
||||
import java.util.Base64;
|
||||
|
||||
/**
|
||||
@@ -40,6 +43,32 @@ public final class RsaCipher {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出对应的公钥(PEM,X.509/SPKI)。
|
||||
*
|
||||
* <p>用于 {@code GET /api/v1/auth/public-key}:前端启动时拉一次,
|
||||
* 之后用它加密登录密码。
|
||||
*
|
||||
* <p><b>为什么不把公钥打包进前端</b>:一是密钥轮换时前端要重新构建、重新发布;
|
||||
* 二是打包进去意味着"改密钥"这件事横跨前后端两个仓库,
|
||||
* 实际操作中一定会出现"后端换了、前端没换"导致全员登不进去。
|
||||
* 公钥是公开信息,放接口上没有任何安全损失。
|
||||
*/
|
||||
public String publicKeyPem() {
|
||||
try {
|
||||
if (!(privateKey instanceof RSAPrivateCrtKey crt)) {
|
||||
throw new IllegalStateException("私钥不是 CRT 格式,无法推导公钥");
|
||||
}
|
||||
RSAPublicKey pub = (RSAPublicKey) KeyFactory.getInstance("RSA")
|
||||
.generatePublic(new RSAPublicKeySpec(crt.getModulus(), crt.getPublicExponent()));
|
||||
String b64 = Base64.getMimeEncoder(64, new byte[]{'\n'})
|
||||
.encodeToString(pub.getEncoded());
|
||||
return "-----BEGIN PUBLIC KEY-----\n" + b64 + "\n-----END PUBLIC KEY-----\n";
|
||||
} catch (Exception e) {
|
||||
throw new IllegalStateException("导出 RSA 公钥失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 解密前端传来的密码。
|
||||
*
|
||||
|
||||
+16
@@ -1,6 +1,7 @@
|
||||
package cn.tianbaotong.fill.module.auth.controller;
|
||||
|
||||
import cn.tianbaotong.fill.common.api.ApiResult;
|
||||
import cn.tianbaotong.fill.common.crypto.RsaCipher;
|
||||
import cn.tianbaotong.fill.module.auth.dto.LoginReq;
|
||||
import cn.tianbaotong.fill.module.auth.dto.LoginVO;
|
||||
import cn.tianbaotong.fill.module.auth.service.AuthService;
|
||||
@@ -29,6 +30,7 @@ public class AuthController {
|
||||
|
||||
private final AuthService authService;
|
||||
private final CaptchaService captchaService;
|
||||
private final RsaCipher rsaCipher;
|
||||
|
||||
@PublicApi
|
||||
@PostMapping("/login")
|
||||
@@ -44,6 +46,20 @@ public class AuthController {
|
||||
return ApiResult.ok(captchaService.generate());
|
||||
}
|
||||
|
||||
/**
|
||||
* 登录密码加密用的公钥。
|
||||
*
|
||||
* <p>公钥是公开信息,无需鉴权。前端启动时拉一次并缓存,
|
||||
* 这样<b>轮换密钥不需要重新构建前端</b>——否则"后端换了、前端没换"
|
||||
* 会表现为"所有人密码都错",而且很难定位。
|
||||
*/
|
||||
@PublicApi
|
||||
@GetMapping("/public-key")
|
||||
@Operation(summary = "获取登录加密公钥", description = "PEM 格式,前端用它与 RSA/ECB/PKCS1Padding 加密密码")
|
||||
public ApiResult<String> publicKey() {
|
||||
return ApiResult.ok(rsaCipher.publicKeyPem());
|
||||
}
|
||||
|
||||
@GetMapping("/me")
|
||||
@Operation(summary = "当前用户", description = "返回用户、租户、角色、菜单与细粒度权限码")
|
||||
public ApiResult<LoginVO> me() {
|
||||
|
||||
@@ -2,6 +2,8 @@ package cn.tianbaotong.fill.support;
|
||||
|
||||
import cn.tianbaotong.fill.common.context.LoginUser;
|
||||
import cn.tianbaotong.fill.common.context.UserContext;
|
||||
import cn.tianbaotong.fill.module.org.entity.SysOrg;
|
||||
import cn.tianbaotong.fill.module.org.mapper.OrgMapper;
|
||||
import cn.tianbaotong.fill.module.tenant.entity.SysTenant;
|
||||
import cn.tianbaotong.fill.module.tenant.mapper.TenantMapper;
|
||||
import cn.tianbaotong.fill.module.user.entity.SysUser;
|
||||
@@ -44,6 +46,7 @@ public class DataSeeder implements ApplicationRunner {
|
||||
|
||||
private final TenantMapper tenantMapper;
|
||||
private final UserMapper userMapper;
|
||||
private final OrgMapper orgMapper;
|
||||
private final RoleProvisioner roleProvisioner;
|
||||
private final PasswordEncoder passwordEncoder;
|
||||
|
||||
@@ -102,6 +105,15 @@ public class DataSeeder implements ApplicationRunner {
|
||||
|
||||
TenantScope.runAs(tid, 0L, Set.of(BuiltinRole.SCHOOL_ADMIN.getCode()), () -> {
|
||||
roleProvisioner.provisionBuiltinRoles(tid);
|
||||
|
||||
// ⚠️ 必须放在 runAs 内部:sys_org 有 tenant_id,
|
||||
// 在租户作用域外查询会触发拦截器的「默认拒绝」直接抛 40101,
|
||||
// 而且它发生在启动阶段(ApplicationRunner),表现是应用起不来。
|
||||
//
|
||||
// ⚠️ 也必须放在下面那个「admin 已存在就早退」之前:
|
||||
// 否则第二次启动之后组织树永远不会被补上(自身已幂等,重复调用无害)。
|
||||
seedDemoOrgs(tid);
|
||||
|
||||
if (findUser(tid, "admin") != null) {
|
||||
return;
|
||||
}
|
||||
@@ -118,16 +130,76 @@ public class DataSeeder implements ApplicationRunner {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 示范组织树。
|
||||
*
|
||||
* <p>空的组织树看不出系统在做什么,所以给个有真实感的三级结构
|
||||
* (学校 → 院系 → 班级)。名字取自客户的真实班级命名习惯(24中技数控1班)。
|
||||
*
|
||||
* <p>幂等:只要该租户已有任何组织就跳过,不覆盖用户自己建的。
|
||||
*/
|
||||
private void seedDemoOrgs(final long tenantId) {
|
||||
Long existing = orgMapper.selectCount(Wrappers.<SysOrg>lambdaQuery());
|
||||
if (existing != null && existing > 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
TenantScope.runAs(tenantId, 0L, Set.of(BuiltinRole.SCHOOL_ADMIN.getCode()), () -> {
|
||||
long school = insertOrg(0L, "示范职业学校", 1, "DEMO", 1);
|
||||
|
||||
long mech = insertOrg(school, "智能制造系", 2, "MECH", 1);
|
||||
insertOrg(mech, "24中技数控1班", 3, "24ZK1", 1);
|
||||
insertOrg(mech, "24中技机电1班", 3, "24JD1", 2);
|
||||
|
||||
long cs = insertOrg(school, "信息工程系", 2, "CS", 2);
|
||||
insertOrg(cs, "24中技计算机1班", 3, "24JSJ1", 1);
|
||||
|
||||
log.info("已为示范租户创建组织树(1 个学校 / 2 个院系 / 3 个班级)");
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 插入一个组织节点并回填 {@code ancestor_path}。
|
||||
*
|
||||
* <p>⚠️ 路径形如 {@code /10/11/12/},**必须包含全部祖先**,末位才是自己。
|
||||
* 这不是显示用的字段 —— 「按院系统计」靠 {@code LIKE '/10/%'} 一次覆盖所有后代,
|
||||
* 路径错了统计就会漏人/多人,而且不会报错。
|
||||
*
|
||||
* <p>路径依赖自身 id,只能先插入再回写;上级路径从库里查(不靠入参传),
|
||||
* 避免调用方漏传或传错 —— 之前就是因为把 parentPath 传成 null,
|
||||
* 导致所有子节点的路径都退化成了只有自己。
|
||||
*/
|
||||
private long insertOrg(Long parentId, String name, int type, String code, int sortNo) {
|
||||
SysOrg o = new SysOrg();
|
||||
o.setParentId(parentId);
|
||||
o.setOrgName(name);
|
||||
o.setOrgType(type);
|
||||
o.setOrgCode(code);
|
||||
o.setSortNo(sortNo);
|
||||
o.setStatus(1);
|
||||
orgMapper.insert(o);
|
||||
|
||||
String parentPath = "/";
|
||||
if (parentId != null && parentId != 0L) {
|
||||
SysOrg parent = orgMapper.selectById(parentId);
|
||||
if (parent == null || parent.getAncestorPath() == null) {
|
||||
throw new IllegalStateException("上级组织的层级路径缺失:" + parentId);
|
||||
}
|
||||
parentPath = parent.getAncestorPath();
|
||||
}
|
||||
String path = parentPath + o.getId() + "/";
|
||||
|
||||
SysOrg patch = new SysOrg();
|
||||
patch.setId(o.getId());
|
||||
patch.setAncestorPath(path);
|
||||
orgMapper.updateById(patch);
|
||||
return o.getId();
|
||||
}
|
||||
|
||||
private SysUser findUser(long tenantId, String username) {
|
||||
return userMapper.selectOne(Wrappers.<SysUser>lambdaQuery()
|
||||
.eq(SysUser::getTenantId, tenantId)
|
||||
.eq(SysUser::getUsername, username)
|
||||
.last("LIMIT 1"));
|
||||
}
|
||||
|
||||
/** 保留:主应用启动时用到的常量,避免未使用告警。 */
|
||||
@SuppressWarnings("unused")
|
||||
private static List<Long> noop() {
|
||||
return List.of();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user