- Rename PascalCase component files to kebab-case (AnnouncementModal → announcement-modal, McGlass → mc-glass) - Replace any types with proper uni-app/WeChat callback types (RequestSuccessCallbackResult, LoginRes, ShowModalRes, etc.) - Add JSDoc documentation comments to all exported/important functions Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
51 lines
1.1 KiB
TypeScript
51 lines
1.1 KiB
TypeScript
/** 数字补零(用于日期格式化) */
|
|
const formatNumber = (n: number): string => {
|
|
const str = n.toString()
|
|
return str[1] ? str : '0' + str
|
|
}
|
|
|
|
/** 格式化日期时间为 `YYYY/M/D HH:mm:ss` */
|
|
function formatTime(date: Date | number | string): string {
|
|
const d = new Date(date)
|
|
const year = d.getFullYear()
|
|
const month = d.getMonth() + 1
|
|
const day = d.getDate()
|
|
const hour = d.getHours()
|
|
const minute = d.getMinutes()
|
|
const second = d.getSeconds()
|
|
return `${year}/${month}/${day} ${[hour, minute, second].map(formatNumber).join(':')}`
|
|
}
|
|
|
|
/** 显示 Toast 提示 */
|
|
function showToast(title: string, icon: 'success' | 'loading' | 'error' | 'none' = 'none'): void {
|
|
uni.showToast({
|
|
title,
|
|
icon,
|
|
duration: 2000
|
|
})
|
|
}
|
|
|
|
/** 跳转到指定页面 */
|
|
function navigateTo(url: string): void {
|
|
uni.navigateTo({ url })
|
|
}
|
|
|
|
/** 重定向到指定页面 */
|
|
function redirectTo(url: string): void {
|
|
uni.redirectTo({ url })
|
|
}
|
|
|
|
/** 切换到 tabBar 页面 */
|
|
function switchTab(url: string): void {
|
|
uni.switchTab({ url })
|
|
}
|
|
|
|
export {
|
|
formatTime,
|
|
formatNumber,
|
|
showToast,
|
|
navigateTo,
|
|
redirectTo,
|
|
switchTab
|
|
}
|