first commit

This commit is contained in:
zhouyanli
2026-10-27 13:54:39 +08:00
commit 5c9aca27e8
24 changed files with 1498 additions and 0 deletions

33
utils/request.js Normal file
View File

@@ -0,0 +1,33 @@
import config from '@/config'
/**
* 服务端请求封装
*
* 约定返回体:{ code: 0, message: '', data: {...} }
* code 为 0 或未返回时视为成功,data 直接透出。
*/
export function request({ url, method = 'GET', data = {}, header = {} }) {
return new Promise((resolve, reject) => {
uni.request({
url: /^https?:\/\//.test(url) ? url : config.apiBaseUrl + url,
method,
data,
header: {
'Content-Type': 'application/json',
...header
},
success: (res) => {
const body = res.data || {}
const ok = res.statusCode >= 200 && res.statusCode < 300
if (ok && (body.code === undefined || body.code === 0)) {
resolve(body.data !== undefined ? body.data : body)
return
}
reject(new Error(body.message || `请求失败(${res.statusCode})`))
},
fail: (err) => {
reject(new Error(err.errMsg || '网络异常,请稍后重试'))
}
})
})
}