133 lines
3.7 KiB
TypeScript
133 lines
3.7 KiB
TypeScript
import type { CollectionConfig } from 'payload'
|
||
import { logAfterChange, logAfterDelete } from '../hooks/logAction'
|
||
import { cacheAfterChange, cacheAfterDelete } from '../hooks/cacheInvalidation'
|
||
import { ProductBaseFields, RelatedProductsField, TaobaoLinksField, MedusaAttributesTab } from './base/ProductBase'
|
||
import {
|
||
AlignFeature,
|
||
BlocksFeature,
|
||
BoldFeature,
|
||
ChecklistFeature,
|
||
HeadingFeature,
|
||
IndentFeature,
|
||
InlineCodeFeature,
|
||
ItalicFeature,
|
||
lexicalEditor,
|
||
LinkFeature,
|
||
OrderedListFeature,
|
||
ParagraphFeature,
|
||
RelationshipFeature,
|
||
UnorderedListFeature,
|
||
UploadFeature,
|
||
FixedToolbarFeature,
|
||
InlineToolbarFeature,
|
||
HorizontalRuleFeature,
|
||
BlockquoteFeature,
|
||
} from '@payloadcms/richtext-lexical'
|
||
|
||
export const Products: CollectionConfig = {
|
||
slug: 'products',
|
||
admin: {
|
||
useAsTitle: 'title',
|
||
defaultColumns: ['thumbnail', 'title', 'medusaId', 'status', 'updatedAt'],
|
||
description: '管理 Medusa 商品的详细内容和描述',
|
||
listSearchableFields: ['title', 'medusaId'],
|
||
pagination: {
|
||
defaultLimit: 25,
|
||
},
|
||
components: {
|
||
beforeListTable: [
|
||
'/components/sync/UnifiedSyncButton#UnifiedSyncButton',
|
||
'/components/list/ProductGridStyler',
|
||
],
|
||
},
|
||
},
|
||
access: {
|
||
read: () => true, // 公开可读
|
||
},
|
||
fields: [
|
||
{
|
||
type: 'tabs',
|
||
tabs: [
|
||
{
|
||
label: 'ℹ️ 基本信息',
|
||
fields: ProductBaseFields,
|
||
},
|
||
{
|
||
label: '📄 商品详情',
|
||
fields: [
|
||
{
|
||
name: 'description',
|
||
type: 'richText',
|
||
editor: lexicalEditor({
|
||
features: [
|
||
ParagraphFeature(),
|
||
HeadingFeature({ enabledHeadingSizes: ['h2', 'h3', 'h4'] }),
|
||
BoldFeature(),
|
||
ItalicFeature(),
|
||
UnorderedListFeature(),
|
||
OrderedListFeature(),
|
||
LinkFeature(),
|
||
AlignFeature(),
|
||
BlockquoteFeature(),
|
||
HorizontalRuleFeature(),
|
||
InlineCodeFeature(),
|
||
IndentFeature(),
|
||
ChecklistFeature(),
|
||
FixedToolbarFeature(),
|
||
InlineToolbarFeature(),
|
||
BlocksFeature({
|
||
blocks: [
|
||
{
|
||
slug: 'image',
|
||
imageURL: '/api/media',
|
||
fields: [
|
||
{
|
||
name: 'caption',
|
||
type: 'text',
|
||
label: '图片说明',
|
||
},
|
||
],
|
||
},
|
||
],
|
||
}),
|
||
UploadFeature({
|
||
collections: {
|
||
media: {
|
||
fields: [
|
||
{
|
||
name: 'caption',
|
||
type: 'text',
|
||
label: '图片说明',
|
||
},
|
||
],
|
||
},
|
||
},
|
||
}),
|
||
RelationshipFeature(),
|
||
],
|
||
}),
|
||
admin: {
|
||
description: '商品详细描述(支持富文本编辑)',
|
||
},
|
||
},
|
||
],
|
||
},
|
||
{
|
||
label: '🔗 关联信息',
|
||
fields: [RelatedProductsField],
|
||
},
|
||
MedusaAttributesTab,
|
||
{
|
||
label: '🛒 淘宝链接',
|
||
fields: [TaobaoLinksField],
|
||
},
|
||
],
|
||
},
|
||
],
|
||
hooks: {
|
||
afterChange: [logAfterChange, cacheAfterChange],
|
||
afterDelete: [logAfterDelete, cacheAfterDelete],
|
||
},
|
||
timestamps: true,
|
||
}
|