From c8b1ccc1dafec0f1e137d2605325ba04f2f7fc13 Mon Sep 17 00:00:00 2001 From: wangsongsole Date: Fri, 19 Aug 2022 17:32:13 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=AB=8B=E5=87=8F=E9=87=91?= =?UTF-8?q?=E7=BB=84=E4=BB=B6=20=E8=A7=84=E5=88=99=E6=97=A5=E6=9C=9F?= =?UTF-8?q?=E6=96=B9=E6=B3=95=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils.js | 44 +++++++++++++++----------------------------- 1 file changed, 15 insertions(+), 29 deletions(-) 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) {