From 899c4eb42e2077a3fbec14cd9fe36ba406d4997a Mon Sep 17 00:00:00 2001 From: zty Date: Tue, 7 Jul 2026 03:29:37 -0400 Subject: [PATCH] feat(web): forum and eco-materials api clients --- .../iapip-web/src/services/api/forum.ts | 58 ++++ .../iapip-web/src/services/api/index.ts | 19 ++ .../iapip-web/src/services/api/material.ts | 295 ++++++++++++++++++ 3 files changed, 372 insertions(+) create mode 100644 空气质量预测/源码/用户端/iapip-web/src/services/api/forum.ts create mode 100644 空气质量预测/源码/用户端/iapip-web/src/services/api/index.ts create mode 100644 空气质量预测/源码/用户端/iapip-web/src/services/api/material.ts diff --git a/空气质量预测/源码/用户端/iapip-web/src/services/api/forum.ts b/空气质量预测/源码/用户端/iapip-web/src/services/api/forum.ts new file mode 100644 index 0000000..ede536c --- /dev/null +++ b/空气质量预测/源码/用户端/iapip-web/src/services/api/forum.ts @@ -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('/api/forum/threads', { method: 'POST', headers: auth(), data: body, ...(options || {}) }) +} +export async function createReply(id: number, body: { content: string }, options?: AnyObj) { + return request(`/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 || {}) }) +} diff --git a/空气质量预测/源码/用户端/iapip-web/src/services/api/index.ts b/空气质量预测/源码/用户端/iapip-web/src/services/api/index.ts new file mode 100644 index 0000000..a777be7 --- /dev/null +++ b/空气质量预测/源码/用户端/iapip-web/src/services/api/index.ts @@ -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 +} diff --git a/空气质量预测/源码/用户端/iapip-web/src/services/api/material.ts b/空气质量预测/源码/用户端/iapip-web/src/services/api/material.ts new file mode 100644 index 0000000..d50e1d0 --- /dev/null +++ b/空气质量预测/源码/用户端/iapip-web/src/services/api/material.ts @@ -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(`/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(`/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(`/api/mtrl/pub`, { + method: 'PATCH', + headers: { + [HTTP_HEADER.AUTHORIZATION]: getLocalToken() + }, + params: query, + data: body, + ...(options || {}) + }) +} + +export async function removeSelf( + query: { + material_id: Arrayable + }, + 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 + 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 + name?: Arrayable + category?: Arrayable + brand?: Arrayable + factory?: Arrayable + spec?: Arrayable + eco_level?: Arrayable + health_level?: Arrayable + sort_order?: Arrayable + display?: number + collected?: number + creator_id?: Arrayable + creator_name?: Arrayable + with_cltrs?: number + sort_key?: Arrayable + sort_val?: Arrayable + page?: number + size?: number + }, + options?: AnyObj +) { + if (type === DATA_TYPE.PRIVATE) { + delete query?.display + delete query?.collected + delete query?.with_cltrs + } + return request(`/api/mtrl/${type}`, { + method: 'GET', + headers: { + [HTTP_HEADER.AUTHORIZATION]: getLocalToken() + }, + params: query, + ...(options || {}) + }) +} + +export async function searchAll( + query?: { + material_id?: Arrayable + name?: Arrayable + type?: DATA_TYPE + category?: Arrayable + brand?: Arrayable + factory?: Arrayable + spec?: Arrayable + eco_level?: Arrayable + health_level?: Arrayable + sort_order?: Arrayable + display?: number + collected?: number + creator_id?: Arrayable + creator_name?: Arrayable + sort_key?: string + sort_val?: string + page?: number + size?: number + }, + options?: AnyObj +) { + return request('/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('/api/mtrl/eco', { method: 'GET', ...(options || {}) }) +}