|
@@ -1,20 +1,18 @@
|
|
|
|
|
+import request from './request'
|
|
|
// 获取用户详细信息
|
|
// 获取用户详细信息
|
|
|
export async function getUserInfo(userId: string | number) {
|
|
export async function getUserInfo(userId: string | number) {
|
|
|
- const token = uni.getStorageSync('token')
|
|
|
|
|
- const res: any = await uni.request({
|
|
|
|
|
|
|
+ // token will be injected by `request` wrapper
|
|
|
|
|
+ const res: any = await request({
|
|
|
url: `https://wx.baiyun.work/user/${userId}`,
|
|
url: `https://wx.baiyun.work/user/${userId}`,
|
|
|
method: 'GET',
|
|
method: 'GET',
|
|
|
- header: {
|
|
|
|
|
- 'content-type': 'application/json',
|
|
|
|
|
- Authorization: `Bearer ${token}`
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ header: { 'content-type': 'application/json' }
|
|
|
})
|
|
})
|
|
|
return res
|
|
return res
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 使用微信 code 登录并获取 token/openid
|
|
// 使用微信 code 登录并获取 token/openid
|
|
|
export async function loginWithWx(code: string, role: number) {
|
|
export async function loginWithWx(code: string, role: number) {
|
|
|
- const res: any = await uni.request({
|
|
|
|
|
|
|
+ const res: any = await request({
|
|
|
url: 'https://wx.baiyun.work/get_openid',
|
|
url: 'https://wx.baiyun.work/get_openid',
|
|
|
method: 'POST',
|
|
method: 'POST',
|
|
|
header: { 'Content-Type': 'application/json' },
|
|
header: { 'Content-Type': 'application/json' },
|
|
@@ -25,14 +23,10 @@ export async function loginWithWx(code: string, role: number) {
|
|
|
|
|
|
|
|
// 拉取当前登录用户信息(统一包装 POST /user_info)
|
|
// 拉取当前登录用户信息(统一包装 POST /user_info)
|
|
|
export async function fetchUserInfo() {
|
|
export async function fetchUserInfo() {
|
|
|
- const token = uni.getStorageSync('token')
|
|
|
|
|
- const res: any = await uni.request({
|
|
|
|
|
|
|
+ const res: any = await request({
|
|
|
url: 'https://wx.baiyun.work/user_info',
|
|
url: 'https://wx.baiyun.work/user_info',
|
|
|
method: 'POST',
|
|
method: 'POST',
|
|
|
- header: {
|
|
|
|
|
- 'Content-Type': 'application/json',
|
|
|
|
|
- Authorization: `Bearer ${token}`
|
|
|
|
|
- },
|
|
|
|
|
|
|
+ header: { 'Content-Type': 'application/json' },
|
|
|
data: {}
|
|
data: {}
|
|
|
})
|
|
})
|
|
|
return res
|
|
return res
|
|
@@ -40,14 +34,10 @@ export async function fetchUserInfo() {
|
|
|
|
|
|
|
|
// 更新用户信息 POST /update_user_info
|
|
// 更新用户信息 POST /update_user_info
|
|
|
export async function updateUserInfo(payload: any) {
|
|
export async function updateUserInfo(payload: any) {
|
|
|
- const token = uni.getStorageSync('token')
|
|
|
|
|
- const res: any = await uni.request({
|
|
|
|
|
|
|
+ const res: any = await request({
|
|
|
url: 'https://wx.baiyun.work/update_user_info',
|
|
url: 'https://wx.baiyun.work/update_user_info',
|
|
|
method: 'POST',
|
|
method: 'POST',
|
|
|
- header: {
|
|
|
|
|
- 'Content-Type': 'application/json',
|
|
|
|
|
- Authorization: `Bearer ${token}`
|
|
|
|
|
- },
|
|
|
|
|
|
|
+ header: { 'Content-Type': 'application/json' },
|
|
|
data: payload
|
|
data: payload
|
|
|
})
|
|
})
|
|
|
return res
|
|
return res
|
|
@@ -64,7 +54,8 @@ export function uploadAvatar(filePath: string) {
|
|
|
header: { Authorization: `Bearer ${token}` },
|
|
header: { Authorization: `Bearer ${token}` },
|
|
|
success: (uploadRes: any) => {
|
|
success: (uploadRes: any) => {
|
|
|
try {
|
|
try {
|
|
|
- const parsed = JSON.parse(uploadRes.data || '{}')
|
|
|
|
|
|
|
+ // 头像上传返回体可能包含 big int 字段,这里使用 json-bigint 安全解析
|
|
|
|
|
+ const parsed = JSON.parse(uploadRes.data || '{}')
|
|
|
resolve(parsed)
|
|
resolve(parsed)
|
|
|
} catch (e) {
|
|
} catch (e) {
|
|
|
resolve({ data: uploadRes.data })
|
|
resolve({ data: uploadRes.data })
|
|
@@ -77,21 +68,18 @@ export function uploadAvatar(filePath: string) {
|
|
|
|
|
|
|
|
// 下载头像(封装 uni.downloadFile)
|
|
// 下载头像(封装 uni.downloadFile)
|
|
|
export async function downloadAvatar(userId: string) {
|
|
export async function downloadAvatar(userId: string) {
|
|
|
- const token = uni.getStorageSync('token')
|
|
|
|
|
const res: any = await uni.downloadFile({
|
|
const res: any = await uni.downloadFile({
|
|
|
url: `https://wx.baiyun.work/user/avatar/${userId}`,
|
|
url: `https://wx.baiyun.work/user/avatar/${userId}`,
|
|
|
- header: { Authorization: `Bearer ${token}` }
|
|
|
|
|
|
|
+ header: { Authorization: `Bearer ${uni.getStorageSync('token')}` }
|
|
|
})
|
|
})
|
|
|
return res
|
|
return res
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 地理编码/最近位置查询
|
|
// 地理编码/最近位置查询
|
|
|
export async function geocodeNearest(latitude: number, longitude: number) {
|
|
export async function geocodeNearest(latitude: number, longitude: number) {
|
|
|
- const token = uni.getStorageSync('token')
|
|
|
|
|
- const res: any = await uni.request({
|
|
|
|
|
|
|
+ const res: any = await request({
|
|
|
url: `https://wx.baiyun.work/geo/nearest?latitude=${latitude}&longitude=${longitude}`,
|
|
url: `https://wx.baiyun.work/geo/nearest?latitude=${latitude}&longitude=${longitude}`,
|
|
|
- method: 'GET',
|
|
|
|
|
- header: { Authorization: `Bearer ${token}` }
|
|
|
|
|
|
|
+ method: 'GET'
|
|
|
})
|
|
})
|
|
|
return res
|
|
return res
|
|
|
}
|
|
}
|