优化立减金组件 规则日期方法代码

This commit is contained in:
wangsongsole 2022-08-19 17:32:13 +08:00
parent 180bd5953b
commit c8b1ccc1da
1 changed files with 15 additions and 29 deletions

View File

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