diff --git a/src/utils.js b/src/utils.js index 9dc9a94d..e8b29599 100644 --- a/src/utils.js +++ b/src/utils.js @@ -85,47 +85,28 @@ export function getNowTime() { export function sortWeeks(weeks) { var _weeks = [] //创建临时排序的数组 for (var i = 0; i < weeks.length; i++) { - if (weeks[i] == '周一') { - var _week = {} - _week['id'] = 1 - _week['name'] = '周一' - _weeks.push(_week) - } - if (weeks[i] == '周二') { - var _week = {} - _week['id'] = 2 - _week['name'] = '周二' - _weeks.push(_week) - } - if (weeks[i] == '周三') { - var _week = {} - _week['id'] = 3 - _week['name'] = '周三' - _weeks.push(_week) - } - if (weeks[i] == '周四') { - var _week = {} - _week['id'] = 4 - _week['name'] = '周四' - _weeks.push(_week) - } - if (weeks[i] == '周五') { - var _week = {} - _week['id'] = 5 - _week['name'] = '周五' - _weeks.push(_week) - } - if (weeks[i] == '周六') { - var _week = {} - _week['id'] = 6 - _week['name'] = '周六' - _weeks.push(_week) - } - if (weeks[i] == '周日') { - var _week = {} - _week['id'] = 7 - _week['name'] = '周日' - _weeks.push(_week) + 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) {