zhb il y a 1 mois
Parent
commit
b0f9356831
3 fichiers modifiés avec 50 ajouts et 24 suppressions
  1. 32 9
      components/cwg-page-wrapper.vue
  2. 1 1
      pages/common/webview.vue
  3. 17 14
      utils/pdf.js

+ 32 - 9
components/cwg-page-wrapper.vue

@@ -228,7 +228,7 @@ const pushRes = (data: any) => {
 
 //获取推送列表
 const searchPush = async () => {
-  if(!userToken.value) return
+  if (!userToken.value) return
   let res = await customApi.PushMessageList({ type: null });
   if (res.code == 200) {
     if (res.data == null) {
@@ -242,7 +242,7 @@ const searchPush = async () => {
 }
 //获取原因列表
 const searchReasons = async () => {
-  if(!userToken.value) return
+  if (!userToken.value) return
   let res = await customApi.reasonsRefusalList({ type: null });
   if (res.code == 200) {
     if (res.data == null) {
@@ -294,22 +294,45 @@ function openRightDrawer() {
 
 const sidebarVisible = ref(false)
 const maskVisible = ref(false)
+let sidebarTimer: any = null
+let isAnimating = ref(false)
+
+function debounce<T extends (...args: any[]) => void>(fn: T, delay: number): T {
+  let timer: any = null
+  return ((...args: any[]) => {
+    if (timer) clearTimeout(timer)
+    timer = setTimeout(() => fn(...args), delay)
+  }) as T
+}
+
+const toggleSidebar = debounce(() => {
+  if (isAnimating.value) return
+
+  isAnimating.value = true
 
-function openLeftDrawer() {
-  // 真正显示时 → 关闭
   if (maskVisible.value) {
     maskVisible.value = false
-    setTimeout(() => {
+    sidebarTimer = setTimeout(() => {
       sidebarVisible.value = false
+      isAnimating.value = false
+      sidebarTimer = null
     }, 200)
-  }
-  // 隐藏时 → 打开
-  else {
+  } else {
     sidebarVisible.value = true
-    setTimeout(() => {
+    sidebarTimer = setTimeout(() => {
       maskVisible.value = true
+      isAnimating.value = false
+      sidebarTimer = null
     }, 200)
   }
+}, 300)
+
+function openLeftDrawer() {
+  if (sidebarTimer) {
+    clearTimeout(sidebarTimer)
+    sidebarTimer = null
+  }
+  toggleSidebar()
 }
 
 function handleDrawerNavigate(path: string) {

+ 1 - 1
pages/common/webview.vue

@@ -33,7 +33,7 @@ const webviewStyles = computed(() => ({
   progress: {
     color: '#ea002a'
   },
-  top: statusBarHeight.value  + 'px',
+  top: statusBarHeight.value + 56 + 'px',
   bounce: 'none',
   scrollIndicator: 'none'
 }))

+ 17 - 14
utils/pdf.js

@@ -2,28 +2,31 @@ import Config from '@/config/index'
 const { Host80 } = Config
 import getWebBase from '@/utils/webBase'
 const webBase = getWebBase()
-// utils/pdf.js 或直接在组件 methods 中定义
+
+// 打开 PDF 文件(修复 URL 编码问题)
 export function openLocalPdf(fileName, title, type = 'pdf') {
-  // #ifdef H5
-  // H5 端直接打开相对路径,会被浏览器渲染或下载(取决于浏览器配置)
+  // 最终要跳转的 url
+  let targetUrl = ''
+
+  // 拼接地址
   if (type === 'pdf') {
-    window.open(`${Host80}${webBase}static/${fileName}`);
+    targetUrl = `${Host80}/${fileName}`
   } else if (type === 'pdf1') {
-    window.open(`${fileName}`);
+    targetUrl = fileName
   }
 
-  // #endif
+  // 传递给 webview(只编码一次,正确格式)
+  const webviewUrl = `/pages/common/webview?url=${encodeURIComponent(targetUrl)}&title=${encodeURIComponent(title)}`
 
-  // #ifdef APP-PLUS
-  // App 端:将静态资源路径转为系统绝对路径,再用 uni.openDocument 调用系统阅读器打开
+  // #ifdef H5
   if (type === 'pdf') {
-    uni.navigateTo({
-      url: `/pages/common/webview?url=${encodeURIComponent(`${Host80}${webBase}static/${fileName}`)}&title=${title}`
-    });
+    window.open(targetUrl)
   } else if (type === 'pdf1') {
-    uni.navigateTo({
-      url: `/pages/common/webview?url=${encodeURIComponent(`${fileName}`)}&title=${title}`
-    });
+    window.open(targetUrl)
   }
   // #endif
+
+  // #ifdef APP-PLUS
+  uni.navigateTo({ url: webviewUrl })
+  // #endif
 }