js实现从chrome生成并下载文件

    let myCodes = ["013103","013106","013107","013109"];
    let authObj = JSON.parse(localStorage.getItem("BTN_AUTH"))
    let content = ""
    content += "--------按钮权限列表----------\r\n"
    for(let menuCode in authObj){
      for(let code of myCodes){
        if((menuCode+"").indexOf(code) >= 0){
          let menuObj = authObj[menuCode+""]
          menuObj.length && (content += (menuObj[0].menuName+"("+menuCode+"): \r\n\r\n"))
          for(let {buttonName, buttonType} of menuObj){
            content += (buttonName+":"+buttonType+"\r\n")
          }
          content += "----------------------------\r\n"
        }
      }
    }
    const uri = "data:text/plain;charset=UTF-8,"
    const url = uri + content
    const a = document.createElement("a")
    a.href = url
    a.download = "按钮权限列表.txt"
    a.click()
    window.URL.revokeObjectURL(url)

你可能感兴趣的:(js实现从chrome生成并下载文件)