添加全局样式和 element ui框架

This commit is contained in:
编码猿
2025-09-24 23:56:55 +08:00
parent 21bf47c8a1
commit 537c7ca60e
37 changed files with 385486 additions and 8374 deletions

View File

@@ -1,10 +1,12 @@
### 依赖注意
DDD 中允许 “外层依赖内层”(交付层依赖领域层),但不允许 “内层依赖外层”。
- 正确features交付层 → domains领域层
- 错误domains领域层 → features交付层
#### 避免类型重复定义
如果不在视图中直接使用领域类型,就需要在交付层重新定义一套类似的类型(如 “视图专用商品类型”),这会导致:
- 代码冗余和不一致风险
@@ -12,14 +14,15 @@ DDD 中允许 “外层依赖内层”(交付层依赖领域层),但不允
- 业务规则分散(领域层的类型约束可能在视图层被忽略)
### 横切关注点
- 特征:横向,影响多个模块,那些无法放入任何一个业务模块,而是会"横着"贯穿多个甚至所有模块的技术性需求。
- 案例:日志记录、身份认证、授权、事务管理、异常处理、缓存、性能监控
## 业务关注点
- 特征:通常局限于一个业务模块内
- 案例:计算订单总额、验证用户邮箱格式、处理库存扣减
### 对象职责的设计理念对比:
#### 贫血模型
@@ -30,33 +33,33 @@ DDD 中允许 “外层依赖内层”(交付层依赖领域层),但不允
```typescript
// 1. 贫血的Order实体只有数据没有行为
class Order {
public id: string;
public items: OrderItem[];
public total: number; // 总额需要外部来计算和设置
public status: string;
public id: string;
public items: OrderItem[];
public total: number; // 总额需要外部来计算和设置
public status: string;
}
// 2. 所有业务逻辑都在外部的“服务”里
class OrderService {
calculateTotal(order: Order): void {
let total = 0;
for (const item of order.items) {
total += item.price * item.quantity;
calculateTotal(order: Order): void {
let total = 0;
for (const item of order.items) {
total += item.price * item.quantity;
}
order.total = total; // 从外部修改对象的数据
}
order.total = total; // 从外部修改对象的数据
}
markAsPaid(order: Order): void {
if (order.total <= 0) {
throw new Error('订单金额无效');
markAsPaid(order: Order): void {
if (order.total <= 0) {
throw new Error('订单金额无效');
}
order.status = 'paid'; // 从外部修改对象的状态
}
order.status = 'paid'; // 从外部修改对象的状态
}
}
// 使用方式
const order = new Order();
order.items = [...];
order.items = [ ... ];
const orderService = new OrderService();
orderService.calculateTotal(order); // 服务来算总额
orderService.markAsPaid(order); // 服务来改状态
@@ -70,42 +73,42 @@ orderService.markAsPaid(order); // 服务来改状态
```typescript
// 充血的Order实体数据 + 行为
class Order {
public id: string;
private _items: OrderItem[];
private _total: number; // 总额是内部计算的结果
public status: string;
public id: string;
private _items: OrderItem[];
private _total: number; // 总额是内部计算的结果
public status: string;
constructor(items: OrderItem[]) {
this._items = items;
this._total = this.calculateTotal(); // 构造时自己计算总额
this.status = 'created';
}
// 业务逻辑封装在实体内部
private calculateTotal(): number {
return this._items.reduce((sum, item) => sum + (item.price * item.quantity), 0);
}
// 一个公开的业务方法
public markAsPaid(): void {
// 它自己 knows 自己的业务规则
if (this._total <= 0) {
throw new Error('订单金额无效,无法支付');
constructor(items: OrderItem[]) {
this._items = items;
this._total = this.calculateTotal(); // 构造时自己计算总额
this.status = 'created';
}
this.status = 'paid';
}
// 提供访问内部数据的方法(如果需要)
get total(): number {
return this._total;
}
// 业务逻辑封装在实体内部
private calculateTotal(): number {
return this._items.reduce((sum, item) => sum + (item.price * item.quantity), 0);
}
get items(): ReadonlyArray<OrderItem> {
return [...this._items]; // 返回副本,保护内部数据
}
// 一个公开的业务方法
public markAsPaid(): void {
// 它自己 knows 自己的业务规则
if (this._total <= 0) {
throw new Error('订单金额无效,无法支付');
}
this.status = 'paid';
}
// 提供访问内部数据的方法(如果需要)
get total(): number {
return this._total;
}
get items(): ReadonlyArray<OrderItem> {
return [ ...this._items ]; // 返回副本,保护内部数据
}
}
// 使用方式:对象是聪明的,告诉它做什么就行,而不是一步步操作它
const order = new Order([...]);
const order = new Order([ ... ]);
order.markAsPaid(); // 对象自己处理状态变更
```