考核考试系统
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
1.4 KiB

import { Pipe, PipeTransform } from '@angular/core';
@Pipe({name: 'size'})
export class SizePipe implements PipeTransform {
transform(byte: number): string {
if(byte < 1048576 && byte != 0){//如果小于1M
let size = byte / 1024
return size.toFixed(1) + 'KB'
}
if(byte >= 1048576 && byte < 1073741824){//如果大于1M 小于1G
let size = byte / 1048576
return size.toFixed(1) + 'MB'
}
if(byte >= 1073741824){//如果大于1G
let size = byte / 1073741824
return size.toFixed(1) + 'GB'
}
if(byte < 1048576 && byte == 0){//如果是文件夹
return '--'
}
}
}
@Pipe({name: 'name'})
export class NamePipe implements PipeTransform {
transform(name: string): string {
let nameArr = name.split("/")
return nameArr[nameArr.length - 1]
}
}
@Pipe({name: 'name2'})
export class NamePipe2 implements PipeTransform {
transform(name: string): string {
let nameArr = name.split("/")
return nameArr[nameArr.length - 2]
}
}
@Pipe({name: 'name3'})
export class NamePipe3 implements PipeTransform {
transform(name: string): string {
if(name.charAt(name.length-1) == "/"){
return name.substr(0, name.length - 1).replace(/\//g,'>').substring(9,name.length)
}else{
return name.replace(/\//g,'>').substring(9,name.length)
}
}
}