index.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. <template>
  2. <view class="login-container">
  3. <view class="base-container">
  4. <!-- <image class="tabbar" src="https://birdseye-img.sysuimars.com/dinggou-mini/tabbar-new.png" mode="" /> -->
  5. </view>
  6. <up-popup :show="showPopup" mode="center" round="10" :overlay="false" :safeAreaInsetBottom="false"
  7. bgColor="transparent">
  8. <view class="popup">
  9. <button class="avatar-none" open-type="chooseAvatar" @chooseavatar="onChooseAvatar">
  10. <view class="avatar-wrapper">
  11. <image class="avatar" :src="userData.icon"></image>
  12. <view class="photo-icon">
  13. <up-icon color="#fff" size="20" name="camera-fill"></up-icon>
  14. </view>
  15. </view>
  16. </button>
  17. <view class="tips">设置头像,可以在地图上显示自己守护树的点位哦~</view>
  18. <button class="arrow-icon" open-type="getPhoneNumber" @getphonenumber="onGetPhoneNumber">
  19. <view class="button">微信授权</view>
  20. </button>
  21. </view>
  22. </up-popup>
  23. </view>
  24. </template>
  25. <script setup>
  26. import {
  27. ref
  28. } from 'vue';
  29. import {
  30. onLoad
  31. } from '@dcloudio/uni-app'
  32. import config from "@/api/config.js"
  33. import upload from '@/utils/uploadUtils.js'
  34. import USER from '@/api/user.js'
  35. const showPopup = ref(true);
  36. const userData = ref({})
  37. const pageUrl = ref('')
  38. const pageParams = ref(null)
  39. onLoad(({
  40. route_path,
  41. params = "{}"
  42. }) => {
  43. pageUrl.value = route_path
  44. pageParams.value = JSON.parse(params)
  45. getUserData()
  46. })
  47. const getUserData = () => {
  48. USER.userInfo().then(res => {
  49. const timestamp = res.data.birthDate && Date.parse(res.data.birthDate); // 返回毫秒级时间戳
  50. userData.value = res.data
  51. })
  52. }
  53. const onChooseAvatar = (e) => {
  54. const {
  55. avatarUrl
  56. } = e.detail
  57. uni.showLoading({title: '上传中'})
  58. upload(userData.value.id + "/" + new Date().getTime() + ".png", avatarUrl, (res) => {
  59. userData.value.icon = config.BASE_IMG_URL + res.key
  60. uni.hideLoading()
  61. })
  62. }
  63. const onGetPhoneNumber = (e) => {
  64. if (e.detail.code) {
  65. USER.getPhone({
  66. code: e.detail.code
  67. }).then(res => {
  68. if (res.success) {
  69. userData.value.tel = res.data
  70. saveUserInfo(userData.value)
  71. }
  72. })
  73. } else {
  74. console.log("用户拒绝了授权");
  75. }
  76. }
  77. const saveUserInfo = (params) => {
  78. if (pageParams.value?.code) {
  79. params = {...params, code: pageParams.value?.code}
  80. }
  81. USER.updateUser(params).then(response => {
  82. uni.hideLoading()
  83. if (response.success) {
  84. uni.showToast({
  85. title: '保存成功',
  86. icon: 'none',
  87. duration: 2000,
  88. mask: true
  89. })
  90. uni.setStorageSync('userInfo', userData.value);
  91. if (pageParams.value?.code) {
  92. uni.reLaunch({
  93. url: `/pages/tabBar/home/subPages/gardenMap?isScanAuthSuccess=true`
  94. });
  95. } else {
  96. uni.reLaunch({
  97. url: `/pages/tabBar/home/subPages/gardenMap?enterSelectTree=true`
  98. });
  99. }
  100. } else {
  101. uni.showToast({
  102. title: '保存失败',
  103. icon: 'none',
  104. duration: 2000,
  105. mask: true
  106. })
  107. }
  108. })
  109. }
  110. </script>
  111. <style lang="scss" scoped>
  112. @import "@/static/style/mixin.scss";
  113. .login-container {
  114. .base-container {
  115. @include ossBg("login-bj.png");
  116. height: 100vh;
  117. .tabbar {
  118. width: 100%;
  119. height: 112rpx;
  120. position: fixed;
  121. bottom: 0;
  122. left: 0;
  123. }
  124. }
  125. }
  126. .popup {
  127. width: 86vw;
  128. padding: 40rpx;
  129. box-sizing: border-box;
  130. background-image: url('https://birdseye-img.sysuimars.com/dinggou-mini/popup-bg.png');
  131. background-size: 100% 100%;
  132. background-repeat: no-repeat;
  133. background-position: center center;
  134. .avatar-none {
  135. width: auto;
  136. height: auto;
  137. display: contents;
  138. pointer-events: none;
  139. .avatar-wrapper {
  140. display: flex;
  141. justify-content: center;
  142. align-items: center;
  143. margin-bottom: 40rpx;
  144. position: relative;
  145. .avatar {
  146. width: 176rpx;
  147. height: 176rpx;
  148. border-radius: 50%;
  149. object-fit: cover;
  150. pointer-events: auto;
  151. }
  152. .photo-icon {
  153. pointer-events: auto;
  154. position: absolute;
  155. bottom: -6rpx;
  156. right: calc(50% - 64rpx - 40rpx);
  157. width: 64rpx;
  158. height: 64rpx;
  159. border-radius: 50%;
  160. background: #2199F8;
  161. display: flex;
  162. justify-content: center;
  163. align-items: center;
  164. border: 4rpx solid #fff;
  165. }
  166. }
  167. }
  168. .tips {
  169. font-size: 30rpx;
  170. color: #666666;
  171. margin-bottom: 48rpx;
  172. }
  173. .arrow-icon {
  174. width: auto;
  175. height: auto;
  176. text-align: left;
  177. background: transparent;
  178. padding-left: 0;
  179. padding-right: 0;
  180. }
  181. .button {
  182. font-size: 32rpx;
  183. text-align: center;
  184. background: #2199F8;
  185. color: #fff;
  186. border-radius: 16rpx;
  187. }
  188. }
  189. </style>