chore: 初始化项目 — uni-app + Vue3 + TypeScript 脚手架
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
const formatNumber = (n: number): string => {
|
||||
const str = n.toString()
|
||||
return str[1] ? str : '0' + str
|
||||
}
|
||||
|
||||
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(':')}`
|
||||
}
|
||||
|
||||
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 })
|
||||
}
|
||||
|
||||
function switchTab(url: string): void {
|
||||
uni.switchTab({ url })
|
||||
}
|
||||
|
||||
export {
|
||||
formatTime,
|
||||
formatNumber,
|
||||
showToast,
|
||||
navigateTo,
|
||||
redirectTo,
|
||||
switchTab
|
||||
}
|
||||
Reference in New Issue
Block a user