localPhoneLogin.vue 8.7 KB

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