@@ -130,26 +130,11 @@ const iconMap = {
130130 skin : SkinIcon ,
131131} ;
132132
133-
134- const colors = [ '#52c41a' , '#f5222d' , '#1890ff' , '#faad14' , '#ff0064' , '#722ed1' ] ;
135-
136- const tagColors = [
137- '#dc3545' ,
138- '#17a2b8' ,
139- '#00b74a' ,
140- '#fc651f' ,
141- '#6c757d' ,
142- '#f5c800' ,
143- '#808695' ,
144- '#2db7f5' ,
145- '#87d068' ,
146- '#108ee9' ,
147- '#52c41a' ,
148- '#f5222d' ,
149- '#1890ff' ,
150- '#faad14' ,
151- '#ff0064' ,
152- '#722ed1' ,
133+ // 统一的颜色数组,避免重复
134+ const colors = [
135+ '#52c41a' , '#f5222d' , '#1890ff' , '#faad14' , '#ff0064' , '#722ed1' ,
136+ '#dc3545' , '#17a2b8' , '#00b74a' , '#fc651f' , '#6c757d' , '#f5c800' ,
137+ '#808695' , '#2db7f5' , '#87d068' , '#108ee9'
153138] ;
154139
155140export const getRandomColor = ( ( ) => {
@@ -164,29 +149,6 @@ export const getRandomColor = (() => {
164149 } ;
165150} ) ( ) ;
166151
167- export function throttle ( fn , threshhold ) {
168- let last ;
169- let timer ;
170- threshhold || ( threshhold = 250 ) ;
171-
172- return function ( ) {
173- const context = this ; // eslint-disable-line @typescript-eslint/no-this-alias
174- const args = arguments ; // eslint-disable-line prefer-rest-params
175- const now = + new Date ( ) ;
176-
177- if ( last && now < last + threshhold ) {
178- clearTimeout ( timer ) ;
179- timer = setTimeout ( function ( ) {
180- last = now ;
181- fn . apply ( context , args ) ;
182- } , threshhold ) ;
183- } else {
184- last = now ;
185- fn . apply ( context , args ) ;
186- }
187- } ;
188- }
189-
190152export function elementInViewport ( el ) {
191153 let top = el . offsetTop ;
192154 let left = el . offsetLeft ;
@@ -206,20 +168,11 @@ export function elementInViewport(el) {
206168 left + width > window . pageXOffset
207169 ) ;
208170}
171+
209172export function getDocumentScrollTop ( ) {
210173 return document . documentElement . scrollTop || window . pageYOffset || window . scrollY || document . body . scrollTop ;
211174}
212175
213- export function download ( { name, url } ) {
214- const eleLink = document . createElement ( 'a' ) ;
215- eleLink . download = name ;
216- eleLink . style . display = 'none' ;
217- eleLink . href = url ;
218- document . body . appendChild ( eleLink ) ;
219- eleLink . click ( ) ;
220- document . body . removeChild ( eleLink ) ;
221- }
222-
223176export const groupBy = function ( data , condition ) {
224177 if ( ! condition || ! Array . isArray ( data ) ) {
225178 return data ;
@@ -252,33 +205,6 @@ export const formatFileSize = (size) => {
252205 return ( size / 1024 / 1024 ) . toFixed ( 2 ) + ' MB' ;
253206} ;
254207
255- export function debounce ( func , wait , immediate = false ) {
256- let timeout ;
257-
258- const debounced = function ( ) {
259- const context = this ; // eslint-disable-line @typescript-eslint/no-this-alias
260- const args = arguments ; // eslint-disable-line prefer-rest-params
261- const later = function ( ) {
262- timeout = null ;
263- if ( ! immediate ) {
264- func . apply ( context , args ) ;
265- }
266- } ;
267- const callNow = immediate && ! timeout ;
268- clearTimeout ( timeout ) ;
269- timeout = setTimeout ( later , wait ) ;
270- if ( callNow ) {
271- func . apply ( context , args ) ;
272- }
273- } ;
274-
275- debounced . cancel = ( ) => {
276- clearTimeout ( timeout ) ;
277- } ;
278-
279- return debounced ;
280- }
281-
282208export function resolveUrl ( baseURL , relativeURL ) {
283209 if ( ! baseURL ) {
284210 baseURL = '/' ;
@@ -298,11 +224,10 @@ export const scrollToBottom = (el: HTMLElement) => {
298224} ;
299225
300226export function getColorFromNumber ( num ) {
301- const index = num % tagColors . length ;
302- return tagColors [ index ] ;
227+ const index = num % colors . length ;
228+ return colors [ index ] ;
303229}
304230
305-
306231export function getIconByName ( name ) {
307232 if ( React . isValidElement ( name ) ) {
308233 return name ;
@@ -311,7 +236,6 @@ export function getIconByName (name) {
311236 return IconComponent ;
312237} ;
313238
314-
315239export function getFirstLevelRoute ( path ) {
316240 // 确保路径以斜杠开头,如果不是则添加斜杠
317241 if ( ! path . startsWith ( '/' ) ) {
0 commit comments