-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
145 lines (141 loc) · 4.69 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Sechdule</title>
<link rel="stylesheet" href="css/index.css">
<script src="lib/vue.js"></script>
</head>
<body>
<div id="base">
<div class="action">
<input :class="{'text-danger':invalidInput}" type="text" v-model="newTodo">
<button @click="pushSchedule()" :disabled="invalidInput">Add</button>
</div>
<ol class="todo-list">
<div v-if="todos.length==0">No Schedule</div>
<todo-item v-for='(todo,index) in todos' :todo='todo' :todos="todos" :key='index' :index='index'></todo-item>
</ol>
<div class="footer">
<span>Doing: {{doingNum}} Done: {{doneNum}}</span>
</div>
</div>
<template id="todo-item-template">
<li class="todo-t">
<span v-if="!todo.edit" type="text" class="things" v-text="todo.todoThing"></span>
<button v-if="!todo.edit" :disabled="!todo.doing" @click="finishThing()">Done! </button>
<button v-if="!todo.edit" @click="enableEdit()">EDIT</button>
<input type="text" v-if="todo.edit" v-model="tempThing">
<button v-if="todo.edit&&!todo.doing" @click="editThing('undone')">标记未完成</button>
<button v-if="todo.edit&&todo.doing" @click="editThing('done')">标记已完成</button>
<button v-if="todo.edit" @click="editThing('save')">保存</button>
<button v-if="todo.edit" @click="editThing('cancel')">取消</button>
<button v-if="todo.edit" @click="editThing('delete')">删除</button>
</li>
</template>
</body>
<script>
Vue.component('todo-item',{
props:['todo','todos','index'],
template:'#todo-item-template',
data:function() {
return{
tempThing:""
}
},
methods:{
finishThing:function(){
this.todo.doing=false
},
enableEdit:function(){
this.tempThing=this.todo.todoThing
this.todo.edit=true
},
editThing:function(action){
switch(action){
case 'done':
this.todo.doing=false
this.todo.edit=false
break
case 'undone':
this.todo.doing=true
this.todo.edit=false
break
case 'save':
this.todo.todoThing=this.tempThing
this.todo.edit=false
this.todo.doing=!this.todo.doing
this.todo.doing=!this.todo.doing
break
case 'cancel':
this.todo.edit=false
break
case 'delete':
this.todos.splice(this.index,1)
break
}
}
}
})
Vue.component('edit-button',{
props:['isInEdit'],
template:''
})
var base=new Vue({
el:'#base',
data:{
newTodo:'',
invalidInput:false,
todos:[
{todoThing:"Finish this program",doing:true,edit:false},
{todoThing:"Ask for a 10ve",doing:true,edit:false},
{todoThing:"do the summary assignment",doing:false,edit:false}
]
},
created:function(){
localStorage.setItem('supportLocalStorage','true')
if(!localStorage.getItem('supportLocalStorage'))
alert('Your browser doesn\'t support LocalStorage, this site maynot run probably.\n你的浏览器不支持LocalStorage,此网站将无法正确运行。')
else localStorage.removeItem('supportLocalStorage')
var t
if(t=localStorage.getItem('YourSchedule'))
this.todos=JSON.parse(t)
},
updated:function(){
localStorage.setItem('YourSchedule',JSON.stringify(this.todos))
},
methods:{
pushSchedule:function(){
this.todos.push({
id : this.todos.length,
todoThing : this.newTodo,
doing : true,
edit : false
})
this.newTodo=""
},
},
computed:{
doingNum:function(){
return this.todos.filter(function(el){
return el.doing===true
}).length||'0'
},
doneNum:function(){
return this.todos.filter(function(el){
return el.doing===false
}).length||'0'
}
},
watch:{
newTodo:function(val){
var test=/^(\s| )+$/
if(!val.search(test))
this.invalidInput=true
else this.invalidInput=false
}
}
})
</script>
</html>