|
| 1 | +<template> |
| 2 | + <view class="fly-login" v-if="modelValue"> |
| 3 | + <view class="fly-login-mask" /> |
| 4 | + <view class="fly-login-content px-4"> |
| 5 | + <view class="font-bold h-16 leading-16">获取您的昵称、头像</view> |
| 6 | + <view |
| 7 | + class="rounded-full bg-light-600 w-6 h-6 text-center absolute top-4 right-4" |
| 8 | + @click="onClose" |
| 9 | + > |
| 10 | + <view class="i-carbon-close text-gray-700" /> |
| 11 | + </view> |
| 12 | + |
| 13 | + <view |
| 14 | + class="flex items-center h-16 leading-16 border-b-gray-400 border-b-solid border-[1rpx]" |
| 15 | + > |
| 16 | + <text class="mr-4 flex-shrink-0">头像</text> |
| 17 | + <button |
| 18 | + class="bg-transparent flex items-center after:b-none w-full h-12 leading-12" |
| 19 | + open-type="chooseAvatar" |
| 20 | + @chooseavatar="onChooseAvatar" |
| 21 | + > |
| 22 | + <image class="w-8 h-8 rounded-full" :src="avatarUrl"></image> |
| 23 | + <text class="ml-auto i-carbon-chevron-right"></text> |
| 24 | + </button> |
| 25 | + </view> |
| 26 | + |
| 27 | + <view |
| 28 | + class="flex items-center h-16 leading-16 border-b-gray-400 border-b-solid border-1 mt-4" |
| 29 | + > |
| 30 | + <text class="mr-4 flex-shrink-0">昵称</text> |
| 31 | + <input type="nickname" placeholder="请输入昵称" @change="onChange" @blur="onChange" /> |
| 32 | + </view> |
| 33 | + |
| 34 | + <button |
| 35 | + size="default" |
| 36 | + type="default" |
| 37 | + style="color: #fff; background-color: #1aad19; border-color: #1aad19" |
| 38 | + class="text-center leading-12 w-40 my-4" |
| 39 | + @click="onSubmit" |
| 40 | + > |
| 41 | + 确定 |
| 42 | + </button> |
| 43 | + </view> |
| 44 | + </view> |
| 45 | +</template> |
| 46 | +<script lang="ts" setup> |
| 47 | +import { useUserStore } from '@/store' |
| 48 | +import defaultAvatarUrl from './defaultAvatar.png' |
| 49 | +
|
| 50 | +const emit = defineEmits(['update:modelValue']) |
| 51 | +defineProps<{ modelValue: boolean }>() |
| 52 | +
|
| 53 | +const userStore = useUserStore() |
| 54 | +
|
| 55 | +const avatarUrl = ref(defaultAvatarUrl) |
| 56 | +const nickname = ref('') |
| 57 | +
|
| 58 | +const onClose = () => { |
| 59 | + emit('update:modelValue', false) |
| 60 | +} |
| 61 | +
|
| 62 | +const onChooseAvatar = (e) => { |
| 63 | + const { avatarUrl: url } = e.detail |
| 64 | + avatarUrl.value = url |
| 65 | + // 这里就要上传,加快速度,提升体验(用户多次选择头像就多次上传吧,总有取舍) |
| 66 | + console.log(url) |
| 67 | +} |
| 68 | +
|
| 69 | +const onChange = (e) => { |
| 70 | + const { value } = e.detail |
| 71 | + nickname.value = value |
| 72 | + console.log(value) |
| 73 | +} |
| 74 | +
|
| 75 | +const onSubmit = () => { |
| 76 | + // 1、上传刚刚的图片,并返回网络地址 |
| 77 | + // 2、把用户信息存起来 |
| 78 | + if (avatarUrl.value === defaultAvatarUrl) { |
| 79 | + uni.showToast({ |
| 80 | + title: '请选择头像', |
| 81 | + icon: 'none', |
| 82 | + }) |
| 83 | + return |
| 84 | + } |
| 85 | + if (!nickname.value) { |
| 86 | + uni.showToast({ |
| 87 | + title: '请填写昵称', |
| 88 | + icon: 'none', |
| 89 | + }) |
| 90 | + return |
| 91 | + } |
| 92 | +
|
| 93 | + emit('update:modelValue', false) |
| 94 | + console.log('保存用户信息') |
| 95 | + userStore.setUserInfo({ nickname: nickname.value, avatar: avatarUrl.value }) |
| 96 | +} |
| 97 | +</script> |
| 98 | + |
| 99 | +<style lang="scss" scoped> |
| 100 | +.fly-login { |
| 101 | + position: fixed; |
| 102 | + inset: 0; |
| 103 | +
|
| 104 | + .fly-login-mask { |
| 105 | + position: fixed; |
| 106 | + inset: 0; |
| 107 | + background-color: rgb(0 0 0 / 30%); |
| 108 | + } |
| 109 | +
|
| 110 | + .fly-login-content { |
| 111 | + position: fixed; |
| 112 | + right: 0; |
| 113 | + bottom: var(--window-bottom); |
| 114 | + left: 0; |
| 115 | + background-color: #fff; |
| 116 | + border-top-left-radius: 16px; |
| 117 | + border-top-right-radius: 16px; |
| 118 | + } |
| 119 | +} |
| 120 | +</style> |
0 commit comments