Explorar o código

feat: 下载目录册模块,逻辑已完成部分v1.1

chenpeng hai 2 semanas
pai
achega
9c1db872b1
Modificáronse 2 ficheiros con 19 adicións e 1 borrados
  1. 2 1
      pages/categories/[slug].vue
  2. 17 0
      utils/common/download.ts

+ 2 - 1
pages/categories/[slug].vue

@@ -8,7 +8,8 @@ const list = [
     title: 'Stationary & Office Supplies',
     description: 'Discover bestsellers and fresh arrivals tailored to your niche.',
     img: 'https://picsum.photos/560/310',
-    pdfUrl: 'https://static.ejetselection.com/temp/导入模板2222_1736660213488.xlsx',
+    pdfUrl: 'https://static.ejetselection.com/temp/baozhen_1748937135247.pdf',
+    // pdfUrl: 'https://static.ejetselection.com/temp/导入模板2222_1736660213488.xlsx',
     type: 'download',
   },
   {

+ 17 - 0
utils/common/download.ts

@@ -36,3 +36,20 @@ export async function downloadFile(url: string, name: string) {
     console.error(error)
   }
 }
+/**
+ * 下载文件
+ * @returns
+ */
+export async function downloadFileA(url: string, name: string) {
+  try {
+    const link = document.createElement('a')
+    link.href = url
+    link.download = name
+    document.body.appendChild(link)
+    link.click()
+    document.body.removeChild(link)
+  }
+  catch (error) {
+    console.log(error)
+  }
+}