简单修改
This commit is contained in:
@@ -10,8 +10,9 @@ src/
|
||||
│ │ └── events/ # 领域事件(如果需要)
|
||||
│ ├── application/ # 应用服务层 - 协调领域对象完成用例
|
||||
│ │ └── services/ # 应用服务(如:ProductApplicationService)
|
||||
│ ├── infrastructure/ # 基础设施层 - 领域层的具体实现
|
||||
│ ├── infr/ # 基础设施层 - 领域层的具体实现
|
||||
│ │ └── api/ # 数据获取实现(如:HttpProductRepository)
|
||||
│ │ └── config/ # 请求接口地址的配置
|
||||
│ ├── ports/ # 端口(接口/抽象类)- 定义契约
|
||||
│ │ └── repositories/ # 仓储接口(如:ProductRepository)
|
||||
│ └── use-cases/ # (可选)或将用例放在这里
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { defineComponent, defineEmits, onMounted} from 'vue'
|
||||
import { defineComponent, defineEmits, onMounted, PropType } from 'vue'
|
||||
import type { JSX } from "vue/jsx-runtime";
|
||||
|
||||
export default defineComponent({
|
||||
@@ -7,6 +7,11 @@ export default defineComponent({
|
||||
text: {
|
||||
type: Array<{ id: number, title: string }>,
|
||||
default: () => []
|
||||
},
|
||||
// 点击事件
|
||||
onClick: {
|
||||
type: Function as PropType<() => void>,
|
||||
default: () => { }
|
||||
}
|
||||
},
|
||||
emits: {
|
||||
@@ -30,13 +35,13 @@ export default defineComponent({
|
||||
|
||||
return () => (
|
||||
<div>
|
||||
<h1>头部组件</h1>
|
||||
<h1 onClick={props.onClick}>头部组件-点我</h1>
|
||||
|
||||
{ button() }
|
||||
{button()}
|
||||
|
||||
{ slots.default?.() }
|
||||
{slots.default?.()}
|
||||
|
||||
{ slots.header?.() }
|
||||
{slots.header?.()}
|
||||
|
||||
<div class="ScopedSlots">
|
||||
<p>作用于插槽:</p>
|
||||
|
||||
@@ -45,7 +45,12 @@ export default defineComponent({
|
||||
|
||||
return () => (
|
||||
<div class="home">
|
||||
<Header text={state.list} onSendMessage={handleChildEvent}>
|
||||
<Header
|
||||
text={state.list}
|
||||
onClick={() => {
|
||||
console.log("通过props自定义事件传给子组件");
|
||||
}}
|
||||
onSendMessage={handleChildEvent}>
|
||||
{{
|
||||
scoped: (item: ListItemType) => <li key={item.id}>{item.title}</li>,
|
||||
header: () => <div class="header">父到子 具名 插槽</div>,
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
import { ErrorText } from "../../domain/enums/ErrorEnums";
|
||||
import { ProductRepository } from "../../ports/repositories/ProductRepository";
|
||||
|
||||
/**
|
||||
* 商品应用服务 - 协调领域对象完成业务用例
|
||||
* 应用服务是领域层的外观,封装了领域逻辑的调用
|
||||
*/
|
||||
export class ProductApplicationService {
|
||||
// 依赖注入仓储接口,而不是具体实现
|
||||
constructor(private productRepository: ProductRepository) { }
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
import { ErrorText } from "../enums/ErrorEnums"
|
||||
|
||||
/**
|
||||
* 商品实体 - 包含商品的核心属性和行为
|
||||
* 在DDD中,实体具有唯一标识和生命周期
|
||||
*/
|
||||
export class Product {
|
||||
private readonly _id: number;
|
||||
private _name: string;
|
||||
|
||||
@@ -2,23 +2,23 @@ import { Product } from "../../domain/entities/Product";
|
||||
import { ProductType } from "../../domain/type/ProductType";
|
||||
import { ProductRepository } from "../../ports/repositories/ProductRepository";
|
||||
import http from "@shared/infra/AxiosInfra";
|
||||
|
||||
import HttpConfig from "../config/HttpConfig";
|
||||
|
||||
/**
|
||||
* HTTP商品仓储实现 - 实现商品数据的HTTP访问
|
||||
* 这是基础设施层,负责具体的数据获取实现
|
||||
* 这是基础设施层,负责具体的数据获取实现
|
||||
*/
|
||||
export class HttpProductRepository implements ProductRepository {
|
||||
|
||||
async findAll(): Promise<Array<ProductType>> {
|
||||
const result: Array<ProductType> = await http.get({ url: "/productsList" });
|
||||
const result: Array<ProductType> = await http.get({ url: HttpConfig.apiUrlList.productsListUrl });
|
||||
const items = result.map((item) => Product.fromDTO(item))
|
||||
return items;
|
||||
}
|
||||
|
||||
async findById(id: number): Promise<Product> {
|
||||
const result: ProductType = await http.get({
|
||||
url: "/productsInfo",
|
||||
url: HttpConfig.apiUrlList.productsInfoUrl,
|
||||
data: { id }
|
||||
});
|
||||
return Product.fromDTO(result);
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
interface apiUrlListType {
|
||||
productsListUrl: string
|
||||
productsInfoUrl: string
|
||||
}
|
||||
|
||||
export default class HttpConfig {
|
||||
public static apiUrlList: apiUrlListType = {
|
||||
productsListUrl: '/productsList',
|
||||
productsInfoUrl: '/productsInfo',
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user