refactor: 登陆逻辑优化
This commit is contained in:
parent
bd67776dcf
commit
006bf537f8
@ -1,5 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<view class="fly-login" v-if="show">
|
<view class="fly-login" v-if="modelValue">
|
||||||
<view class="fly-login-mask" />
|
<view class="fly-login-mask" />
|
||||||
<view class="fly-login-content px-4">
|
<view class="fly-login-content px-4">
|
||||||
<view class="font-bold h-16 leading-16">获取您的昵称、头像</view>
|
<view class="font-bold h-16 leading-16">获取您的昵称、头像</view>
|
||||||
@ -28,7 +28,7 @@
|
|||||||
class="flex items-center h-16 leading-16 border-b-gray-400 border-b-solid border-1 mt-4"
|
class="flex items-center h-16 leading-16 border-b-gray-400 border-b-solid border-1 mt-4"
|
||||||
>
|
>
|
||||||
<text class="mr-4 flex-shrink-0">昵称</text>
|
<text class="mr-4 flex-shrink-0">昵称</text>
|
||||||
<input type="nickname" placeholder="请输入昵称" @change="onChange" />
|
<input type="nickname" placeholder="请输入昵称" @change="onChange" @blur="onChange" />
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<button
|
<button
|
||||||
@ -47,14 +47,16 @@
|
|||||||
import { useUserStore } from '@/store'
|
import { useUserStore } from '@/store'
|
||||||
import defaultAvatarUrl from './defaultAvatar.png'
|
import defaultAvatarUrl from './defaultAvatar.png'
|
||||||
|
|
||||||
|
const emit = defineEmits(['update:modelValue'])
|
||||||
|
defineProps<{ modelValue: boolean }>()
|
||||||
|
|
||||||
const userStore = useUserStore()
|
const userStore = useUserStore()
|
||||||
|
|
||||||
const show = ref(true)
|
|
||||||
const avatarUrl = ref(defaultAvatarUrl)
|
const avatarUrl = ref(defaultAvatarUrl)
|
||||||
const nickname = ref('')
|
const nickname = ref('')
|
||||||
|
|
||||||
const onClose = () => {
|
const onClose = () => {
|
||||||
show.value = false
|
emit('update:modelValue', false)
|
||||||
}
|
}
|
||||||
|
|
||||||
const onChooseAvatar = (e) => {
|
const onChooseAvatar = (e) => {
|
||||||
@ -67,6 +69,7 @@ const onChooseAvatar = (e) => {
|
|||||||
const onChange = (e) => {
|
const onChange = (e) => {
|
||||||
const { value } = e.detail
|
const { value } = e.detail
|
||||||
nickname.value = value
|
nickname.value = value
|
||||||
|
console.log(value)
|
||||||
}
|
}
|
||||||
|
|
||||||
const onSubmit = () => {
|
const onSubmit = () => {
|
||||||
@ -87,6 +90,7 @@ const onSubmit = () => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
emit('update:modelValue', false)
|
||||||
console.log('保存用户信息')
|
console.log('保存用户信息')
|
||||||
userStore.setUserInfo({ nickname: nickname.value, avatar: avatarUrl.value })
|
userStore.setUserInfo({ nickname: nickname.value, avatar: avatarUrl.value })
|
||||||
}
|
}
|
||||||
|
@ -11,10 +11,10 @@
|
|||||||
<view class="ml-2">{{ userStore.userInfo?.nickname }}</view>
|
<view class="ml-2">{{ userStore.userInfo?.nickname }}</view>
|
||||||
</view>
|
</view>
|
||||||
<view class="flex items-center leading-6" v-else @click="show = true">
|
<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="i-carbon-user-avatar"></view>
|
||||||
<view class="ml-2">点击显示微信头像</view>
|
<view class="ml-2">点击显示微信头像</view>
|
||||||
</view>
|
</view>
|
||||||
|
<fly-login v-model="show" />
|
||||||
<fly-content :line="10" />
|
<fly-content :line="10" />
|
||||||
<button v-if="hasLogin" class="mt-2" @click="logout">退出登录</button>
|
<button v-if="hasLogin" class="mt-2" @click="logout">退出登录</button>
|
||||||
</view>
|
</view>
|
||||||
@ -31,7 +31,6 @@ const logout = () => {
|
|||||||
title: '确认退出当前账号?',
|
title: '确认退出当前账号?',
|
||||||
success: (res) => {
|
success: (res) => {
|
||||||
if (res.confirm) {
|
if (res.confirm) {
|
||||||
show.value = false
|
|
||||||
userStore.clearUserInfo()
|
userStore.clearUserInfo()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
23
uni-pages.d.ts
vendored
23
uni-pages.d.ts
vendored
@ -5,32 +5,13 @@
|
|||||||
|
|
||||||
interface NavigateToOptions {
|
interface NavigateToOptions {
|
||||||
url: "pages/index/index" |
|
url: "pages/index/index" |
|
||||||
"pages/demo/index" |
|
|
||||||
"pages/login/index" |
|
"pages/login/index" |
|
||||||
"pages/my/index" |
|
"pages/my/index";
|
||||||
"pages/demo/demo/clock" |
|
|
||||||
"pages/demo/demo/component-auto-import" |
|
|
||||||
"pages/demo/demo/lottery" |
|
|
||||||
"pages/demo/demo/lottery2" |
|
|
||||||
"pages/demo/demo/mp-weixin-share" |
|
|
||||||
"pages/demo/demo/navbar" |
|
|
||||||
"pages/demo/demo/pages-auto-import" |
|
|
||||||
"pages/demo/demo/pinia" |
|
|
||||||
"pages/demo/demo/request" |
|
|
||||||
"pages/demo/demo/throughout" |
|
|
||||||
"pages/demo/demo/uni-ui-icons" |
|
|
||||||
"pages/demo/demo/uni-ui" |
|
|
||||||
"pages/demo/demo/unocss-icons" |
|
|
||||||
"pages/demo/demo/unocss" |
|
|
||||||
"pages/demo/demo/img-min/index" |
|
|
||||||
"pages/demo/demo/lottery/big-wheel" |
|
|
||||||
"pages/demo/demo/lottery/nine-grid" |
|
|
||||||
"pages/demo/demo/throughout/index";
|
|
||||||
}
|
}
|
||||||
interface RedirectToOptions extends NavigateToOptions {}
|
interface RedirectToOptions extends NavigateToOptions {}
|
||||||
|
|
||||||
interface SwitchTabOptions {
|
interface SwitchTabOptions {
|
||||||
url: 'pages/index/index' | 'pages/demo/index' | 'pages/my/index'
|
url: 'pages/index/index' | 'pages/my/index'
|
||||||
}
|
}
|
||||||
|
|
||||||
type ReLaunchOptions = NavigateToOptions | SwitchTabOptions
|
type ReLaunchOptions = NavigateToOptions | SwitchTabOptions
|
||||||
|
Loading…
x
Reference in New Issue
Block a user