register.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. <template>
  2. <view class="register_box">
  3. <template v-if="isRegister==0">
  4. <image src="https://cdn.his.cdwjyyh.com/minapp/kc_hb_bg1.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,loginByMp} 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. isLoginH5: 0, // 1服务号授权
  28. }
  29. },
  30. computed:{
  31. ...mapGetters(['coureLogin']),
  32. },
  33. watch: {
  34. coureLogin: {
  35. immediate: true, // 页面一进入就检查一次
  36. handler(val) {
  37. if (val == 2&&this.isLogin) {
  38. console.log("注册AppToken失效,请重新登录")
  39. uni.removeStorageSync('web_userInfo');
  40. uni.removeStorageSync('TOKEN_WEXIN');
  41. this.isLogin = false
  42. this.goLogin()
  43. }
  44. }
  45. }
  46. },
  47. onLoad(option) {
  48. this.urlOption = option.link ? JSON.parse(decodeURIComponent(option.link)) : {}
  49. this.sortLink = this.urlOption.link || ''
  50. uni.$on('usercode',(data)=>{
  51. if(data) {
  52. this.goLogin(data)
  53. }
  54. })
  55. },
  56. beforeDestroy() {
  57. uni.$off('usercode')
  58. },
  59. onUnload() {
  60. uni.$off('usercode')
  61. },
  62. methods: {
  63. getLink() {
  64. if(!this.sortLink){
  65. uni.showToast({
  66. title: '链接错误',
  67. icon: 'none'
  68. });
  69. return
  70. }
  71. let that = this;
  72. uni.showLoading({
  73. title: '注册中'
  74. })
  75. getRealLink({sortLink:this.sortLink}).then(res=>{
  76. uni.hideLoading()
  77. if(res.code == 200) {
  78. if(res.config&&res.config.userCourseAuthDomain) {
  79. uni.setStorageSync('weixinOauth',res.config.userCourseAuthDomain)
  80. if(this.isLoginH5==0) {
  81. this.utils.isLoginCourse().then(
  82. isLogin => {
  83. this.isLogin = isLogin
  84. if(this.isLogin) {
  85. this.getAddCompanyUser()
  86. } else {
  87. this.goLogin()
  88. }
  89. },
  90. rej => {}
  91. );
  92. }else {
  93. this.utils.isLoginResCourse().then(
  94. isLogin => {
  95. this.isLogin = isLogin
  96. if(this.isLogin) {
  97. this.getAddCompanyUser()
  98. } else {
  99. this.goLogin()
  100. }
  101. },
  102. rej => {}
  103. );
  104. }
  105. }else {
  106. uni.showToast({
  107. title: '授权地址错误',
  108. icon: 'none'
  109. });
  110. }
  111. } else {
  112. uni.showToast({
  113. title: res.msg,
  114. icon: 'none'
  115. });
  116. }
  117. }).catch(err=>{
  118. uni.hideLoading()
  119. uni.showToast({
  120. title: '发生错误,请稍后再试',
  121. icon: 'none'
  122. });
  123. })
  124. },
  125. goLogin(data) {
  126. if(this.isLoginH5==0) {
  127. this.goWXLogin()
  128. return
  129. }
  130. if(data) {
  131. this.utils.getProvider().then(provider=>{
  132. console.log('当前的环境商',provider)
  133. if (!provider) {
  134. reject()
  135. }
  136. uni.login({
  137. provider: provider,
  138. success: loginRes => {
  139. console.log(loginRes)
  140. uni.getUserInfo({
  141. provider: provider,
  142. success: (infoRes)=> {
  143. const param = {
  144. code: loginRes.code, // 必填参数,不能为空,code参数缺失时会报错
  145. appId: getApp().globalData.appId, // 应用ID
  146. userId: data.userId // 用户id
  147. }
  148. uni.showLoading({
  149. title: '注册中'
  150. })
  151. handleFsUserWx(param).then(res=>{
  152. uni.hideLoading()
  153. if(res.code==200) {
  154. this.getAddCompanyUser()
  155. } else {
  156. uni.removeStorageSync('web_userInfo');
  157. uni.removeStorageSync('TOKEN_WEXIN');
  158. uni.showToast({
  159. title: res.msg,
  160. icon: 'none'
  161. });
  162. }
  163. }).catch(err=>{
  164. uni.hideLoading()
  165. })
  166. }
  167. });
  168. }
  169. })
  170. })
  171. } else {
  172. uni.setStorageSync('H5course',{
  173. companyId: this.urlOption.companyId,
  174. companyUserId:this.urlOption.companyUserId,
  175. })
  176. uni.navigateTo({
  177. url:'/pages_course/webview'
  178. })
  179. }
  180. },
  181. getAddCompanyUser() {
  182. isAddCompanyUser(this.urlOption).then(res=>{
  183. if(res.code==200) {
  184. this.isRegister = 1
  185. } else {
  186. uni.showToast({
  187. title: res.msg,
  188. icon: 'none'
  189. });
  190. }
  191. })
  192. },
  193. goWXLogin() {
  194. this.utils.getProvider().then(provider=>{
  195. console.log('当前的环境商',provider)
  196. if (!provider) {
  197. reject()
  198. }
  199. uni.login({
  200. provider: provider,
  201. success: async loginRes => {
  202. console.log(loginRes)
  203. uni.getUserInfo({
  204. provider: provider,
  205. success: (infoRes)=> {
  206. uni.showToast({
  207. title: '注册中...',
  208. icon: 'loading'
  209. });
  210. loginByMp({code: loginRes.code,encryptedData:infoRes.encryptedData,iv:infoRes.iv,appId:getApp().globalData.appId}).then(res=>{
  211. uni.hideLoading();
  212. if (res.code == 200) {
  213. this.$store.commit('setCoureLogin', 1);
  214. uni.setStorageSync('AppTokenmini_RTCourse', res.token);
  215. uni.setStorageSync('auto_userInfo', JSON.stringify(res.user));
  216. this.isLogin = true
  217. this.getAddCompanyUser()
  218. } else {
  219. uni.showToast({
  220. title: res.msg,
  221. icon: 'none'
  222. });
  223. }
  224. }).catch(err=>{
  225. uni.hideLoading();
  226. uni.showToast({
  227. icon:'none',
  228. title: "登录失败,请重新登录",
  229. });
  230. });
  231. }
  232. });
  233. }
  234. })
  235. }).catch(err => {})
  236. }
  237. }
  238. }
  239. </script>
  240. <style>
  241. page {
  242. background-color: #fff;
  243. }
  244. </style>
  245. <style scoped lang="scss">
  246. .register_box {
  247. position: relative;
  248. min-height: 100vh;
  249. }
  250. @keyframes scaleAnimation {
  251. 0% {
  252. transform: translate(-50%, -50%) scale(1);
  253. }
  254. 50% {
  255. transform: translate(-50%, -50%) scale(1.05);
  256. }
  257. 100% {
  258. transform: translate(-50%, -50%) scale(1);
  259. }
  260. }
  261. .success_box {
  262. height: 100vh;
  263. width: 100%;
  264. display: flex;
  265. flex-direction: column;
  266. align-items: center;
  267. justify-content: center;
  268. font-family: PingFang SC, PingFang SC;
  269. font-weight: 500;
  270. font-size: 64rpx;
  271. color: #222222;
  272. image {
  273. width: 404rpx;
  274. height: 404rpx;
  275. margin-bottom: 26rpx;
  276. }
  277. }
  278. .imgbg {
  279. width: 100%;
  280. }
  281. .kc_footer {
  282. width: 100%;
  283. position: absolute;
  284. bottom: 0;
  285. left: 0;
  286. &_btn {
  287. width: 528rpx;
  288. height: 96rpx;
  289. background: #FF5C03;
  290. border-radius: 48rpx 48rpx 48rpx 48rpx;
  291. font-family: PingFang SC, PingFang SC;
  292. font-weight: 500;
  293. font-size: 32rpx;
  294. color: #FFFFFF;
  295. display: flex;
  296. align-items: center;
  297. justify-content: center;
  298. position: absolute;
  299. bottom: 20%;
  300. left: 50%;
  301. transform: translate(-50%, -50%) scale(1);
  302. // will-change: transform;
  303. // animation: scaleAnimation 1s ease infinite;
  304. }
  305. }
  306. .imgft {
  307. width: 100%;
  308. }
  309. </style>