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
+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')