function getWeekNumString(weekNumList) { var orderedWeekNumList = weekNumList.sort(function (a, b) { return parseInt(a) - parseInt(b); }); var isSingle = true; var isDouble = true; var minWeekNum = 0; var maxWeekNum = 0; if (weekNumList.length > 0) { minWeekNum = orderedWeekNumList[0]; maxWeekNum = orderedWeekNumList[orderedWeekNumList.length - 1]; } for (var i = 0; i < orderedWeekNumList.length; i++) { var curWeekNum = orderedWeekNumList[i]; if (curWeekNum == 0) { isSingle = false; isDouble = false; break; } if (curWeekNum != minWeekNum + (i * 2)) { isSingle = false; isDouble = false; break; } //判断单周 if (curWeekNum % 2 != 1) { isSingle = false; } //判断双周 if (curWeekNum % 2 != 0) { isDouble = false; } } if (minWeekNum == 0 && maxWeekNum == 0) { return ""; } if (isSingle) { return minWeekNum.toString() + "-" + maxWeekNum.toString() + "单周"; } if (isDouble) { return minWeekNum.toString() + "-" + maxWeekNum.toString() + "双周"; } return mergeInt(orderedWeekNumList).join(","); } function mergeInt(enumerable) { var result = new Array(); var orderedEnumerable = enumerable.sort(function (a, b) { return parseInt(a) - parseInt(b); }); var numberCount = orderedEnumerable.length; if (numberCount == 0) return result; var firstNum = orderedEnumerable[0]; var lastNum = orderedEnumerable[0]; for (var i = 1; i < numberCount; i++) { var curNum = orderedEnumerable[i]; if (curNum > (lastNum + 1)) { if (firstNum == lastNum) { result.push(firstNum.toString()); } else { result.push(firstNum.toString() + '-' + lastNum.toString()); } firstNum = curNum; } lastNum = curNum; } if (firstNum == lastNum) { result.push(firstNum.toString()); } else { result.push(firstNum.toString() + '-' + lastNum.toString()); } return result; } CMSFunction.DataTableFormatter.WeekNum = function (index, row, value) { if (!value || !Array.isArray(value)) { return ""; } return getWeekNumString(value); }