butlogin.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <template>
  2. <view>
  3. <uni-popup ref="popup" type="bottom" :mask-click="false" >
  4. <view class="zheshow" >
  5. <view class="cen_ter">
  6. <view class="box_At">
  7. <view class="box_At_text">获取您的昵称、头像、手机号</view>
  8. <view class="box_At_co">获取用户头像、昵称、手机号信息,主要用于完善个人资料,向用户提供更好使用体验</view>
  9. <view class="box_B" style="border-top:1px solid #f3f3f3 ;">
  10. <view class="acvter">头像</view>
  11. <button v-if="!active" class="acvter_all" open-type="chooseAvatar" @chooseavatar="onChooseAvatar">
  12. <view class="mast">请选择头像</view>
  13. </button>
  14. <view v-if="active" class="img"><image :src="active" ></image></view>
  15. </view>
  16. <view class="box_B">
  17. <view class="acvter">昵称</view>
  18. <input class="acvter_all" type="nickname" :value="nickname" @blur="bindblur" placeholder="请输入昵称" />
  19. </view>
  20. <view class="Brn_S">
  21. <view class="btn_btns" @click="colse">取消</view>
  22. <button class="btn" open-type="getPhoneNumber" @getphonenumber="btns" >
  23. <view class="btn">保存</view>
  24. </button>
  25. </view>
  26. </view>
  27. </view>
  28. </view>
  29. </uni-popup>
  30. </view>
  31. </template>
  32. <script>
  33. export default {
  34. props:['zheshow'],
  35. data() {
  36. return {
  37. on_zheshows:false,
  38. zheshow1:false,
  39. active:'',
  40. nickname:''
  41. }
  42. },
  43. watch:{
  44. zheshow() {
  45. this.$refs.popup.open('bottom')
  46. },
  47. },
  48. methods: {
  49. colse(){
  50. this.$refs.popup.close()
  51. },
  52. onChooseAvatar(e) {
  53. let that = this
  54. uni.getFileSystemManager().readFile({
  55. filePath: e.detail.avatarUrl, //选择图片返回的相对路径
  56. encoding: "base64",
  57. success: (res) => {
  58. let base64s = "data:image/jpeg;base64," + res.data
  59. that.active = base64s
  60. },
  61. fail: (res) => reject(res.errMsg),
  62. });
  63. },
  64. bindblur(e){this.nickname = e.detail.value},
  65. btns(e){
  66. console.log(e,'e.detail.code换取手机号')
  67. console.log('微信返回详情:', e.detail)
  68. // 用户拒绝授权
  69. if (e.detail.errMsg == 'getPhoneNumber:fail user deny') {
  70. uni.showToast({title:'已取消授权登录',icon:'none'})
  71. this.$refs.popup.close()
  72. return
  73. }
  74. // 微信返回其他错误(如 errorCode: -10000 系统错误)
  75. if (e.detail.errMsg && e.detail.errMsg.includes('fail')) {
  76. console.error('获取手机号失败:', e.detail.errMsg, 'errorCode:', e.detail.errorCode)
  77. // 开发环境提示:继续登录但使用默认手机号
  78. uni.showModal({
  79. title: '提示',
  80. content: '获取手机号失败(开发环境可忽略)\n是否继续登录?',
  81. success: (res) => {
  82. if (res.confirm) {
  83. // 用户选择继续,使用空code(后端会使用mock手机号)
  84. this.proceedLogin(null)
  85. } else {
  86. this.$refs.popup.close()
  87. }
  88. }
  89. })
  90. return
  91. }
  92. if(this.active==''){
  93. uni.showToast({title:'请选择上传头像',icon:'none'})
  94. return
  95. }
  96. if(this.nickname==''){
  97. uni.showToast({title:'请填写昵称',icon:'none'})
  98. return
  99. }
  100. // 成功获取到code,继续登录
  101. this.proceedLogin(e.detail.code)
  102. },
  103. // 执行登录流程
  104. proceedLogin(code) {
  105. // 将微信返回的手机号 code 一并传递给父组件
  106. this.$parent.loset({
  107. nickname: this.nickname,
  108. active: this.active,
  109. code: code || 'mock_dev_code' // 如果没有code,使用mock
  110. })
  111. }
  112. }
  113. }
  114. </script>
  115. <style lang="scss" scoped>
  116. .zheshow{
  117. width: 100%;height: 100%;background-color: rgba(0,0,0,0.3);position: fixed;top: 0;left: 0;
  118. display: flex;align-items: center;align-items: flex-end;
  119. .mast{margin-top: 6rpx;}
  120. .Brn_S{width: 70%;height: 100rpx;display: flex;align-items: center;justify-content: space-between;margin: 10rpx auto;}
  121. .btn_btns{width: 300rpx;height: 80rpx;background: antiquewhite; display: flex;align-items: center;
  122. justify-content: center; border-radius: 10rpx; margin-right: 70rpx;background-color: #fafafa;color: #39B54A;}
  123. .imgs{position: absolute;right: 6%;width: 32rpx;height: 32rpx;}
  124. .img{width: 90rpx;height: 90rpx;border-radius: 50%;margin-left: 80rpx;image{width: 100%;height: 100%;border-radius: 50%;}}
  125. .cen_ter{
  126. width: 100%;height: 600rpx;border-top-left-radius: 30rpx;border-top-right-radius: 30rpx;background-color: #FFFFFF;
  127. display: flex;align-items: center;justify-content: center;
  128. .box_At{width: 90%;height: 92%;margin-top: 20rpx;display: flex;flex-direction: column;.box_At_text{font-weight: bold;font-size: 30rpx}
  129. .box_At_co{font-size: 28rpx;color: #ababab;margin-top: 24rpx;}
  130. .box_B{width: 100%;height: 120rpx;border-bottom: 1px solid #f3f3f3;display: flex;align-items: center;
  131. margin-top: 12rpx;.acvter_all{font-size: 28rpx;color: #ababab;margin-left: 80rpx;}}
  132. .btn{width:300rpx;margin: 35rpx auto;height: 80rpx;display: flex;align-items: center;justify-content: center;
  133. background-color: #39B54A;color: #FFFFFF;border-radius: 10rpx;font-size: 30rpx;}
  134. }}
  135. }
  136. button {
  137. border-radius: 30rpx;height: 80rpx !important;padding-left: 0!important ;
  138. padding-right: 0!important ; background-color: rgba(0,0,0,0) !important;color: #ababab !important;font-family: PingFang SC !important;
  139. }
  140. button:after {
  141. top: 0;left: 0; border: 1px solid rgba(0,0,0,0) !important; -webkit-transform: scale(.5);
  142. transform: scale(.5); -webkit-transform-origin: 0 0; transform-origin: 0 0; box-sizing: border-box; border-radius: 10px;
  143. }
  144. </style>