// 通用工具函数 // 格式化时间 export function formatTime(date) { const year = date.getFullYear() const month = date.getMonth() + 1 const day = date.getDate() const hour = date.getHours() const minute = date.getMinutes() const second = date.getSeconds() return `${[year, month, day].map(formatNumber).join('/')} ${[hour, minute, second].map(formatNumber).join(':')}` } function formatNumber(n) { n = n.toString() return n[1] ? n : `0${n}` } // 手机号验证 export function validatePhone(phone) { const reg = /^1[3-9]\d{9}$/ return reg.test(phone) } // 显示loading export function showLoading(title = '加载中...') { uni.showLoading({ title, mask: true }) } // 隐藏loading export function hideLoading() { uni.hideLoading() } // 显示toast export function showToast(title, icon = 'none') { uni.showToast({ title, icon, duration: 2000 }) } // 确认对话框 export function showConfirm(content, title = '提示') { return new Promise((resolve) => { uni.showModal({ title, content, success: (res) => { resolve(res.confirm) } }) }) } // 获取用户信息 export function getUserInfo() { return uni.getStorageSync('userInfo') || {} } // 设置用户信息 export function setUserInfo(userInfo) { uni.setStorageSync('userInfo', userInfo) } // 清除用户信息 export function clearUserInfo() { uni.removeStorageSync('token') uni.removeStorageSync('userInfo') }