123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199 |
- <template>
- <view class="login-container">
- <view class="base-container">
- <!-- <image class="tabbar" src="https://birdseye-img.sysuimars.com/dinggou-mini/tabbar-new.png" mode="" /> -->
- </view>
- <up-popup :show="showPopup" mode="center" round="10" :overlay="false" :safeAreaInsetBottom="false"
- bgColor="transparent">
- <view class="popup">
- <button class="avatar-none" open-type="chooseAvatar" @chooseavatar="onChooseAvatar">
- <view class="avatar-wrapper">
- <image class="avatar" :src="userData.icon"></image>
- <view class="photo-icon">
- <up-icon color="#fff" size="20" name="camera-fill"></up-icon>
- </view>
- </view>
- </button>
- <view class="tips">设置头像,可以在地图上显示自己守护树的点位哦~</view>
- <button class="arrow-icon" open-type="getPhoneNumber" @getphonenumber="onGetPhoneNumber">
- <view class="button">微信授权</view>
- </button>
- </view>
- </up-popup>
- </view>
- </template>
- <script setup>
- import {
- ref
- } from 'vue';
- import {
- onLoad
- } from '@dcloudio/uni-app'
- import config from "@/api/config.js"
- import upload from '@/utils/uploadUtils.js'
- import USER from '@/api/user.js'
- const showPopup = ref(true);
- const userData = ref({})
- const pageUrl = ref('')
- const pageParams = ref(null)
- onLoad(({
- route_path,
- params = "{}"
- }) => {
- pageUrl.value = route_path
- pageParams.value = params
- getUserData()
- })
- const getUserData = () => {
- USER.userInfo().then(res => {
- const timestamp = res.data.birthDate && Date.parse(res.data.birthDate); // 返回毫秒级时间戳
- userData.value = res.data
- })
- }
- const onChooseAvatar = (e) => {
- const {
- avatarUrl
- } = e.detail
- uni.showLoading({title: '上传中'})
- upload(userData.value.id + "/" + new Date().getTime() + ".png", avatarUrl, (res) => {
- userData.value.icon = config.BASE_IMG_URL + res.key
- uni.hideLoading()
- })
- }
- const onGetPhoneNumber = (e) => {
- if (e.detail.code) {
- USER.getPhone({
- code: e.detail.code
- }).then(res => {
- if (res.success) {
- userData.value.tel = res.data
- saveUserInfo(userData.value)
- }
- })
- } else {
- console.log("用户拒绝了授权");
- }
- }
- const saveUserInfo = (params) => {
- USER.updateUser(params).then(response => {
- uni.hideLoading()
- if (response.success) {
- uni.showToast({
- title: '保存成功',
- icon: 'none',
- duration: 2000,
- mask: true
- })
- uni.setStorageSync('userInfo', userData.value);
- uni.reLaunch({
- url: `/pages/tabBar/home/subPages/gardenMap?enterSelectTree=true`
- });
- } else {
- uni.showToast({
- title: '保存失败',
- icon: 'none',
- duration: 2000,
- mask: true
- })
- }
- })
- }
- </script>
- <style lang="scss" scoped>
- @import "@/static/style/mixin.scss";
-
- .login-container {
- .base-container {
- @include ossBg("login-bj.png");
- height: 100vh;
-
- .tabbar {
- width: 100%;
- height: 112rpx;
- position: fixed;
- bottom: 0;
- left: 0;
- }
- }
- }
- .popup {
- width: 86vw;
- padding: 40rpx;
- box-sizing: border-box;
- background-image: url('https://birdseye-img.sysuimars.com/dinggou-mini/popup-bg.png');
- background-size: 100% 100%;
- background-repeat: no-repeat;
- background-position: center center;
- .avatar-none {
- width: auto;
- height: auto;
- display: contents;
- pointer-events: none;
- .avatar-wrapper {
- display: flex;
- justify-content: center;
- align-items: center;
- margin-bottom: 40rpx;
- position: relative;
- .avatar {
- width: 176rpx;
- height: 176rpx;
- border-radius: 50%;
- object-fit: cover;
- pointer-events: auto;
- }
- .photo-icon {
- pointer-events: auto;
- position: absolute;
- bottom: -6rpx;
- right: calc(50% - 64rpx - 40rpx);
- width: 64rpx;
- height: 64rpx;
- border-radius: 50%;
- background: #2199F8;
- display: flex;
- justify-content: center;
- align-items: center;
- border: 4rpx solid #fff;
- }
- }
- }
- .tips {
- font-size: 30rpx;
- color: #666666;
- margin-bottom: 48rpx;
- }
- .arrow-icon {
- width: auto;
- height: auto;
- text-align: left;
- background: transparent;
- padding-left: 0;
- padding-right: 0;
- }
- .button {
- font-size: 32rpx;
- text-align: center;
- background: #2199F8;
- color: #fff;
- border-radius: 16rpx;
- }
- }
- </style>
|