From dfcd429a5d4d6a6a9b15f423382ef3fd201d92b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=BC=BA?= <1206709430@qq.com> Date: Mon, 16 May 2022 10:45:21 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E6=A1=86=E6=9E=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/src/libs/util.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/web/src/libs/util.js b/web/src/libs/util.js index f97be8b..0b00d8b 100644 --- a/web/src/libs/util.js +++ b/web/src/libs/util.js @@ -1,6 +1,8 @@ import cookies from './util.cookies' import db from './util.db' import log from './util.log' +import dayjs from 'dayjs' + const util = { cookies, db, @@ -46,5 +48,33 @@ util.baseURL = function () { } return baseURL } +/** + * 自动生成ID + */ +util.autoCreateCode = function () { + return dayjs().format('YYYYMMDDHHmmssms') + Math.round(Math.random() * 80 + 20) +} +/** + * 自动生成短 ID + */ +util.autoShortCreateCode = function () { + var Num = '' + for (var i = 0; i < 4; i++) { + Num += Math.floor(Math.random() * 10) + } + return dayjs().format('YYMMDD') + Num +} + +/** + * 生产随机字符串 + */ +util.randomString = function (e) { + e = e || 32 + var t = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678' + var a = t.length + var n = '' + for (let i = 0; i < e; i++) n += t.charAt(Math.floor(Math.random() * a)) + return n +} export default util