update
This commit is contained in:
136
utils/rpc.ts
Normal file
136
utils/rpc.ts
Normal file
@ -0,0 +1,136 @@
|
||||
import { JsonRpcClient } from './rpc-client.ts'
|
||||
|
||||
interface images {
|
||||
src:string
|
||||
}
|
||||
|
||||
interface result<T> {
|
||||
code : number
|
||||
message : string
|
||||
data : 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
|
||||
column_tag: string
|
||||
column_tag_url: string
|
||||
second_column_tag: string
|
||||
second_column_tag_url: string
|
||||
}
|
||||
export async function newsIndex({websiteId = 0, limit = 10, page = 1, filter = []} = {}):Promise<{
|
||||
code : number
|
||||
message : string
|
||||
data : InewsIndex[]
|
||||
total: number
|
||||
hot: {
|
||||
cover: string
|
||||
id: string
|
||||
title: string
|
||||
created_at: string
|
||||
}[]
|
||||
}>{console.log({
|
||||
id:websiteId,
|
||||
limit: limit,
|
||||
page: page,
|
||||
filter: filter
|
||||
})
|
||||
const client = getRpcClient()
|
||||
const result = await client.call('baoxian/news/index', {
|
||||
id:websiteId,
|
||||
limit: limit,
|
||||
page: page,
|
||||
filter: filter
|
||||
})
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
|
||||
// 新闻详情
|
||||
export interface InewsDetail {
|
||||
id: number
|
||||
title: string
|
||||
keywords: string
|
||||
description: string
|
||||
content: string
|
||||
created_at: string
|
||||
updated_at: string
|
||||
column_tag: string
|
||||
column_tag_url: string
|
||||
second_column_tag: string
|
||||
second_column_tag_url: string
|
||||
about: {
|
||||
id: number
|
||||
title: string
|
||||
}[]
|
||||
prevNews: {
|
||||
id: number
|
||||
title: string
|
||||
}
|
||||
nextNews: {
|
||||
id: number
|
||||
title: string
|
||||
}
|
||||
}
|
||||
export async function newsDetail(id:string, config: IWebsiteConfig):Promise<result<InewsDetail>>{
|
||||
const client = getRpcClient()
|
||||
const result = await client.call('baoxian/news/view', {
|
||||
id:id,
|
||||
app_id: config.id
|
||||
})
|
||||
return result
|
||||
}
|
||||
|
||||
|
||||
// 网站配置
|
||||
export interface IWebsiteConfig {
|
||||
id: number
|
||||
app_extra_tag: string
|
||||
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_filing: string
|
||||
app_filing_url: string
|
||||
app_baidu_zhanzhang: string
|
||||
}
|
||||
export async function websiteConfig(host:string):Promise<result<IWebsiteConfig>>{
|
||||
const client = getRpcClient()
|
||||
const result = await client.call('website/config', {
|
||||
host:host
|
||||
})
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
|
||||
export interface Icolumns {
|
||||
id: number
|
||||
title: string
|
||||
link: string
|
||||
desc:string
|
||||
}
|
||||
export async function columns(id: number):Promise<result<Icolumns>>{
|
||||
const client = getRpcClient()
|
||||
const result = await client.call('column/index', {
|
||||
app_id:id,
|
||||
})
|
||||
return result
|
||||
}
|
Reference in New Issue
Block a user