重构项目文件夹目录
This commit is contained in:
@@ -0,0 +1,338 @@
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
const request = require('../utils/request')
|
||||
/**
|
||||
* 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')
|
||||
|
||||
/**
|
||||
* 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
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
getUserInfo() {
|
||||
return request({
|
||||
url: '/user/info'
|
||||
})
|
||||
},
|
||||
|
||||
// 我的页常用数据:
|
||||
// 资产、余额流水、消息、公告、VIP 充值档位和所属关系都从这里拿。
|
||||
getMyAsset() {
|
||||
return request({
|
||||
url: '/user/asset/me'
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 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'
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 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'
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 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'
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 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'
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 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: {}
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 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: {}
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 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'
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 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`
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 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}`
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 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`,
|
||||
params: artistId ? { artistId } : {}
|
||||
})
|
||||
},
|
||||
|
||||
getPlatformContact() {
|
||||
return request({
|
||||
url: '/contact-info/platform'
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
updateUserInfo(data) {
|
||||
return request({
|
||||
url: '/user/update',
|
||||
method: 'PUT',
|
||||
data
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
updatePassword(data) {
|
||||
return request({
|
||||
url: '/user/password',
|
||||
method: 'PUT',
|
||||
data
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 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
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 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
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 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'
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 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: '上传处理中,请勿重复操作'
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
checkAccountAvailability(account) {
|
||||
return request({
|
||||
url: `/user/check/account/${encodeURIComponent(account)}`
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
checkLoginAccountAvailability(account) {
|
||||
return request({
|
||||
url: `/user/check/login-account/${encodeURIComponent(account)}`
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
getLoginShopsByAccount(account) {
|
||||
return request({
|
||||
url: `/user/check/login-shops/account/${encodeURIComponent(account)}`
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
getLoginShopsByPhone(phone) {
|
||||
return request({
|
||||
url: `/user/check/login-shops/phone/${encodeURIComponent(phone)}`
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
checkPhoneAvailability(phone) {
|
||||
return request({
|
||||
url: `/user/check/phone/${encodeURIComponent(phone)}`
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
sendVerificationCode(data) {
|
||||
return request({
|
||||
url: '/user/send-verification-code',
|
||||
method: 'POST',
|
||||
data
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user