Commit cdf251ba authored by Damon's avatar Damon

feat: 登录流程

parent 9497f9d6
......@@ -3,6 +3,8 @@ export default {
onLaunch: function () {
// 版本更新
this.updateApp()
// 检查登录是否已过期
this.checkLogin()
},
onShow: function () {
console.log('App Show')
......@@ -11,6 +13,27 @@ export default {
console.log('App Hide')
},
methods: {
checkLogin() {
if (this.vuex_token) {
uni.checkSession({
success: (result) => {
//session_key 未过期,并且在本生命周期一直有效
console.log("session未过期", result)
},
fail: (error) => {
// session_key 已经失效,需要重新执行登录流程
console.log("error", error)
this.$u.route({
url: 'pages/login/index'
})
}
})
} else {
this.$u.route({
url: 'pages/login/index'
})
}
},
/* 版本更新 */
updateApp() {
if (uni.canIUse('getUpdateManager')) {
......
<template>
<view>
<view class="u-flex user-box u-p-l-30 u-p-t-30 u-p-r-20 u-p-b-30">
<view class="u-m-r-10">
<view class="avatar">
<open-data type="userAvatarUrl"></open-data>
</view>
</view>
<view class="u-flex-1">
<view class="u-font-18 u-p-b-20">
<open-data type="userNickName"></open-data>
</view>
<view class="u-font-14 u-tips-color">累计刷题俩999次</view>
</view>
</view>
<view class="u-m-t-20">
<u-cell-group>
<u-cell-item icon="star" title="个人信息" value="完善度40%" @tap="login"></u-cell-item>
<u-cell-item icon="photo" title="我的题库"></u-cell-item>
<u-cell-item icon="coupon" title="联系客服"></u-cell-item>
</u-cell-group>
</view>
</view>
<view>
<view class="u-flex user-box u-p-l-30 u-p-t-30 u-p-r-20 u-p-b-30" @tap="login">
<view class="u-m-r-10">
<u-avatar :src="avatar" size="140"></u-avatar>
</view>
<view class="u-flex-1">
<view class="u-font-18 u-p-b-20">{{ nikeName }}</view>
<view class="u-font-14 u-tips-color">累计刷题俩999次</view>
</view>
</view>
<view class="u-m-t-20">
<u-cell-group>
<u-cell-item icon="star" title="个人信息" value="完善度40%"></u-cell-item>
<u-cell-item icon="photo" title="我的题库"></u-cell-item>
<u-cell-item icon="coupon" title="联系客服"></u-cell-item>
<u-cell-item icon="coupon" title="退出登录" @tap="logout"></u-cell-item>
</u-cell-group>
</view>
</view>
</template>
<script>
export default {
data() {
return {
pic: 'https://uviewui.com/common/logo.png',
show: true,
}
},
computed: {},
onLoad() {},
methods: {
login() {
this.$u.route({
url: 'pages/login/index',
})
},
},
}
export default {
data() {
return {
pic:'https://uviewui.com/common/logo.png',
show:true
}
},
computed: {
avatar() {
return this.userInfo.avatarUrl || this.pic
},
nikeName() {
return this.userInfo.nickName || '未登录'
}
},
onLoad() {
},
methods: {
login() {
this.$u.route({
url: 'pages/login/index'
})
},
logout() {
this.$u.vuex('vuex_token', '')
this.$u.vuex('userInfo', {})
}
}
}
</script>
<style lang="scss">
page {
background-color: #ededed;
page{
background-color: #ededed;
}
.camera {
width: 54px;
height: 44px;
&:active {
background-color: #ededed;
}
.camera{
width: 54px;
height: 44px;
&:active{
background-color: #ededed;
}
}
.user-box {
background-color: #fff;
.avatar {
width: 120rpx;
height: 120rpx;
}
.user-box{
background-color: #fff;
}
</style>
\ No newline at end of file
......@@ -18,22 +18,33 @@ export default {
}
},
onShow() {
console.log("this", this)
this.checkLogin()
},
methods: {
checkLogin() {
if (this.vuex_token) {
uni.checkSession({
success: (result) => {
this.$u.route({ type: 'back' })
}
})
}
},
wxLogin() {
// 获取code 小程序专有,用户登录凭证。
uni.getUserProfile({
desc: '获取用户基本资料',
lang: 'zh_CN',
success: (user) => {
//获取成功基本资料后开启登录,因为基本资料首先要授权
// 获取成功基本资料后开启登录,因为基本资料首先要授权
uni.login({
provider: 'weixin',
success: (code_res) => {
if (code_res.errMsg == 'login:ok') {
let code = code_res.code
console.log('user, code', user, code)
this.$u.vuex('vuex_token', code)
this.$u.vuex('userInfo', user.userInfo)
this.$u.route({
type: 'back'
})
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment