register.vue 5.6 KB

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