enterPage.vue 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <template>
  2. <div></div>
  3. </template>
  4. <script>
  5. import { CheckBookPreviewIdentityCode } from '@/api/app';
  6. import { setToken, setLocalStore } from '@/utils/auth';
  7. import { updateBaseURL } from '@/utils/http';
  8. export default {
  9. name: 'EnterPage',
  10. data() {
  11. return {
  12. identityCode: this.$route.query.identity_code || '',
  13. data: {
  14. book_id: null,
  15. access_token: null,
  16. gcls_sys_session_info: null,
  17. },
  18. };
  19. },
  20. created() {
  21. if (process.env.NODE_ENV === 'production') {
  22. let serverAddress = `${window.location.origin}/`;
  23. setLocalStore('server_address', serverAddress);
  24. updateBaseURL(serverAddress);
  25. }
  26. this.checkIdentityCode();
  27. },
  28. methods: {
  29. checkIdentityCode() {
  30. if (!this.identityCode) {
  31. this.$message.error('缺少身份码参数');
  32. return;
  33. }
  34. CheckBookPreviewIdentityCode({ identity_code: this.identityCode })
  35. .then((response) => {
  36. this.data = response;
  37. setToken(response);
  38. setLocalStore('book_id', this.data.book_id);
  39. if (this.isMobile()) {
  40. this.$router.replace({ name: 'MobileBookPreview' });
  41. } else {
  42. if (this.data.preview_type === 1) {
  43. setLocalStore('task_id', this.data.task_id); // 课程预览需要 task_id
  44. setLocalStore('courseware_id', this.data.courseware_id);
  45. this.$router.replace({ name: 'CoursewarePreview' });
  46. return;
  47. }
  48. this.$router.replace({ name: 'BookPreview' });
  49. }
  50. })
  51. .catch(() => {});
  52. },
  53. // 判断当前是web端还是手机端
  54. isMobile() {
  55. const userAgent = navigator.userAgent || navigator.vendor || window.opera;
  56. return /android|iphone|ipad|ipod/i.test(userAgent);
  57. },
  58. },
  59. };
  60. </script>