69 lines
1.4 KiB
Vue
69 lines
1.4 KiB
Vue
<template>
|
|
<view>
|
|
<view v-if="isLogin">111111</view>
|
|
<view v-else>
|
|
<view class="button-login" @click="login">登录</view>
|
|
</view>
|
|
</view>
|
|
</template>
|
|
|
|
<script>
|
|
import { getUserInfoRequest } from '@/api/user'
|
|
import { useUserStore } from '@/stores/user'
|
|
import { mapState, mapActions } from 'pinia'
|
|
|
|
export default {
|
|
data() {
|
|
return {
|
|
|
|
}
|
|
},
|
|
computed: {
|
|
...mapState(useUserStore, ['userInfo', 'isLogin'])
|
|
},
|
|
async onLoad() {
|
|
uni.showLoading({
|
|
title: '加载中'
|
|
})
|
|
const token = uni.getStorageSync('token')
|
|
if(token) {
|
|
this.updateLoginStatus(true)
|
|
await this.getUserInfo()
|
|
}
|
|
uni.hideLoading()
|
|
},
|
|
methods: {
|
|
...mapActions(useUserStore, ['updateUserInfo', 'updateLoginStatus', 'login']),
|
|
async getUserInfo() {
|
|
const { code, data } = await getUserInfoRequest()
|
|
if(code === 0) {
|
|
this.updateUserInfo(data)
|
|
console.log(this.userInfo)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<style lang="scss">
|
|
page {
|
|
background-color: $uni-bg-color-grey;
|
|
}
|
|
</style>
|
|
|
|
<style scoped lang="scss">
|
|
.button-login {
|
|
margin-top: 40vh;
|
|
border-radius: 46rpx;
|
|
width: 650rpx;
|
|
height: 120rpx;
|
|
line-height: 120rpx;
|
|
text-align: center;
|
|
margin-left: 50rpx;
|
|
background: #63b8af;
|
|
color: #ffffff;
|
|
font-size: 48rpx;
|
|
font-weight: bold;
|
|
}
|
|
</style>
|