导入 AKSRT 主题开发源码
This commit is contained in:
1 parent
9681dd3d48
commit
1268a55dd0
595 files changed
+127705
No files matched your search
@@ -0,0 +1,114 @@
|
||||
/**
|
||||
* Schema Registry — central index for all admin section schemas.
|
||||
*
|
||||
* Each section's schema defines the form fields, groups, API endpoints,
|
||||
* and default values for a settings page. The AksFormRenderer component
|
||||
* consumes these schemas to render settings pages automatically.
|
||||
*
|
||||
* Schema shape per section:
|
||||
* {
|
||||
* key: 'global.seo',
|
||||
* title: 'SEO优化',
|
||||
* icon: 'fas fa-search',
|
||||
* description: '...',
|
||||
* api: { get: () => api.getSeoSettings(), save: (data) => api.saveSeoSettings(data) },
|
||||
* defaults: { ... },
|
||||
* groups: [
|
||||
* {
|
||||
* key: 'basic',
|
||||
* title: '基础SEO',
|
||||
* icon: 'fas fa-globe',
|
||||
* fields: [
|
||||
* { key: 'site_title', label: '站点标题', type: 'input', default: '' },
|
||||
* ...
|
||||
* ]
|
||||
* }
|
||||
* ]
|
||||
* }
|
||||
*/
|
||||
import { globalSchemas } from './sections/global/index.js'
|
||||
import { pageDisplaySchemas } from './sections/page-display/index.js'
|
||||
import { postListSchemas } from './sections/post-list/index.js'
|
||||
import { permissionsSchemas } from './sections/permissions/index.js'
|
||||
import { usersSchemas } from './sections/users/index.js'
|
||||
import { paymentSchemas } from './sections/payment/index.js'
|
||||
import { extensionsSchemas } from './sections/extensions/index.js'
|
||||
import { toolsSchemas } from './sections/tools/index.js'
|
||||
import { shopSchemas } from './sections/shop/index.js'
|
||||
import { forumSchemas } from './sections/forum/index.js'
|
||||
|
||||
export function normalizeSchemaDomain(domain = '') {
|
||||
const value = String(domain).trim()
|
||||
if (!value) {
|
||||
return 'global'
|
||||
}
|
||||
|
||||
return value.replace(/-/g, '_')
|
||||
}
|
||||
|
||||
export const CANONICAL_SCHEMA_DOMAINS = [
|
||||
'global',
|
||||
'page_display',
|
||||
'post_list',
|
||||
'permissions',
|
||||
'users',
|
||||
'payment',
|
||||
'extensions',
|
||||
'tools',
|
||||
'shop',
|
||||
'forum',
|
||||
]
|
||||
|
||||
/** All schemas organized by domain */
|
||||
export const ALL_SCHEMAS = Object.freeze({
|
||||
global: globalSchemas,
|
||||
page_display: pageDisplaySchemas,
|
||||
post_list: postListSchemas,
|
||||
permissions: permissionsSchemas,
|
||||
users: usersSchemas,
|
||||
payment: paymentSchemas,
|
||||
extensions: extensionsSchemas,
|
||||
tools: toolsSchemas,
|
||||
shop: shopSchemas,
|
||||
forum: forumSchemas,
|
||||
})
|
||||
|
||||
/**
|
||||
* Get a specific section schema by its key path.
|
||||
* @param {string} domain - e.g. 'global'
|
||||
* @param {string} section - e.g. 'seo'
|
||||
* @returns {Object|null}
|
||||
*/
|
||||
export function getSchema(domain, section) {
|
||||
const domainSchemas = ALL_SCHEMAS[normalizeSchemaDomain(domain)]
|
||||
if (!domainSchemas) return null
|
||||
return domainSchemas[section] || null
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all schemas for a domain.
|
||||
* @param {string} domain
|
||||
* @returns {Object}
|
||||
*/
|
||||
export function getDomainSchemas(domain) {
|
||||
return ALL_SCHEMAS[normalizeSchemaDomain(domain)] || {}
|
||||
}
|
||||
|
||||
export function getSchemaSectionKeys(domain) {
|
||||
return Object.keys(getDomainSchemas(domain))
|
||||
}
|
||||
|
||||
export function getSchemaDefaults(domain, section = '') {
|
||||
const domainKey = normalizeSchemaDomain(domain)
|
||||
|
||||
if (section) {
|
||||
return { ...(getSchema(domainKey, section)?.defaults || {}) }
|
||||
}
|
||||
|
||||
return Object.values(getDomainSchemas(domainKey)).reduce((defaults, schema) => {
|
||||
return {
|
||||
...defaults,
|
||||
...(schema?.defaults || {}),
|
||||
}
|
||||
}, {})
|
||||
}
|
||||
Reference in new issue
Block a user