enterPage.vue 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <template>
  2. <div></div>
  3. </template>
  4. <script>
  5. import { CheckBookPreviewIdentityCode } from '@/api/app';
  6. import { setToken, setLocalStore } 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. setLocalStore('book_id', this.data.book_id);
  33. if (this.isMobile()) {
  34. this.$router.replace({ name: 'MobileBookPreview' });
  35. } else {
  36. this.$router.replace({ name: 'BookPreview' });
  37. }
  38. })
  39. .catch(() => {});
  40. },
  41. // 判断当前是web端还是手机端
  42. isMobile() {
  43. const userAgent = navigator.userAgent || navigator.vendor || window.opera;
  44. return /android|iphone|ipad|ipod/i.test(userAgent);
  45. },
  46. },
  47. };
  48. </script>
  49. <style lang="scss" scoped></style>