localPhoneLogin.vue 8.1 KB

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