1
1
<script setup lang="ts">
2
+ import { useScriptTag } from ' @vueuse/core'
2
3
import { useI18n } from ' vue-i18n'
3
4
import Captcha from ' @/components/Captcha.vue'
4
5
import { Button } from ' @/components/ui/button'
5
6
import { Card , CardContent , CardDescription , CardFooter , CardHeader , CardTitle } from ' @/components/ui/card'
7
+ import { Dialog , DialogClose , DialogContent , DialogHeader , DialogTitle , DialogTrigger } from ' @/components/ui/dialog'
6
8
import { Input } from ' @/components/ui/input'
7
- import { useSiliconFlowStore } from ' @/stores'
9
+ import { useSiliconFlowStore , useThemeStore } from ' @/stores'
8
10
9
- const { t } = useI18n ()
11
+ const { t, locale } = useI18n ()
10
12
const siliconFlowStore = useSiliconFlowStore ()
13
+ const themeStore = useThemeStore ()
14
+
15
+ useScriptTag (' http://res.wx.qq.com/connect/zh_CN/htmledition/js/wxLogin.js' )
16
+
17
+ function wxLogin() {
18
+ setTimeout (() => {
19
+ // @ts-expect-error WeChat SDK
20
+ // eslint-disable-next-line no-new
21
+ new window .WxLogin ({
22
+ self_redirect: ! 1 ,
23
+ id: ' SF_wx_login_qr_code_f' ,
24
+ appid: ' wx637ec58e4e15a258' ,
25
+ scope: ' snsapi_login' ,
26
+ style: themeStore .isDark ? ' white' : ' black' ,
27
+ lang: locale .value === ' zh-CN' ? ' cn' : ' en' ,
28
+ // stylelite: 1,
29
+ // fast_login: 1,
30
+ redirect_uri: encodeURIComponent (' https://account.siliconflow.cn/api/open/weixin' ),
31
+ })
32
+ }, 500 )
33
+ }
11
34
</script >
12
35
13
36
<template >
@@ -17,11 +40,12 @@ const siliconFlowStore = useSiliconFlowStore()
17
40
{{ t('siliconFlow.loginTitle') }}
18
41
</CardTitle >
19
42
<CardDescription class =" text-sm" >
20
- {{ t('siliconFlow.loginDescription') }}
43
+ {{ siliconFlowStore.isEmailLogin ? t('siliconFlow.emailLoginDescription') : t('siliconFlow.loginDescription') }}
21
44
</CardDescription >
22
45
</CardHeader >
23
46
<CardContent class =" space-y-4" >
24
- <div class =" flex rounded-md border border-input bg-background" >
47
+ <!-- Phone Number Input -->
48
+ <div v-if =" !siliconFlowStore.isEmailLogin" class =" flex rounded-md border border-input bg-background" >
25
49
<div class =" flex items-center px-3 border-r border-input bg-muted/50 rounded-l-md" >
26
50
<span class =" text-sm font-medium text-muted-foreground" >+86</span >
27
51
</div >
@@ -30,21 +54,34 @@ const siliconFlowStore = useSiliconFlowStore()
30
54
class =" border-0 rounded-l-none focus-visible:ring-0 focus-visible:ring-offset-0 h-10"
31
55
/>
32
56
</div >
57
+
58
+ <!-- Email Input -->
59
+ <div v-if =" siliconFlowStore.isEmailLogin" class =" flex rounded-md border border-input bg-background" >
60
+ <Input
61
+ id =" email" v-model =" siliconFlowStore.email" :placeholder =" t('siliconFlow.emailAddressPlaceholder')" type =" email"
62
+ class =" border-0 focus-visible:ring-0 focus-visible:ring-offset-0 h-10"
63
+ />
64
+ </div >
65
+
66
+ <!-- SMS/Email Code Input -->
33
67
<div class =" flex rounded-md border border-input bg-background" >
34
68
<Input
35
- id =" sms" v-model =" siliconFlowStore.smsCode" :placeholder =" t('siliconFlow.smsCode')" type =" text" maxlength =" 6"
69
+ id =" sms" v-model =" siliconFlowStore.smsCode"
70
+ :placeholder =" siliconFlowStore.isEmailLogin ? t('siliconFlow.emailCode') : t('siliconFlow.smsCode')"
71
+ type =" text" maxlength =" 6"
36
72
class =" w-fit flex-grow border-0 rounded-r-none focus-visible:ring-0 focus-visible:ring-offset-0 h-10"
37
73
/>
38
74
<div class =" border-l border-input" >
39
75
<Captcha
40
- :enabled =" siliconFlowStore.phoneNumber.length > 0" :config =" siliconFlowStore.captchaConfig"
76
+ :enabled =" siliconFlowStore.isEmailLogin ? siliconFlowStore.email.length > 0 : siliconFlowStore.phoneNumber.length > 0"
77
+ :config =" siliconFlowStore.captchaConfig"
41
78
class =" h-10 px-4 bg-muted/50 rounded-r-md border-0 text-xs text-primary hover:bg-muted/70 transition-colors disabled:opacity-50"
42
79
@next =" siliconFlowStore.sendSMS"
43
80
/>
44
81
</div >
45
82
</div >
46
83
</CardContent >
47
- <CardFooter class =" flex flex-col space-y-3 pt-3" >
84
+ <CardFooter class =" flex flex-col space-y-3 pt-3 items-start " >
48
85
<div class =" flex items-center space-x-2 text-xs text-muted-foreground" >
49
86
<input id =" agree" v-model =" siliconFlowStore.agreed" type =" checkbox" class =" h-3 w-3 rounded border border-input" >
50
87
<label for =" agree" class =" flex items-center gap-1 cursor-pointer" >
@@ -60,14 +97,33 @@ const siliconFlowStore = useSiliconFlowStore()
60
97
>{{ t('siliconFlow.privacyPolicy') }}</a >
61
98
</label >
62
99
</div >
63
- <Button class =" w-full h-10" :disabled =" !siliconFlowStore.canLogin" @click =" siliconFlowStore.login" >
100
+ <Button class =" w-full h-10" :disabled =" !siliconFlowStore.canLogin" @click =" siliconFlowStore.login() " >
64
101
<span v-if =" siliconFlowStore.isLoading" >{{ t('siliconFlow.loggingIn') }}</span >
65
102
<span v-else >{{ t('siliconFlow.registerLogin') }}</span >
66
103
</Button >
67
- <div class =" flex items-center space-x-2 text-xs text-muted-foreground" >
104
+ <div class =" w-full grid grid-cols-2 gap-3" >
105
+ <Dialog >
106
+ <DialogTrigger >
107
+ <Button variant =" outline" class =" w-full h-10" @click =" wxLogin" >
108
+ {{ t('siliconFlow.wechatLogin') }}
109
+ </Button >
110
+ </DialogTrigger >
111
+ <DialogContent class =" max-w-sm" >
112
+ <DialogHeader >
113
+ <DialogTitle >{{ t('siliconFlow.wechatLogin') }}</DialogTitle >
114
+ <DialogClose />
115
+ </DialogHeader >
116
+ <div id =" SF_wx_login_qr_code_f" class =" w-full flex justify-center" />
117
+ </DialogContent >
118
+ </Dialog >
119
+ <Button variant =" outline" class =" w-full h-10" @click =" siliconFlowStore.isEmailLogin = !siliconFlowStore.isEmailLogin" >
120
+ {{ siliconFlowStore.isEmailLogin ? t('siliconFlow.phoneLogin') : t('siliconFlow.emailLogin') }}
121
+ </Button >
122
+ </div >
123
+ <!-- <div class="flex items-center space-x-2 text-xs text-muted-foreground">
68
124
<input id="keep" v-model="siliconFlowStore.keepLogin" type="checkbox" class="h-3 w-3 rounded border border-input" checked>
69
125
<label for="keep" class="cursor-pointer">{{ t('siliconFlow.keepLoggedIn30Days') }}</label>
70
- </div >
126
+ </div> -->
71
127
</CardFooter >
72
128
</Card >
73
129
</template >
0 commit comments