enterPage.vue 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <template>
  2. <div></div>
  3. </template>
  4. <script>
  5. import { CheckBookPreviewIdentityCode } from '@/api/app';
  6. import { setToken } from '@/utils/auth';
  7. export default {
  8. name: 'EnterPage',
  9. data() {
  10. return {
  11. identityCode: this.$route.query.identity_code || '',
  12. data: {
  13. book_id: null,
  14. access_token: null,
  15. gcls_sys_session_info: null,
  16. },
  17. };
  18. },
  19. created() {
  20. this.checkIdentityCode();
  21. },
  22. methods: {
  23. checkIdentityCode() {
  24. if (!this.identityCode) {
  25. this.$message.error('缺少身份码参数');
  26. return;
  27. }
  28. CheckBookPreviewIdentityCode({ identity_code: this.identityCode })
  29. .then((response) => {
  30. this.data = response;
  31. setToken(response);
  32. if (this.isMobile()) {
  33. this.$router.replace({ name: 'MobileBookPreview', query: { book_id: this.data.book_id } });
  34. } else {
  35. this.$router.replace({ name: 'BookPreview', query: { book_id: this.data.book_id } });
  36. }
  37. })
  38. .catch(() => {});
  39. },
  40. // 判断当前是web端还是手机端
  41. isMobile() {
  42. const userAgent = navigator.userAgent || navigator.vendor || window.opera;
  43. return /android|iphone|ipad|ipod/i.test(userAgent);
  44. },
  45. },
  46. };
  47. </script>
  48. <style lang="scss" scoped></style>