feat: 实现微信登录demo
This commit is contained in:
40
src/pages/login/index.vue
Normal file
40
src/pages/login/index.vue
Normal file
@@ -0,0 +1,40 @@
|
||||
<route lang="json5">
|
||||
{
|
||||
style: { navigationBarTitleText: '登录' },
|
||||
}
|
||||
</route>
|
||||
|
||||
<template>
|
||||
<view class="p-4">
|
||||
<view class="flex items-center leading-6" v-if="hasLogin">
|
||||
<image class="w-8 h-8 rounded-full" :src="userStore.userInfo?.avatar"></image>
|
||||
<view class="ml-2">{{ userStore.userInfo?.nickname }}</view>
|
||||
</view>
|
||||
<view class="flex items-center leading-6" v-else @click="show = true">
|
||||
<fly-login v-if="show" />
|
||||
<view class="i-carbon-user-avatar"></view>
|
||||
<view class="ml-2">点击显示微信头像</view>
|
||||
</view>
|
||||
<fly-content :line="10" />
|
||||
<button v-if="hasLogin" class="mt-2" @click="logout">退出登录</button>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { useUserStore } from '@/store'
|
||||
|
||||
const show = ref(false)
|
||||
const userStore = useUserStore()
|
||||
const hasLogin = computed(() => userStore.userInfo?.nickname)
|
||||
const logout = () => {
|
||||
uni.showModal({
|
||||
title: '确认退出当前账号?',
|
||||
success: (res) => {
|
||||
if (res.confirm) {
|
||||
show.value = false
|
||||
userStore.clearUserInfo()
|
||||
}
|
||||
},
|
||||
})
|
||||
}
|
||||
</script>
|
||||
@@ -1,9 +0,0 @@
|
||||
<route lang="json5">
|
||||
{
|
||||
style: { navigationBarTitleText: '登录' },
|
||||
}
|
||||
</route>
|
||||
|
||||
<template>
|
||||
<view>登录</view>
|
||||
</template>
|
||||
@@ -5,4 +5,12 @@
|
||||
</route>
|
||||
<template>
|
||||
<view>我的</view>
|
||||
<view @click="goLoginPage">去登录</view>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
const goLoginPage = () => {
|
||||
uni.navigateTo({ url: '/pages/login/index' })
|
||||
}
|
||||
// 用户登录,获取openId
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user