Files
frontend/utils/rpc.ts
toom1996 be3b82a10a update
2025-07-02 16:32:48 +08:00

92 lines
1.7 KiB
TypeScript

import { JsonRpcClient } from './rpc-client.ts'
interface images {
src:string
}
interface result<T> {
code : number
message : string
data : T
}
interface data<T> {
page_title: string
page_module: T
}
function getRpcClient() {
return new JsonRpcClient(import.meta.env.RPC_REMOTE, import.meta.env.RPC_PORT)
}
// 新闻列表
export interface InewsIndex {
id: number
title: string
cover: string
keywords: string
description: string
content: string
created_at: string
updated_at: string
}
export async function newsIndex():Promise<result<InewsIndex[]>>{
const client = getRpcClient()
const result = await client.call('news/index', {})
return result
}
// 新闻详情
export interface InewsDetail {
title: string
keywords: string
description: string
content: string
created_at: string
updated_at: string
about: {
id: number
title: string
}[]
prevNews: {
id: number
title: string
}
nextNews: {
id: number
title: string
}
}
export async function newsDetail(id:string):Promise<result<InewsDetail>>{
const client = getRpcClient()
const result = await client.call('news/view', {
id:id
})
return result
}
// 网站配置
export interface IWebsiteConfig {
app_name: string
app_description: string
app_keywords: string
app_company: string
app_logo: string
app_favicon: string
app_copyright: string
app_icp: string
app_biling: string
}
export async function websiteConfig(host:string):Promise<result<IWebsiteConfig>>{
const client = getRpcClient()
const result = await client.call('website/config', {
host:host
})
return result
}