Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
S
shop-vite-main
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
front-base-project
shop-vite-main
Commits
84971b19
提交
84971b19
authored
12月 10, 2024
作者:
郁骅焌
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
登录修改
上级
f5627979
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
49 行增加
和
13 行删除
+49
-13
.env.development
.env.development
+2
-2
.env.production
.env.production
+1
-2
user.ts
src/api/user.ts
+12
-0
request.ts
src/utils/request.ts
+4
-1
Login.vue
src/views/login/Login.vue
+30
-8
没有找到文件。
.env.development
浏览文件 @
84971b19
...
...
@@ -5,4 +5,5 @@
NODE_ENV=development
# api接口地址
VITE_APP_BASE_URL=''
\ No newline at end of file
VITE_APP_BASE_URL='http://139.196.169.103:9003'
# VITE_APP_BASE_URL=''
.env.production
浏览文件 @
84971b19
...
...
@@ -5,4 +5,4 @@
NODE_ENV=production
# api接口地址
VITE_APP_BASE_URL=''
\ No newline at end of file
VITE_APP_BASE_URL='http://139.196.169.103:9003'
src/api/user.ts
浏览文件 @
84971b19
...
...
@@ -56,3 +56,15 @@ export const lock = () => {
method
:
'get'
,
})
}
// 获取验证码
export
const
getCodeImg
=
()
=>
{
return
request
({
url
:
'/captchaImage'
,
headers
:
{
isToken
:
false
,
},
method
:
'get'
,
timeout
:
20000
,
})
}
src/utils/request.ts
浏览文件 @
84971b19
...
...
@@ -47,8 +47,11 @@ const requestConfig = (config: any): any => {
// 不规范写法 可根据setting.config.js tokenName配置随意自定义headers
// if (token) config.headers[tokenName] = token
// 是否需要设置 token
const
isToken
=
(
config
.
headers
||
{}).
isToken
===
false
// 规范写法 不可随意自定义
if
(
token
)
config
.
headers
[
'Authorization'
]
=
`Bearer
${
token
}
`
if
(
token
&&
!
isToken
)
config
.
headers
[
'Authorization'
]
=
`Bearer
${
token
}
`
if
(
config
.
data
&&
config
.
headers
[
'Content-Type'
]
===
'application/x-www-form-urlencoded;charset=UTF-8'
)
config
.
data
=
stringify
(
config
.
data
)
...
...
src/views/login/Login.vue
浏览文件 @
84971b19
...
...
@@ -27,14 +27,14 @@
</el-input>
</el-form-item>
<!-- 验证码验证逻辑需自行开发,如不需要验证码功能建议注释 -->
<
!-- <el-form-item prop="verificationC
ode">
<el-input v-model.trim="form.
verificationC
ode" :placeholder="translate('验证码') + previewText" type="text">
<
el-form-item
v-if=
"captchaEnabled"
prop=
"c
ode"
>
<el-input
v-model
.
trim=
"form.
c
ode"
:placeholder=
"translate('验证码') + previewText"
type=
"text"
>
<
template
#
prefix
>
<vab-icon
icon=
"barcode-box-line"
/>
</
template
>
</el-input>
<img class="code" :src="codeUrl" @click="changeCode" />
</el-form-item>
-->
<img
class=
"code"
:src=
"codeUrl"
style=
"width: 120px; height: 40px"
@
click=
"changeCode"
/>
</el-form-item>
<el-button
v-throttle=
"handleLogin"
class=
"login-btn"
:loading=
"loading"
type=
"primary"
>
{{ translate('登录') }}
</el-button>
...
...
@@ -65,6 +65,7 @@
<
script
lang=
"ts"
setup
>
import
type
{
FormInstance
,
FormRules
,
InputInstance
}
from
'element-plus'
import
{
getCodeImg
}
from
'/@/api/user'
import
leftImg
from
'/@/assets/login_images/left_img_1.png'
import
{
translate
}
from
'/@/i18n'
import
{
useSettingsStore
}
from
'/@/store/modules/settings'
...
...
@@ -78,7 +79,8 @@ defineOptions({
interface
FormType
{
username
:
string
password
:
string
verificationCode
:
string
code
:
string
uuid
:
string
}
const
route
=
useRoute
()
...
...
@@ -96,10 +98,14 @@ const previewText = ref<string>('')
const
formRef
=
ref
<
FormInstance
>
()
const
passwordRef
=
ref
<
InputInstance
>
()
// 验证码开关
const
captchaEnabled
=
ref
<
boolean
>
(
true
)
const
form
=
reactive
<
FormType
>
({
username
:
''
,
password
:
''
,
verificationCode
:
''
,
code
:
''
,
uuid
:
''
,
})
const
validateUsername
=
(
rule
:
any
,
value
:
any
,
callback
:
any
)
=>
{
...
...
@@ -143,6 +149,11 @@ const handleLogin = async () => {
loading
.
value
=
true
await
login
(
form
).
catch
(()
=>
{
loading
.
value
=
false
// 重新获取验证码
if
(
captchaEnabled
.
value
)
{
changeCode
()
}
})
await
router
.
push
(
handleRoute
())
}
finally
{
...
...
@@ -151,12 +162,23 @@ const handleLogin = async () => {
})
}
const
changeCode
=
()
=>
{
codeUrl
.
value
=
`https://www.oschina.net/action/user/captcha?timestamp=
${
Date
.
now
()}
`
// codeUrl.value = `https://www.oschina.net/action/user/captcha?timestamp=${Date.now()}`
getCodeImg
().
then
((
res
:
any
)
=>
{
captchaEnabled
.
value
=
res
.
captchaEnabled
===
undefined
?
true
:
res
.
captchaEnabled
if
(
captchaEnabled
.
value
)
{
codeUrl
.
value
=
`data:image/gif;base64,
${
res
.
img
}
`
form
.
uuid
=
res
.
uuid
}
})
}
onMounted
(()
=>
{
changeCode
()
})
onBeforeMount
(()
=>
{
form
.
username
=
'admin'
form
.
password
=
'
123456
'
form
.
password
=
'
admin123
'
// 为了演示效果,会在官网演示页自动登录到首页,正式开发可删除
if
(
location
.
hostname
.
includes
(
'vuejs-core'
))
{
previewText
.
value
=
'(演示地址验证码可不填)'
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论