学员端小程序
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.

238 lines
6.1 KiB

1 year ago
10 months ago
1 year ago
11 months ago
10 months ago
1 year ago
1 year ago
1 year ago
1 year ago
10 months ago
1 year ago
10 months ago
1 year ago
11 months ago
1 year ago
11 months ago
10 months ago
11 months ago
1 year ago
10 months ago
1 year ago
10 months ago
1 year ago
1 year ago
1 year ago
1 year ago
  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. <view class="btn" @click="getPhoneNumber">手机号快捷登录 <button open-type="getPhoneNumber" @getphonenumber="getPhoneNumber" class="hide">手机号</button></view>
  8. <view class="btn border" @click="$goPage('/pages/userCenter/login/loginByPhone');">手机号登录/注册</view>
  9. </view>
  10. <view style="margin-top: 40rpx;">
  11. <privacyRadion :isCheck="isCheck" @changeRadio="changeRadio"></privacyRadion>
  12. </view>
  13. <u-popup :show="show" :round="10" mode="center" >
  14. <view class="">
  15. <view class="popupCon">
  16. <view class="h1"> </view>
  17. <view class="msg">授权手机号我们才能继续为您 <br>提供服务哦~</view>
  18. <view class="oneBtn">我知道了</view>
  19. </view>
  20. </view>
  21. </u-popup>
  22. </view>
  23. </template>
  24. <script>
  25. import { imgUrl } from '@/config/site.config'
  26. import privacyRadion from './comp/privacyRadion.vue'
  27. import { weixinLogin } from '@/config/api.js'
  28. export default {
  29. components: {privacyRadion},
  30. data() {
  31. return {
  32. isCheck: false,
  33. show: false,
  34. decodePhoneParams: {},
  35. imgUrl: imgUrl+'loginTopBg.png',
  36. backgroundSize: '100% 360rpx',
  37. }
  38. },
  39. onLoad() {
  40. this.getCode()
  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. // 获取code
  115. getCode() {
  116. uni.login({
  117. provider: 'weixin',
  118. success: loginRes => {
  119. this.decodePhoneParams.code = loginRes.code
  120. console.log('loginRes')
  121. console.log(loginRes)
  122. }
  123. });
  124. },
  125. // 是否选择协议
  126. changeRadio(val) {
  127. this.isCheck = val
  128. },
  129. init() {
  130. uni.login({
  131. provider: 'weixin',
  132. "onlyAuthorize": true,
  133. success: function (loginRes) {
  134. console.log('11')
  135. console.log(loginRes)
  136. // 登录成功
  137. uni.getUserInfo({
  138. provider: 'weixin',
  139. success: function(info) {
  140. // 获取用户信息成功, info.authResult保存用户信息
  141. console.log('11')
  142. console.log(info)
  143. }
  144. })
  145. },
  146. fail: function (err) {
  147. // 登录授权失败
  148. // err.code是错误码
  149. }
  150. });
  151. },
  152. }
  153. }
  154. </script>
  155. <style lang="scss" scoped>
  156. .main {
  157. width: 100%;
  158. display: flex;
  159. flex-direction: column;
  160. align-items: center;
  161. // background: url('../../../static/images/userCenter/loginTopBg.png') no-repeat;
  162. // background-size: 100% 360rpx;
  163. .h1Img {
  164. width: 658rpx;
  165. height: 94rpx;
  166. margin: 288rpx 0 120rpx 0;
  167. }
  168. .btnCon {
  169. .btn {
  170. width: 396rpx;
  171. height: 72rpx;
  172. background: #1989FA;
  173. border-radius: 8rpx;
  174. color: #fff;
  175. margin-bottom: 32rpx;
  176. text-align: center;
  177. line-height: 72rpx;
  178. font-size: 28rpx;
  179. position: relative;
  180. overflow: hidden;
  181. .hide {
  182. position: absolute;
  183. left: 0;
  184. top: 0;
  185. width: 100%;
  186. height: 100%;
  187. display: inline-block;
  188. opacity: 0;
  189. }
  190. &.border {
  191. background: rgba(25,137,250,0.1);
  192. border: 2rpx solid #1989FA;
  193. color: $themC;
  194. }
  195. }
  196. }
  197. }
  198. .popupCon {
  199. width: 558rpx;
  200. height: 344rpx;
  201. border-radius: 16rpx;
  202. overflow: hidden;
  203. .h1 {
  204. line-height: 124rpx;
  205. text-align: center;
  206. font-size: 36rpx;
  207. font-weight: 600;
  208. height: 124rpx;
  209. width: 100%;
  210. background: linear-gradient(180deg, #C1DFFE 0%, #FFFFFF 100%);
  211. }
  212. .msg {
  213. font-size: 28rpx;
  214. color: #686B73;
  215. padding: 0 0 30rpx 0;
  216. text-align: center;
  217. }
  218. .oneBtn {
  219. line-height: 112rpx;
  220. height: 112rpx;
  221. border-top: 1px solid #E8E9EC;
  222. text-align: center;
  223. font-size: 36rpx;
  224. color: $themC;
  225. font-weight: 600;
  226. }
  227. }
  228. </style>