-
Notifications
You must be signed in to change notification settings - Fork 0
/
indexV2.html
89 lines (75 loc) · 2.18 KB
/
indexV2.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<!-- toastr -->
<link
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/toastr.min.css"
/>
</head>
<body>
<input id="file" type="file" />
<!-- axios -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/axios/1.0.0/axios.min.js"></script>
<!-- cookie.js -->
<script
src="https://cdnjs.cloudflare.com/ajax/libs/js-cookie/3.0.1/js.cookie.min.js"
integrity="sha512-wT7uPE7tOP6w4o28u1DN775jYjHQApdBnib5Pho4RB0Pgd9y7eSkAV1BTqQydupYDB9GBhTcQQzyNMPMV3cAew=="
crossorigin="anonymous"
referrerpolicy="no-referrer"
></script>
<!-- jquery -->
<!-- toastr 的依賴 -->
<script
src="https://code.jquery.com/jquery-3.6.1.min.js"
integrity="sha256-o88AwQnZB+VDvE9tvIXrMQaPlFFSUTR+nldQm1LuPXQ="
crossorigin="anonymous"
></script>
<!-- toastr -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/toastr.min.js"></script>
<!-- 封裝的 axios V2 -->
<script src="./requestV2.js"></script>
<script>
const { httpGet, httpPost, httpFileUpload } = useRequest()
const api = {
signIn: '/Token/signin',
claims: '/Token/claims',
userName: '/Token/username'
}
const apiCaller = {
signIn: (data = {}) => httpPost(api.signIn, data),
claims: () => httpGet(api.claims),
userName: () => httpGet(api.userName)
}
const setToken = (token, expire) =>
Cookies.set('token', token, {
expires: new Date(expire * 1000)
})
apiCaller
.signIn({
username: '煞氣a',
password: '1314'
})
.then((res) => {
console.log(res)
if (res.isSuccess) {
const { expireTime, token } = res.body
setToken(token, expireTime)
}
return apiCaller.userName()
})
.then((res) => {
return apiCaller.claims()
})
const file = document.querySelector('#file')
file.addEventListener('change', async (e) => {
const file = e.target.files[0]
await httpFileUpload(file)
})
</script>
</body>
</html>