break;
}
}
},
//初始化
created() {
let list = localStorage.list;
if (list) {
this.list = JSON.parse(list);
}
},
computed: {
nolength() {
let i = 0;
this.list.map(item => {
if (!item.done) {
i++;
}
});
return i;
},
yeslength() {
let i = 0;
this.list.map(item => {
if (item.done) {
i++;
}
});
return i;
}
},
methods: {
// 添加
add() {
this.list.push({
text: this.value,
time: new Date().getTime(),
done: false
});
this.value = “”;
this.tb(); //调用同步
this.list.sort((a, b) => {
//排序
return b.time - a.time;
});
},
//删除
del(index) {
this.list.splice(index, 1);
this.tb(); //调用同步
},
//双击修改
update(item, index) {
this.tempvalue = item.text;
this.updateindex = index;
},
updatesave() {
//修改后保存
this.tb();
this.updateindex = -1;
},
updateesc(item) {
//还原
item.text = this.tempvalue;
this.updateindex = -1;
},
//复选框点击
chang(item, checked) {
if (checked) {
item.done = true;
} else {
item.done = false;
}
this.tb();
this.list.sort((a, b) => {
//排序
return b.time - a.time;
});
},
//同步函数
tb() {
localStorage.list = JSON.stringify(this.list);
}
},
//过滤器
filters: {
timeFilters(ms) {
let data = new Date();
let now = data.getTime();
let rel = (now - ms) / 1000 / 60;
let daystr = “”;
if (rel < 5) {
daystr = “刚刚”;
} else if (rel >= 5 && rel < 10) {
daystr = “5分钟前”;
} else if (rel >= 10 && rel < 30) {
daystr = “10分钟前”;
} else if (rel >= 30 && rel < 40) {
daystr = “30分钟前”;
} else if (rel >= 40 && rel < 60) {
daystr = “40分钟前”;
} else if (rel >= 60 && rel < 120) {
daystr = “1小时前”;
} else if (rel >= 120 && rel < 300) {
daystr = “2小时前”;
} else if (rel >= 300 && rel < 1440) {
daystr = “5小时前”;
} else if (rel >= 1440 && rel < 2880) {
daystr = “1天前”;
} else if (rel >= 2880 && rel < 10080) {
daystr = “2天前”;
} else if (rel >= 10080 && rel < 43200) {
daystr = “7天前”;
} else if (rel >= 43200) {
daystr = “30天前”;
}
return daystr;
}
}
};