App.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <template>
  2. <div id="app">
  3. <div class="mobile" v-if="mobile">
  4. <a-result status="warning" title="使用电脑访问页面" class="mid">
  5. <template #subtitle>
  6. 该网页专为电脑用户打造,使用电脑访问页面可获得最佳体验。您也可继续使用移动设备访问
  7. </template>
  8. <template #extra>
  9. <a-space>
  10. <a-button type='primary' @click="mobileGoOn">继续访问</a-button>
  11. </a-space>
  12. </template>
  13. </a-result>
  14. </div>
  15. <router-view></router-view>
  16. </div>
  17. </template>
  18. <script setup>
  19. import { ref, onMounted } from 'vue'
  20. import storage from 'store'
  21. import { Modal, Message } from '@arco-design/web-vue'
  22. import { getAppVersion } from '@/api/public'
  23. const mobile = ref(false)
  24. function checkMobile() {
  25. const isMobileWidth = window.innerWidth <= 768
  26. const ua = navigator.userAgent.toLowerCase()
  27. const isMobileUA = /android|iphone|ipad|ipod|windows phone/i.test(ua)
  28. if (isMobileWidth || isMobileUA) {
  29. const mobileShow = storage.get('mobileShow')
  30. if (!mobileShow)
  31. mobile.value = true
  32. }
  33. }
  34. function mobileGoOn() {
  35. mobile.value = false
  36. storage.set('mobileShow', true)
  37. }
  38. async function GetAppVersion() {
  39. try {
  40. const current = import.meta.env.VITE_APP_VERSION
  41. const res = await getAppVersion()
  42. if (!res || res.code !== 0 || !res.data)
  43. return Message.error(`获取版本更新内容失败!${res?.msg ?? ''}`)
  44. if (res.data.version === current) return
  45. Modal.info({
  46. title: '版本更新',
  47. escToClose: false,
  48. maskClosable: false,
  49. width: '300px',
  50. content: `发现新版本,是否立即刷新页面?\n${res.data?.msg ?? ''}`,
  51. onBeforeOk: () => {
  52. window.location.reload()
  53. }
  54. })
  55. } catch (error) {
  56. Message.error('获取版本更新内容失败')
  57. }
  58. }
  59. onMounted(() => {
  60. // checkMobile()
  61. GetAppVersion()
  62. })
  63. </script>
  64. <style scoped>
  65. .mobile {
  66. position: absolute;
  67. top: 0;
  68. left: 0;
  69. z-index: 999;
  70. width: 100%;
  71. height: 100%;
  72. background-color: white;
  73. }
  74. .mid {
  75. position: absolute;
  76. top: 50%;
  77. transform: translateY(-50%);
  78. }
  79. </style>