Signed-off-by: 吴文峰 <kevin@lmve.net>
This commit is contained in:
2026-04-17 20:46:21 +08:00
parent 3bb51d0794
commit 8dce0346a7
10 changed files with 370 additions and 78 deletions
+23 -16
View File
@@ -4,21 +4,28 @@
*/
// 用户相关
export const user = {
login: (data) => post('/api/user/login', data),
logout: () => post('/api/user/logout'),
info: () => get('/api/user/info')
export const api = {
/**
* GET 请求(一般不需要认证)
*/
get(path) {
},
/**
* POST JSON
*/
post(path, data = {},callback) {
console.log("post")
},
/**
* POST FormData(文件上传)
*/
upload(path, file) {
},
}
// 订单相关
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 })
}
export default api
+1 -47
View File
@@ -1,50 +1,4 @@
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)
}
})
})
}
const useConfig=useConfigStore()
/**
* GET 请求
*/
export const get = (path, data) => request(path, data, 'GET')
/**
* POST 请求
*/
export const post = (path, data) => request(path, data, 'POST')
+9
View File
@@ -0,0 +1,9 @@
import api from ".";
export const userApi = {
login(username, password, remember) {
return api.post('/users/login', { username, password, remember })
},
}