localPhoneLogin.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. <template>
  2. <view>
  3. <en-nav @navHeight="setNavHeight" ></en-nav>
  4. <view class="login-box" v-show="false" :style="{'height':'calc(100vh - '+navHeight+'px)'}">
  5. <view class="login-top">
  6. <view class="login-title">
  7. <text class="title-item sys-color-black sys-weight-600">登录/注册</text>
  8. <text class="title-item title-two sys-color-black sys-weight-600">更精彩</text>
  9. </view>
  10. <view class="local-txt sys-color-gray-9">本机号码登录</view>
  11. <view class="local-phone sys-color-black sys-weight-400">188****4188</view>
  12. <view class="login-but sys-color-white sys-background-black" @click="login">一键登录</view>
  13. <view @click="goToOther" class="other-phone sys-color-gray-6">其他手机号登录</view>
  14. </view>
  15. <view class="login-bottom">
  16. <other-login></other-login>
  17. <login-agreement :type="2"></login-agreement>
  18. </view>
  19. </view>
  20. </view>
  21. </template>
  22. <script>
  23. import EnNav from "@/components/en-utils/en-nav/en-nav";
  24. import LoginAgreement from "@/pages/login/model/loginAgreement";
  25. import OtherLogin from "@/pages/login/model/otherLogin";
  26. import tools from "@/service/tools";
  27. export default {
  28. name:'localPhoneLogin',
  29. components: {OtherLogin, LoginAgreement, EnNav},
  30. data() {
  31. return {
  32. navHeight:40
  33. }
  34. },
  35. onLoad(query) {
  36. this.getPhoneNum()
  37. },
  38. methods: {
  39. getPhoneNum(){
  40. let that=this
  41. uni.login({
  42. provider: 'univerify',
  43. univerifyStyle: {
  44. "fullScreen": true, // 是否全屏显示,默认值: false
  45. "backgroundColor": "#ffffff", // 授权页面背景颜色,默认值:#ffffff
  46. "backgroundImage": "", // 全屏显示的背景图片,默认值:"" (仅支持本地图片,只有全屏显示时支持)
  47. "icon": {
  48. "path": "static/xxx.png" // 自定义显示在授权框中的logo,仅支持本地图片 默认显示App logo
  49. },
  50. "closeIcon": {
  51. "path": "static/xxx.png" // 自定义关闭按钮,仅支持本地图片。 HBuilderX3.3.7+版本支持
  52. },
  53. "phoneNum": {
  54. "color": "#202020" // 手机号文字颜色 默认值:#202020
  55. },
  56. "slogan": {
  57. "color": "#BBBBBB" // slogan 字体颜色 默认值:#BBBBBB
  58. },
  59. "authButton": {
  60. "normalColor": "#141414", // 授权按钮正常状态背景颜色 默认值:#3479f5
  61. "highlightColor": "#141414", // 授权按钮按下状态背景颜色 默认值:#2861c5(仅ios支持)
  62. "disabledColor": "#141414", // 授权按钮不可点击时背景颜色 默认值:#73aaf5(仅ios支持)
  63. "textColor": "#ffffff", // 授权按钮文字颜色 默认值:#ffffff
  64. "title": "本机号码一键登录", // 授权按钮文案 默认值:“本机号码一键登录”
  65. "borderRadius": "24px" // 授权按钮圆角 默认值:"24px" (按钮高度的一半)
  66. },
  67. "otherLoginButton": {
  68. "visible": true, // 是否显示其他登录按钮,默认值:true
  69. "normalColor": "", // 其他登录按钮正常状态背景颜色 默认值:透明
  70. "highlightColor": "", // 其他登录按钮按下状态背景颜色 默认值:透明
  71. "textColor": "#656565", // 其他登录按钮文字颜色 默认值:#656565
  72. "title": "其他登录方式", // 其他登录方式按钮文字 默认值:“其他登录方式”
  73. "borderColor": "", //边框颜色 默认值:透明(仅iOS支持)
  74. "borderRadius": "0px" // 其他登录按钮圆角 默认值:"24px" (按钮高度的一半)
  75. },
  76. "privacyTerms": {
  77. "defaultCheckBoxState":true, // 条款勾选框初始状态 默认值: true
  78. "isCenterHint":false, //未勾选服务条款时点击登录按钮的提示是否居中显示 默认值: false (3.7.13+ 版本支持)
  79. "uncheckedImage":"", // 可选 条款勾选框未选中状态图片(仅支持本地图片 建议尺寸 24x24px)(3.2.0+ 版本支持)
  80. "checkedImage":"", // 可选 条款勾选框选中状态图片(仅支持本地图片 建议尺寸24x24px)(3.2.0+ 版本支持)
  81. "checkBoxSize":12, // 可选 条款勾选框大小,仅android支持
  82. "textColor": "#BBBBBB", // 文字颜色 默认值:#BBBBBB
  83. "termsColor": "#5496E3", // 协议文字颜色 默认值: #5496E3
  84. "prefix": "我已阅读并同意", // 条款前的文案 默认值:“我已阅读并同意”
  85. "suffix": "并使用本机号码登录", // 条款后的文案 默认值:“并使用本机号码登录”
  86. "privacyItems": [ // 自定义协议条款,最大支持2个,需要同时设置url和title. 否则不生效
  87. {
  88. "url": "https://", // 点击跳转的协议详情页面
  89. "title": "用户服务协议" // 协议名称
  90. }
  91. ]
  92. }
  93. },
  94. success(res){ // 登录成功
  95. console.log(res.authResult); // {openid:'登录授权唯一标识',access_token:'接口返回的 token'}
  96. that.cloudGetPhoneNum(res.authResult)
  97. },
  98. fail(res){ // 登录失败
  99. console.log(res)
  100. console.log(res.errCode)
  101. console.log(res.errMsg)
  102. that.goToOther()
  103. }
  104. })
  105. },
  106. cloudGetPhoneNum(authResult){
  107. tools.showLoading()
  108. uniCloud.callFunction({
  109. name: 'getPhoneNumber', // 你的云函数名称
  110. data: {
  111. 'access_token': authResult.access_token,
  112. 'openid': authResult.openid
  113. }
  114. }).then(res => {
  115. tools.hideLoading()
  116. console.log(res)
  117. }).catch(err=>{
  118. tools.hideLoading()
  119. tools.error('手机号码获取失败')
  120. setTimeout(()=>{
  121. this.goToOther()
  122. },1500)
  123. })
  124. },
  125. setNavHeight(navHeight){
  126. console.log('navHeight:'+navHeight)
  127. this.navHeight=navHeight
  128. },
  129. login(){
  130. uni.navigateTo({
  131. 'url':'/pages/perfect/sexAndAge'
  132. })
  133. },
  134. goToOther(){
  135. uni.redirectTo({
  136. 'url':'/pages/login/otherPhoneLogin'
  137. })
  138. }
  139. }
  140. }
  141. </script>
  142. <style scoped lang="scss">
  143. .login-box{
  144. padding: 82rpx 80rpx 0 80rpx;
  145. box-sizing: border-box;
  146. position: relative;
  147. .login-top{
  148. .login-title{
  149. padding-bottom: 60rpx;
  150. .title-item{
  151. font-size: 48rpx;
  152. }
  153. .title-two{
  154. margin-left: 30rpx;
  155. }
  156. }
  157. .local-txt{
  158. padding-bottom: 40rpx;
  159. font-size: 24rpx;
  160. }
  161. .local-phone{
  162. padding-bottom: 120rpx;
  163. font-size: 48rpx;
  164. }
  165. .login-but{
  166. border-radius: 200rpx;
  167. height: 88rpx;
  168. line-height: 88rpx;
  169. text-align: center;
  170. }
  171. .other-phone{
  172. padding-top: 60rpx;
  173. font-size: 28rpx;
  174. text-align: center;
  175. }
  176. }
  177. .login-bottom{
  178. padding-bottom: calc(62rpx + env(safe-area-inset-bottom));
  179. position: absolute;
  180. bottom: 0;
  181. left: 80rpx;
  182. width:calc(100vw - 160rpx);
  183. }
  184. }
  185. </style>