import type { GlobalConfig, NavConfig, SectionBlock, I18nEntry, ProductsData, NewsArticle, NewsDetail, NewsListConfig, ProductListConfig, AboutConfig, SupportConfig, ContactConfig, PageSeo } from '~/types/site'; /** * 官网前台公开接口服务层 * * 消费 dashboard 后端的 /api/site/* 只读接口(免鉴权)。 */ export function useSiteApi() { const { get } = useRequest(); /** 全局配置:站点信息 + 页脚 + 社交链接 + SEO 默认值 */ function getGlobal() { return get('/site/global'); } /** 导航:可见入口 + 外观 */ function getNav() { return get('/site/nav'); } /** Section 区块列表(按页面类型,仅可见) */ function getSections(pageType: string, productId?: number) { const params: Record = { page_type: pageType }; if (productId) params.product_id = productId; return get<{ items: SectionBlock[]; total: number }>('/site/sections', params); } /** i18n 词条列表 */ function getI18n() { return get<{ items: I18nEntry[]; total: number }>('/site/i18n'); } /** 产品:可见系列及其下可见产品 */ function getProducts() { return get('/site/products'); } /** 新闻列表(仅已发布) */ function getNews(skip = 0, limit = 9) { return get<{ items: NewsArticle[]; total: number; skip: number; limit: number }>('/site/news', { skip, limit }); } /** 新闻详情(按 slug,含推荐) */ function getNewsDetail(slug: string) { return get(`/site/news/${encodeURIComponent(slug)}`); } /** 页面配置:product-list / news-list / about / support */ function getPageConfig(type: 'product-list' | 'news-list' | 'about' | 'support') { return get('/site/page', { type }); } /** 页面 SEO 配置 */ function getPageSeo(pageType: string, entityId?: number) { const params: Record = { page_type: pageType }; if (entityId) params.entity_id = entityId; return get('/site/page-seo', params); } /** 联系表单配置 + 字段 */ function getContact() { return get('/site/contact'); } /** 提交联系表单 */ function submitContact(formData: Record) { return useRequest().post('/site/contact/submit', { form_data: formData }); } return { getGlobal, getNav, getSections, getI18n, getProducts, getNews, getNewsDetail, getPageConfig, getPageSeo, getContact, submitContact }; }