diff --git a/src/api/topic/index.ts b/src/api/topic/index.ts index 9e38de0d..8f514f2f 100644 --- a/src/api/topic/index.ts +++ b/src/api/topic/index.ts @@ -1,17 +1,17 @@ -import { request } from '@/utils/request' +import { fetchGet } from '@/utils/request' import { KUNGalgameTopic } from './types/topic' export async function getTopicApi(id: number) { - return await request(`/topic/${id}`) + return await fetchGet(`/topic/${id}`) } export async function getTopicReplyApi(id: number) { - return await request(`/topic/reply/${id}`) + return await fetchGet(`/topic/reply/${id}`) } export async function getTopicCommentApi(id: number) { - return await request(`/topic/comment/${id}`) + return await fetchGet(`/topic/comment/${id}`) } // 获取指定范围内的帖子数据 @@ -20,15 +20,9 @@ export async function getTopicRangeApi( count: number ): Promise { const url = `http://127.0.0.1:10007/topic/topics/kun?start=${start}&count=${count}` - const options = { - method: 'GET', - headers: { - 'Content-Type': 'application/json', - }, - } try { - const response = await request(url, options) + const response = await fetchGet(url) return response } catch (error) { console.error('Error fetching topics:', error) diff --git a/src/styles/editor/editor.scss b/src/styles/editor/editor.scss index 07545b9b..7890104e 100644 --- a/src/styles/editor/editor.scss +++ b/src/styles/editor/editor.scss @@ -12,6 +12,14 @@ } } +s { + text-decoration: line-through; +} + +* { + text-shadow: none; +} + :root { // textarea - css vars --w-e-textarea-bg-color: var(--kungalgame-white); diff --git a/src/utils/request.ts b/src/utils/request.ts index 7cadefce..048a0f3d 100644 --- a/src/utils/request.ts +++ b/src/utils/request.ts @@ -1,10 +1,85 @@ -// request.ts +type HttpMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' -export async function request( - url: string, - options: RequestInit = {} -): Promise { - const response = await fetch(url, options) - const data = await response.json() - return data as T +type FetchOptions = { + method: HttpMethod + headers?: Record + body?: BodyInit } + +const fetchRequest = async ( + url: string, + options: FetchOptions +): Promise => { + try { + const response = await fetch(url, options) + + if (!response.ok) { + throw new Error('Request Error!') + } + + const data: T = await response.json() + return data + } catch (error) { + throw new Error('Request Error!') + } +} + +const fetchGet = async ( + url: string, + headers?: Record +): Promise => { + const options: FetchOptions = { + method: 'GET', + headers: headers, + } + + return await fetchRequest(url, options) +} + +const fetchPost = async ( + url: string, + body?: Record, + headers?: Record +): Promise => { + const options: FetchOptions = { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + ...headers, + }, + body: JSON.stringify(body), + } + + return await fetchRequest(url, options) +} + +const fetchPut = async ( + url: string, + body?: Record, + headers?: Record +): Promise => { + const options: FetchOptions = { + method: 'PUT', + headers: { + 'Content-Type': 'application/json', + ...headers, + }, + body: JSON.stringify(body), + } + + return await fetchRequest(url, options) +} + +const fetchDelete = async ( + url: string, + headers?: Record +): Promise => { + const options: FetchOptions = { + method: 'DELETE', + headers: headers, + } + + return await fetchRequest(url, options) +} + +export { fetchGet, fetchPost, fetchPut, fetchDelete }