forked from opentiny/tiny-engine
fix(download): Optimize download logic and adapt to iframe (#739)
* fix(download): Optimize download logic and adapt to iframe
This commit is contained in:
parent
1ed91983b0
commit
59eaf035bb
|
@ -19,13 +19,13 @@ import JSZIP from 'jszip'
|
|||
* @param {string} fileName 文件名
|
||||
*/
|
||||
export function saveAs(blobData, fileName) {
|
||||
const zipLink = document.createElement('a')
|
||||
zipLink.download = fileName
|
||||
zipLink.style.display = 'none'
|
||||
zipLink.href = URL.createObjectURL(blobData)
|
||||
document.body.appendChild(zipLink)
|
||||
zipLink.click()
|
||||
document.body.removeChild(zipLink)
|
||||
const downloadLink = document.createElement('a')
|
||||
downloadLink.download = fileName
|
||||
downloadLink.style.display = 'none'
|
||||
downloadLink.href = URL.createObjectURL(blobData)
|
||||
document.body.appendChild(downloadLink)
|
||||
downloadLink.click()
|
||||
document.body.removeChild(downloadLink)
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -25,7 +25,7 @@ export const isSupportFileSystemAccess =
|
|||
* @returns dirHandle 目录句柄
|
||||
*/
|
||||
export const getUserBaseDirHandle = async (options = {}) => {
|
||||
if (!window.showOpenFilePicker) {
|
||||
if (!isSupportFileSystemAccess) {
|
||||
return createZip()
|
||||
}
|
||||
const dirHandle = await window.showDirectoryPicker({ mode: 'readwrite', ...options })
|
||||
|
@ -81,8 +81,8 @@ export async function getFileHandle(baseDirHandle, filePath, { create = false }
|
|||
* @returns fileHandle 文件句柄
|
||||
*/
|
||||
export const getUserFileHandle = async (options = {}) => {
|
||||
if (!window.showOpenFilePicker) {
|
||||
throw new Error('不支持的浏览器!')
|
||||
if (!isSupportFileSystemAccess) {
|
||||
throw new Error('不支持的浏览器或处于iframe中')
|
||||
}
|
||||
const [fileHandle] = await window.showOpenFilePicker({ mode: 'readwrite', ...options })
|
||||
return fileHandle
|
||||
|
|
Loading…
Reference in New Issue