支持文件列表可指定下载文件名

This commit is contained in:
aixianling
2023-06-20 09:59:25 +08:00
parent b09cfd62a5
commit e983bd22a1

View File

@@ -40,7 +40,8 @@ const addChild = (parent, pending, config) => {
* @param config 配置 * @param config 配置
*/ */
const $arr2tree = (list, config = {}) => { const $arr2tree = (list, config = {}) => {
const {key = 'id', parent = 'parentId', children = 'children'} = config, result = [], itemMap = {}, ids = list?.map(e => `#${e[key]}#`)?.toString() const {key = 'id', parent = 'parentId', children = 'children'} = config, result = [], itemMap = {},
ids = list?.map(e => `#${e[key]}#`)?.toString()
for (const e of list) { for (const e of list) {
const id = e[key], pid = e[parent] const id = e[key], pid = e[parent]
itemMap[id] = {...e, [children]: [itemMap[id]?.[children]].flat().filter(Boolean)} itemMap[id] = {...e, [children]: [itemMap[id]?.[children]].flat().filter(Boolean)}
@@ -202,11 +203,12 @@ export default {
.replace('Invalid Date', '') .replace('Invalid Date', '')
}, },
$copy, $copy,
$download: url => { $download: (url, name) => {
fetch(url).then(res => res.blob()).then(blob => { fetch(url).then(res => res.blob()).then(blob => {
const link = document.createElement('a') const link = document.createElement('a')
link.style.display = 'none' link.style.display = 'none'
link.href = URL.createObjectURL(blob) link.href = URL.createObjectURL(blob)
!!name && link.setAttribute("download", name)
document.body.appendChild(link) document.body.appendChild(link)
link.click() link.click()
document.body.removeChild(link) document.body.removeChild(link)