-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathindex.html
217 lines (195 loc) · 6.46 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
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" href="asset/img/favicon.png">
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>一只会飞的旺旺</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.16/dist/tailwind.min.css">
<style>
body {
background: url('https://i0.wp.com/wangwangit001.cachefly.net/wangwangit/image/master/img/%E6%B5%8B%E8%AF%952.jpg') center/cover fixed;
/* 设置背景图片 */
font-family: 'Arial', sans-serif;
/* 设置默认字体 */
color: #333;
/* 设置默认文本颜色 */
}
main {
display: flex;
align-items: center;
justify-content: center;
min-height: calc(100vh - 8rem);
text-align: center;
}
.container {
background-color: rgba(255, 255, 255, 0.8);
/* 设置容器背景颜色及透明度 */
border-radius: 10px;
padding: 40px;
box-shadow: 0px 5px 15px rgba(0, 0, 0, 0.2);
/* 添加阴影 */
max-width: 600px;
}
input:focus {
outline: none;
box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.5);
/* 绿色聚焦效果 */
}
button {
background-color: #22c55e;
/* 绿色按钮 */
color: white;
transition: background-color 0.3s ease;
}
button:hover {
background-color: #16a34a;
/* 深绿色悬停效果 */
}
footer {
background-color: rgba(255, 255, 255, 0.9);
/* 设置页脚背景颜色及透明度 */
padding: 20px;
text-align: center;
position: fixed;
bottom: 0;
left: 0;
width: 100%;
box-shadow: 0px -2px 5px rgba(0, 0, 0, 0.1);
/* 添加顶部阴影 */
}
h1 {
font-size: 3em;
/* 加大标题字体 */
font-weight: 700;
/* 设置标题字体粗细 */
margin-bottom: 20px;
color: #22c55e;
/* 设置标题颜色 */
}
.success,
.error {
padding: 10px 20px;
border-radius: 5px;
margin-bottom: 20px;
font-weight: 600;
/* 设置消息字体粗细 */
}
.success {
background-color: #d1fae5;
/* 浅绿色成功消息 */
color: #047857;
}
.error {
background-color: #fee2e2;
/* 浅红色错误消息 */
color: #b91c1c;
}
</style>
</head>
<body>
<main>
<div class="container">
<h1 class="text-3xl font-bold text-gray-800">一只会飞的旺旺</h1>
<div x-data="app" x-cloak>
<p x-show.transition.opacity="alert" :class="alert?.type" x-text="alert?.message"></p>
<div class="mb-4">
<input placeholder="输入要缩短的网址..." x-model="url" x-ref="url"
class="shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:shadow-outline" />
</div>
<!-- 在 x-data="app" 下的 input url 后添加 -->
<div class="mb-4">
<input type="password"
placeholder="请输入访问密码..."
x-model="password"
class="shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:shadow-outline" />
</div>
<details class="mb-4 border border-gray-300 rounded-md">
<summary class="px-4 py-2 cursor-pointer font-medium">自定义设置</summary>
<div class="px-4 py-2">
<input placeholder="自定义短链接 (可选)" x-model="slug"
class="shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:shadow-outline" />
<div class="mt-2">
<label for="expiry" class="block text-sm font-medium text-gray-700">过期时间 (可选):</label>
<select id="expiry" x-model="expiry"
class="mt-1 block w-full pl-3 pr-10 py-2 text-base border-gray-300 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm rounded-md">
<option value="">永不过期</option>
<option value="5m">5 分钟</option>
<option value="1h">1 小时</option>
<option value="12h">12 小时</option>
<option value="1d">1 天</option>
<option value="7d">1 周</option>
</select>
</div>
</div>
</details>
<button :class="{ loading }" :disabled="loading || isValidated()" @click="submit($refs, $nextTick)"
class="bg-green-500 hover:bg-green-700 text-white font-bold py-2 px-4 rounded focus:outline-none focus:shadow-outline">
生成
</button>
</div>
</div>
</main>
<footer class="text-gray-600">
<a href="https://www.wangwangit.com">一只会飞的旺旺</a>
</footer>
<script src="asset/js/alpine.js"></script>
<script>
const app = {
url: '',
slug: '',
expiry: '', // 添加过期时间属性
password: '', // 添加访问密码属性
alert: null,
loading: false,
isValidated() {
return !/^https?:\/\/.{3,}/.test(this.url)
},
submit($refs, $nextTick) {
if (!this.url) {
this.alert = { type: 'error', message: '缺少必需的参数:url。' }
return
}
if (!this.password) {
this.alert = { type: 'error', message: '请输入访问密码。' }
return
}
if (this.isValidated()) {
this.alert = { type: 'error', message: '非法格式:url。' }
return
}
this.alert = null
this.loading = true
const body = {
url: this.url,
slug: this.slug,
expiry: this.expiry,
password: this.password
}
fetch('/create', {
method: 'post',
headers: { 'content-type': 'application/json' },
body: JSON.stringify(body)
})
.then(res => res.json())
.then(res => {
this.loading = false
if (res.message) {
this.alert = { type: 'error', message: res.message }
return
}
this.url = res.link
$nextTick(() => {
$refs.url.select()
this.alert = { type: 'success', message: `链接 ${document.execCommand('Copy') ? '复制' : '生成'} ` }
})
})
.catch(e => {
this.alert = { type: 'error', message: e.message }
this.loading = false
})
}
}
</script>
</body>
</html>