From 0dcfd5286e39f4281ade70f0f3e49c315483b130 Mon Sep 17 00:00:00 2001 From: haoxr <1490493387@qq.com> Date: Tue, 28 Feb 2023 23:56:32 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E5=88=A0=E9=99=A4=E6=97=A0?= =?UTF-8?q?=E7=94=A8=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Former-commit-id: b3b84e30aa22b9157fcddf4b8d6f493b05952c56 --- src/utils/auth.ts | 15 -------- src/utils/filter.ts | 80 ------------------------------------------- src/utils/validate.ts | 12 ------- 3 files changed, 107 deletions(-) delete mode 100644 src/utils/auth.ts delete mode 100644 src/utils/filter.ts delete mode 100644 src/utils/validate.ts diff --git a/src/utils/auth.ts b/src/utils/auth.ts deleted file mode 100644 index 5674f921..00000000 --- a/src/utils/auth.ts +++ /dev/null @@ -1,15 +0,0 @@ -import Cookies from 'js-cookie'; - -const TokenKey = 'vue3-element-admin-token'; - -export function getToken() { - return Cookies.get(TokenKey); -} - -export function setToken(token: string) { - Cookies.set(TokenKey, token); -} - -export function removeToken() { - return Cookies.remove(TokenKey); -} diff --git a/src/utils/filter.ts b/src/utils/filter.ts deleted file mode 100644 index 38c28bc2..00000000 --- a/src/utils/filter.ts +++ /dev/null @@ -1,80 +0,0 @@ -/** - * Show plural label if time is plural number - * @param {number} time - * @param {string} label - * @return {string} - */ -function pluralize(time: number, label: string) { - if (time === 1) { - return time + label; - } - return time + label + 's'; -} - -/** - * @param {number} time - */ -export function timeAgo(time: number) { - const between = Date.now() / 1000 - Number(time); - if (between < 3600) { - return pluralize(~~(between / 60), ' minute'); - } else if (between < 86400) { - return pluralize(~~(between / 3600), ' hour'); - } else { - return pluralize(~~(between / 86400), ' day'); - } -} - -/** - * Number formatting - * like 10000 => 10k - * @param {number} num - * @param {number} digits - */ -export function numberFormatter(num: number, digits: number) { - const si = [ - { value: 1e18, symbol: 'E' }, - { value: 1e15, symbol: 'P' }, - { value: 1e12, symbol: 'T' }, - { value: 1e9, symbol: 'G' }, - { value: 1e6, symbol: 'M' }, - { value: 1e3, symbol: 'k' } - ]; - for (let i = 0; i < si.length; i++) { - if (num >= si[i].value) { - return ( - (num / si[i].value) - .toFixed(digits) - .replace(/\.0+$|(\.[0-9]*[1-9])0+$/, '$1') + si[i].symbol - ); - } - } - return num.toString(); -} - -/** - * 10000 => "10,000" - * @param {number} num - */ -export function toThousandFilter(num: number) { - return (+num || 0) - .toString() - .replace(/^-?\d+/g, m => m.replace(/(?=(?!\b)(\d{3})+$)/g, ',')); -} - -/** - * Upper case first char - * @param {String} string - */ -export function uppercaseFirst(string: string) { - return string.charAt(0).toUpperCase() + string.slice(1); -} - -/** - * 金额转换(分->元) - * 100 => 1 - * @param {number} num - */ -export function moneyFormatter(num: number) { - return '¥' + (isNaN(num) ? 0.0 : parseFloat((num / 100).toFixed(2))); -} diff --git a/src/utils/validate.ts b/src/utils/validate.ts deleted file mode 100644 index bc8cceec..00000000 --- a/src/utils/validate.ts +++ /dev/null @@ -1,12 +0,0 @@ -/** - * Created by PanJiaChen on 16/11/18. - */ - -/** - * @param {string} path - * @returns {Boolean} - */ -export function isExternal(path: string) { - const isExternal = /^(https?:|http?:|mailto:|tel:)/.test(path); - return isExternal; -}