Signed-off-by: 吴文峰 <kevin@lmve.net>
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
/**
|
||||
* API 接口汇总
|
||||
* 按模块分组管理接口
|
||||
*/
|
||||
|
||||
// 用户相关
|
||||
export const user = {
|
||||
login: (data) => post('/api/user/login', data),
|
||||
logout: () => post('/api/user/logout'),
|
||||
info: () => get('/api/user/info')
|
||||
}
|
||||
|
||||
// 订单相关
|
||||
export const order = {
|
||||
list: (data) => get('/api/order/list', data),
|
||||
detail: (id) => get('/api/order/detail', { id }),
|
||||
create: (data) => post('/api/order/create', data)
|
||||
}
|
||||
|
||||
// 消息相关
|
||||
export const message = {
|
||||
list: (data) => get('/api/message/list', data),
|
||||
read: (id) => post('/api/message/read', { id })
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
import { useConfigStore } from '@/stores/config'
|
||||
|
||||
/**
|
||||
* 基础请求封装
|
||||
* @param {string} path - 接口路径
|
||||
* @param {object} data - 请求参数
|
||||
* @param {string} method - 请求方法
|
||||
*/
|
||||
export const request = (path, data = {}, method = 'GET') => {
|
||||
const config = useConfigStore()
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
uni.request({
|
||||
url: config.apiBaseUrl + path,
|
||||
data,
|
||||
method,
|
||||
header: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
success: (res) => {
|
||||
if (res.statusCode === 200) {
|
||||
resolve(res.data)
|
||||
} else {
|
||||
uni.showToast({
|
||||
title: '请求失败',
|
||||
icon: 'none'
|
||||
})
|
||||
reject(res)
|
||||
}
|
||||
},
|
||||
fail: (err) => {
|
||||
uni.showToast({
|
||||
title: '网络错误',
|
||||
icon: 'none'
|
||||
})
|
||||
reject(err)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* GET 请求
|
||||
*/
|
||||
export const get = (path, data) => request(path, data, 'GET')
|
||||
|
||||
/**
|
||||
* POST 请求
|
||||
*/
|
||||
export const post = (path, data) => request(path, data, 'POST')
|
||||
Reference in New Issue
Block a user