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

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) {
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) {