| | |
| | | const hours = date.getHours().toString().padStart(2, '0'); |
| | | const minutes = date.getMinutes().toString().padStart(2, '0'); |
| | | if (type) { |
| | | return `${year}-${month}-${day} ${hours}:${minutes}`; |
| | | return type=='riqi' ? `${month}-${day}`: `${year}-${month}-${day} ${hours}:${minutes}`; |
| | | } |
| | | return `${year}-${month}-${day}`; |
| | | }, |
| | |
| | | } |
| | | }); |
| | | }, |
| | | //生成时间戳+随机数 |
| | | // 生成时间戳+随机数的函数 |
| | | generateTimestampWithRandom(filename) { |
| | | // 获取当前日期和时间 |
| | | const now = new Date(); |
| | | // 获取年份,确保为四位数 |
| | | const year = now.getFullYear(); |
| | | // 获取月份,确保为两位数 |
| | | const month = String(now.getMonth() + 1).padStart(2, '0'); |
| | | // 获取日期,确保为两位数 |
| | | const day = String(now.getDate()).padStart(2, '0'); |
| | | // 获取小时,确保为两位数 |
| | | const hours = String(now.getHours()).padStart(2, '0'); |
| | | // 获取分钟,确保为两位数 |
| | | const minutes = String(now.getMinutes()).padStart(2, '0'); |
| | | // 获取秒数,确保为两位数 |
| | | const seconds = String(now.getSeconds()).padStart(2, '0'); |
| | | // 拼接时间戳 |
| | | const timestamp = `${year}${month}${day}${hours}${minutes}${seconds}`; |
| | | // 生成一个 0 到 9999 之间的随机数,并格式化为四位数 |
| | | const randomNumber = String(Math.floor(Math.random() * 10000)).padStart(4, '0'); |
| | | // 拼接时间戳和随机数 |
| | | return `cylsg/${timestamp}_${randomNumber}` + filename.match(/\.[^.]+$/); |
| | | }, |
| | | getFileExtensionWithDotRegex(filename) { |
| | | const match = filename.match(/\.[^.]+$/); |
| | | return match ? match[0] : ''; |
| | | } |
| | | } |