-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.html
167 lines (152 loc) · 5.68 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>MyUrls</title>
<link rel="icon" href="//img.znnu.com/favicon.ico" type="image/x-icon">
<!--<link rel="stylesheet" href="https://unpkg.com/[email protected]/lib/theme-chalk/index.css">-->
<!--<script src="https://unpkg.com/[email protected]/dist/vue.min.js"></script>-->
<!--<script src="https://unpkg.com/[email protected]/dist/axios.min.js"></script>-->
<!--<script src="https://unpkg.com/[email protected]/lib/index.js"></script>-->
<!--<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue-clipboard.min.js"></script>-->
<!-- 引入 jQuery -->
<!--<script src="https://code.jquery.com/jquery-3.6.0.min.js" type="application/javascript"></script>-->
<!-- 字节静态资源CDN -->
<link href="//lf26-cdn-tos.bytecdntp.com/cdn/expire-1-M/element-ui/2.13.0/theme-chalk/index.css" type="text/css" rel="stylesheet" />
<script src="//lf6-cdn-tos.bytecdntp.com/cdn/expire-1-M/vue/2.6.11/vue.min.js" type="application/javascript"></script>
<script src="//lf26-cdn-tos.bytecdntp.com/cdn/expire-1-M/element-ui/2.13.0/index.js" type="application/javascript"></script>
<script src="//lf26-cdn-tos.bytecdntp.com/cdn/expire-1-M/vue-clipboard2/0.3.1/vue-clipboard.min.js" type="application/javascript"></script>
<script src="//lf3-cdn-tos.bytecdntp.com/cdn/expire-1-M/jquery/3.6.0/jquery.min.js" type="application/javascript"></script>
<!-- 字节静态资源CDN -->
</head>
<body>
<div id="app">
<el-container>
<el-header></el-header>
<el-main>
<div :class="[isPc ? 'body-center body-width-pc' : 'body-center body-width-mb']">
<img width="300" src="//img.znnu.com/myurls/logo.png" @click="goToGayHub">
<el-input ref="long" v-model="longUrl" size="medium" @keyup.enter.native="enterToDoShort">
<el-button slot="append" icon="el-icon-magic-stick" @click="doShort" :loading="loading"></el-button>
</el-input>
<el-input ref="shortUrl" @dblclick.native="changeDisableStatus" class="copy-content" v-model="shortUrl" size="medium">
<el-button slot="append" v-clipboard:copy="shortUrl" v-clipboard:success="onCopy" ref="copy-btn"
icon="el-icon-document-copy"></el-button>
</el-input>
</div>
</el-main>
</el-container>
</div>
<script>
const repo = 'https://github.com/kiko923/MyUrls-Workers'
let app = new Vue({
el: "#app",
data() {
return {
isPc: true,
loading: false,
longUrl: '',
shortUrl: ''
}
},
created() {
const os = this.getOS()
if (os.isPc !== true) {
this.isPc = false
}
},
mounted() {
this.$refs.long.focus()
},
methods: {
enterToDoShort(ev) {
ev.keyCode === 13 && this.doShort()
},
doShort() {
let re = new RegExp('http(s*)://[^\s]*')
if (re.exec(this.longUrl) === null) {
this.$message.warning('请输入正确格式的长链接')
return
}
this.loading = true
let data = new URLSearchParams();
data.append("longUrl", btoa(this.longUrl));
data.append("shortKey", this.shortUrl.indexOf('http') < 0 ? this.shortUrl : '');
// 使用 jQuery 的 ajax 方法代替 axios
$.ajax({
url: '/short',
type: 'POST',
data: data.toString(),
contentType: 'application/x-www-form-urlencoded; charset=utf-8',
success: (res) => {
if (res.Code === 1 && res.ShortUrl !== "") {
this.shortUrl = res.ShortUrl;
this.$copyText(this.shortUrl)
this.$refs.shortUrl.disabled = true
this.$message.success("短链接已复制到剪贴板");
} else {
this.$message.error("短链接获取失败:" + res.Message);
}
},
error: () => {
this.$message.error("短链接获取失败");
},
complete: () => {
this.loading = false;
}
});
},
goToGayHub() {
window.open(repo)
},
getOS() {
let ua = navigator.userAgent,
isWindowsPhone = /(?:Windows Phone)/.test(ua),
isSymbian = /(?:SymbianOS)/.test(ua) || isWindowsPhone,
isAndroid = /(?:Android)/.test(ua),
isFireFox = /(?:Firefox)/.test(ua),
isChrome = /(?:Chrome|CriOS)/.test(ua),
isTablet = /(?:iPad|PlayBook)/.test(ua) || (isAndroid && !/(?:Mobile)/.test(ua)) || (isFireFox && /(?:Tablet)/.test(ua)),
isPhone = /(?:iPhone)/.test(ua) && !isTablet,
isPc = !isPhone && !isAndroid && !isSymbian;
return {
isTablet: isTablet,
isPhone: isPhone,
isAndroid: isAndroid,
isPc: isPc
};
},
getBodyClass() {
return this.isPc ? 'body-center body-width-pc' : 'body-center'
},
onCopy() {
this.$message.success("Copied!");
},
changeDisableStatus(event) {
this.$refs.shortUrl.disabled = false
}
},
})
</script>
<style>
.body-center {
width: 40%;
position: absolute;
left: 50%;
top: 30%;
transform: translate(-50%, -50%);
text-align: center;
}
.body-width-pc {
width: 40%;
}
.body-width-mb {
width: 90%;
}
.el-input {
margin-top: 20px;
}
</style>
</body>
</html>