register.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <template>
  2. <view class="register_box">
  3. <image src="https://image.cdwjyyh.com/images/kc_hb_bg.png" class="imgbg" mode="widthFix"></image>
  4. <view class="kc_footer">
  5. <image src="https://image.cdwjyyh.com/images/kc_footer_bg.png" class="imgft" mode="widthFix"></image>
  6. <view class="kc_footer_btn" @click="goLogin">{{isRegister==1?'注册成功':'立即注册'}}</view>
  7. </view>
  8. </view>
  9. </template>
  10. <script>
  11. import {loginByMp,getUserPhoneDeviceType} from "@/api/course.js"
  12. export default {
  13. data() {
  14. return {
  15. isRegister: 0,
  16. isLoading: false
  17. }
  18. },
  19. methods: {
  20. goLogin() {
  21. if (this.isRegister == 1) {
  22. uni.showToast({
  23. title: '注册成功',
  24. icon: 'none'
  25. });
  26. return
  27. }
  28. if (this.isLoading) return;
  29. this.utils.getProvider().then(provider => {
  30. console.log('当前的环境商', provider)
  31. if (!provider) {
  32. reject()
  33. }
  34. uni.login({
  35. provider: provider,
  36. success: async loginRes => {
  37. console.log(loginRes)
  38. uni.getUserInfo({
  39. provider: provider,
  40. success: (infoRes) => {
  41. this.isLoading = true
  42. uni.showToast({
  43. title: '注册中...',
  44. icon: 'loading'
  45. });
  46. loginByMp({
  47. code: loginRes.code,
  48. encryptedData: infoRes.encryptedData,
  49. iv: infoRes.iv,
  50. appId: getApp().globalData.appId
  51. }).then(res => {
  52. uni.hideLoading();
  53. this.isLoading = false
  54. if (res.code == 200) {
  55. this.isRegister = 1
  56. this.$store.commit('setCoureLogin', 1);
  57. uni.setStorageSync('AppTokenmini_RTCourse', res.token);
  58. uni.setStorageSync('auto_userInfo', JSON.stringify(res.user));
  59. uni.showToast({
  60. title: '注册成功',
  61. icon: 'loading'
  62. });
  63. this.getUserPhoneDeviceType()
  64. } else {
  65. uni.showToast({
  66. title: res.msg,
  67. icon: 'none'
  68. });
  69. }
  70. }).catch(err => {
  71. this.isLoading = false
  72. uni.hideLoading();
  73. uni.showToast({
  74. icon: 'none',
  75. title: "登录失败,请重新登录",
  76. });
  77. });
  78. }
  79. });
  80. }
  81. })
  82. }).catch(err => {})
  83. },
  84. getUserPhoneDeviceType(){
  85. uni.getSystemInfo({
  86. success: (result) => {
  87. const param = {
  88. os: result.osName || '',
  89. deviceId: result.deviceId || '',
  90. appId: getApp().globalData.appId
  91. }
  92. getUserPhoneDeviceType({param:JSON.stringify(param)})
  93. },
  94. fail: (error) => {
  95. console.log('获取型号失败',JSON.stringify(error))
  96. }
  97. })
  98. },
  99. }
  100. }
  101. </script>
  102. <style scoped lang="scss">
  103. .register_box {
  104. position: relative;
  105. }
  106. .imgbg {
  107. width: 100%;
  108. }
  109. .kc_footer {
  110. width: 100%;
  111. position: absolute;
  112. bottom: 0;
  113. left: 0;
  114. &_btn {
  115. width: 528rpx;
  116. height: 96rpx;
  117. background: #FF5C03;
  118. border-radius: 48rpx 48rpx 48rpx 48rpx;
  119. font-family: PingFang SC, PingFang SC;
  120. font-weight: 500;
  121. font-size: 32rpx;
  122. color: #FFFFFF;
  123. display: flex;
  124. align-items: center;
  125. justify-content: center;
  126. position: absolute;
  127. bottom: 20%;
  128. left: 50%;
  129. transform: translate(-50%, -50%);
  130. }
  131. }
  132. .imgft {
  133. width: 100%;
  134. }
  135. </style>