register.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. <template>
  2. <view class="register_box">
  3. <template v-if="isRegister==0">
  4. <image src="https://image.cdwjyyh.com/images/kc_hb_bg.png" class="imgbg" mode="widthFix"></image>
  5. <view class="kc_footer">
  6. <image src="https://image.cdwjyyh.com/images/kc_footer_bg.png" class="imgft" mode="widthFix"></image>
  7. <view class="kc_footer_btn" @click="getLink">{{isRegister==1?'注册成功':'立即注册'}}</view>
  8. </view>
  9. </template>
  10. <view v-else class="success_box">
  11. <image src="https://image.cdwjyyh.com/images/course_register_img.png" mode="heightFix"></image>
  12. <view>注册成功</view>
  13. </view>
  14. </view>
  15. </template>
  16. <script>
  17. import { mapGetters } from 'vuex';
  18. import {getRealLink,handleFsUserWx,isAddCompanyUser} from "@/api/course.js"
  19. export default {
  20. data() {
  21. return {
  22. isLogin: false,
  23. isRegister: 0,
  24. isLoading: false,
  25. urlOption: {},
  26. sortLink: ''
  27. }
  28. },
  29. computed:{
  30. ...mapGetters(['coureLogin']),
  31. },
  32. watch: {
  33. coureLogin: {
  34. immediate: true, // 页面一进入就检查一次
  35. handler(val) {
  36. if (val == 2&&this.isLogin) {
  37. console.log("注册AppToken失效,请重新登录")
  38. this.isLogin = false
  39. this.goLogin()
  40. }
  41. }
  42. }
  43. },
  44. onLoad(option) {
  45. this.urlOption = option.link ? JSON.parse(decodeURIComponent(option.link)) : {}
  46. this.sortLink = this.urlOption.link || ''
  47. uni.$on('usercode',(data)=>{
  48. if(data) {
  49. this.goLogin(data)
  50. }
  51. })
  52. },
  53. beforeDestroy() {
  54. uni.$off('usercode')
  55. },
  56. onUnload() {
  57. uni.$off('usercode')
  58. },
  59. methods: {
  60. getLink() {
  61. if(!this.sortLink){
  62. uni.showToast({
  63. title: '链接错误',
  64. icon: 'none'
  65. });
  66. return
  67. }
  68. let that = this;
  69. uni.showLoading({
  70. title: '注册中'
  71. })
  72. getRealLink({sortLink:this.sortLink}).then(res=>{
  73. uni.hideLoading()
  74. if(res.code == 200) {
  75. if(res.config&&res.config.userCourseAuthDomain) {
  76. uni.setStorageSync('weixinOauth',res.config.userCourseAuthDomain)
  77. this.utils.isLoginResCourse().then(
  78. isLogin => {
  79. this.isLogin = isLogin
  80. if(this.isLogin) {
  81. this.getAddCompanyUser()
  82. } else {
  83. this.goLogin()
  84. }
  85. },
  86. rej => {}
  87. );
  88. }else {
  89. uni.showToast({
  90. title: '授权地址错误',
  91. icon: 'none'
  92. });
  93. }
  94. } else {
  95. uni.showToast({
  96. title: res.msg,
  97. icon: 'none'
  98. });
  99. }
  100. }).catch(err=>{
  101. uni.hideLoading()
  102. uni.showToast({
  103. title: '发生错误,请稍后再试',
  104. icon: 'none'
  105. });
  106. })
  107. },
  108. goLogin(data) {
  109. if(data) {
  110. this.utils.getProvider().then(provider=>{
  111. console.log('当前的环境商',provider)
  112. if (!provider) {
  113. reject()
  114. }
  115. uni.login({
  116. provider: provider,
  117. success: loginRes => {
  118. console.log(loginRes)
  119. uni.getUserInfo({
  120. provider: provider,
  121. success: (infoRes)=> {
  122. const param = {
  123. code: loginRes.code, // 必填参数,不能为空,code参数缺失时会报错
  124. appId: getApp().globalData.appId, // 应用ID
  125. userId: data.userId // 用户id
  126. }
  127. uni.showLoading({
  128. title: '注册中'
  129. })
  130. handleFsUserWx(param).then(res=>{
  131. uni.hideLoading()
  132. if(res.code==200) {
  133. this.getAddCompanyUser()
  134. } else {
  135. uni.removeStorageSync('web_userInfo');
  136. uni.removeStorageSync('TOKEN_WEXIN');
  137. uni.showToast({
  138. title: res.msg,
  139. icon: 'none'
  140. });
  141. }
  142. }).catch(err=>{
  143. uni.hideLoading()
  144. })
  145. }
  146. });
  147. }
  148. })
  149. })
  150. } else {
  151. uni.setStorageSync('H5course',{
  152. companyId: this.urlOption.companyId,
  153. companyUserId:this.urlOption.companyUserId,
  154. })
  155. uni.navigateTo({
  156. url:'/pages_course/webview'
  157. })
  158. }
  159. },
  160. getAddCompanyUser() {
  161. isAddCompanyUser(this.urlOption).then(res=>{
  162. if(res.code==200) {
  163. this.isRegister = 1
  164. } else {
  165. uni.showToast({
  166. title: res.msg,
  167. icon: 'none'
  168. });
  169. }
  170. })
  171. }
  172. }
  173. }
  174. </script>
  175. <style>
  176. page {
  177. background-color: #fff;
  178. }
  179. </style>
  180. <style scoped lang="scss">
  181. .register_box {
  182. position: relative;
  183. min-height: 100vh;
  184. }
  185. @keyframes scaleAnimation {
  186. 0% {
  187. transform: translate(-50%, -50%) scale(1);
  188. }
  189. 50% {
  190. transform: translate(-50%, -50%) scale(1.05);
  191. }
  192. 100% {
  193. transform: translate(-50%, -50%) scale(1);
  194. }
  195. }
  196. .success_box {
  197. height: 100vh;
  198. width: 100%;
  199. display: flex;
  200. flex-direction: column;
  201. align-items: center;
  202. justify-content: center;
  203. font-family: PingFang SC, PingFang SC;
  204. font-weight: 500;
  205. font-size: 64rpx;
  206. color: #222222;
  207. image {
  208. width: 404rpx;
  209. height: 404rpx;
  210. margin-bottom: 26rpx;
  211. }
  212. }
  213. .imgbg {
  214. width: 100%;
  215. }
  216. .kc_footer {
  217. width: 100%;
  218. position: absolute;
  219. bottom: 0;
  220. left: 0;
  221. &_btn {
  222. width: 528rpx;
  223. height: 96rpx;
  224. background: #FF5C03;
  225. border-radius: 48rpx 48rpx 48rpx 48rpx;
  226. font-family: PingFang SC, PingFang SC;
  227. font-weight: 500;
  228. font-size: 32rpx;
  229. color: #FFFFFF;
  230. display: flex;
  231. align-items: center;
  232. justify-content: center;
  233. position: absolute;
  234. bottom: 20%;
  235. left: 50%;
  236. transform: translate(-50%, -50%) scale(1);
  237. // will-change: transform;
  238. // animation: scaleAnimation 1s ease infinite;
  239. }
  240. }
  241. .imgft {
  242. width: 100%;
  243. }
  244. </style>