Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
comment_app
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
莫晓莉
comment_app
Commits
0321957c
Commit
0321957c
authored
Sep 17, 2020
by
莫晓莉
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
mxl登录
parent
77807522
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
172 additions
and
153 deletions
+172
-153
pages.json
+4
-2
pages/login/login.vue
+0
-0
pages/main/main.vue
+105
-71
pages/reg/reg.vue
+63
-80
No files found.
pages.json
View file @
0321957c
...
...
@@ -5,12 +5,14 @@
"style"
:
{
"navigationBarTitleText"
:
"登录模板"
}
},
{
},
{
"path"
:
"pages/login/login"
,
"style"
:
{
"navigationBarTitleText"
:
"登录"
}
},
{
},
{
"path"
:
"pages/reg/reg"
,
"style"
:
{
"navigationBarTitleText"
:
"注册"
...
...
pages/login/login.vue
View file @
0321957c
This diff is collapsed.
Click to expand it.
pages/main/main.vue
View file @
0321957c
...
...
@@ -27,85 +27,119 @@
mapMutations
}
from
'vuex'
export
default
{
computed
:
mapState
([
'forcedLogin'
,
'hasLogin'
,
'userName'
]),
onLoad
()
{
const
loginType
=
uni
.
getStorageSync
(
'login_type'
)
if
(
loginType
===
'local'
)
{
this
.
login
(
uni
.
getStorageSync
(
'username'
))
return
}
let
uniIdToken
=
uni
.
getStorageSync
(
'uniIdToken'
)
if
(
uniIdToken
)
{
this
.
login
(
uni
.
getStorageSync
(
'username'
))
uniCloud
.
callFunction
({
name
:
'user-center'
,
data
:
{
action
:
'checkToken'
,
},
success
:
(
e
)
=>
{
console
.
log
(
'checkToken success'
,
e
);
if
(
e
.
result
.
code
>
0
)
{
//token过期或token不合法,重新登录
if
(
this
.
forcedLogin
)
{
uni
.
reLaunch
({
url
:
'../login/login'
});
}
else
{
uni
.
navigateTo
({
url
:
'../login/login'
});
}
}
},
fail
(
e
)
{
uni
.
showModal
({
content
:
JSON
.
stringify
(
e
),
showCancel
:
false
})
}
import
{
getUserByToken
}
from
"@/api/login"
export
default
{
onLoad
:
function
()
{
const
token
=
uni
.
getStorageSync
(
'token'
)
console
.
log
(
token
);
if
(
token
){
uni
.
switchTab
({
url
:
'/pages/login/login'
})
}
else
{
this
.
guideToLogin
()
}
},
methods
:
{
...
mapMutations
([
'login'
]),
guideToLogin
()
{
uni
.
showModal
({
title
:
'未登录'
,
content
:
'您未登录,需要登录后才能继续'
,
/**
* 如果需要强制登录,不显示取消按钮
*/
showCancel
:
!
this
.
forcedLogin
,
success
:
(
res
)
=>
{
if
(
res
.
confirm
)
{
/**
* 如果需要强制登录,使用reLaunch方式
*/
if
(
this
.
forcedLogin
)
{
uni
.
reLaunch
({
url
:
'../login/login'
});
}
else
{
uni
.
navigateTo
({
url
:
'../login/login'
});
}
}
}
});
}
// getUserByToken().then(res=>{
// if (res.code == 200) {
// uni.setStorageSync('token', res.data.data);
// uni.switchTab({
// url:'/pages/login/login'
// })
// }else{
// uni.switchTab({
// url:'/pages/reg/reg'
// })
// }
// })
// const token=uni.getStorageSync('token')
// if(token){
// uni.switchTab({
// url:'/pages/index/index'
// })
// }
}
// computed: mapState(['forcedLogin', 'hasLogin', 'userName']),
// onLoad() {
// const loginType = uni.getStorageSync('login_type')
// if (loginType === 'local') {
// this.login(uni.getStorageSync('username'))
// return
// }
// let uniIdToken = uni.getStorageSync('uniIdToken')
// if (uniIdToken) {
// this.login(uni.getStorageSync('username'))
// uniCloud.callFunction({
// name: 'user-center',
// data: {
// action: 'checkToken',
// },
// success: (e) => {
// console.log('checkToken success', e);
// if (e.result.code > 0) {
// //token过期或token不合法,重新登录
// if (this.forcedLogin) {
// uni.reLaunch({
// url: '../login/login'
// });
// } else {
// uni.navigateTo({
// url: '../login/login'
// });
// }
// }
// },
// fail(e) {
// uni.showModal({
// content: JSON.stringify(e),
// showCancel: false
// })
// }
// })
// } else {
// this.guideToLogin()
// }
// },
// methods: {
// ...mapMutations(['login']),
// guideToLogin() {
// uni.showModal({
// title: '未登录',
// content: '您未登录,需要登录后才能继续',
// /**
// * 如果需要强制登录,不显示取消按钮
// */
// showCancel: !this.forcedLogin,
// success: (res) => {
// if (res.confirm) {
// /**
// * 如果需要强制登录,使用reLaunch方式
// */
// if (this.forcedLogin) {
// uni.reLaunch({
// url: '../login/login'
// });
// } else {
// uni.navigateTo({
// url: '../login/login'
// });
// }
// }
// }
// });
// }
// }
}
</
script
>
<
style
>
.hello
{
/*
.hello {
display: flex;
flex: 1;
flex-direction: column;
...
...
@@ -124,5 +158,5 @@
.ul>view {
line-height: 25px;
}
}
*/
</
style
>
pages/reg/reg.vue
View file @
0321957c
<
template
>
<view
class=
"content"
>
<!--
<view
class=
"input-group"
>
<view
class=
"input-row border"
>
<text
class=
"title"
>
账号:
</text>
<m-input
type=
"text"
focus
clearable
v-model=
"username"
placeholder=
"请输入账号"
></m-input>
</view>
<view
class=
"input-row border"
>
<text
class=
"title"
>
密码:
</text>
<m-input
type=
"password"
displayable
v-model=
"password"
placeholder=
"请输入密码"
></m-input>
</view>
<view
class=
"input-row"
>
<text
class=
"title"
>
确认密码:
</text>
<m-input
type=
"password"
displayable
v-model=
"confirmPassword"
placeholder=
"请确认密码"
></m-input>
</view>
</view>
-->
<!-- 登录新样式start -->
<view
style=
"text-align: center;color:#CA0000;font-size:45upx;padding:50upx;"
>
<!--
<image
class=
"head-icon"
style=
""
src=
"../../static/login/personal.png"
></image>
-->
欢迎注册!
</view>
<view
class=
"login-area"
>
<view
class=
"login-item"
>
<image
class=
"login-icon"
src=
"../../static/login/mine.png"
></image>
<input
class=
"login-item-input"
placeholder=
"请输入姓名"
v-model=
"addForm.name"
/>
...
...
@@ -49,7 +32,7 @@
<view
class=
"login-item mt25"
>
<image
class=
"login-icon"
src=
"../../static/login/code.png"
></image>
<input
class=
"login-item-input"
placeholder=
"请输入手机号码"
v-model=
"addForm.phone"
/>
<input
name=
"phone"
type=
"number"
class=
"login-item-input"
placeholder=
"请输入手机号码"
v-model=
"addForm.phone"
/>
<view
class=
"code-btn"
style=
""
@
click=
"codeInfo.clickType ? getCode() : ''"
>
{{
codeInfo
.
msg
}}
</view>
</view>
<view
class=
"login-item mt25"
>
...
...
@@ -177,70 +160,70 @@
})
},
register
()
{
/**
* 客户端对账号信息进行一些必要的校验。
* 实际开发中,根据业务需要进行处理,这里仅做示例。
*/
if
(
this
.
username
.
length
<
3
)
{
uni
.
showToast
({
icon
:
'none'
,
title
:
'账号最短为 3 个字符'
});
return
;
}
if
(
this
.
password
.
length
<
6
)
{
uni
.
showToast
({
icon
:
'none'
,
title
:
'密码最短为 6 个字符'
});
return
;
}
if
(
this
.
password
!==
this
.
confirmPassword
)
{
uni
.
showToast
({
icon
:
'none'
,
title
:
'两次密码输入不一致'
});
return
;
}
//
register() {
//
/**
//
* 客户端对账号信息进行一些必要的校验。
//
* 实际开发中,根据业务需要进行处理,这里仅做示例。
//
*/
//
if (this.username.length
<
3
)
{
//
uni.showToast({
//
icon: 'none',
//
title: '账号最短为 3 个字符'
//
});
//
return;
//
}
//
if (this.password.length
<
6
)
{
//
uni.showToast({
//
icon: 'none',
//
title: '密码最短为 6 个字符'
//
});
//
return;
//
}
//
if (this.password !== this.confirmPassword) {
//
uni.showToast({
//
icon: 'none',
//
title: '两次密码输入不一致'
//
});
//
return;
//
}
const
data
=
{
username
:
this
.
username
,
password
:
this
.
password
}
uniCloud
.
callFunction
({
name
:
'user-center'
,
data
:
{
action
:
'register'
,
params
:
data
},
success
(
e
)
{
console
.
log
(
"注册成功"
,
e
);
//
const data = {
//
username: this.username,
//
password: this.password
//
}
//
uniCloud.callFunction({
//
name: 'user-center',
//
data: {
//
action: 'register',
//
params: data
//
},
//
success(e) {
//
console.log("注册成功", e);
if
(
e
.
result
.
code
===
0
)
{
uni
.
showToast
({
title
:
'注册成功'
});
uni
.
setStorageSync
(
'uniIdToken'
,
e
.
result
.
token
)
uni
.
setStorageSync
(
'username'
,
e
.
result
.
username
)
uni
.
reLaunch
({
url
:
'../main/main'
,
});
}
else
{
uni
.
showModal
({
content
:
JSON
.
stringify
(
e
.
result
),
showCancel
:
false
})
}
},
fail
(
e
)
{
uni
.
showModal
({
content
:
JSON
.
stringify
(
e
),
showCancel
:
false
})
}
})
}
//
if (e.result.code === 0) {
//
uni.showToast({
//
title: '注册成功'
//
});
//
uni.setStorageSync('uniIdToken', e.result.token)
//
uni.setStorageSync('username', e.result.username)
//
uni.reLaunch({
//
url: '../main/main',
//
});
//
} else {
//
uni.showModal({
//
content: JSON.stringify(e.result),
//
showCancel: false
//
})
//
}
//
},
//
fail(e) {
//
uni.showModal({
//
content: JSON.stringify(e),
//
showCancel: false
//
})
//
}
//
})
//
}
}
}
</
script
>
...
...
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