App.vue 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <template>
  2. <div id="app">
  3. <router-view v-if="isRouterAlive" />
  4. </div>
  5. </template>
  6. <script>
  7. export default {
  8. name: 'App',
  9. provide() {
  10. return {
  11. reload: this.reload,
  12. };
  13. },
  14. watch: {
  15. // 监听 $route 对象的变化
  16. '$route'(to, from) {
  17. // 防止重复判断设备
  18. if (this.deviceType =='PC'){
  19. return;
  20. }
  21. //排出手机扫码验证页面
  22. if (to.path!="/prod/validate"){
  23. this.detectDeviceType();
  24. }
  25. }
  26. },
  27. data() {
  28. return {
  29. isRouterAlive: true,
  30. deviceType:null
  31. };
  32. },
  33. created() {
  34. // 在组件创建时检测设备类型
  35. //this.detectDeviceType();
  36. },
  37. methods: {
  38. reload() {
  39. this.isRouterAlive = false;
  40. this.$nextTick(function () {
  41. this.isRouterAlive = true;
  42. });
  43. //this.noreadCounts()
  44. },
  45. // 监听访问网页的设备类型
  46. detectDeviceType() {
  47. const userAgent = navigator.userAgent;
  48. // 判断是否是移动端设备的一般方法
  49. const isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(userAgent);
  50. if (isMobile) {
  51. // 跳转到移动端
  52. window.location.replace(process.env.VUE_APP_MOBILE);
  53. }else{
  54. this.deviceType='PC';
  55. }
  56. },
  57. },
  58. components: {},
  59. };
  60. </script>
  61. <style lang="scss" scoped>
  62. #app {
  63. }
  64. #nav {
  65. padding: 30px;
  66. a {
  67. font-weight: bold;
  68. color: #2c3e50;
  69. &.router-link-exact-active {
  70. color: #42b983;
  71. }
  72. }
  73. }
  74. .el-table th.gutter {
  75. display: table-cell !important;
  76. }
  77. </style>