From 000fccef2466c87e4d7ba157fa4ead6c6ef156ea Mon Sep 17 00:00:00 2001 From: YunLei Date: Mon, 27 Mar 2023 17:13:53 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=9D=E5=AD=98=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/router/index.js | 2 +- src/views/About.vue | 156 +++++++++++++++++++++++++++++++------------- static/code.txt | 29 ++++++++ 3 files changed, 141 insertions(+), 46 deletions(-) create mode 100644 static/code.txt diff --git a/src/router/index.js b/src/router/index.js index b1eaf06..0726a85 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -71,7 +71,7 @@ const routes = [ path: '/about', component: Layout, meta: { - title: "关于", + title: "时间格式化", icon: "el-icon-info" }, children: [ diff --git a/src/views/About.vue b/src/views/About.vue index ae30e38..bb5eb8f 100644 --- a/src/views/About.vue +++ b/src/views/About.vue @@ -1,57 +1,123 @@ \ No newline at end of file diff --git a/static/code.txt b/static/code.txt new file mode 100644 index 0000000..b048ddc --- /dev/null +++ b/static/code.txt @@ -0,0 +1,29 @@ +friendlyTimeFilter (val) { + if (!val) { + return "--"; + } + let length = `${val}`.length; + if (length != 13 && length != 10) { + return "--"; + } + if (length == 13) { + val = parseInt(val / 1000); + } + let valObj = dayjs(val * 1000); + let currObj = dayjs(); + if (!valObj.isSame(currObj, "year")) { + return valObj.format("MMM DD,YYYY") + } + let curr = currObj.unix(); + let diff = curr - val; + if (diff < 60) { + return "a minute ago"; + } else if (diff < 60 * 60) { + return `${parseInt(diff / 60)} minutes ago`; + } else if (diff < 60 * 60 * 2) { + return `a hour ago`; + } else if (diff < 60 * 60 * 24) { + return `${parseInt(diff / (60 * 60))} hours ago`; + } + return valObj.format("MMM DD") +} \ No newline at end of file