Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
VueElementTemplate
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
HireTest
VueElementTemplate
Commits
0094f449
Commit
0094f449
authored
Aug 22, 2017
by
Pan
Committed by
花裤衩
Aug 28, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
change login by username
parent
d06d476b
Changes
8
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
109 additions
and
93 deletions
+109
-93
login.js
src/api/login.js
+3
-3
iconfont.js
src/assets/iconfont/iconfont.js
+1
-1
index.js
src/mock/index.js
+16
-18
login.js
src/mock/login.js
+3
-3
user.js
src/store/modules/user.js
+5
-5
validate.js
src/utils/validate.js
+3
-3
index.vue
src/views/dashboard/index.vue
+0
-1
index.vue
src/views/login/index.vue
+78
-59
No files found.
src/api/login.js
View file @
0094f449
import
fetch
from
'utils/fetch'
;
import
fetch
from
'utils/fetch'
;
export
function
loginBy
Email
(
email
,
password
)
{
export
function
loginBy
Username
(
username
,
password
)
{
const
data
=
{
const
data
=
{
email
,
username
,
password
password
};
};
return
fetch
({
return
fetch
({
url
:
'/login/login
byemail
'
,
url
:
'/login/login'
,
method
:
'post'
,
method
:
'post'
,
data
data
});
});
...
...
src/assets/iconfont/iconfont.js
View file @
0094f449
This diff is collapsed.
Click to expand it.
src/mock/index.js
View file @
0094f449
import
Mock
from
'mockjs'
;
import
Mock
from
'mockjs'
import
loginAPI
from
'./login'
;
import
loginAPI
from
'./login'
import
articleAPI
from
'./article'
;
import
articleAPI
from
'./article'
import
article_tableAPI
from
'./article_table'
;
import
article_tableAPI
from
'./article_table'
import
remoteSearchAPI
from
'./remoteSearch'
;
import
remoteSearchAPI
from
'./remoteSearch'
// 登录相关
// 登录相关
Mock
.
mock
(
/
\/
login
\/
login
byemail/
,
'post'
,
loginAPI
.
loginByEmail
);
Mock
.
mock
(
/
\/
login
\/
login
/
,
'post'
,
loginAPI
.
loginByUsername
)
Mock
.
mock
(
/
\/
login
\/
logout/
,
'post'
,
loginAPI
.
logout
)
;
Mock
.
mock
(
/
\/
login
\/
logout/
,
'post'
,
loginAPI
.
logout
)
Mock
.
mock
(
/
\/
user
\/
info
\.
*/
,
'get'
,
loginAPI
.
getInfo
)
Mock
.
mock
(
/
\/
user
\/
info
\.
*/
,
'get'
,
loginAPI
.
getInfo
)
// // 文章相关
// 文章相关
Mock
.
mock
(
/
\/
article
\/
list/
,
'get'
,
articleAPI
.
getList
);
Mock
.
mock
(
/
\/
article
\/
list/
,
'get'
,
articleAPI
.
getList
)
Mock
.
mock
(
/
\/
article
\/
detail/
,
'get'
,
articleAPI
.
getArticle
);
Mock
.
mock
(
/
\/
article
\/
detail/
,
'get'
,
articleAPI
.
getArticle
)
// // table example相关
Mock
.
mock
(
/
\/
article_table
\/
list/
,
'get'
,
article_tableAPI
.
getList
);
Mock
.
mock
(
/
\/
article_table
\/
p/
,
'get'
,
article_tableAPI
.
getPv
);
// // 搜索相关
// table example相关
Mock
.
mock
(
/
\/
search
\/
user/
,
'get'
,
remoteSearchAPI
.
searchUser
);
Mock
.
mock
(
/
\/
article_table
\/
list/
,
'get'
,
article_tableAPI
.
getList
)
Mock
.
mock
(
/
\/
article_table
\/
p/
,
'get'
,
article_tableAPI
.
getPv
)
// 搜索相关
Mock
.
mock
(
/
\/
search
\/
user/
,
'get'
,
remoteSearchAPI
.
searchUser
)
export
default
Mock
;
export
default
Mock
src/mock/login.js
View file @
0094f449
...
@@ -25,9 +25,9 @@ const userMap = {
...
@@ -25,9 +25,9 @@ const userMap = {
}
}
export
default
{
export
default
{
loginBy
Email
:
config
=>
{
loginBy
Username
:
config
=>
{
const
{
email
}
=
JSON
.
parse
(
config
.
body
);
const
{
username
}
=
JSON
.
parse
(
config
.
body
);
return
userMap
[
email
.
split
(
'@'
)[
0
]
];
return
userMap
[
username
];
},
},
getInfo
:
config
=>
{
getInfo
:
config
=>
{
const
{
token
}
=
param2Obj
(
config
.
url
);
const
{
token
}
=
param2Obj
(
config
.
url
);
...
...
src/store/modules/user.js
View file @
0094f449
import
{
loginBy
Email
,
logout
,
getInfo
}
from
'api/login'
;
import
{
loginBy
Username
,
logout
,
getInfo
}
from
'api/login'
;
import
{
getToken
,
setToken
,
removeToken
}
from
'utils/auth'
;
import
{
getToken
,
setToken
,
removeToken
}
from
'utils/auth'
;
const
user
=
{
const
user
=
{
...
@@ -50,11 +50,11 @@ const user = {
...
@@ -50,11 +50,11 @@ const user = {
},
},
actions
:
{
actions
:
{
//
邮箱
登录
//
用户名
登录
LoginBy
Email
({
commit
},
userInfo
)
{
LoginBy
Username
({
commit
},
userInfo
)
{
const
email
=
userInfo
.
email
.
trim
();
const
username
=
userInfo
.
username
.
trim
();
return
new
Promise
((
resolve
,
reject
)
=>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
loginBy
Email
(
email
,
userInfo
.
password
).
then
(
response
=>
{
loginBy
Username
(
username
,
userInfo
.
password
).
then
(
response
=>
{
const
data
=
response
.
data
;
const
data
=
response
.
data
;
setToken
(
response
.
data
.
token
);
setToken
(
response
.
data
.
token
);
commit
(
'SET_TOKEN'
,
data
.
token
);
commit
(
'SET_TOKEN'
,
data
.
token
);
...
...
src/utils/validate.js
View file @
0094f449
...
@@ -3,9 +3,9 @@
...
@@ -3,9 +3,9 @@
*/
*/
/* 是否是公司邮箱*/
/* 是否是公司邮箱*/
export
function
is
WscnEmail
(
str
)
{
export
function
is
validUsername
(
str
)
{
const
reg
=
/^
[
a-z0-9
](?:[
-_.+
]?[
a-z0-9
]
+
)
*@wallstreetcn
\.
com$/i
;
const
valid_map
=
[
'admin'
,
'editor'
]
return
reg
.
test
(
str
.
trim
())
;
return
valid_map
.
indexOf
(
str
.
trim
())
>=
0
;
}
}
/* 合法uri*/
/* 合法uri*/
...
...
src/views/dashboard/index.vue
View file @
0094f449
...
@@ -21,7 +21,6 @@
...
@@ -21,7 +21,6 @@
...
mapGetters
([
...
mapGetters
([
'name'
,
'name'
,
'avatar'
,
'avatar'
,
'email'
,
'introduction'
,
'introduction'
,
'roles'
'roles'
])
])
...
...
src/views/login/index.vue
View file @
0094f449
<
template
>
<
template
>
<div
class=
"login-container"
>
<div
class=
"login-container"
>
<el-form
autoComplete=
"on"
:model=
"loginForm"
:rules=
"loginRules"
ref=
"loginForm"
label-position=
"left"
label-width=
"0px"
<el-form
class=
"card-box login-form"
autoComplete=
"on"
:model=
"loginForm"
:rules=
"loginRules"
ref=
"loginForm"
label-position=
"left"
>
class=
"card-box login-form"
>
<h3
class=
"title"
>
系统登录
</h3>
<h3
class=
"title"
>
系统登录
</h3>
<el-form-item
prop=
"email"
>
<span
class=
"svg-container"
><icon-svg
icon-class=
"jiedianyoujian"
></icon-svg></span>
<el-form-item
prop=
"username"
>
<el-input
name=
"email"
type=
"text"
v-model=
"loginForm.email"
autoComplete=
"on"
placeholder=
"邮箱"
></el-input>
<span
class=
"svg-container svg-container_login"
>
<icon-svg
icon-class=
"yonghuming"
/>
</span>
<el-input
name=
"username"
type=
"text"
v-model=
"loginForm.username"
autoComplete=
"on"
placeholder=
"邮箱"
/>
</el-form-item>
</el-form-item>
<el-form-item
prop=
"password"
>
<el-form-item
prop=
"password"
>
<span
class=
"svg-container"
><icon-svg
icon-class=
"mima"
></icon-svg></span>
<span
class=
"svg-container"
>
<el-input
name=
"password"
type=
"password"
@
keyup
.
enter
.
native=
"handleLogin"
v-model=
"loginForm.password"
autoComplete=
"on"
<icon-svg
icon-class=
"mima"
/>
placeholder=
"密码"
></el-input>
</span>
<el-input
name=
"password"
:type=
"pwdType"
@
keyup
.
enter
.
native=
"handleLogin"
v-model=
"loginForm.password"
autoComplete=
"on"
placeholder=
"密码"
/>
<span
class=
'show-pwd'
@
click=
'showPwd'
><icon-svg
icon-class=
"yanjing"
/></span>
</el-form-item>
</el-form-item>
<el-form-item>
<el-button
type=
"primary"
style=
"width:100%;"
:loading=
"loading"
@
click
.
native
.
prevent=
"handleLogin"
>
<el-button
type=
"primary"
style=
"width:100%;margin-bottom:30px;"
:loading=
"loading"
@
click
.
native
.
prevent=
"handleLogin"
>
登录
</el-button>
登录
</el-button>
<div
class=
'tips'
>
账号:admin 密码随便填
</div>
</el-form-item>
<div
class=
'tips'
>
账号:editor 密码随便填
</div>
<div
class=
'tips'
>
admin账号为:admin@wallstreetcn.com 密码随便填
</div>
<div
class=
'tips'
>
editor账号:editor@wallstreetcn.com 密码随便填
</div>
</el-form>
</el-form>
<el-dialog
title=
"第三方验证"
:visible
.
sync=
"showDialog"
>
<el-dialog
title=
"第三方验证"
:visible
.
sync=
"showDialog"
>
邮箱登录成功,请选择第三方验证
邮箱登录成功,请选择第三方验证
<social-sign
></social-sign
>
<social-sign
/
>
</el-dialog>
</el-dialog>
</div>
</div>
</
template
>
</
template
>
<
script
>
<
script
>
import
{
is
WscnEmail
}
from
'utils/validate'
;
import
{
is
validUsername
}
from
'utils/validate'
import
socialSign
from
'./socialsignin'
;
import
socialSign
from
'./socialsignin'
export
default
{
export
default
{
components
:
{
socialSign
},
components
:
{
socialSign
},
name
:
'login'
,
name
:
'login'
,
data
()
{
data
()
{
const
validate
Email
=
(
rule
,
value
,
callback
)
=>
{
const
validate
Username
=
(
rule
,
value
,
callback
)
=>
{
if
(
!
is
WscnEmail
(
value
))
{
if
(
!
is
validUsername
(
value
))
{
callback
(
new
Error
(
'请输入正确的
合法邮箱'
));
callback
(
new
Error
(
'请输入正确的
用户名'
))
}
else
{
}
else
{
callback
();
callback
()
}
}
}
};
const
validatePassword
=
(
rule
,
value
,
callback
)
=>
{
const
validatePass
=
(
rule
,
value
,
callback
)
=>
{
if
(
value
.
length
<
6
)
{
if
(
value
.
length
<
6
)
{
callback
(
new
Error
(
'密码不能小于6位'
))
;
callback
(
new
Error
(
'密码不能小于6位'
))
}
else
{
}
else
{
callback
();
callback
()
}
}
}
};
return
{
return
{
loginForm
:
{
loginForm
:
{
email
:
'admin@wallstreetcn.com
'
,
username
:
'admin
'
,
password
:
''
password
:
'
1111111
'
},
},
loginRules
:
{
loginRules
:
{
email
:
[
username
:
[{
required
:
true
,
trigger
:
'blur'
,
validator
:
validateUsername
}],
{
required
:
true
,
trigger
:
'blur'
,
validator
:
validateEmail
}
password
:
[{
required
:
true
,
trigger
:
'blur'
,
validator
:
validatePassword
}]
],
password
:
[
{
required
:
true
,
trigger
:
'blur'
,
validator
:
validatePass
}
]
},
},
pwdType
:
'password'
,
loading
:
false
,
loading
:
false
,
showDialog
:
false
showDialog
:
false
}
}
},
},
methods
:
{
methods
:
{
showPwd
()
{
if
(
this
.
pwdType
===
'password'
)
{
this
.
pwdType
=
''
}
else
{
this
.
pwdType
=
'password'
}
},
handleLogin
()
{
handleLogin
()
{
this
.
$refs
.
loginForm
.
validate
(
valid
=>
{
this
.
$refs
.
loginForm
.
validate
(
valid
=>
{
if
(
valid
)
{
if
(
valid
)
{
this
.
loading
=
true
;
this
.
loading
=
true
this
.
$store
.
dispatch
(
'LoginBy
Email
'
,
this
.
loginForm
).
then
(()
=>
{
this
.
$store
.
dispatch
(
'LoginBy
Username
'
,
this
.
loginForm
).
then
(()
=>
{
this
.
loading
=
false
;
this
.
loading
=
false
this
.
$router
.
push
({
path
:
'/'
})
;
this
.
$router
.
push
({
path
:
'/'
})
// this.showDialog = true
;
// this.showDialog = true
}).
catch
(()
=>
{
}).
catch
(()
=>
{
this
.
loading
=
false
;
this
.
loading
=
false
})
;
})
}
else
{
}
else
{
console
.
log
(
'error submit!!'
)
;
console
.
log
(
'error submit!!'
)
return
false
;
return
false
}
}
})
;
})
},
},
afterQRScan
()
{
afterQRScan
()
{
// const hash = window.location.hash.slice(1)
;
// const hash = window.location.hash.slice(1)
// const hashObj = getQueryObject(hash)
;
// const hashObj = getQueryObject(hash)
// const originUrl = window.location.origin
;
// const originUrl = window.location.origin
// history.replaceState({}, '', originUrl)
;
// history.replaceState({}, '', originUrl)
// const codeMap = {
// const codeMap = {
// wechat: 'code',
// wechat: 'code',
// tencent: 'code'
// tencent: 'code'
// }
;
// }
// const codeName = hashObj[codeMap[this.auth_type]]
;
// const codeName = hashObj[codeMap[this.auth_type]]
// if (!codeName) {
// if (!codeName) {
// alert('第三方登录失败')
;
// alert('第三方登录失败')
// } else {
// } else {
// this.$store.dispatch('LoginByThirdparty', codeName).then(() => {
// this.$store.dispatch('LoginByThirdparty', codeName).then(() => {
// this.$router.push({ path: '/' })
;
// this.$router.push({ path: '/' })
// })
;
// })
// }
// }
}
}
},
},
created
()
{
created
()
{
// window.addEventListener('hashchange', this.afterQRScan)
;
// window.addEventListener('hashchange', this.afterQRScan)
},
},
destroyed
()
{
destroyed
()
{
// window.removeEventListener('hashchange', this.afterQRScan)
;
// window.removeEventListener('hashchange', this.afterQRScan)
}
}
}
}
</
script
>
</
script
>
...
@@ -119,7 +127,7 @@
...
@@ -119,7 +127,7 @@
.tips
{
.tips
{
font-size
:
14px
;
font-size
:
14px
;
color
:
#fff
;
color
:
#fff
;
margin-bottom
:
5
px
;
margin-bottom
:
10
px
;
}
}
.login-container
{
.login-container
{
...
@@ -147,6 +155,12 @@
...
@@ -147,6 +155,12 @@
.svg-container
{
.svg-container
{
padding
:
6px
5px
6px
15px
;
padding
:
6px
5px
6px
15px
;
color
:
#889aa4
;
color
:
#889aa4
;
vertical-align
:
middle
;
width
:
30px
;
display
:
inline-block
;
&
_login
{
font-size
:
20px
;
}
}
}
.title
{
.title
{
font-size
:
26px
;
font-size
:
26px
;
...
@@ -170,8 +184,13 @@
...
@@ -170,8 +184,13 @@
border-radius
:
5px
;
border-radius
:
5px
;
color
:
#454545
;
color
:
#454545
;
}
}
.forget-pwd
{
.show-pwd
{
color
:
#fff
;
position
:
absolute
;
right
:
10px
;
top
:
7px
;
font-size
:
16px
;
color
:
#889aa4
;
cursor
:
pointer
;
}
}
}
}
</
style
>
</
style
>
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment