Files
JayuCloud/WeChatProgram/api/user.js
T

333 lines
12 KiB
JavaScript
Raw Normal View History

/**
* Mini program API wrapper for this module.
* Call guide: require this module in a page, then invoke the matching method from page event handlers or lifecycle hooks.
*/
2026-04-01 15:18:35 +08:00
const request = require('../utils/request')
2026-05-23 18:45:41 +08:00
/**
* Purpose: actionGuard supports user.js by holding or executing the action guard page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const actionGuard = require('../utils/action-guard')
const { API_BASE_URL, REQUEST_TIMEOUT } = require('../utils/config')
2026-05-23 18:45:41 +08:00
/**
* Purpose: normalizeUploadResponse supports user.js by holding or executing the normalize upload response page or API role.
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
*/
function normalizeUploadResponse(response) {
if (!response) {
throw new Error('头像上传失败')
}
if (response.statusCode === 401) {
throw new Error('登录已过期,请重新登录')
}
if (response.statusCode >= 400) {
throw new Error('头像上传失败')
}
let payload = response.data
if (typeof payload === 'string') {
try {
payload = JSON.parse(payload)
} catch (error) {}
}
if (payload && typeof payload === 'object' && Object.prototype.hasOwnProperty.call(payload, 'code')) {
if (payload.code === 200) {
return payload.data
}
throw new Error(payload.message || '头像上传失败')
}
return payload
}
2026-04-01 15:18:35 +08:00
module.exports = {
2026-05-23 18:45:41 +08:00
/**
* Purpose: getUserInfo supports user.js by holding or executing the get user info page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
2026-04-01 15:18:35 +08:00
getUserInfo() {
return request({
url: '/user/info'
})
},
// 我的页常用数据:
// 资产、余额流水、消息、公告、VIP 充值档位和所属关系都从这里拿。
getMyAsset() {
return request({
url: '/user/asset/me'
})
},
2026-05-23 18:45:41 +08:00
/**
* Purpose: getMyBalanceHistory supports user.js by holding or executing the get my balance history page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
getMyBalanceHistory() {
return request({
url: '/user/balance/history/me'
})
},
2026-05-23 18:45:41 +08:00
/**
* Purpose: listMyMessages supports user.js by holding or executing the list my messages page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
listMyMessages() {
return request({
url: '/system-message/my/list'
})
},
2026-05-23 18:45:41 +08:00
/**
* Purpose: listMyPopupMessages supports user.js by holding or executing the list my popup messages page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
listMyPopupMessages() {
return request({
url: '/system-message/my/popup'
})
},
2026-05-23 18:45:41 +08:00
/**
* Purpose: getMyUnreadMessageCount supports user.js by holding or executing the get my unread message count page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
getMyUnreadMessageCount() {
return request({
url: '/system-message/my/unread-count'
})
},
2026-05-23 18:45:41 +08:00
/**
* Purpose: markMessagePopupShown supports user.js by holding or executing the mark message popup shown page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
markMessagePopupShown(id) {
return request({
url: `/system-message/my/${id}/popup-shown`,
method: 'PUT',
data: {}
})
},
2026-05-23 18:45:41 +08:00
/**
* Purpose: markMessageRead supports user.js by holding or executing the mark message read page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
markMessageRead(id) {
return request({
url: `/system-message/my/${id}/read`,
method: 'PUT',
data: {}
})
},
2026-05-23 18:45:41 +08:00
/**
* Purpose: listMyAnnouncements supports user.js by holding or executing the list my announcements page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
listMyAnnouncements() {
return request({
url: '/announcement/my/list'
})
},
// 这里只是“展示型充值档位”,不发起支付、不改余额。
listMyVipRechargePlans() {
return request({
url: '/vip-recharge-plan/my/list'
})
},
2026-05-23 18:45:41 +08:00
/**
* Purpose: getShopManagerContact supports user.js by holding or executing the get shop manager contact page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
getShopManagerContact(shopId) {
return request({
url: `/contact-info/shop/${shopId}/manager`
})
},
2026-05-23 18:45:41 +08:00
/**
* Purpose: getProductArtistContact supports user.js by holding or executing the get product artist contact page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
getProductArtistContact(productId, artistId) {
return request({
url: `/contact-info/product/${productId}/artist/${artistId}`
})
},
2026-05-23 18:45:41 +08:00
/**
* Purpose: getOrderArtistContact supports user.js by holding or executing the get order artist contact page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
getOrderArtistContact(orderId, artistId) {
return request({
url: `/contact-info/order/${orderId}/artist`,
data: artistId ? { artistId } : {}
})
},
2026-05-23 18:45:41 +08:00
/**
* Purpose: updateUserInfo supports user.js by holding or executing the update user info page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
2026-04-01 15:18:35 +08:00
updateUserInfo(data) {
return request({
url: '/user/update',
method: 'PUT',
data
})
},
2026-05-23 18:45:41 +08:00
/**
* Purpose: updatePassword supports user.js by holding or executing the update password page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
2026-04-01 15:18:35 +08:00
updatePassword(data) {
return request({
url: '/user/password',
method: 'PUT',
data
})
},
2026-05-23 18:45:41 +08:00
/**
* Purpose: bindPhone supports user.js by holding or executing the bind phone page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
bindPhone(data) {
return request({
url: '/user/bind-phone',
method: 'POST',
data
})
},
2026-05-23 18:45:41 +08:00
/**
* Purpose: updatePhone supports user.js by holding or executing the update phone page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
updatePhone(data) {
return request({
url: '/user/phone',
method: 'PUT',
data
})
},
2026-05-23 18:45:41 +08:00
/**
* Purpose: deactivateAccount supports user.js by holding or executing the deactivate account page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
deactivateAccount() {
return request({
url: '/user/deactivate',
method: 'DELETE'
})
},
2026-05-23 18:45:41 +08:00
/**
* Purpose: uploadAvatar supports user.js by holding or executing the upload avatar page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
uploadAvatar(filePath) {
const signedHeaders = request.buildSignatureHeaders({
url: '/user/upload-avatar',
method: 'POST',
formData: {}
})
return actionGuard.run(null, `POST:/user/upload-avatar:${filePath || ''}`, () => new Promise((resolve, reject) => {
wx.uploadFile({
url: `${API_BASE_URL}/user/upload-avatar`,
filePath,
name: 'file',
timeout: REQUEST_TIMEOUT,
header: signedHeaders,
success: response => {
try {
resolve(normalizeUploadResponse(response))
} catch (error) {
reject(error)
}
},
fail: error => {
reject(new Error(error.errMsg || '头像上传失败'))
}
})
}), {
message: '上传处理中,请勿重复操作'
})
},
2026-05-23 18:45:41 +08:00
/**
* Purpose: checkAccountAvailability supports user.js by holding or executing the check account availability page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
2026-04-01 15:18:35 +08:00
checkAccountAvailability(account) {
return request({
url: `/user/check/account/${encodeURIComponent(account)}`
})
},
2026-05-23 18:45:41 +08:00
/**
* Purpose: checkLoginAccountAvailability supports user.js by holding or executing the check login account availability page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
2026-04-01 15:18:35 +08:00
checkLoginAccountAvailability(account) {
return request({
url: `/user/check/login-account/${encodeURIComponent(account)}`
})
},
2026-05-23 18:45:41 +08:00
/**
* Purpose: getLoginShopsByAccount supports user.js by holding or executing the get login shops by account page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
2026-04-01 15:18:35 +08:00
getLoginShopsByAccount(account) {
return request({
url: `/user/check/login-shops/account/${encodeURIComponent(account)}`
})
},
2026-05-23 18:45:41 +08:00
/**
* Purpose: getLoginShopsByPhone supports user.js by holding or executing the get login shops by phone page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
2026-04-01 15:18:35 +08:00
getLoginShopsByPhone(phone) {
return request({
url: `/user/check/login-shops/phone/${encodeURIComponent(phone)}`
})
},
2026-05-23 18:45:41 +08:00
/**
* Purpose: checkPhoneAvailability supports user.js by holding or executing the check phone availability page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
2026-04-01 15:18:35 +08:00
checkPhoneAvailability(phone) {
return request({
url: `/user/check/phone/${encodeURIComponent(phone)}`
})
},
2026-05-23 18:45:41 +08:00
/**
* Purpose: sendVerificationCode supports user.js by holding or executing the send verification code page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
2026-04-01 15:18:35 +08:00
sendVerificationCode(data) {
return request({
url: '/user/send-verification-code',
method: 'POST',
data
})
}
}