Files
tk-mini-program/components/generateFileName.js
pengxiaolong 050ceedd59 优化页面
2025-05-30 22:04:45 +08:00

18 lines
601 B
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 生成 6位随机字符包含大小写字母和数字
function generateRandomString(length = 6) {
const chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
let result = '';
for (let i = 0; i < length; i++) {
result += chars[Math.floor(Math.random() * chars.length)];
}
return result;
}
// 生成文件名
function generateFileName() {
const randomPart = generateRandomString();
const timestamp = Date.now(); // 当前时间戳(毫秒级)
return `${randomPart}${timestamp}.jpg`;
}
export default generateFileName;