🎨 增加 Go 后端
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
export const formatTimeAgo = (dateString: string) => {
|
||||
const now = new Date();
|
||||
const date = new Date(dateString);
|
||||
const seconds = Math.floor((now.getTime() - date.getTime()) / 1000);
|
||||
|
||||
let interval = seconds / 31536000;
|
||||
|
||||
if (interval > 1) {
|
||||
return Math.floor(interval) + " 年前";
|
||||
}
|
||||
interval = seconds / 2592000;
|
||||
if (interval > 1) {
|
||||
return Math.floor(interval) + " 月前";
|
||||
}
|
||||
interval = seconds / 86400;
|
||||
if (interval > 1) {
|
||||
return Math.floor(interval) + " 天前";
|
||||
}
|
||||
interval = seconds / 3600;
|
||||
if (interval > 1) {
|
||||
return Math.floor(interval) + " 小时前";
|
||||
}
|
||||
interval = seconds / 60;
|
||||
if (interval > 1) {
|
||||
return Math.floor(interval) + " 分钟前";
|
||||
}
|
||||
return Math.floor(seconds) + " 秒前";
|
||||
};
|
||||
@@ -0,0 +1,12 @@
|
||||
// 自动导出
|
||||
export const useHttp = {
|
||||
post<T = any>(url: string, config?: any): Promise<T> {
|
||||
const runtimeConfig = useRuntimeConfig()
|
||||
const baseUrl = runtimeConfig.public.baseUrl
|
||||
return $fetch(url, {
|
||||
baseURL: baseUrl,
|
||||
method: 'POST',
|
||||
body: config,
|
||||
})
|
||||
},
|
||||
}
|
||||
Reference in New Issue
Block a user