|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Pipe({name: 'testState'})
|
|
|
|
export class testState implements PipeTransform {
|
|
|
|
transform(name: string): string {
|
|
|
|
if(name == "1"){
|
|
|
|
return "未开考"
|
|
|
|
}else if(name == "2"){
|
|
|
|
return "开考中"
|
|
|
|
}else{
|
|
|
|
return "已结束"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|