洛阳学员端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

226 lines
5.9 KiB

  1. <template>
  2. <view class="main" :style="{ background: `url(${imgUrl}) no-repeat`, backgroundSize: backgroundSize }">
  3. <view class="h1Img">
  4. <image src="../../../static/images/userCenter/loginTitle.png" mode=""></image>
  5. </view>
  6. <view class="btnCon">
  7. <!-- #ifdef MP-WEIXIN -->
  8. <view class="btn" @click="getPhoneNumber">手机号快捷登录 <button open-type="getPhoneNumber" @getphonenumber="getPhoneNumber" class="hide" v-if="isCheck">手机号</button> </view>
  9. <!-- #endif -->
  10. <view class="btn border" @click="$goPage('/pages/userCenter/login/loginByPhone?isCheck='+isCheck);">手机号登录/注册</view>
  11. </view>
  12. <view style="margin-top: 40rpx;">
  13. <privacyRadion :isCheck="isCheck" @changeRadio="changeRadio"></privacyRadion>
  14. </view>
  15. <!-- <u-popup :show="show" :round="10" mode="center" >
  16. <view class="">
  17. <view class="popupCon">
  18. <view class="h1"> </view>
  19. <view class="msg">授权手机号我们才能继续为您 <br>提供服务哦~</view>
  20. <view class="oneBtn">我知道了</view>
  21. </view>
  22. </view>
  23. </u-popup> -->
  24. </view>
  25. </template>
  26. <script>
  27. import { imgUrl } from '@/config/site.config'
  28. import privacyRadion from './comp/privacyRadion.vue'
  29. import { weixinLogin } from '@/config/api.js'
  30. export default {
  31. components: {privacyRadion},
  32. data() {
  33. return {
  34. isCheck: false,
  35. show: false,
  36. imgUrl: imgUrl+'loginTopBg.png',
  37. backgroundSize: '100% 360rpx',
  38. }
  39. },
  40. onLoad() {
  41. // uni.getLocation({
  42. // type: 'wgs84',
  43. // success: function (res) {
  44. // console.log(res)
  45. // console.log('当前位置的经度:' + res.longitude);
  46. // console.log('当前位置的纬度:' + res.latitude);
  47. // }
  48. // });
  49. },
  50. methods: {
  51. async getPhoneNumber (e) {
  52. if(!this.isCheck) return this.$u.toast('请勾选产品协议与隐私政策');
  53. let phoneCode = e.detail.code
  54. console.log(e.detail.errMsg) // 回调信息(成功失败都会返回)
  55. console.log(e.detail) // 错误码(失败时返回)
  56. const loginCode = await this.loginFn()
  57. if(!loginCode||!phoneCode) return
  58. console.log('登录验证码')
  59. console.log(loginCode)
  60. let obj = {
  61. phoneCode,
  62. loginCode
  63. }
  64. const {data: res} = await weixinLogin(obj)
  65. this.$store.commit('update_vuex_loginInfo',res)
  66. this.$store.dispatch('getUserInfo')
  67. // this.$goPage('/pages/userCenter/login/face')
  68. uni.switchTab({
  69. url: '/pages/tabbar/index/index'
  70. })
  71. },
  72. loginFn() {
  73. // 微信登录
  74. return new Promise((resolve,reject)=>{
  75. uni.login({
  76. provider: 'weixin',
  77. success: loginRes => {
  78. if (loginRes.code) {
  79. // 登录成功,获取用户信息
  80. console.log('loginRes.code')
  81. console.log(loginRes.code)
  82. resolve(loginRes.code)
  83. // this.getUserInfo(loginRes.code);
  84. } else {
  85. console.error('微信登录失败');
  86. }
  87. },
  88. fail: err => {
  89. reject(null)
  90. console.error('微信登录失败', err);
  91. }
  92. });
  93. })
  94. },
  95. getUserInfo(code) {
  96. // 获取用户信息
  97. uni.getUserInfo({
  98. provider: 'weixin',
  99. success: userInfoRes => {
  100. // 在这里处理获取到的用户信息
  101. console.log('用户信息', userInfoRes);
  102. // 发送 code 和用户信息到后台进行登录操作
  103. this.loginBackend(code, userInfoRes);
  104. },
  105. fail: err => {
  106. console.error('获取用户信息失败', err);
  107. }
  108. });
  109. },
  110. loginBackend(code, userInfo) {
  111. // 在这里发送 code 和用户信息到后台进行登录操作
  112. // 可以使用 uni.request 或其他 HTTP 库发送请求
  113. },
  114. // 是否选择协议
  115. changeRadio(val) {
  116. this.isCheck = val
  117. },
  118. init() {
  119. uni.login({
  120. provider: 'weixin',
  121. "onlyAuthorize": true,
  122. success: function (loginRes) {
  123. console.log('11')
  124. console.log(loginRes)
  125. // 登录成功
  126. uni.getUserInfo({
  127. provider: 'weixin',
  128. success: function(info) {
  129. // 获取用户信息成功, info.authResult保存用户信息
  130. console.log('11')
  131. console.log(info)
  132. }
  133. })
  134. },
  135. fail: function (err) {
  136. // 登录授权失败
  137. // err.code是错误码
  138. }
  139. });
  140. },
  141. }
  142. }
  143. </script>
  144. <style lang="scss" scoped>
  145. .main {
  146. width: 100%;
  147. display: flex;
  148. flex-direction: column;
  149. align-items: center;
  150. // background: url('../../../static/images/userCenter/loginTopBg.png') no-repeat;
  151. // background-size: 100% 360rpx;
  152. .h1Img {
  153. width: 658rpx;
  154. height: 94rpx;
  155. margin: 288rpx 0 120rpx 0;
  156. }
  157. .btnCon {
  158. .btn {
  159. width: 396rpx;
  160. height: 72rpx;
  161. background: #1989FA;
  162. border-radius: 8rpx;
  163. color: #fff;
  164. margin-bottom: 32rpx;
  165. text-align: center;
  166. line-height: 72rpx;
  167. font-size: 28rpx;
  168. position: relative;
  169. overflow: hidden;
  170. .hide {
  171. position: absolute;
  172. left: 0;
  173. top: 0;
  174. width: 100%;
  175. height: 100%;
  176. display: inline-block;
  177. opacity: 0;
  178. }
  179. &.border {
  180. background: rgba(25,137,250,0.1);
  181. border: 2rpx solid #1989FA;
  182. color: $themC;
  183. }
  184. }
  185. }
  186. }
  187. .popupCon {
  188. width: 558rpx;
  189. height: 344rpx;
  190. border-radius: 16rpx;
  191. overflow: hidden;
  192. .h1 {
  193. line-height: 124rpx;
  194. text-align: center;
  195. font-size: 36rpx;
  196. font-weight: 600;
  197. height: 124rpx;
  198. width: 100%;
  199. background: linear-gradient(180deg, #C1DFFE 0%, #FFFFFF 100%);
  200. }
  201. .msg {
  202. font-size: 28rpx;
  203. color: #686B73;
  204. padding: 0 0 30rpx 0;
  205. text-align: center;
  206. }
  207. .oneBtn {
  208. line-height: 112rpx;
  209. height: 112rpx;
  210. border-top: 1px solid #E8E9EC;
  211. text-align: center;
  212. font-size: 36rpx;
  213. color: $themC;
  214. font-weight: 600;
  215. }
  216. }
  217. </style>