feat: 实现微信登录demo

This commit is contained in:
Burt
2024-01-16 10:15:20 +08:00
parent d84dd87dc7
commit 26068635dc
13 changed files with 224 additions and 35 deletions

40
src/pages/login/index.vue Normal file
View 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>

View File

@@ -1,9 +0,0 @@
<route lang="json5">
{
style: { navigationBarTitleText: '登录' },
}
</route>
<template>
<view>登录</view>
</template>

View File

@@ -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>