@hyperse-hub/hps-plugin-showcase
Vendure Showcase(案例展示)插件,提供管理端维护 Showcase/分类/亮点特性/关联商品变体,并通过 Shop API 对外查询。
功能
- Showcase(案例)管理(Admin API + Admin UI)
- 支持多语言字段:
title、description、slug、metaTitle、metaDescription、tags
- 支持发布与排序:
published、displayOrder
- 支持链接:
liveUrl、repoUrl
- 支持资源:
featuredAsset、assets
- 支持分类关联:
collections
- ShowcaseCollection(分类)管理(Admin API)
- 支持树形结构:
parent / children / breadcrumbs
- 支持发布与排序:
published、displayOrder
- 支持图标:
icon、iconActive
- 支持多语言字段:
name、shortDesc、slug、metaTitle、metaDescription
- 支持 channel:
channelId(创建时可不传,默认使用当前 Admin API channel)
- ShowcaseHighlightFeature(亮点特性)管理(Admin API)
- 绑定 Showcase:
showcaseId
- 支持发布与排序:
published、displayOrder
- 支持多语言字段:
title、description、featureItems
- ShowcaseRelatedProductVariant(关联商品变体)管理(Admin API)
- 为 Showcase 批量设置关联的
productVariantIds
- 扩展字段:
ProductVariant.relatedShowcases
Showcase.relatedProductVariants
- Shop API 查询
- 支持按
id 或 slug 查询 Showcase / Collection
- 支持按
collectionIds、slug 过滤 Showcase 列表
安装
在 Vendure 服务端安装依赖(monorepo/本仓库按实际包管理方式引入即可):
pnpm add @hyperse-hub/hps-plugin-showcase
Vendure 配置
在 vendure-config.ts(或你的 Vendure 配置文件)中注册插件:
import { HpsPluginShowcase } from '@hyperse-hub/hps-plugin-showcase';
export const config = {
plugins: [
HpsPluginShowcase.init({
}),
],
};
Admin UI(管理端)
- 菜单路由:
/showcase
- 显示名称:英文
Showcase / 中文 案例展示
- 权限:
Permission.Authenticated
GraphQL(Admin API)
Showcase
query Showcases($options: ShowcaseListOptions) {
showcases(options: $options) {
items {
id
title
slug
published
displayOrder
}
totalItems
}
}
mutation CreateShowcase($input: CreateShowcaseInput!) {
createShowcase(input: $input) {
id
}
}
mutation UpdateShowcase($input: UpdateShowcaseInput!) {
updateShowcase(input: $input) {
id
}
}
mutation DeleteShowcase($id: ID!) {
deleteShowcase(id: $id) {
result
message
}
}
ShowcaseCollection
query ShowcaseCollections($options: ShowcaseCollectionListOptions) {
showcaseCollections(options: $options) {
items {
id
name
slug
published
displayOrder
parent {
id
}
children {
id
}
breadcrumbs {
id
name
slug
}
}
totalItems
}
}
mutation CreateShowcaseCollection($input: CreateShowcaseCollectionInput!) {
createShowcaseCollection(input: $input) {
id
name
}
}
ShowcaseHighlightFeature
query ShowcaseHighlightFeatures($options: ShowcaseHighlightFeatureListOptions) {
showcaseHighlightFeatures(options: $options) {
items {
id
title
published
displayOrder
showcaseId
featureItems {
title
shortDesc
fullDesc
icon
link
}
}
totalItems
}
}
query ShowcaseRelatedProductVariants($showcaseId: ID!) {
showcaseRelatedProductVariants(showcaseId: $showcaseId) {
showcaseId
productVariantId
}
}
mutation UpdateShowcaseRelatedProductVariants(
$showcaseId: ID!
$productVariantIds: [ID!]!
) {
updateShowcaseRelatedProductVariants(
showcaseId: $showcaseId
productVariantIds: $productVariantIds
)
}
GraphQL(Shop API)
Showcase / Collection 查询
query ShowcaseBySlug($slug: String!) {
showcase(slug: $slug) {
id
title
slug
published
displayOrder
featuredAsset {
id
source
}
assets {
id
source
}
collections {
id
name
slug
}
highlightFeatures {
id
title
featureItems {
title
shortDesc
fullDesc
icon
link
}
}
}
}
query ShowcaseCollections {
showcaseCollections {
items {
id
name
slug
published
displayOrder
}
totalItems
}
}
数据模型(简要)
- Showcase:案例主体,带多语言翻译、资源(Asset)、分类(ShowcaseCollection)、亮点特性(ShowcaseHighlightFeature)与关联商品变体(ShowcaseRelatedProductVariant)
- ShowcaseCollection:分类(可树形),带多语言翻译与 breadcrumbs
- ShowcaseHighlightFeature:绑定 Showcase 的亮点特性,
featureItems 为数组结构(翻译存储为字符串形式)
- ShowcaseRelatedProductVariant:Showcase 与 ProductVariant 的关联关系
开发与测试
- e2e:
packages/plugin-showcase/e2e/admin-showcase.e2e.spec.ts
packages/plugin-showcase/e2e/admin-showcase-highlight-feature.e2e.spec.ts
- unit tests:
packages/plugin-showcase/tests/unit/resolvers/admin/showcase.resolvers.spec.ts
packages/plugin-showcase/tests/unit/services/showcase.services.spec.ts
packages/plugin-showcase/tests/unit/validators/showcase-slug-validator.spec.ts
在仓库根目录按项目既有脚本运行(例如):