-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrea.html
170 lines (167 loc) · 4.34 KB
/
rea.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Rea.js Example - Todo List</title>
<style>
*,
*::before,
*::after {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
padding: 1em;
}
input, select {
padding: 5px 10px;
font-size: 16px;
outline: none;
}
button {
padding: 3px 6px;
font-size: 16px;
cursor: pointer;
}
.todo-tip {
color: red;
}
.todo-item {
display: flex;
align-items: center;
padding: 5px;
}
.todo-item:hover {
background: ghostwhite;
}
.todo-item span {
flex: 1
}
.todo-item-true {
color: gray;
}
.todo-item-check {
display: inline-block;
width: 16px;
height: 16px;
border: 1px solid gray;
margin-right: 10px;
cursor: pointer;
}
.todo-item-check-true {
border-color: green;
background: green;
}
</style>
</head>
<body>
<h1><a href="https://github.com/baoanj/rea.js" target="_blank">Rea.js</a> Example - Todo List</h1>
<br><br>
<div>
待办名称:
<input type="text" placeholder="开启你的待办事项" maxlength="20" r-model-todoName>
<span r-show-isShowLimit r-todoNameLimit></span>
<br><br>
优先级:
<select r-model-todoType r-for-typeList>
<option value="r-prop-value">r-prop-label</option>
</select>
<br><br>
待办时间:
<input type="datetime-local" r-model-todoTime>
<br><br>
<button r-event="click:addTodo">添加待办</button>
<span r-show-todoTip r-todoTip class="todo-tip"></span>
<br><br><hr>
</div>
<div r-for-todoListFormat>
<div class="todo-item todo-item-r-prop-check">
<div r-event="click:checkTodo" class="todo-item-check todo-item-check-r-prop-check"></div>
<span>r-prop-name</span>
<span>r-prop-type</span>
<span>r-prop-time</span>
<button r-event="click:delTodo">删除</button>
</div>
</div>
<script src="./rea.js"></script>
<script>
Rea({
data: {
typeList: [
{ label: '高', value: 'h' },
{ label: '中', value: 'm' },
{ label: '低', value: 'l' }
],
todoName: '',
todoType: null,
todoTime: null,
todoList: [
{ name: 'Todo Example 1', type: 'h', time: '2023-08-12T15:18', check: false },
{ name: 'Todo Example 2', type: 'm', time: '2023-08-12T15:18', check: true }
],
todoTip: ''
},
computed: {
isShowLimit() {
return this.todoName.length > 0
},
todoNameLimit() {
return this.todoName.length + '/20'
},
todoListFormat() {
return this.todoList.map(m => {
return {
name: m.name,
type: this.typeList.find(f => f.value === m.type).label,
time: m.time.replace('T', ' '),
check: m.check
}
})
}
},
methods: {
addTodo() {
if (!this.todoName) {
this.showTip('请填写待办名称')
return
}
if (!this.todoType) {
this.showTip('请选择优先级')
return
}
if (!this.todoTime) {
this.showTip('请选择待办时间')
return
}
this.todoList.unshift({
name: this.todoName,
type: this.todoType,
time: this.todoTime,
check: false
})
this.todoName = ''
this.todoType = null
this.todoTime = null
},
showTip(msg) {
this.todoTip = msg
setTimeout(() => {
this.todoTip = ''
}, 3000)
},
delTodo(event, index) {
this.todoList.splice(index, 1)
},
checkTodo(event, index) {
this.todoList[index] = Object.assign(this.todoList[index], {
check: !this.todoList[index].check
})
}
}
})
</script>
</body>
</html>