12 changed files with 205 additions and 24324 deletions
@ -0,0 +1,8 @@ |
|||||
|
import request from "../utils/request.js"; |
||||
|
export function getList(params) { |
||||
|
return request({ |
||||
|
url: "/api/v1/user/list", |
||||
|
method: "get", |
||||
|
params, |
||||
|
}); |
||||
|
} |
After Width: | Height: | Size: 737 B |
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -0,0 +1 @@ |
|||||
|
export const baseUrl = ""; |
@ -0,0 +1,40 @@ |
|||||
|
// utils/request.js
|
||||
|
const BASE_URL = 'https://your-api-url.com'; // 替换为你的后端地址
|
||||
|
|
||||
|
export default function request(options = {}) { |
||||
|
// 获取token(假设存储在本地storage)
|
||||
|
const token = uni.getStorageSync('token') || ''; |
||||
|
|
||||
|
return new Promise((resolve, reject) => { |
||||
|
uni.request({ |
||||
|
url: BASE_URL + options.url, |
||||
|
method: options.method || "GET", |
||||
|
data: |
||||
|
options.method === "GET" ? options.data : JSON.stringify(options.data), |
||||
|
header: { |
||||
|
"Content-Type": options.contentType || "application/json", |
||||
|
Authorization: token ? `Bearer ${token}` : "", |
||||
|
...options.header, |
||||
|
}, |
||||
|
success: (res) => { |
||||
|
// 这里可根据后端返回结构统一处理
|
||||
|
if (res.statusCode === 200) { |
||||
|
resolve(res.data); |
||||
|
} else if (res.statusCode === 401) { |
||||
|
uni.showToast({ title: "登录失效,请重新登录", icon: "none" }); |
||||
|
uni.redirectTo({ |
||||
|
url: "/pages/login/login", |
||||
|
}); |
||||
|
reject(res); |
||||
|
} else { |
||||
|
uni.showToast({ title: res.data.msg || "请求失败", icon: "none" }); |
||||
|
reject(res); |
||||
|
} |
||||
|
}, |
||||
|
fail: (err) => { |
||||
|
uni.showToast({ title: "网络异常", icon: "none" }); |
||||
|
reject(err); |
||||
|
}, |
||||
|
}); |
||||
|
}); |
||||
|
} |
Loading…
Reference in new issue