1
1
<script lang="ts" setup>
2
- import { NButton , NSpace , NAlert , NImage , useMessage , NSelect } from ' naive-ui' ;
3
- import { ref } from ' vue' ;
4
- import { api } from ' ../api'
5
-
6
- const alist_redirect_uri = " https://alist.nn.ci/tool/aliyundrive/callback"
7
- const app_id = " 76917ccccd4441c39457a04f6084fb2f"
8
-
2
+ import { NButton , NSpace , NAlert , NImage , useMessage , NSelect } from " naive-ui" ;
3
+ import { ref } from " vue" ;
4
+ import { api } from " ../api" ;
9
5
6
+ const alist_redirect_uri = " https://alist.nn.ci/tool/aliyundrive/callback" ;
7
+ const app_id = " 76917ccccd4441c39457a04f6084fb2f" ;
10
8
11
9
function goGet() {
12
10
const url = new URL (" https://open.aliyundrive.com/oauth/authorize" );
13
11
url .searchParams .set (" client_id" , app_id );
14
12
url .searchParams .set (" redirect_uri" , alist_redirect_uri );
15
- url .searchParams .set (
16
- " scope" ,
17
- " user:base,file:all:read,file:all:write"
18
- );
13
+ url .searchParams .set (" scope" , " user:base,file:all:read,file:all:write" );
19
14
url .searchParams .set (" response_type" , " code" );
20
- url .searchParams .set (
21
- " state" , " "
22
- );
15
+ url .searchParams .set (" state" , " " );
16
+ url .searchParams .set (" relogin" , " true" );
23
17
window .open (url .toString (), " _blank" );
24
18
}
25
19
26
20
interface QrCodeResp {
27
21
qrCodeUrl: string ;
28
22
sid: string ;
29
- error: string
23
+ error: string ;
30
24
}
31
25
32
- const qrcode = ref <QrCodeResp >()
26
+ const qrcode = ref <QrCodeResp >();
33
27
34
- const gettingQrCode = ref (false )
28
+ const gettingQrCode = ref (false );
35
29
36
30
async function getQrCode() {
37
31
try {
38
- gettingQrCode .value = true
32
+ gettingQrCode .value = true ;
39
33
const resp = await fetch (api () + " /alist/ali_open/qr" , {
40
34
method: " POST" ,
41
35
headers: {
42
- " Content-Type" : " application/json"
36
+ " Content-Type" : " application/json" ,
43
37
},
44
- body: JSON .stringify ({})
45
- })
46
- const res: QrCodeResp = await resp .json ()
47
- qrcode .value = res
38
+ body: JSON .stringify ({}),
39
+ });
40
+ const res: QrCodeResp = await resp .json ();
41
+ qrcode .value = res ;
48
42
} catch (e ) {
49
- console .log (e )
43
+ console .log (e );
50
44
qrcode .value = {
51
45
error: " error" ,
52
46
qrCodeUrl: " " ,
53
- sid: " "
54
- }
47
+ sid: " " ,
48
+ };
55
49
} finally {
56
- gettingQrCode .value = false
50
+ gettingQrCode .value = false ;
57
51
}
58
52
}
59
53
60
54
interface ScanStatus {
61
- status: string
62
- authCode: string
55
+ status: string ;
56
+ authCode: string ;
63
57
}
64
58
65
- const scanStatus = ref <ScanStatus >()
66
- const gettingScanStatus = ref (false )
59
+ const scanStatus = ref <ScanStatus >();
60
+ const gettingScanStatus = ref (false );
67
61
68
- const message = useMessage ()
62
+ const message = useMessage ();
69
63
70
64
async function haveScan() {
71
65
try {
72
- gettingScanStatus .value = true
73
- const resp = await fetch (` ${api ()}/proxy/https://open.aliyundrive.com/oauth/qrcode/${qrcode .value ?.sid }/status ` )
74
- const res: ScanStatus = await resp .json ()
75
- scanStatus .value = res
66
+ gettingScanStatus .value = true ;
67
+ const resp = await fetch (
68
+ ` ${api ()}/proxy/https://open.aliyundrive.com/oauth/qrcode/${
69
+ qrcode .value ?.sid
70
+ }/status `
71
+ );
72
+ const res: ScanStatus = await resp .json ();
73
+ scanStatus .value = res ;
76
74
if (res .status === " LoginSuccess" ) {
77
75
const url = new URL (alist_redirect_uri );
78
76
url .searchParams .set (" code" , res .authCode );
79
77
window .open (url .toString (), " _blank" );
80
78
} else {
81
- message .warning (res .status )
79
+ message .warning (res .status );
82
80
}
83
81
} catch (e ) {
84
- console .log (e )
85
- message .error (String (e ))
82
+ console .log (e );
83
+ message .error (String (e ));
86
84
} finally {
87
- gettingScanStatus .value = false
85
+ gettingScanStatus .value = false ;
88
86
}
89
87
}
90
-
91
88
</script >
92
89
93
90
<template >
94
91
<NSpace vertical size =" large" >
95
- <NButton size =" large" type =" primary" @click =" goGet" block >Go to login</NButton >
96
- <NButton size =" large" type =" info" @click =" getQrCode" block :loading =" gettingQrCode" :disabled =" !!qrcode" >Scan QrCode
92
+ <NButton size =" large" type =" primary" @click =" goGet" block
93
+ >Go to login</NButton
94
+ >
95
+ <NButton
96
+ size =" large"
97
+ type =" info"
98
+ @click =" getQrCode"
99
+ block
100
+ :loading =" gettingQrCode"
101
+ :disabled =" !!qrcode"
102
+ >Scan QrCode
97
103
</NButton >
98
104
<NAlert title =" Error" type =" error" v-if =" qrcode?.error" >
99
105
{{ qrcode.error }}
@@ -102,10 +108,23 @@ async function haveScan() {
102
108
<NSpace justify =" center" >
103
109
<NImage width =" 300" :src =" qrcode.qrCodeUrl" />
104
110
</NSpace >
105
- <NAlert title =" Scan the QrCode" type =" info" >Use AliyunDrive APP To Scan Then Click the Button Below</NAlert >
106
- <NButton size =" large" @click =" haveScan" type =" info" block :loading =" gettingScanStatus" >I have scan</NButton >
111
+ <NAlert title =" Scan the QrCode" type =" info"
112
+ >Use AliyunDrive APP To Scan Then Click the Button Below</NAlert
113
+ >
114
+ <NButton
115
+ size =" large"
116
+ @click =" haveScan"
117
+ type =" info"
118
+ block
119
+ :loading =" gettingScanStatus"
120
+ >I have scan</NButton
121
+ >
107
122
</NSpace >
108
- <NAlert title =" Warning" type =" warning" v-if =" scanStatus && scanStatus.status !== 'LoginSuccess'" >
123
+ <NAlert
124
+ title =" Warning"
125
+ type =" warning"
126
+ v-if =" scanStatus && scanStatus.status !== 'LoginSuccess'"
127
+ >
109
128
{{ scanStatus.status }}
110
129
</NAlert >
111
130
</NSpace >
0 commit comments