-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmy-form.vue
175 lines (163 loc) · 4.44 KB
/
my-form.vue
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
171
172
<template>
<form @submit.prevent="login" id="my-form"
class="container"
action="https://api.staticman.net/v2/entry/QueenYoung/zerostudio/master/"
method="POST"
name="zero"
>
<my-field v-for="(field, index) in fields" :key="index"
v-bind="field"
:status="status[index]"
:index="index"
@showInput="yo"
/>
<div class="field">
<label for="" class="label">同学是女装大佬还是?</label>
<div class="control">
<div class="select">
<select v-model="sex" name="fields[sex]">
<option disabled value="">性别</option>
<option value="男">👨🏻</option>
<option value="女">👩🏻</option>
</select>
</div>
</div>
</div>
<div class="field">
<label for="" class="label">同学哪个院的?</label>
<div class="control">
<div class="select">
<select v-model="college" name="fields[college]">
<option disabled value="">院系</option>
<option>软件院</option>
<option>计信院</option>
<option>工学院</option>
<option>其他</option>
</select>
</div>
</div>
</div>
<div class="field">
<label class="label">我们喜欢妹子多的班级🤓</label>
<div class="control">
<div class="select">
<select v-model="classroom" name="fields[classroom]">
<option disabled value="">班级</option>
<option v-for="n in 14" :key="n">{{n}}</option>
</select>
</div>
</div>
</div>
<div class="field">
<label class="label">很酷, 真的</label>
<div class="control">
<textarea class="textarea" name="fields[introduce]"
placeholder="介绍一下你自己" v-model="introduce"/>
</div>
</div>
<div class="field">
<p class="control">
<button
:disabled="!canLogin()"
class="button is-success"
>Login</button>
</p>
</div>
</form>
</template>
<script>
import Field from './BaseField'
import Hero from './Hero'
export default {
components: {
'my-field': Field,
hero: Hero
},
data() {
return {
fields: [
{
iconName: 'user',
placeholder: '比如: 乔布斯',
type: 'text',
labelTitle: '名字',
warning: '不要用英文名耍我',
name: 'fields[name]'
},
{
iconName: 'mobile',
placeholder: '不要瞎给手机号码',
type: 'tel',
labelTitle: '手机',
name: 'fields[telphone]'
}
],
status: Array.apply(null, { length: 2 }),
inputs: ['', ''],
sex: '',
college: '',
classroom: '',
introduce: ''
}
},
methods: {
clearInput() {
this.inputs = ['', '']
this.sex = ''
this.college = ''
this.classroom = ''
this.introduce = ''
},
yo(input, index) {
this.inputs.splice(index, 1, input)
if (index === 0) {
this.status.splice(index, 1, this.legalName(input))
} else {
this.status.splice(index, 1, this.legalTelphone(input))
}
},
login() {
const fields = {
fields: {
'fields[name]': this.inputs[0],
'fields[telphone]': this.inputs[1],
'fields[classroom]': this.classroom,
'fields[sex]': this.sex,
'fields[introduce]': this.introduce,
'fields[college]': this.college
}
}
const urls = 'https://api.staticman.net/v2/entry/QueenYoung/zerostudio/master/'
fetch(urls, {
method: 'POST',
body: JSON.stringify(fields),
mode: 'cors',
headers: {
'Content-Type': 'application/json'
}
})
this.clearInput()
},
canLogin() {
return (
this.status.every(Boolean) &&
[this.sex, this.college, this.classroom, this.introduce].every(Boolean)
)
},
legalTelphone(input) {
const tel = /^1[3578]\d{9}$/
return tel.test(input)
},
legalName(input) {
if (input === '乔布斯') {
alert('老子去你妈的!')
alert('给我好好填!')
return false
}
const range = [0x4e00, 0x9fa5]
const codePoints = Array.from(input, code => code.codePointAt(0))
return codePoints.every(point => point >= range[0] && point <= range[1])
}
}
}
</script>