支持文件列表可指定下载文件名
This commit is contained in:
@@ -40,7 +40,8 @@ const addChild = (parent, pending, config) => {
|
||||
* @param 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) {
|
||||
const id = e[key], pid = e[parent]
|
||||
itemMap[id] = {...e, [children]: [itemMap[id]?.[children]].flat().filter(Boolean)}
|
||||
@@ -202,11 +203,12 @@ export default {
|
||||
.replace('Invalid Date', '')
|
||||
},
|
||||
$copy,
|
||||
$download: url => {
|
||||
$download: (url, name) => {
|
||||
fetch(url).then(res => res.blob()).then(blob => {
|
||||
const link = document.createElement('a')
|
||||
link.style.display = 'none'
|
||||
link.href = URL.createObjectURL(blob)
|
||||
!!name && link.setAttribute("download", name)
|
||||
document.body.appendChild(link)
|
||||
link.click()
|
||||
document.body.removeChild(link)
|
||||
|
||||
Reference in New Issue
Block a user