var isChinese = function(temp) {
var re = /[^\u4E00-\u9FA5]/;
if (re.test(temp)) {
return false;
}
return true;
}
var isnumber= function(theObj) {
var reg = /^[0-9]+.?[0-9]*$/;
if (reg.test(theObj)) {
return true;
}
return false;
}
var isChar = function(char) {
var reg = /[A-Za-z]/;
if (!reg.test(char)) {
return false;
}
return true;
}
var pySort = function(arr, empty) {
var $this = this;
// alert($this)
if (!String.prototype.localeCompare)
return null;
// var letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ#".split('');
var letters = "ABCDEFGHJKLMNOPQRSTWXYZ#123456789".split('');
var zh = "啊把差大额发噶哈级卡啦吗那哦爬器然撒他哇西呀咋".split(''); //*占位没有i,u,v拼音开头的汉字
// console.log(arr)
var arrList = [];
for (var m = 0; m < arr.length; m++) {
arrList.push(arr[m]);
}
var result = [];
var curr;
for (var i = 0; i < letters.length; i++) {
curr = {
letter: letters[i],
data: []
};
// console.log(arrList)
if (i != 26) {
for (var j = 0; j < arrList.length; j++) {
var initial = arrList[j].name.charAt(0); //截取第一个字符
// console.log(initial)
if (arrList[j].name.charAt(0) == letters[i] || arrList[j].name.charAt(0) == letters[i].toLowerCase()) { //首字符是英文的
// console.log("1")
curr.data.push(arrList[j]);
} else if (zh[i] != '*' && isChinese(initial)) { //判断是否是无汉字,是否是中文
// console.log("2")
if (initial.localeCompare(zh[i]) >= 0 && (!zh[i + 1] || initial.localeCompare(zh[i + 1]) < 0)) { //判断中文字符在哪一个类别
console.log(initial)
console.log(zh[i])
console.log(letters[i])
console.log(initial.localeCompare(zh[i]))
console.log(initial.localeCompare(zh[i + 1]))
console.log("--------------------")
curr.data.push(arrList[j]);
}
// curr.data.push(arrList[j]);
}
}
} else {
// for (var k = 0; k < arrList.length; k++) {
// var ini = arrList[k].name.charAt(0); //截取第一个字符
// if (!isChar(ini) && !isChinese(ini)) {
// curr.data.push(arrList[k]);
// console.log(ini)
// }
// }
}
if (empty || curr.data.length) {
console.log(curr.data.length)
console.log(result)
result.push(curr);
console.log(result)
curr.data.sort(function(a, b) {
console.log(a)
console.log(b)
return b.name.localeCompare(a.name); //排序,英文排序,汉字排在英文后面
});
}
}
return result;
}
exports.isChinese = isChinese
exports.isChar = isChar
exports.pySort = pySort
uview客户管理js
最新推荐文章于 2024-11-08 16:09:18 发布