first commit
This commit is contained in:
69
utils/rpc.ts
Normal file
69
utils/rpc.ts
Normal file
@ -0,0 +1,69 @@
|
||||
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('127.0.0.1', 9504)
|
||||
}
|
||||
|
||||
// 新闻列表
|
||||
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
|
||||
}
|
Reference in New Issue
Block a user