Signed-off-by: 吴文峰 <kevin@lmve.net>

This commit is contained in:
2026-04-16 20:36:03 +08:00
commit 3bb51d0794
29 changed files with 1063 additions and 0 deletions
+50
View File
@@ -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')