jinx hai 4 meses
pai
achega
dcf34e6349

+ 5 - 1
packages/web/src/pages/showdoc/[id].vue

@@ -288,6 +288,10 @@ watchEffect(() => {
 
 const handleToArticle = (article: ArticleDetailType) => {
   console.log('article', article)
+  if (!article) {
+    return
+  }
+  
   router.replace(`/showdoc/${article.id}`)
   setTimeout(() => {
     location.reload()
@@ -483,7 +487,7 @@ const handleBreadcrumb = (bread: TreeNode) => {
           color: #000000;
           line-height: 0.48rem;
         }
-        video{
+        video {
           width: 100%;
           height: auto;
         }

+ 7 - 1
packages/web/src/plugins/router.ts

@@ -7,5 +7,11 @@ const router = createRouter({
   history: createWebHistory(import.meta.env.BASE_URL),
   routes: setupLayouts(routes),
 })
-
+router.beforeEach((to, from, next) => {
+  // 检查是否需要滚动到顶部
+  if (to.meta.scrollToTop !== false) {
+    window.scrollTo(0, 0) // 滚动到顶部
+  }
+  next()
+})
 export default router

+ 0 - 405
packages/web/src/utils/browser.ts

@@ -1,127 +1,4 @@
-function mobileVersion(e, t) {
-  //ios的版本
-  var i = window.navigator.userAgent,
-    n = i.match(e)
-  return (
-    (n = n ? n[1].split(t) : []),
-    {
-      major: parseInt(n[0]) || 0,
-      minor: parseInt(n[1]) || 0,
-      patch: parseInt(n[2]) || 0,
-    }
-  )
-}
 var browser = {
-  changeURLArg: function (url, arg, arg_val) {
-    var pattern = arg + '=([^&]*)'
-    var replaceText = arg + '=' + arg_val
-    if (url.match(pattern)) {
-      var tmp = '/(' + arg + '=)([^&]*)/gi'
-      tmp = url.replace(eval(tmp), replaceText)
-      return tmp
-    } else {
-      if (url.match('[?]')) {
-        return url + '&' + replaceText
-      } else {
-        return url + '?' + replaceText
-      }
-    }
-  },
-
-  isFullscreen: function () {
-    return (
-      document.fullscreenElement ||
-      document.mozFullscreenElement ||
-      document.mozFullScreenElement ||
-      document.webkitFullscreenElement ||
-      document.msFullscreenElement
-    )
-  },
-  supportsFullscreen: function () {
-    return (
-      document.fullscreenEnabled ||
-      document.mozFullscreenEnabled ||
-      document.mozFullScreenEnabled ||
-      document.webkitFullscreenEnabled ||
-      document.msFullscreenEnabled
-    )
-  },
-  isPointerLocked: function () {
-    return (
-      document.pointerLockElement ||
-      document.mozPointerLockElement ||
-      document.webkitPointerLockElement
-    )
-  },
-  requestFullscreen: function (dom, t) {
-    dom.requestFullscreen
-      ? dom.requestFullscreen()
-      : dom.mozRequestFullScreen
-        ? dom.mozRequestFullScreen()
-        : dom.webkitRequestFullscreen
-          ? dom.webkitRequestFullscreen(Element.ALLOW_KEYBOARD_INPUT)
-          : dom.msRequestFullscreen && dom.msRequestFullscreen(),
-      t &&
-        $(document).on(
-          'fullscreenchange webkitfullscreenchange mozfullscreenchange MSFullscreenChange',
-          browser.requestPointerLock,
-        )
-  },
-  requestPointerLock: function () {
-    var e
-    if (document.fullscreenElement) e = document.fullscreenElement()
-    else if (document.mozFullscreenElement) e = document.mozFullscreenElement()
-    else if (document.mozFullScreenElement) e = document.mozFullScreenElement()
-    else {
-      if (!document.webkitFullscreenElement) return
-      e = document.webkitFullscreenElement()
-    }
-    ;(e.requestPointerLock =
-      e.requestPointerLock || e.mozRequestPointerLock || e.webkitRequestPointerLock),
-      e.requestPointerLock(),
-      $(document).off(
-        'fullscreenchange webkitfullscreenchange mozfullscreenchange MSFullscreenChange',
-        this,
-      )
-  },
-  exitPointerLock: function () {
-    ;(document.exitPointerLock =
-      document.exitPointerLock || document.mozExitPointerLock || document.webkitExitPointerLock),
-      document.exitPointerLock()
-  },
-  exitFullscreen: function () {
-    document.exitFullscreen
-      ? document.exitFullscreen()
-      : document.msExitFullscreen
-        ? document.msExitFullscreen()
-        : document.mozCancelFullScreen
-          ? document.mozCancelFullScreen()
-          : document.webkitExitFullscreen && document.webkitExitFullscreen()
-  },
-  details: function () {
-    var e = navigator.userAgent.match('(Firefox|Chrome|Safari)/([\\d]+)')
-    return e
-      ? {
-          name: e[1],
-          version: parseInt(e[2]),
-          platform: navigator.platform,
-        }
-      : {}
-  },
-  is: function (e) {
-    return this.details() && this.details().name === e
-  },
-  inIframe: function () {
-    return window.parent !== window
-  },
-  aspectRatio: function ($elem) {
-    $elem = $elem || $('#player')
-    var e = $elem.width() / $elem.height()
-    return isFinite(e) ? e : 0
-  },
-  userAgent: function () {
-    return window.navigator.userAgent
-  },
   isMobile: function () {
     var e = navigator.userAgent || navigator.vendor || window.opera
     return (
@@ -133,288 +10,6 @@ var browser = {
       )
     )
   },
-  isLandscape: function () {
-    return this.isMobile && this.aspectRatio() > 1
-  },
-  isSmallScreen: function () {
-    var e = screen.width / window.devicePixelRatio
-    return e < 240
-  },
-  detectIE: function () {
-    var e = window.navigator.userAgent,
-      t = e.indexOf('MSIE ')
-    return t !== -1 || !!navigator.userAgent.match(/Trident.*rv\:11\./)
-  },
-  detectSafari: function () {
-    var e = window.navigator.userAgent,
-      t = e.indexOf('Safari')
-    return t !== -1 && !this.detectOpera() && !this.detectChrome() //xzw add detectOpera
-  },
-  detectFirefox: function () {
-    var e = window.navigator.userAgent
-    return e.indexOf('Firefox') !== -1
-  },
-  detectChrome: function () {
-    var e = window.navigator.userAgent
-    return e.indexOf('Chrome') !== -1 && !this.detectOpera()
-  },
-  detectOpera: function () {
-    var e = window.navigator.userAgent
-    return e.indexOf('OPR') !== -1
-  },
-  detectApp: function () {
-    return this.hasURLParam('app')
-  },
-  detectPad: function () {
-    return this.hasURLParam('pad')
-  },
-  detectIOS: function () {
-    return this.detectIPhone() || this.detectIPad() || this.detectIPod()
-  },
-  detectIPad: function () {
-    if (window.navigator.platform === 'MacIntel' && window.navigator.maxTouchPoints > 1) {
-      return true
-    }
-    var e = window.navigator.userAgent,
-      t = /iPad/
-    return t.test(e)
-  },
-  detectIPod: function () {
-    var e = window.navigator.userAgent,
-      t = /iPod/
-    return t.test(e)
-  },
-  detectIPhone: function () {
-    var e = window.navigator.userAgent,
-      t = /iPhone/
-    return t.test(e)
-  },
-  detectAndroid: function () {
-    var e = window.navigator.userAgent
-    return e.indexOf('Android') !== -1
-  },
-  detectAndroidMobile: function () {
-    var e = window.navigator.userAgent
-    return this.detectAndroid() && e.indexOf('Mobile') !== -1
-  },
-  detectSamsungNative: function () {
-    var e = window.navigator.userAgent
-    return (
-      e.indexOf('SM-G900H') !== -1 || e.indexOf('GT-I9500') !== -1 || e.indexOf('SM-N900') !== -1
-    )
-  },
-  detectSamsungS6: function () {
-    var e = window.navigator.userAgent
-    return e.indexOf('SM-G92') !== -1
-  },
-  /************************************************************徐世廷*************************************************************/
-  detectHUAWEI5X: function () {
-    return -1 !== window.navigator.userAgent.indexOf('KIW-TL00H')
-  },
-  /*******************************************************************************************************************************/
-  detectWebVR: function () {
-    return !(!window.navigator.getVRDisplays || !window.VRDisplay)
-  },
-  getVRDisplay: function () {
-    var e = $.Deferred()
-    return this.detectWebVR()
-      ? (navigator.getVRDisplays().then(function (t) {
-          t.length >= 1 && e.resolve(t[0]), e.reject(null)
-        }),
-        e)
-      : e.reject(null)
-  },
-  iosVersion: function () {
-    if (!this.detectIOS()) throw new DeviceMismatchException('Did not detect an iDevice')
-    var e = /((?:\d+\_?){1,3}) like Mac OS/,
-      t = '_'
-    return mobileVersion(e, t)
-  },
-  androidVersion: function () {
-    if (!this.detectAndroid())
-      throw new DeviceMismatchException('Did not detect an Android based device')
-    var e = /Android ((?:\d+\.?){1,3})/,
-      t = '.'
-    return mobileVersion(e, t)
-  },
-  valueFromCookie: function (e, t) {
-    var i = new RegExp(e + '=([0-9a-f]+)(; ?|$)').exec(document.cookie)
-    if (!i) return t
-    var n = i[1]
-    return 'boolean' == typeof t
-      ? 'true' === n || '1' === n
-      : 'number' == typeof t
-        ? parseFloat(n)
-        : n
-  },
-  valueFromHash: function (e, t) {
-    var i = new RegExp('[#&?]' + e + '=([^#&?]*)'),
-      n = i.exec(window.location.href)
-    if (!n) return t
-    var r = n[1]
-    return 'boolean' == typeof t
-      ? 'true' === r || '1' === r
-      : 'number' == typeof t
-        ? parseFloat(r)
-        : window.decodeURIComponent(r)
-  },
-  //-------许钟文:-------------------------------------------------
-
-  getProjectNum: function () {
-    //获取场景projectNum
-
-    if (window.__ProjectNum && window.__ProjectNum != '__ProjectNum__') {
-      return window.__ProjectNum
-    }
-
-    var number = window.location.href.substring(window.location.href.indexOf('=') + 1)
-    if (number.indexOf('&') != -1) {
-      number = number.substring(0, number.indexOf('&'))
-    }
-    if (number.indexOf('#') != -1) {
-      number = number.substring(0, number.indexOf('#'))
-    }
-    return number
-  },
-
-  getLang() {
-    return this.getURLParam('lang') || 'zh'
-  },
-
-  urlHasValue: function (key, isGetValue) {
-    // debugger
-    // if (getValue) { //得到类似n=1 的 1
-    //     var b = window.location.href.substring(window.location.href.indexOf("?") + 1);
-    //     var a = b.indexOf('&' + t + "=");
-    //     if (a > -1) {
-    //         var s = b.substring(a + ('&' + t + "=").length);
-    //         s.indexOf("&") > -1 && (s = s.substring(0, s.indexOf("&")));
-    //         s.indexOf("#") > -1 && (s = s.substring(0, s.indexOf("#")));
-    //         return s;
-    //     } else return false;
-    // } else return window.location.search.match("&" + t + "|\\?" + t) != null; //window.location.href.substring(window.location.href.indexOf("?") + 1).indexOf('&' + t) > -1;
-
-    //const value = window.location.search.match("&" + t + "|\\?" + t)
-
-    if (key === 'm' && window.__ProjectNum && window.__ProjectNum != '__ProjectNum__') {
-      return window.__ProjectNum
-    }
-
-    let querys = window.location.search.substr(1).split('&')
-    if (isGetValue) {
-      for (let i = 0; i < querys.length; i++) {
-        let keypair = querys[i].split('=')
-        if (keypair.length === 2 && keypair[0] === key) {
-          return keypair[1]
-        }
-      }
-      return ''
-    } else {
-      //return window.location.search.match("&" + key + "|\\?" + key) != null  有bug
-      for (let i = 0; i < querys.length; i++) {
-        let keypair = querys[i].split('=')
-        if (keypair[0] == key) {
-          return true
-        }
-      }
-      return false
-    }
-  },
-  /**
-   * 获取查询参数的值
-   * @param {String} key
-   * @returns String
-   */
-  urlQueryValue(key) {
-    return this.urlHasValue(key, true) || ''
-  },
-  /**
-   * 获取hash参数的值
-   * @param {String} key
-   * @returns String
-   */
-  urlHashValue(key) {
-    let querys = window.location.hash.substr(1).replace('/?', '').split('&')
-    for (let i = 0; i < querys.length; i++) {
-      let keypair = querys[i].split('=')
-
-      if (keypair.length === 2 && keypair[0] === key) {
-        return keypair[1]
-      }
-    }
-    return ''
-  },
-  /**
-   * 判断是否存在hash
-   * @param {String} key
-   * @returns Boolean
-   */
-  urlIsHasHash(key) {
-    let querys = window.location.hash.substr(1).replace('/?', '').split('&')
-    return querys.includes(key)
-  },
-  islongPhone: function () {
-    //是否是刘海全面屏幕 仅仅根据比例判断 - -
-    //screen.height == 812 && screen.width == 375)
-    var r = screen.height / screen.width //可能横屏
-    return this.isMobile() && (r > 1.99 || r < 0.502512) //18/9=2.165   //???
-  },
-  detectWeixin: function () {
-    //微信 包括PC的微信
-    return window.navigator.userAgent.toLowerCase().match(/MicroMessenger/i) == 'micromessenger'
-  },
-  detectWeixinMiniProgram: function () {
-    return window.navigator.userAgent.match('miniProgram')
-  },
-  detectAlipay: function () {
-    //微信 包括PC的微信
-    return window.navigator.userAgent.toLowerCase().match(/Alipay/i) == 'alipay'
-  },
-  detectEdge: function () {
-    return window.navigator.userAgent.indexOf('Edge') > -1
-  },
-  // detectApp: function () {
-  //     return this.urlHasValue('app')
-  // },
-
-  /**
-   * 判断标签页是否切换状态
-   */
-  isTabHidden: function () {
-    var prefixes = ['webkit', 'moz', 'ms', 'o']
-
-    if ('hidden' in document) return document.hidden
-
-    for (var i = 0; i < prefixes.length; i++) {
-      if (prefixes[i] + 'Hidden' in document) return document[prefixes[i] + 'Hidden']
-    }
-
-    return false
-  },
-  hasURLParam: function (key) {
-    let querys = window.location.search.substring(1).split('&')
-    for (let i = 0; i < querys.length; i++) {
-      let keypair = querys[i].split('=')
-      if (keypair[0] == key) {
-        return true
-      }
-    }
-    return false
-  },
-  getURLParam: function (key) {
-    let querys = window.location.search.substring(1).split('&')
-    for (let i = 0; i < querys.length; i++) {
-      let keypair = querys[i].split('=')
-      if (keypair.length === 2 && keypair[0] === key) {
-        try {
-          return decodeURIComponent(keypair[1])
-        } catch (error) {
-          return keypair[1]
-        }
-      }
-    }
-    return ''
-  },
 }
 
 export default browser