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

239 lines
6.2 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
10 months 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" v-if="isCheck">手机号</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. console.log(111)
  53. if(!this.isCheck) return this.$u.toast('请勾选产品协议与隐私政策');
  54. let phoneCode = e.detail.code
  55. console.log(e.detail.errMsg) // 回调信息(成功失败都会返回)
  56. console.log(e.detail) // 错误码(失败时返回)
  57. const loginCode = await this.loginFn()
  58. if(!loginCode||!phoneCode) return
  59. console.log('登录验证码')
  60. console.log(loginCode)
  61. let obj = {
  62. phoneCode,
  63. loginCode
  64. }
  65. const {data: res} = await weixinLogin(obj)
  66. this.$store.commit('update_vuex_loginInfo',res)
  67. this.$store.dispatch('getUserInfo')
  68. // this.$goPage('/pages/userCenter/login/face')
  69. uni.switchTab({
  70. url: '/pages/tabbar/index/index'
  71. })
  72. },
  73. loginFn() {
  74. // 微信登录
  75. return new Promise((resolve,reject)=>{
  76. uni.login({
  77. provider: 'weixin',
  78. success: loginRes => {
  79. if (loginRes.code) {
  80. // 登录成功,获取用户信息
  81. console.log('loginRes.code')
  82. console.log(loginRes.code)
  83. resolve(loginRes.code)
  84. // this.getUserInfo(loginRes.code);
  85. } else {
  86. console.error('微信登录失败');
  87. }
  88. },
  89. fail: err => {
  90. reject(null)
  91. console.error('微信登录失败', err);
  92. }
  93. });
  94. })
  95. },
  96. getUserInfo(code) {
  97. // 获取用户信息
  98. uni.getUserInfo({
  99. provider: 'weixin',
  100. success: userInfoRes => {
  101. // 在这里处理获取到的用户信息
  102. console.log('用户信息', userInfoRes);
  103. // 发送 code 和用户信息到后台进行登录操作
  104. this.loginBackend(code, userInfoRes);
  105. },
  106. fail: err => {
  107. console.error('获取用户信息失败', err);
  108. }
  109. });
  110. },
  111. loginBackend(code, userInfo) {
  112. // 在这里发送 code 和用户信息到后台进行登录操作
  113. // 可以使用 uni.request 或其他 HTTP 库发送请求
  114. },
  115. // 获取code
  116. getCode() {
  117. uni.login({
  118. provider: 'weixin',
  119. success: loginRes => {
  120. this.decodePhoneParams.code = loginRes.code
  121. console.log('loginRes')
  122. console.log(loginRes)
  123. }
  124. });
  125. },
  126. // 是否选择协议
  127. changeRadio(val) {
  128. this.isCheck = val
  129. },
  130. init() {
  131. uni.login({
  132. provider: 'weixin',
  133. "onlyAuthorize": true,
  134. success: function (loginRes) {
  135. console.log('11')
  136. console.log(loginRes)
  137. // 登录成功
  138. uni.getUserInfo({
  139. provider: 'weixin',
  140. success: function(info) {
  141. // 获取用户信息成功, info.authResult保存用户信息
  142. console.log('11')
  143. console.log(info)
  144. }
  145. })
  146. },
  147. fail: function (err) {
  148. // 登录授权失败
  149. // err.code是错误码
  150. }
  151. });
  152. },
  153. }
  154. }
  155. </script>
  156. <style lang="scss" scoped>
  157. .main {
  158. width: 100%;
  159. display: flex;
  160. flex-direction: column;
  161. align-items: center;
  162. // background: url('../../../static/images/userCenter/loginTopBg.png') no-repeat;
  163. // background-size: 100% 360rpx;
  164. .h1Img {
  165. width: 658rpx;
  166. height: 94rpx;
  167. margin: 288rpx 0 120rpx 0;
  168. }
  169. .btnCon {
  170. .btn {
  171. width: 396rpx;
  172. height: 72rpx;
  173. background: #1989FA;
  174. border-radius: 8rpx;
  175. color: #fff;
  176. margin-bottom: 32rpx;
  177. text-align: center;
  178. line-height: 72rpx;
  179. font-size: 28rpx;
  180. position: relative;
  181. overflow: hidden;
  182. .hide {
  183. position: absolute;
  184. left: 0;
  185. top: 0;
  186. width: 100%;
  187. height: 100%;
  188. display: inline-block;
  189. opacity: 0;
  190. }
  191. &.border {
  192. background: rgba(25,137,250,0.1);
  193. border: 2rpx solid #1989FA;
  194. color: $themC;
  195. }
  196. }
  197. }
  198. }
  199. .popupCon {
  200. width: 558rpx;
  201. height: 344rpx;
  202. border-radius: 16rpx;
  203. overflow: hidden;
  204. .h1 {
  205. line-height: 124rpx;
  206. text-align: center;
  207. font-size: 36rpx;
  208. font-weight: 600;
  209. height: 124rpx;
  210. width: 100%;
  211. background: linear-gradient(180deg, #C1DFFE 0%, #FFFFFF 100%);
  212. }
  213. .msg {
  214. font-size: 28rpx;
  215. color: #686B73;
  216. padding: 0 0 30rpx 0;
  217. text-align: center;
  218. }
  219. .oneBtn {
  220. line-height: 112rpx;
  221. height: 112rpx;
  222. border-top: 1px solid #E8E9EC;
  223. text-align: center;
  224. font-size: 36rpx;
  225. color: $themC;
  226. font-weight: 600;
  227. }
  228. }
  229. </style>