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