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.
68 lines
1.9 KiB
68 lines
1.9 KiB
import { Pipe, PipeTransform } from '@angular/core'; |
|
import { FacilityInfoUIItem } from '../babylon/view/facilityinfoinscene-window/facilityinfo-ui-item'; |
|
|
|
@Pipe({ |
|
name: 'facilitySort', |
|
pure: false, |
|
}) |
|
export class FacilitySortPipe implements PipeTransform { |
|
|
|
transform(items: FacilityInfoUIItem[]) { |
|
items.forEach(item=>{ |
|
if (!this.isHasNumber(item.getPropertyData().name)) { |
|
item.getPropertyData().name = this.handleChineseNumber(item.getPropertyData().name) |
|
} |
|
}) |
|
items.sort(function (a, b) { |
|
var _a = a.getPropertyData().name.match(/^(.*?)(\d*)$/); |
|
var _b = b.getPropertyData().name.match(/^(.*?)(\d*)$/); |
|
if (_a[1] === _b[1]) { |
|
return parseInt(_a[2] || 0) - parseInt(_b[2] || 0); |
|
} else { |
|
return _a[1].localeCompare(_b[1]); |
|
} |
|
}) |
|
return items; |
|
} |
|
|
|
//处理 汉字数字 |
|
handleChineseNumber(str: string): string { |
|
if (str.includes('一')) { |
|
str = str.replace("一", "") |
|
return `1${str}` |
|
} else if (str.includes('二')) { |
|
str = str.replace("二", "") |
|
return `2${str}` |
|
} else if (str.includes('三')) { |
|
str = str.replace("三", "") |
|
return `3${str}` |
|
} else if (str.includes('四')) { |
|
str = str.replace("四", "") |
|
return `4${str}` |
|
} else if (str.includes('五')) { |
|
str = str.replace("五", "") |
|
return `5${str}` |
|
} else if (str.includes('六')) { |
|
str = str.replace("六", "") |
|
return `6${str}` |
|
} else if (str.includes('七')) { |
|
str = str.replace("七", "") |
|
return `7${str}` |
|
} else if (str.includes('八')) { |
|
str = str.replace("八", "") |
|
return `8${str}` |
|
} else if (str.includes('九')) { |
|
str = str.replace("九", "") |
|
return `9${str}` |
|
} else { |
|
return str |
|
} |
|
} |
|
|
|
//正则校验 是否包含阿拉伯数字 |
|
isHasNumber(str: string): boolean { |
|
let reg = /\d/; |
|
return reg.test(str) |
|
} |
|
|
|
}
|
|
|