-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtest.html
69 lines (61 loc) · 1.37 KB
/
test.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
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<script>
var dict = 'a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,0,1,2,3,4,5,6,7,8,9';
var dictTable = dict.split(',');
var link = '';
//10进制转成62进制
function idEncode(dataId) {
var value = [];
while (dataId > 0) {
var i = dataId % 62;
value.push(i);
dataId = parseInt(dataId / 62);
}
value.reverse();
while (value.length < 6) {
value.unshift(0);
};
return value;
}
//62进制id转成对应字符
function idToURL(id) {
var value = idEncode(id);
var URL = '';
var temp = [];
while (value.length) {
URL += dictTable[value.shift()];
};
return URL;
};
function URLDecode(url){
//将url打散,存放打散后的字符
var urlArray= Array.from(url);
//存放打散后的字符对应的id
var idArray=[];
idArray=urlArray.map((item,key)=>{
return dictTable.indexOf(item);
})
var drawId=idArray.reverse();
return drawId;
}
function URLToId(url){
var dataId=0;
var drawId=URLDecode(url);
console.log(drawId)
while (drawId.length) {
var i = drawId.pop() *62;
//console.log(i)
dataId+=i;
//console.log(dataId)
}
return dataId;
}
</script>
</body>
</html>