支持文件列表可指定下载文件名
This commit is contained in:
@@ -15,12 +15,12 @@ import $reg from "./regular"
|
|||||||
*/
|
*/
|
||||||
const addChild = (parent, pending, config) => {
|
const addChild = (parent, pending, config) => {
|
||||||
let conf = {
|
let conf = {
|
||||||
key: 'id',
|
key: 'id',
|
||||||
parent: 'parentId',
|
parent: 'parentId',
|
||||||
children: 'children',
|
children: 'children',
|
||||||
...config
|
...config
|
||||||
},
|
},
|
||||||
doBeforeCount = pending.length
|
doBeforeCount = pending.length
|
||||||
for (let i = pending.length - 1; i >= 0; i--) {
|
for (let i = pending.length - 1; i >= 0; i--) {
|
||||||
let e = pending[i]
|
let e = pending[i]
|
||||||
if (e[conf.parent] == parent[conf.key]) {
|
if (e[conf.parent] == parent[conf.key]) {
|
||||||
@@ -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)}
|
||||||
@@ -86,7 +87,7 @@ const $decimalCalc = (...arr) => {
|
|||||||
return ('' + e).length - index
|
return ('' + e).length - index
|
||||||
})
|
})
|
||||||
let maxDecimal = Math.max(...decimalLengthes),
|
let maxDecimal = Math.max(...decimalLengthes),
|
||||||
precision = Math.pow(10, maxDecimal)
|
precision = Math.pow(10, maxDecimal)
|
||||||
// 计算
|
// 计算
|
||||||
let intArr = arr.map(e => (Number(e) || 0) * precision)
|
let intArr = arr.map(e => (Number(e) || 0) * precision)
|
||||||
// 返回计算值
|
// 返回计算值
|
||||||
@@ -114,10 +115,10 @@ const $colorUtils = {
|
|||||||
if (color.length == 4) {
|
if (color.length == 4) {
|
||||||
// 检测诸如#FFF简写格式
|
// 检测诸如#FFF简写格式
|
||||||
color =
|
color =
|
||||||
'#' +
|
'#' +
|
||||||
color.charAt(1).repeat(2) +
|
color.charAt(1).repeat(2) +
|
||||||
color.charAt(2).repeat(2) +
|
color.charAt(2).repeat(2) +
|
||||||
color.charAt(3).repeat(2)
|
color.charAt(3).repeat(2)
|
||||||
}
|
}
|
||||||
hex = parseInt(color.slice(1), 16)
|
hex = parseInt(color.slice(1), 16)
|
||||||
}
|
}
|
||||||
@@ -198,15 +199,16 @@ export default {
|
|||||||
},
|
},
|
||||||
$dateFormat: (time, format) => {
|
$dateFormat: (time, format) => {
|
||||||
return $moment(time)
|
return $moment(time)
|
||||||
.format(format || 'YYYY-MM-DD')
|
.format(format || 'YYYY-MM-DD')
|
||||||
.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)
|
||||||
|
|||||||
Reference in New Issue
Block a user