获取上传文件名,生成随机名

UploadFile(option) {
      let file = option.file
      const self = this
      return new Promise((resolve, reject) => {
        let dateTime = Utils.dateFormat(new Date(), 'yyyyMMddhhmmss') // 当前时间
        let index = file.name.lastIndexOf('.')
        //获取后缀
        let extensionName = file.name.substr(index + 1)
        let str = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
        let result = ''
        for (let i = 6; i > 0; --i) {
          result += str[Math.floor(Math.random() * str.length)]
        }
        //输出结果
        let fileName = 'duojiaAdmin_dev/' + file.uid + dateTime + result + '.' + extensionName // 文件名字(相对于根目录的路径 + 文件名)
        console.log('flLENAM', fileName)
}

你可能感兴趣的:(获取上传文件名,生成随机名)