unibest/src/pages/my/index.vue

39 lines
871 B
Vue
Raw Normal View History

<route lang="json5">
{
style: { navigationBarTitleText: '我的' },
}
</route>
2024-01-03 17:09:44 +08:00
<template>
<view>我的</view>
2024-01-20 18:21:42 +08:00
<view>wx的openid:{{ openId }} </view>
2024-01-16 10:15:20 +08:00
<view @click="goLoginPage">去登录</view>
2024-01-03 17:09:44 +08:00
</template>
2024-01-16 10:15:20 +08:00
<script lang="ts" setup>
2024-01-20 18:21:42 +08:00
import { useUserStore } from '@/store'
import { http } from '@/utils/http'
const userStore = useUserStore()
const openId = ref('')
2024-01-16 10:15:20 +08:00
const goLoginPage = () => {
uni.navigateTo({ url: '/pages/login/index' })
}
2024-01-20 18:21:42 +08:00
2024-01-16 10:15:20 +08:00
// 用户登录获取openId
2024-01-20 18:21:42 +08:00
uni.login({
provider: 'weixin',
success: async ({ code }) => {
const res = await http<{ session_key: string; openid: string }>({
method: 'GET',
url: '/weixin/jscode2session',
data: {
code,
},
})
openId.value = res.result.openid
userStore.setUserInfo({ nickname: '微信用户', avatar: '', openid: res.result.openid })
},
})
2024-01-16 10:15:20 +08:00
</script>