login.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. <template>
  2. <view class="content">
  3. <view class="login-logo">
  4. <view class="login-logo-body">
  5. <image src="/static/image/logo.png"></image>
  6. <view class="logo-text">奥莱优品</view>
  7. </view>
  8. </view>
  9. <view class="test">
  10. <textarea v-model="loginInfo" maxlength="-1" style="height: 120upx;"></textarea>
  11. </view>
  12. <view class="logi-btn">
  13. <!-- <button class="u-button full" @click="getUserInfo" v-if="checkTrueState">快捷一键登录</button> -->
  14. <button class="u-button full" open-type="getPhoneNumber" @getphonenumber="toLogin" v-if="checkTrueState">手机号一键登录</button>
  15. <button class="u-button full" @click="toLoginCheck" v-else>快捷登录</button>
  16. <!-- <button class="u-button" @click="popState(1)">展示</button> -->
  17. <button class="u-button" @click="reback">返回</button>
  18. </view>
  19. <view class="login-footer">
  20. <view :class="checkTrueState?'checkBox active':'checkBox'" @click="checkTrue"></view>
  21. <view @click="checkTrue">我已阅读并同意</view>
  22. <text @click="toWeb('privacy')">用户协议、</text><text @click="toWeb('privacy')">隐私协议</text>
  23. </view>
  24. <uni-popup ref="userpopup" type="bottom" border-radius="10px 10px 0 0" background-color="#ffffff" :mask-click="false">
  25. <view class="user-pop">
  26. <view class="title">登录提醒</view>
  27. <view class="pop-body">为了更好的区分完善信息,还需授权获取到您的头像、昵称信息</view>
  28. <view class="pop-btn">
  29. <button class="u-button full" open-type="getUserInfo" @click="getUserInfo">授权头像、昵称信息</button>
  30. </view>
  31. </view>
  32. </uni-popup>
  33. </view>
  34. </template>
  35. <script>
  36. import * as Api from "@/static/api/auth.js";
  37. var app;
  38. export default {
  39. data() {
  40. return {
  41. checkTrueState:false,
  42. avatar:"https://yunenv.oss-cn-shenzhen.aliyuncs.com/poem/avatar.jpg",
  43. nickname:"",
  44. loginShow:false,
  45. reUri:null,
  46. reType:"switchTab",
  47. storeId:"",
  48. loginCode:"",
  49. loginInfo:"",
  50. mobileData:null
  51. }
  52. },
  53. onLoad({store,type,url}) {
  54. app = this;
  55. app.reType = type?type:"switchTab";
  56. app.reUri = url?url:null;
  57. // app.storeId = app.$dialog.shopId();
  58. uni.login({
  59. force:true,
  60. success(resp){
  61. app.loginCode = resp.code;
  62. }
  63. })
  64. },
  65. methods: {
  66. popState(type){
  67. if (type == 1) {
  68. app.$refs.userpopup.open()
  69. } else {
  70. app.$refs.userpopup.close()
  71. }
  72. return ;
  73. },
  74. reback(){
  75. uni.navigateBack();
  76. },
  77. checkTrue(){
  78. app.checkTrueState = !app.checkTrueState;
  79. },
  80. toWeb(type){
  81. uni.navigateTo({
  82. url:"/pages/web/web?lk="+type
  83. })
  84. },
  85. toLoginCheck(){
  86. if (!app.checkTrueState) {
  87. return app.$dialog.showSuccess("请先阅读并同意用户协议以及隐私政策");
  88. }
  89. },
  90. getUserInfo(e){
  91. uni.getUserProfile({
  92. force: true,
  93. success(resp) {
  94. if (resp.errMsg == 'getUserProfile:ok') {
  95. var detail = {};
  96. detail.avatar = resp.userInfo.avatarUrl
  97. detail.nickname = resp.userInfo.nickName
  98. detail.mobile = JSON.stringify(app.mobileData)
  99. Api.nicknameAuth(detail).then((res)=>{
  100. if (res.code == 0) {
  101. return app.$dialog.showSuccess(res.msg);
  102. }
  103. app.popState(2)
  104. uni.setStorageSync("user_token", res.data.access_token)
  105. uni.navigateBack();
  106. })
  107. }
  108. },
  109. fail(e) {
  110. console.log(e)
  111. }
  112. })
  113. },
  114. toLogin(e){
  115. var detail = e.detail;
  116. detail.login = app.loginCode;
  117. Api.mobileAuth(detail).then((res)=>{
  118. if (!res.data.mobile) {
  119. return app.$dialog.showSuccess(res.msg);
  120. }
  121. app.mobileData = res.data;
  122. app.popState(1)
  123. })
  124. },
  125. }
  126. }
  127. </script>
  128. <style>
  129. .user-pop .title{padding: 20upx;border-bottom: 2upx solid #f8f8f8;font-size: 28upx;font-weight: bold;color: #000;}
  130. .user-pop .pop-body{padding: 20upx;font-size: 24upx;color: #555;line-height: 60upx;text-align: center;}
  131. .user-pop .pop-btn{display: flex;align-items: center;margin-top: 20upx;justify-content: end;}
  132. .user-pop .u-button{font-size: 28upx;height: 80upx;border-radius: 40upx;line-height: 80upx;margin-bottom: 40upx;color: #333;border: 2upx solid #007aff;background-color: #fff;padding: 0 40upx;}
  133. .user-pop .u-button::after{border: 0;}
  134. .user-pop .u-button.full{background-color: #007aff;color: #fff;}
  135. .test{width: 80%;overflow: auto;height: 100upx;}
  136. .content{position: relative;height: 100vh;display: flex;flex-direction: column;}
  137. .login-logo{width: 80%;margin: 60upx auto;text-align: center;height: 40%;display: flex;align-items: center;justify-content: center;}
  138. .login-logo .logo-text{font-size: 32upx;color: #333;font-family: "logofont";margin-top: 20upx;}
  139. .login-logo image{width: 180upx;height: 180upx;}
  140. .logi-btn{width: 50%;margin: 20upx auto;height: 40%;}
  141. .logi-btn .u-button{font-size: 28upx;height: 80upx;border-radius: 40upx;line-height: 80upx;margin-bottom: 40upx;color: #333;border: 2upx solid #007aff;background-color: #fff;}
  142. .logi-btn .u-button::after{border: 0;}
  143. .logi-btn .u-button.full{background-color: #007aff;color: #fff;}
  144. .login-footer{text-align: center;font-size: 28upx;color: #666;height: 20%;display: flex;align-items: center;justify-content: center;}
  145. .login-footer text{color: #007aff;}
  146. .checkBox{width: 30upx;height: 30upx;margin-right: 20upx;border: 2upx solid #007aff;position: relative;}
  147. .checkBox.active{background-color: #007aff;}
  148. .checkBox.active::after{content: "√";font-size: 24upx;position: absolute;left: 0;top: 0;color: #fff;bottom: 0;right: 0;}
  149. .popup-login{padding: 20upx;}
  150. .popup-login .login-container{margin-top: 20upx;}
  151. .login-control{display: flex;align-items: center;font-size: 28upx;color: #333;border-bottom: 2upx solid #f8f8f8;padding: 20upx 0;}
  152. .login-control .name{margin-right: 40upx;}
  153. .login-control .btn-control{margin-left: 9px;}
  154. .popup-login .mobile-btn{border:2upx solid #fff;background-color: #fff;padding-left: 0;padding-right: 0;font-size: 28upx;color: #999;}
  155. .popup-login .mobile-btn::after{border: 0;}
  156. .avatar-btn-img{width: 80upx;height: 80upx;border-radius: 10upx;}
  157. .popup-login .avatar-btn{width:80upx;height:80upx;line-height:80upx;border-radius:10upx;font-size:24upx;border:0 solid #F6F1E7;background:#fff;padding-left: 0;padding-right: 0;}
  158. .popup-login .avatar-btn::after{border:0}
  159. .popup-login .avatar{margin-left: 9px;}
  160. .popup-login .title-sub{border-bottom: 2upx solid #f8f8f8;font-size: 30upx;color: #000;font-weight: bold;padding: 30upx 0;}
  161. .popup-login .title-sub text{display: block;font-size: 24upx;color: #666;font-weight: normal;margin-top: 20upx;}
  162. .popup-login .title{display: flex;align-items: center;}
  163. .popup-login .title .left{font-size: 28upx;color: #000;font-weight: bold;display: flex;align-items: center;}
  164. .popup-login .title .left image{width: 50upx;height: 50upx;border-radius: 10upx;margin-right: 20upx;}
  165. .popup-login .title .close{margin-left: auto;margin-right: 0;width: 40upx;height: 40upx;background-color: aliceblue;font-size: 24upx;color: #666;border-radius: 40upx;text-align: center;}
  166. </style>