feat: 优化微信登陆

This commit is contained in:
Burt 2024-01-20 18:41:18 +08:00
parent 70b74eb3cb
commit 2d30a05712
3 changed files with 6 additions and 9 deletions

View File

@ -20,7 +20,7 @@
</view> </view>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup name="WxLogin">
import { useUserStore } from '@/store' import { useUserStore } from '@/store'
const show = ref(false) const show = ref(false)

View File

@ -6,19 +6,16 @@
<template> <template>
<view>我的</view> <view>我的</view>
<view>wx的openid:{{ openId }} </view> <view>wx的openid:{{ openId }} </view>
<view @click="goLoginPage">去登录</view> <wx-login />
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { useUserStore } from '@/store' import { useUserStore } from '@/store'
import { http } from '@/utils/http' import { http } from '@/utils/http'
import WxLogin from './components/wx-login.vue'
const userStore = useUserStore() const userStore = useUserStore()
const openId = ref('') const openId = ref('')
const goLoginPage = () => {
uni.navigateTo({ url: '/pages/login/index' })
}
// openId // openId
uni.login({ uni.login({
@ -32,7 +29,7 @@ uni.login({
}, },
}) })
openId.value = res.result.openid openId.value = res.result.openid
userStore.setUserInfo({ nickname: '微信用户', avatar: '', openid: res.result.openid }) userStore.setUserInfo({ openid: res.result.openid })
}, },
}) })
</script> </script>

4
src/typings.d.ts vendored
View File

@ -1,6 +1,6 @@
export type UserInfo = { export type UserInfo = {
nickname: string nickname?: string
avatar: string avatar?: string
/** 微信的 openid非微信没有这个字段 */ /** 微信的 openid非微信没有这个字段 */
openid?: string openid?: string
token?: string token?: string