搜索结果列表页面开发
This commit is contained in:
31
src/utils/asset.ts
Normal file
31
src/utils/asset.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
export const FindFileName = (path: string) => {
|
||||
/* find filename */
|
||||
const isName = /.*\/.*\/(.*\..*)/;
|
||||
const result = isName.exec(path)?.length
|
||||
? (isName.exec(path) as Array<string>)[1]
|
||||
: '';
|
||||
return result.split('.')[0];
|
||||
};
|
||||
/** 用于合并静态资源请求数量, 如果目录中的资源文件过多而需要引用的较少时不建议使用
|
||||
* 可以将数量可观并且公用的抽放到同一层文件夹,可以提升页面渲染速度
|
||||
*/
|
||||
export const TransAssetsUrl = (
|
||||
source: Record<string, any>,
|
||||
key: string,
|
||||
path?: string
|
||||
): any => {
|
||||
if (key) {
|
||||
let target: string | undefined = '';
|
||||
target = Object.keys(source).find((pathName) => {
|
||||
const p = path ? `${path}${key}` : key;
|
||||
return p === FindFileName(pathName);
|
||||
});
|
||||
if (target) {
|
||||
return source[target].default;
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user