diff --git a/src/utils.js b/src/utils.js index e8b29599..b91cf442 100644 --- a/src/utils.js +++ b/src/utils.js @@ -83,35 +83,21 @@ export function getNowTime() { /* 周天排序 */ export function sortWeeks(weeks) { - var _weeks = [] //创建临时排序的数组 - for (var i = 0; i < weeks.length; i++) { - switch (weeks[i]) { - case '周一': - _weeks.push({ id: 1, name: '周一' }) - break - case '周二': - _weeks.push({ id: 2, name: '周二' }) - break - case '周三': - _weeks.push({ id: 3, name: '周三' }) - break - case '周四': - _weeks.push({ id: 4, name: '周四' }) - break - case '周五': - _weeks.push({ id: 5, name: '周五' }) - break - case '周六': - _weeks.push({ id: 6, name: '周六' }) - break - case '周日': - _weeks.push({ id: 7, name: '周日' }) - break - } - } - _weeks.sort(function (a, b) { - return a.id - b.id - }) + const staticWeeks = [ + { id: 1, name: '周一' }, + { id: 2, name: '周二' }, + { id: 3, name: '周三' }, + { id: 4, name: '周四' }, + { id: 5, name: '周五' }, + { id: 6, name: '周六' }, + { id: 7, name: '周日' } + ] + + var _weeks = weeks + .map((item) => staticWeeks.filter((item1) => item1.name === item)) + .flat(Infinity) + .sort((a, b) => a.id - b.id) + //将weeks清空并将排序好的值赋给weeks const weeksData = [] if (isContinuityNum(_weeks.map((item) => item.id)) && _weeks.length > 1) {