+1
-47
@@ -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')
|
||||
|
||||
Reference in New Issue
Block a user