pet/http/config/constants.js

179 lines
4.0 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* HTTP模块统一配置常量文件
* 统一管理所有配置模板、Loading文本常量和其他共享常量
*/
// ==================== 配置模板 ====================
/**
* 统一的请求配置模板
* 合并了REQUEST_CONFIG_TEMPLATES、COMMON_CONFIG_TEMPLATES、DEFAULT_CONFIG_TEMPLATES
*/
export const CONFIG_TEMPLATES = {
// 需要认证的查询请求无loading
AUTHENTICATED_QUERY: {
auth: true,
loading: false,
toast: true
},
// 需要认证的查询请求有loading
AUTHENTICATED_QUERY_WITH_LOADING: {
auth: true,
loading: true,
toast: true
},
// 需要认证的更新请求
AUTHENTICATED_UPDATE: {
auth: true,
loading: true,
toast: true
},
// 需要认证的删除请求
AUTHENTICATED_DELETE: {
auth: true,
loading: true,
toast: true
},
// 无需认证的公开请求
PUBLIC_REQUEST: {
auth: false,
loading: true,
toast: true
},
// 静默请求无loading和toast
SILENT_REQUEST: {
auth: false,
loading: false,
toast: false
},
// 需要认证的上传请求
AUTHENTICATED_UPLOAD: {
auth: true,
loading: true,
toast: true
},
// 需要认证的提交请求
AUTHENTICATED_SUBMIT: {
auth: true,
loading: true,
toast: true
},
// 公开的下载请求
PUBLIC_DOWNLOAD: {
auth: false,
loading: true,
toast: true
},
// 静默的配置获取请求
SILENT_CONFIG: {
auth: false,
loading: false,
toast: false
}
}
// ==================== Loading文本常量 ====================
/**
* 统一的Loading文本配置
* 合并了所有模块中的LOADING_TEXTS常量
*/
export const LOADING_TEXTS = {
// 通用操作
LOADING: '正在加载...',
SAVING: '正在保存...',
DELETING: '正在删除...',
UPDATING: '正在更新...',
SUBMITTING: '正在提交...',
UPLOADING: '正在上传...',
// 认证相关
LOGIN: '正在登录...',
LOGOUT: '正在退出...',
REGISTER: '正在注册...',
PHONE_VERIFY: '正在验证手机号...',
SEND_SMS: '正在发送验证码...',
VERIFY_SMS: '正在验证...',
RESET_PASSWORD: '正在重置密码...',
// 用户相关
UPDATING_USER_INFO: '正在更新用户信息...',
UPLOADING_AVATAR: '正在上传头像...',
SAVING_PROFILE: '正在保存...',
DELETING_ACCOUNT: '正在注销账户...',
LOADING_DATA: '正在加载...',
// 宠物相关
ADD_PET: '正在添加宠物...',
UPDATE_PET: '正在更新宠物信息...',
DELETE_PET: '正在删除宠物...',
ADD_RECORD: '正在添加记录...',
UPDATE_RECORD: '正在更新记录...',
DELETE_RECORD: '正在删除记录...',
// 文件相关
UPLOAD_IMAGE: '正在上传图片...',
UPLOAD_FILE: '正在上传文件...',
UPLOAD_IMAGES: '正在批量上传...',
DOWNLOAD_FILE: '正在下载文件...',
// AI助手相关
AI_THINKING: 'AI正在思考中...',
SPEECH_RECOGNITION: '正在识别语音...',
// 领养相关
SUBMIT_APPLICATION: '正在提交申请...',
CANCEL_APPLICATION: '正在取消申请...',
// 评价相关
SUBMIT_REVIEW: '正在提交评价...',
UPDATE_REVIEW: '正在更新评价...',
DELETE_REVIEW: '正在删除评价...',
SUBMIT_REPORT: '正在提交举报...',
REPLY_REVIEW: '正在回复评价...',
// 其他
SUBMIT_FEEDBACK: '正在提交反馈...',
CHECK_UPDATE: '正在检查更新...'
}
// ==================== 工具函数 ====================
/**
* 创建标准化的请求配置
* @param {string} template 配置模板名称
* @param {Object} customConfig 自定义配置
* @param {string} loadingText 自定义loading文本
* @returns {Object} 标准化的请求配置
*/
export const createRequestConfig = (template, customConfig = {}, loadingText = null) => {
const baseConfig = CONFIG_TEMPLATES[template] || {}
const config = {
custom: {
...baseConfig,
...(loadingText && { loadingText }),
...customConfig.custom
},
...customConfig
}
// 移除custom属性中的undefined值
Object.keys(config.custom).forEach(key => {
if (config.custom[key] === undefined) {
delete config.custom[key]
}
})
return config
}