forked from 0-RTT/telegraph
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
367 lines (316 loc) · 8.35 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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0,viewport-fit=cover">
<script src="https://cdn.bootcdn.net/ajax/libs/vue/2.6.14/vue.min.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.4/axios.min.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/vue-clipboard2/0.3.3/vue-clipboard.min.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/clipboard.js/2.0.11/clipboard.min.js"></script>
<link rel="stylesheet" href="https://cdn.bootcdn.net/ajax/libs/element-ui/2.15.3/theme-chalk/index.css">
<script src="https://cdn.bootcdn.net/ajax/libs/element-ui/2.15.3/index.js"></script>
<link rel="icon" href="/favicon.ico" type="image/x-icon">
<style>
/* 全局样式 */
body {
background: #f1f1f1;
}
/* 默认样式,适用于PC端(大于等于1200px宽度) */
.container {
width: 50%;
margin: 30px auto 0;
background: #fff;
border-radius: 10px;
padding-bottom: 10px;
}
.el-dialog {
width: 30%;
}
/* 媒体查询,适用于PAD端(768px - 1199px宽度) */
@media screen and (min-width: 768px) and (max-width: 1199px) {
.container {
width: 80%;
border-radius: 10px;
}
.el-dialog {
width: 30%;
}
}
/* 媒体查询,适用于手机端(小于768px宽度) */
@media screen and (max-width: 767px) {
.container {
width: 90%;
border-radius: 10px;
}
.el-dialog {
width: 80%;
}
}
/* 标题样式 */
.h2 {
font-size: 35px;
font-weight: 400;
text-align: center;
line-height: 100px;
margin-bottom: 10px;
}
/* 按钮组样式 */
.container .button-group {
width: calc(100% - 60px);
padding: 30px;
padding-top: 0;
}
/* 错误提示样式 */
.upload-error {
width: calc(100% - 60px);
padding: 30;
margin: 15px auto 20px;
}
/* 输出类型按钮样式 */
.output-types button {
display: inline-block;
background-color: #f8f9fa;
border: none;
border-radius: 4px;
color: #6e7687;
cursor: pointer;
font-size: 14px;
margin-right: 10px;
padding: 8px 12px;
transition: all 0.2s ease-in-out;
margin-left: 2px;
}
.output-types button.selected {
background-color: #6772e5;
color: #fff;
}
/* 上传图片样式 */
.upload-demo {
border-radius: 4px;
color: #6e7687;
font-size: 14px;
margin: 0 auto;
margin-top: 10px;
padding: 12px;
resize: none;
width: 100%;
}
.el-upload {
width: 100%;
}
.el-upload-dragger {
width: 100%;
}
/* 输出链接样式 */
.output-link textarea {
background-color: #f8f9fa;
border: none;
height: 80px;
border-radius: 4px;
color: #6e7687;
font-size: 14px;
margin: 10px 2px; /* 上边距保持10px,左右边距设置为2px */
padding: 12px;
resize: none;
width: calc(100% - 4px); /* 总宽度减去左右各2px的边距 */
box-sizing: border-box; /* 确保宽度包括padding和border */
display: block;
}
/* 复制/清空按钮样式 */
.output-buttons {
display: flex;
justify-content: flex-end;
margin-top: 10px;
}
.output-buttons button {
background-color: #f8f9fa;
border: none;
border-radius: 4px;
color: #6e7687;
cursor: pointer;
font-size: 14px;
margin-left: 10px;
padding: 8px 12px;
transition: all 0.2s ease-in-out;
}
.output-buttons button:hover {
background-color: #6772e5;
color: #fff;
}
/* API标题样式 */
.api-title {
font-size: 16px;
font-weight: normal;
margin-bottom: 10px;
}
/* 隐藏v-cloak样式 */
[v-cloak] {
display: none;
}
</style>
</head>
<body>
<div id="app" v-cloak>
<div class="container">
<!--网页标题-->
<title>{{ webtitle }}</title>
<!--大标题-->
<p class="h2">{{ webtitle }}</p>
<!--API接口-->
<div class="button-group">
<el-upload class="output-link" :action="`./api/${selectedApi}.php`" :auto-upload="true" drag :on-success="handleSuccess" :on-error="handleError">
<i class="el-icon-upload"></i>
<div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
</el-upload>
<br>
<!--输出链接-->
<div class="output-types">
<button v-for="type in outputTypes" :key="type.key" @click="selectLinkType(type)" :class="{ 'selected': currentOutputType === type.key }">{{ type.title }}</button>
<div class="output-link">
<textarea class="form-control" id="output" v-model="result" rows="8" placeholder=""></textarea>
<div class="output-buttons">
<button class="btn btn-sm btn-outline-light reset-btn" @click="reset"><em class="icon el-icon-delete"></em>清除</button>
<button class="btn btn-sm btn-outline-light copy-btn" @click="copy"><em class="icon el-icon-document-copy"></em>复制</button>
</div>
<p style="font-size: 10px; text-align: center;">
<span id="num"></span><br>
当前IP:<span id="ip"></span><br>
请遵守相关法律法规,合理使用本站资源!
<br>项目开源于 GitHub - <a href="https://github.com/0-RTT/telegraph" target="_blank" rel="noopener noreferrer">0-RTT/telegraph</a>
</p>
</div>
<div class="upload-error" v-if="error">
<el-alert
title="上传失败"
type="error"
:description="msg"
show-icon
></el-alert>
</div>
</div>
</div>
</div>
</div>
<script>
new Vue({
el: "#app",
data: {
webtitle: "图床",
selectedApi: "api", // 默认选中的API,无需用户选择
url: false,
error: false,
msg: "",
outputTypes: [
{
title: 'Markdown',
key: 'Markdown',
template: '![image](#url#)',
},
{
title: 'BBCode',
key: 'BBCode',
template: '[img]#url#[/img]',
},
{
title: 'URL',
key: 'URL',
template: '#url#',
}
],
currentOutputType: 'Markdown',
result: '',
clipboard: null,
},
mounted() {
const script = document.createElement('script');
script.onload = () => {
console.log('clipboard.js loaded');
};
document.head.appendChild(script);
},
methods: {
selectApi(api) {
this.selectedApi = api;
},
handleSuccess(response, file) {
console.log("请求成功", response);
if (response.code == 200) {
this.url = response.url;
this.generateResult();
} else {
this.url = false;
this.error = true;
this.msg = response.msg;
}
},
handleError(err, file) {
console.error("上传失败", err);
this.url = false;
this.error = true;
this.msg = this.selectedApi + ".php" + "服务器发生错误!";
},
generateResult() {
if (!this.url) {
return;
}
const currentOutputType = this.outputTypes.find(v => v.key === this.currentOutputType) || this.outputTypes[0];
this.result = currentOutputType.template.replace(/#url#/g, this.url);
this.convertLink();
},
convertLink() {
const selectedType = this.outputTypes.find(type => type.key === this.currentOutputType);
if (selectedType) {
let link = selectedType.template.replace(/#url#/g, this.url);
this.result = this.url ? link : '';
}
},
copy() {
if (this.result) {
if (!this.clipboard) {
this.clipboard = new ClipboardJS(".copy-btn", {
text: () => this.result,
});
}
this.clipboard.onClick(event);
const copyBtn = document.querySelector('.copy-btn');
copyBtn.textContent = "已复制";
setTimeout(() => {
copyBtn.textContent = "复制";
}, 500);
}
},
reset() {
if (!this.result) {
return;
}
this.url = false;
this.error = false;
this.msg = "";
this.currentOutputType = 'Markdown';
this.result = '';
if (this.clipboard) {
this.clipboard.destroy();
this.clipboard = null;
}
const resetBtn = document.querySelector('.reset-btn');
resetBtn.textContent = "已清除";
setTimeout(() => {
resetBtn.textContent = "清除";
}, 500);
},
selectLinkType(type) {
this.currentOutputType = type.key;
this.convertLink();
},
},
});
// 获取访问者IP
fetch('https://www.cloudflare.com/cdn-cgi/trace')
.then(response => response.text())
.then(data => {
const ip = data.match(/(?:ip=)(.*)/)[1];
document.getElementById('ip').textContent = ip;
});
</script>
</body>
</html>