feat(web): forum and eco-materials api clients
This commit is contained in:
parent
e4ccbf733d
commit
899c4eb42e
|
|
@ -0,0 +1,58 @@
|
|||
import { HTTP_HEADER } from '@/common/constants'
|
||||
import { AnyObj } from '@/common/types'
|
||||
import { getLocalToken } from '@/common/utils'
|
||||
import { request } from '@umijs/max'
|
||||
|
||||
export interface ForumThreadListItem {
|
||||
id: number
|
||||
board: string
|
||||
title: string
|
||||
author_name: string
|
||||
like_count: number
|
||||
reply_count: number
|
||||
created_at: string
|
||||
}
|
||||
export interface ForumThread extends ForumThreadListItem {
|
||||
content: string
|
||||
author_id: string
|
||||
updated_at: string
|
||||
}
|
||||
export interface ForumReply {
|
||||
id: number
|
||||
thread_id: number
|
||||
floor: number
|
||||
content: string
|
||||
author_id: string
|
||||
author_name: string
|
||||
created_at: string
|
||||
}
|
||||
|
||||
const auth = () => ({ [HTTP_HEADER.AUTHORIZATION]: getLocalToken() })
|
||||
|
||||
export async function getBoards(options?: AnyObj) {
|
||||
return request<{ board: string, count: number }[]>('/api/forum/boards', { method: 'GET', ...(options || {}) })
|
||||
}
|
||||
export async function getThreads(params: { board?: string, page?: number, size?: number }, options?: AnyObj) {
|
||||
return request<{ list: ForumThreadListItem[], total: number }>('/api/forum/threads', { method: 'GET', params, ...(options || {}) })
|
||||
}
|
||||
export async function getThread(id: number, options?: AnyObj) {
|
||||
return request<{ thread: ForumThread, replies: ForumReply[] }>(`/api/forum/threads/${id}`, { method: 'GET', ...(options || {}) })
|
||||
}
|
||||
export async function getLikeStatus(id: number, options?: AnyObj) {
|
||||
return request<{ liked: boolean, like_count: number }>(`/api/forum/threads/${id}/like`, { method: 'GET', headers: auth(), ...(options || {}) })
|
||||
}
|
||||
export async function createThread(body: { board: string, title: string, content: string }, options?: AnyObj) {
|
||||
return request<ForumThread>('/api/forum/threads', { method: 'POST', headers: auth(), data: body, ...(options || {}) })
|
||||
}
|
||||
export async function createReply(id: number, body: { content: string }, options?: AnyObj) {
|
||||
return request<ForumReply>(`/api/forum/threads/${id}/replies`, { method: 'POST', headers: auth(), data: body, ...(options || {}) })
|
||||
}
|
||||
export async function toggleLike(id: number, options?: AnyObj) {
|
||||
return request<{ liked: boolean, like_count: number }>(`/api/forum/threads/${id}/like`, { method: 'POST', headers: auth(), ...(options || {}) })
|
||||
}
|
||||
export async function deleteThread(id: number, options?: AnyObj) {
|
||||
return request<{ ok: boolean }>(`/api/forum/threads/${id}`, { method: 'DELETE', headers: auth(), ...(options || {}) })
|
||||
}
|
||||
export async function deleteReply(id: number, options?: AnyObj) {
|
||||
return request<{ ok: boolean }>(`/api/forum/replies/${id}`, { method: 'DELETE', headers: auth(), ...(options || {}) })
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
import * as admin from './admin'
|
||||
import * as config from './config'
|
||||
import * as material from './material'
|
||||
import * as predict from './predict'
|
||||
import * as project from './project'
|
||||
import * as template from './template'
|
||||
import * as user from './user'
|
||||
import * as forum from './forum'
|
||||
|
||||
export default {
|
||||
admin,
|
||||
user,
|
||||
project,
|
||||
template,
|
||||
material,
|
||||
config,
|
||||
predict,
|
||||
forum
|
||||
}
|
||||
|
|
@ -0,0 +1,295 @@
|
|||
import { DATA_TYPE, HTTP_HEADER } from '@/common/constants'
|
||||
import { AnyObj, Arrayable, ECO_LEVEL, Material } from '@/common/types'
|
||||
import { getLocalToken } from '@/common/utils'
|
||||
import { request } from '@umijs/max'
|
||||
|
||||
export async function batchCreateSelf(
|
||||
body: {
|
||||
name?: string
|
||||
category?: string
|
||||
brand?: string
|
||||
factory?: string
|
||||
spec?: string
|
||||
eco_level?: ECO_LEVEL
|
||||
health_level?: string
|
||||
methanal_min_be?: number
|
||||
methanal_be_area?: number
|
||||
methanal_be_roc?: number
|
||||
tvoc_min_be?: number
|
||||
tvoc_be_area?: number
|
||||
tvoc_be_roc?: number
|
||||
benzene_min_be?: number
|
||||
benzene_be_area?: number
|
||||
benzene_be_roc?: number
|
||||
toluene_min_be?: number
|
||||
toluene_be_area?: number
|
||||
toluene_be_roc?: number
|
||||
p_xylene_min_be?: number
|
||||
p_xylene_be_area?: number
|
||||
p_xylene_be_roc?: number
|
||||
}[],
|
||||
options?: AnyObj
|
||||
) {
|
||||
return request<{ count: number }>(`/api/mtrl/self/batch`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
[HTTP_HEADER.AUTHORIZATION]: getLocalToken()
|
||||
},
|
||||
data: body,
|
||||
...(options || {})
|
||||
})
|
||||
}
|
||||
|
||||
export async function createSelf(
|
||||
body: {
|
||||
name?: string
|
||||
category?: string
|
||||
brand?: string
|
||||
factory?: string
|
||||
spec?: string
|
||||
eco_level?: ECO_LEVEL
|
||||
health_level?: string
|
||||
methanal_min_be?: number
|
||||
methanal_be_area?: number
|
||||
methanal_be_roc?: number
|
||||
tvoc_min_be?: number
|
||||
tvoc_be_area?: number
|
||||
tvoc_be_roc?: number
|
||||
benzene_min_be?: number
|
||||
benzene_be_area?: number
|
||||
benzene_be_roc?: number
|
||||
toluene_min_be?: number
|
||||
toluene_be_area?: number
|
||||
toluene_be_roc?: number
|
||||
p_xylene_min_be?: number
|
||||
p_xylene_be_area?: number
|
||||
p_xylene_be_roc?: number
|
||||
},
|
||||
options?: AnyObj
|
||||
) {
|
||||
return request<Material>(`/api/mtrl/self`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
[HTTP_HEADER.AUTHORIZATION]: getLocalToken()
|
||||
},
|
||||
data: body,
|
||||
...(options || {})
|
||||
})
|
||||
}
|
||||
|
||||
export async function patchSelf(
|
||||
query: {
|
||||
material_id: string
|
||||
},
|
||||
body: {
|
||||
name?: string
|
||||
category?: string
|
||||
brand?: string
|
||||
factory?: string
|
||||
spec?: string
|
||||
eco_level?: ECO_LEVEL
|
||||
health_level?: string
|
||||
methanal_min_be?: number
|
||||
methanal_be_area?: number
|
||||
methanal_be_roc?: number
|
||||
tvoc_min_be?: number
|
||||
tvoc_be_area?: number
|
||||
tvoc_be_roc?: number
|
||||
benzene_min_be?: number
|
||||
benzene_be_area?: number
|
||||
benzene_be_roc?: number
|
||||
toluene_min_be?: number
|
||||
toluene_be_area?: number
|
||||
toluene_be_roc?: number
|
||||
p_xylene_min_be?: number
|
||||
p_xylene_be_area?: number
|
||||
p_xylene_be_roc?: number
|
||||
},
|
||||
options?: AnyObj
|
||||
) {
|
||||
return request<Material>(`/api/mtrl/self`, {
|
||||
method: 'PATCH',
|
||||
headers: {
|
||||
[HTTP_HEADER.AUTHORIZATION]: getLocalToken()
|
||||
},
|
||||
params: query,
|
||||
data: body,
|
||||
...(options || {})
|
||||
})
|
||||
}
|
||||
|
||||
export async function patchPub(
|
||||
query: {
|
||||
material_id: string
|
||||
},
|
||||
body: {
|
||||
name?: string
|
||||
category?: string
|
||||
brand?: string
|
||||
factory?: string
|
||||
spec?: string
|
||||
eco_level?: ECO_LEVEL
|
||||
health_level?: string
|
||||
methanal_min_be?: number
|
||||
methanal_be_area?: number
|
||||
methanal_be_roc?: number
|
||||
tvoc_min_be?: number
|
||||
tvoc_be_area?: number
|
||||
tvoc_be_roc?: number
|
||||
benzene_min_be?: number
|
||||
benzene_be_area?: number
|
||||
benzene_be_roc?: number
|
||||
toluene_min_be?: number
|
||||
toluene_be_area?: number
|
||||
toluene_be_roc?: number
|
||||
p_xylene_min_be?: number
|
||||
p_xylene_be_area?: number
|
||||
p_xylene_be_roc?: number
|
||||
},
|
||||
options?: AnyObj
|
||||
) {
|
||||
return request<Material>(`/api/mtrl/pub`, {
|
||||
method: 'PATCH',
|
||||
headers: {
|
||||
[HTTP_HEADER.AUTHORIZATION]: getLocalToken()
|
||||
},
|
||||
params: query,
|
||||
data: body,
|
||||
...(options || {})
|
||||
})
|
||||
}
|
||||
|
||||
export async function removeSelf(
|
||||
query: {
|
||||
material_id: Arrayable<string>
|
||||
},
|
||||
options?: AnyObj
|
||||
) {
|
||||
return request<{ count: number }>('/api/mtrl/self', {
|
||||
method: 'DELETE',
|
||||
headers: {
|
||||
[HTTP_HEADER.AUTHORIZATION]: getLocalToken()
|
||||
},
|
||||
params: query,
|
||||
...(options || {})
|
||||
})
|
||||
}
|
||||
|
||||
export async function collectPub(
|
||||
body: {
|
||||
material_id: Arrayable<string>
|
||||
c: number
|
||||
},
|
||||
options?: AnyObj
|
||||
) {
|
||||
return request<{ count: number }>('/api/mtrl/pub/collect', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
[HTTP_HEADER.AUTHORIZATION]: getLocalToken()
|
||||
},
|
||||
data: body,
|
||||
...(options || {})
|
||||
})
|
||||
}
|
||||
|
||||
export async function search(
|
||||
type: DATA_TYPE,
|
||||
query?: {
|
||||
material_id?: Arrayable<string>
|
||||
name?: Arrayable<string>
|
||||
category?: Arrayable<string>
|
||||
brand?: Arrayable<string>
|
||||
factory?: Arrayable<string>
|
||||
spec?: Arrayable<string>
|
||||
eco_level?: Arrayable<ECO_LEVEL>
|
||||
health_level?: Arrayable<string>
|
||||
sort_order?: Arrayable<string>
|
||||
display?: number
|
||||
collected?: number
|
||||
creator_id?: Arrayable<string>
|
||||
creator_name?: Arrayable<string>
|
||||
with_cltrs?: number
|
||||
sort_key?: Arrayable<string>
|
||||
sort_val?: Arrayable<string>
|
||||
page?: number
|
||||
size?: number
|
||||
},
|
||||
options?: AnyObj
|
||||
) {
|
||||
if (type === DATA_TYPE.PRIVATE) {
|
||||
delete query?.display
|
||||
delete query?.collected
|
||||
delete query?.with_cltrs
|
||||
}
|
||||
return request<Material[]>(`/api/mtrl/${type}`, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
[HTTP_HEADER.AUTHORIZATION]: getLocalToken()
|
||||
},
|
||||
params: query,
|
||||
...(options || {})
|
||||
})
|
||||
}
|
||||
|
||||
export async function searchAll(
|
||||
query?: {
|
||||
material_id?: Arrayable<string>
|
||||
name?: Arrayable<string>
|
||||
type?: DATA_TYPE
|
||||
category?: Arrayable<string>
|
||||
brand?: Arrayable<string>
|
||||
factory?: Arrayable<string>
|
||||
spec?: Arrayable<string>
|
||||
eco_level?: Arrayable<ECO_LEVEL>
|
||||
health_level?: Arrayable<string>
|
||||
sort_order?: Arrayable<string>
|
||||
display?: number
|
||||
collected?: number
|
||||
creator_id?: Arrayable<string>
|
||||
creator_name?: Arrayable<string>
|
||||
sort_key?: string
|
||||
sort_val?: string
|
||||
page?: number
|
||||
size?: number
|
||||
},
|
||||
options?: AnyObj
|
||||
) {
|
||||
return request<Material[]>('/api/mtrl', {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
[HTTP_HEADER.AUTHORIZATION]: getLocalToken()
|
||||
},
|
||||
params: query,
|
||||
...(options || {})
|
||||
})
|
||||
}
|
||||
|
||||
export async function updatePubSort(
|
||||
body: {
|
||||
material_id: string
|
||||
sort_order: number
|
||||
},
|
||||
options?: AnyObj
|
||||
) {
|
||||
return request<{ material_id: string; sort_order: number }>(`/api/mtrl/pub/sort`, {
|
||||
method: 'PATCH',
|
||||
headers: {
|
||||
[HTTP_HEADER.AUTHORIZATION]: getLocalToken()
|
||||
},
|
||||
data: body,
|
||||
...(options || {})
|
||||
})
|
||||
}
|
||||
|
||||
export interface EcoMaterial {
|
||||
material_id: string
|
||||
name: string
|
||||
category: string
|
||||
brand: string
|
||||
factory: string
|
||||
eco_level: string
|
||||
methanal: number
|
||||
}
|
||||
export async function getEcoMaterials(options?: AnyObj) {
|
||||
return request<EcoMaterial[]>('/api/mtrl/eco', { method: 'GET', ...(options || {}) })
|
||||
}
|
||||
Loading…
Reference in New Issue