feat(tenant): 租户品牌定制(子模块 + openspec change)
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
parent
35028a69d2
commit
27bdb6f164
2
openspec/changes/tenant-brand/.openspec.yaml
Normal file
2
openspec/changes/tenant-brand/.openspec.yaml
Normal file
@ -0,0 +1,2 @@
|
||||
schema: spec-driven
|
||||
created: 2026-10-11
|
||||
47
openspec/changes/tenant-brand/design.md
Normal file
47
openspec/changes/tenant-brand/design.md
Normal file
@ -0,0 +1,47 @@
|
||||
## Context
|
||||
|
||||
tenant 已有 `code`/`name`/`status`/`remark`,前端顶栏标题「投云科技」、Logo(本地资源)、主色(app store 默认 `#2E7FA3`)、底部版权均为全局硬编码。动机见 proposal.md - Why。
|
||||
|
||||
## Goals / Non-Goals
|
||||
|
||||
**Goals:**
|
||||
|
||||
- 租户可配置品牌名/Logo/主色/版权,登录后前端按当前租户渲染。
|
||||
|
||||
**Non-Goals:**
|
||||
|
||||
- 不做登录页的租户级品牌预渲染(多租户下登录前无法确定租户,登录页仍用全局配置)。
|
||||
- 不做品牌图床/上传(Logo 用 URL)。
|
||||
|
||||
## Decisions
|
||||
|
||||
### D1 — tenant 加 4 个可空品牌字段
|
||||
`brand_name`(64)、`logo_url`(255)、`theme_color`(16,如 `#2E7FA3`)、`copyright`(255),均可空;空则前端回退。
|
||||
|
||||
### D2 — `GET /auth/brand` 放在 auth,仅登录态
|
||||
`AuthService.getBrand(tenantCode)` 查 tenant,返回 `{ name, brandName, logoUrl, themeColor, copyright }`;字段为空原样返回 null,由前端回退。放在 auth 与既有 `menus`/`permissions`(当前用户上下文)一致。
|
||||
|
||||
### D3 — 前端登录后应用品牌
|
||||
layout `onMounted` 随 menu/dict/permission 一并拉取 `GET /auth/brand`,存进 auth store(`brand` ref):
|
||||
- 主色:`brand.themeColor` 非空则 `app.themeColor = brand.themeColor`;
|
||||
- 标题:`brand.brandName ?? tenant.name ?? '投云科技'`;
|
||||
- Logo:`brand.logoUrl ?? 本地默认 logo`;
|
||||
- 版权:`brand.copyright ?? '云南投云科技有限公司'`。
|
||||
|
||||
### D4 — 租户管理表单加品牌字段
|
||||
tenant 表单加 4 个可选字段(theme_color 用颜色选择器或文本),列表/详情展示 brand_name。
|
||||
|
||||
## Risks / Trade-offs
|
||||
|
||||
- **[主色覆盖用户手动选择]** → 登录时仅当 `brand.themeColor` 非空才覆盖;用户在设置面板改色仍即时生效。
|
||||
- **[Logo 外链失效]** → 前端 `img` 加载失败时回退默认(onerror 或留空)。
|
||||
|
||||
## Migration Plan
|
||||
|
||||
1. Prisma migration:`sys_tenant` 加 4 列(可空,无回填)。
|
||||
2. 代码上线。
|
||||
3. 回滚:向后兼容,回滚代码即可。
|
||||
|
||||
## Open Questions
|
||||
|
||||
无。
|
||||
24
openspec/changes/tenant-brand/proposal.md
Normal file
24
openspec/changes/tenant-brand/proposal.md
Normal file
@ -0,0 +1,24 @@
|
||||
## Why
|
||||
|
||||
租户之间没有品牌区分:顶栏标题/Logo/主色/版权都是全局硬编码(「投云科技」等)。fork 后每个租户应有自己的品牌(Logo/品牌名/主色/版权),登录后前端按当前租户应用。
|
||||
|
||||
## What Changes
|
||||
|
||||
- `tenant` 新增品牌字段:`brand_name`、`logo_url`、`theme_color`、`copyright`(均可空,空则前端回退默认)。
|
||||
- 新增 `GET /auth/brand`(仅登录态)返回当前租户品牌;tenant 增删改查支持品牌字段。
|
||||
- 前端登录后拉取品牌,应用到顶栏标题/Logo、主题色、底部版权;租户管理页加品牌字段。
|
||||
|
||||
## Capabilities
|
||||
|
||||
### Modified Capabilities
|
||||
|
||||
- `shared/data-model`: `tenant` 实体新增品牌字段。
|
||||
- `shared/api-contract`: 新增 `GET /auth/brand`;tenant 接口支持品牌字段。
|
||||
- `backend/tenants`: 租户 CRUD 支持品牌字段。
|
||||
- `frontend/AD/layout`: 登录后按租户品牌应用主色/Logo/标题/版权。
|
||||
|
||||
## Impact
|
||||
|
||||
- **后端**:`tenant` 模型加 4 字段;`tenants` DTO/CRUD 扩展;`auth` 加 `GET /auth/brand`;Prisma migration。
|
||||
- **前端**:`api/tenant.ts` + `api/auth.ts`(brand)扩展;layout 应用品牌;租户管理表单加字段。
|
||||
- **数据**:Prisma migration(`sys_tenant` 加 4 列)。
|
||||
@ -0,0 +1,8 @@
|
||||
## ADDED Requirements
|
||||
|
||||
### Requirement: 租户品牌维护
|
||||
系统 SHALL 支持管理员在新增/编辑租户时填写品牌名、Logo、主色、版权,并在租户详情/列表中返回。
|
||||
|
||||
#### Scenario: 编辑租户品牌
|
||||
- **WHEN** 管理员编辑某租户的品牌字段
|
||||
- **THEN** 品牌字段保存并可查询
|
||||
@ -0,0 +1,12 @@
|
||||
## ADDED Requirements
|
||||
|
||||
### Requirement: 租户品牌应用
|
||||
前端 SHALL 在登录后拉取当前租户品牌,并应用:主色覆盖默认主题色、Logo/品牌名显示于顶栏、版权显示于底部;字段为空时回退默认。
|
||||
|
||||
#### Scenario: 应用租户品牌
|
||||
- **WHEN** 用户登录某租户
|
||||
- **THEN** 顶栏标题/Logo、主题色、底部版权按该租户品牌渲染
|
||||
|
||||
#### Scenario: 缺省回退
|
||||
- **WHEN** 租户未配置某品牌字段
|
||||
- **THEN** 该字段回退为默认值(标题回退 name、主题色回退默认主色)
|
||||
@ -0,0 +1,12 @@
|
||||
## ADDED Requirements
|
||||
|
||||
### Requirement: 租户品牌接口
|
||||
系统 SHALL 提供 `GET /auth/brand`(仅登录态),返回当前租户品牌(name、brandName、logoUrl、themeColor、copyright);tenant 的新增/编辑/列表接口 SHALL 支持品牌字段。
|
||||
|
||||
#### Scenario: 拉取当前租户品牌
|
||||
- **WHEN** 已登录用户请求 GET /auth/brand
|
||||
- **THEN** 返回其所在租户的品牌字段(缺省为空)
|
||||
|
||||
#### Scenario: 维护租户品牌
|
||||
- **WHEN** 管理员新增或编辑租户并填写品牌字段
|
||||
- **THEN** 品牌字段随 tenant 一并保存与返回
|
||||
@ -0,0 +1,8 @@
|
||||
## ADDED Requirements
|
||||
|
||||
### Requirement: 租户品牌字段
|
||||
tenant 实体 SHALL 新增可空品牌字段:`brand_name`(品牌显示名)、`logo_url`(Logo 地址)、`theme_color`(主色,如 #2E7FA3)、`copyright`(版权文案);为空时前端回退默认值或 `name`。
|
||||
|
||||
#### Scenario: 租户配置品牌
|
||||
- **WHEN** 管理员为租户填写品牌名/Logo/主色/版权
|
||||
- **THEN** 存入 tenant 对应字段,登录该租户后前端按此渲染
|
||||
22
openspec/changes/tenant-brand/tasks.md
Normal file
22
openspec/changes/tenant-brand/tasks.md
Normal file
@ -0,0 +1,22 @@
|
||||
## 1. 数据模型与迁移
|
||||
|
||||
- [x] 1.1 Prisma:`Tenant` 加 `brandName`/`logoUrl`/`themeColor`/`copyright`(可空)
|
||||
- [x] 1.2 生成并部署 migration
|
||||
|
||||
## 2. 后端
|
||||
|
||||
- [x] 2.1 `tenants` DTO:Create/Update 加品牌字段;list 返回品牌字段
|
||||
- [x] 2.2 `auth` 加 `GET /auth/brand`(仅登录态),返回当前租户品牌
|
||||
|
||||
## 3. 前端
|
||||
|
||||
- [x] 3.1 `api/auth.ts` 加 `fetchBrand`;`api/tenant.ts` 类型扩展品牌字段
|
||||
- [x] 3.2 auth store 加 `brand` 状态
|
||||
- [x] 3.3 layout 登录后拉取品牌并应用:主题色/标题/Logo/版权
|
||||
- [x] 3.4 租户管理表单加品牌字段
|
||||
|
||||
## 4. 验证
|
||||
|
||||
- [x] 4.1 后端 build + 单测 + e2e 通过
|
||||
- [x] 4.2 前端 type-check 通过
|
||||
- [x] 4.3 冒烟:设置租户品牌 → GET /auth/brand 返回 → 前端应用主题色/标题
|
||||
@ -1 +1 @@
|
||||
Subproject commit 64bbb0a987a1f66373b6470b7c2001a582c3394f
|
||||
Subproject commit 3746198f19ef7f636c6df394b6d52a2780a9fe7f
|
||||
@ -1 +1 @@
|
||||
Subproject commit bad863917502c08afedc4f504bf04bc80dda59e8
|
||||
Subproject commit f747ad5442e314f41d9319b61941da5f7af69096
|
||||
Loading…
x
Reference in New Issue
Block a user