refactor(api): 重构请求函数并优化代码格式

- 重构了 http.js 中的 request 函数,使用解构赋值简化参数
- 更新了 auth 和 goods模块中的请求函数,采用新的 request 函数格式
- 优化了代码格式,包括缩进、换行和空格
This commit is contained in:
xingyy 2025-01-22 11:34:36 +08:00
parent 635bca0fb6
commit 63e24791f2
3 changed files with 32 additions and 27 deletions

View File

@ -1,23 +1,25 @@
import { getHttp } from '~/api/http.js'
import { request } from '@/api/http.js'
export async function senCode(data) {
const http = getHttp()
return await http('/api/v1/m/user/send', {
return await request({
url:'/api/v1/m/user/send',
method: 'POST',
body: data,
})
}
export async function userLogin(data) {
const http = getHttp()
return await http('/api/v1/m/user/login', {
return await request( {
url:'/api/v1/m/user/login',
method: 'POST',
body: data,
data
})
}
export async function userUpdate(data) {
const http = getHttp()
return await http('/api/v1/m/user/update', {
return await request( {
url:'/api/v1/m/user/update',
method: 'POST',
body: data,
data
})
}

View File

@ -1,28 +1,32 @@
import { request } from '~/api/http.js'
import { request } from '@/api/http.js'
export async function artworkList(data) {
return await request('/api/v1/m/auction/default/artwork/list', {
return await request( {
url:'/api/v1/m/auction/default/artwork/list',
method: 'POST',
body: data,
data
})
}
export async function defaultDetail(data) {
return await request('/api/v1/m/auction/default/detail', {
return await request ({
url:'/api/v1/m/auction/default/detail',
method: 'POST',
body: data,
data
})
}
export async function artworkDetail(data) {
return await request('/api/v1/m/artwork/detail', {
return await request( {
url:'/api/v1/m/artwork/detail',
method: 'POST',
body: data,
data,
})
}
export async function userArtworks(data) {
return await request('/api/v1/m/user/artworks', {
return await request( {
url:'/api/v1/m/user/artworks',
method: 'POST',
body: data,
data
})
}

View File

@ -1,9 +1,9 @@
import { useRuntimeConfig } from '#app'
import { ofetch} from 'ofetch'
import { message } from '@/components/x-message/useMessage.js'
import { authStore } from "@/stores/auth/index.js"
import {useRuntimeConfig} from '#app'
import {ofetch} from 'ofetch'
import {message} from '@/components/x-message/useMessage.js'
import {authStore} from "@/stores/auth/index.js"
let httpStatusErrorHandler
let httpStatusErrorHandler
let http
// HTTP 状态码映射
@ -120,11 +120,10 @@ export function getHttp() {
}
// 导出请求工具函数
export async function request(url, options) {
export async function request({url,...options}) {
const http = getHttp()
try {
const response = await http(url, options)
return response.data
return await http(url, {...options,body:options.data})
} catch (error) {
throw error
}