116 lines
3.9 KiB
TypeScript
116 lines
3.9 KiB
TypeScript
import type {
|
||
GlobalConfig,
|
||
NavConfig,
|
||
SectionBlock,
|
||
I18nEntry,
|
||
ProductsData,
|
||
NewsArticle,
|
||
NewsDetail,
|
||
NewsListConfig,
|
||
ProductListConfig,
|
||
AboutConfig,
|
||
SupportConfig,
|
||
ContactConfig,
|
||
SupportFeedbackItem,
|
||
SupportFeedbackMessage,
|
||
PageSeo
|
||
} from '~/types/site';
|
||
|
||
/**
|
||
* 官网前台公开接口服务层
|
||
*
|
||
* 消费 dashboard 后端的 /api/site/* 只读接口(免鉴权)。
|
||
*/
|
||
export function useSiteApi() {
|
||
const { get } = useRequest();
|
||
|
||
/** 全局配置:站点信息 + 页脚 + 社交链接 + SEO 默认值 */
|
||
function getGlobal() {
|
||
return get<GlobalConfig>('/site/global');
|
||
}
|
||
|
||
/** 导航:可见入口 + 外观 */
|
||
function getNav() {
|
||
return get<NavConfig>('/site/nav');
|
||
}
|
||
|
||
/** Section 区块列表(按页面类型,仅可见) */
|
||
function getSections(pageType: string, productId?: number) {
|
||
const params: Record<string, unknown> = { 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<ProductsData>('/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<NewsDetail>(`/site/news/${encodeURIComponent(slug)}`);
|
||
}
|
||
|
||
/** 页面配置:product-list / news-list / about / support */
|
||
function getPageConfig<T>(type: 'product-list' | 'news-list' | 'about' | 'support') {
|
||
return get<T>('/site/page', { type });
|
||
}
|
||
|
||
/** 页面 SEO 配置 */
|
||
function getPageSeo(pageType: string, entityId?: number) {
|
||
const params: Record<string, unknown> = { page_type: pageType };
|
||
if (entityId) params.entity_id = entityId;
|
||
return get<PageSeo | null>('/site/page-seo', params);
|
||
}
|
||
|
||
/** 联系表单配置 + 字段 */
|
||
function getContact() {
|
||
return get<ContactConfig>('/site/contact');
|
||
}
|
||
|
||
/** 提交联系表单 */
|
||
function submitContact(formData: Record<string, string>) {
|
||
return useRequest().post<null>('/site/contact/submit', { form_data: formData });
|
||
}
|
||
|
||
/** 提交问题反馈(multipart/form-data:product_id / description / email / log_file[可选]) */
|
||
function submitSupportFeedback(formData: FormData) {
|
||
return useRequest().postForm<{ feedback_no: string }>('/site/support/feedback', formData);
|
||
}
|
||
|
||
/** 按邮箱或反馈编号查询问题反馈 */
|
||
function getSupportFeedbacks(params: { email?: string; feedback_no?: string }) {
|
||
return get<{ items: SupportFeedbackItem[]; total: number }>('/site/support/feedbacks', params);
|
||
}
|
||
|
||
/** 拉取反馈对话消息(含当前反馈状态,便于轮询时同步状态) */
|
||
function getFeedbackMessages(feedbackNo: string, email: string, sinceId?: number) {
|
||
const params: Record<string, unknown> = { email };
|
||
if (sinceId && sinceId > 0) params.since_id = sinceId;
|
||
return get<{ items: SupportFeedbackMessage[]; total: number; status: string }>(
|
||
`/site/support/feedbacks/${encodeURIComponent(feedbackNo)}/messages`,
|
||
params,
|
||
);
|
||
}
|
||
|
||
/** 用户发送反馈对话消息 */
|
||
function sendFeedbackMessage(feedbackNo: string, email: string, content: string) {
|
||
return useRequest().post<{ items: SupportFeedbackMessage[]; total: number }>(
|
||
`/site/support/feedbacks/${encodeURIComponent(feedbackNo)}/messages`,
|
||
{ email, content },
|
||
);
|
||
}
|
||
|
||
return { getGlobal, getNav, getSections, getI18n, getProducts, getNews, getNewsDetail, getPageConfig, getPageSeo, getContact, submitContact, submitSupportFeedback, getSupportFeedbacks, getFeedbackMessages, sendFeedbackMessage };
|
||
}
|