Commit db3092db2eb7d5346778847757adb2b9c4041ed5
1 parent
1d45617e
feat: add file download demo
Showing
6 changed files
with
54 additions
and
0 deletions
CHANGELOG.zh_CN.md
src/components/registerGlobComp.ts
@@ -6,6 +6,7 @@ import { | @@ -6,6 +6,7 @@ import { | ||
6 | 6 | ||
7 | // Optional | 7 | // Optional |
8 | Select, | 8 | Select, |
9 | + Alert, | ||
9 | Checkbox, | 10 | Checkbox, |
10 | DatePicker, | 11 | DatePicker, |
11 | Radio, | 12 | Radio, |
@@ -48,6 +49,7 @@ export function registerGlobComp() { | @@ -48,6 +49,7 @@ export function registerGlobComp() { | ||
48 | // If you don’t need it, you can delete it | 49 | // If you don’t need it, you can delete it |
49 | getApp() | 50 | getApp() |
50 | .use(Select) | 51 | .use(Select) |
52 | + .use(Alert) | ||
51 | .use(Checkbox) | 53 | .use(Checkbox) |
52 | .use(DatePicker) | 54 | .use(DatePicker) |
53 | .use(Radio) | 55 | .use(Radio) |
src/router/menus/modules/demo/feat.ts
@@ -4,6 +4,9 @@ const menu: MenuModule = { | @@ -4,6 +4,9 @@ const menu: MenuModule = { | ||
4 | menu: { | 4 | menu: { |
5 | name: '功能', | 5 | name: '功能', |
6 | path: '/feat', | 6 | path: '/feat', |
7 | + tag: { | ||
8 | + dot: true, | ||
9 | + }, | ||
7 | children: [ | 10 | children: [ |
8 | { | 11 | { |
9 | path: 'icon', | 12 | path: 'icon', |
@@ -18,6 +21,13 @@ const menu: MenuModule = { | @@ -18,6 +21,13 @@ const menu: MenuModule = { | ||
18 | name: '右键菜单', | 21 | name: '右键菜单', |
19 | }, | 22 | }, |
20 | { | 23 | { |
24 | + path: 'download', | ||
25 | + name: '文件下载', | ||
26 | + tag: { | ||
27 | + content: 'new', | ||
28 | + }, | ||
29 | + }, | ||
30 | + { | ||
21 | path: 'click-out-side', | 31 | path: 'click-out-side', |
22 | name: 'ClickOutSide', | 32 | name: 'ClickOutSide', |
23 | }, | 33 | }, |
src/router/routes/modules/demo/feat.ts
@@ -41,6 +41,14 @@ const feat: AppRouteModule = { | @@ -41,6 +41,14 @@ const feat: AppRouteModule = { | ||
41 | }, | 41 | }, |
42 | }, | 42 | }, |
43 | { | 43 | { |
44 | + path: '/download', | ||
45 | + name: 'DownLoadDemo', | ||
46 | + component: () => import('/@/views/demo/feat/download/index.vue'), | ||
47 | + meta: { | ||
48 | + title: '文件下载', | ||
49 | + }, | ||
50 | + }, | ||
51 | + { | ||
44 | path: '/click-out-side', | 52 | path: '/click-out-side', |
45 | name: 'ClickOutSideDemo', | 53 | name: 'ClickOutSideDemo', |
46 | component: () => import('/@/views/demo/feat/click-out-side/index.vue'), | 54 | component: () => import('/@/views/demo/feat/click-out-side/index.vue'), |
src/utils/file/FileDownload.ts
@@ -25,6 +25,7 @@ export function downloadByData(data: BlobPart, filename: string, mime?: string, | @@ -25,6 +25,7 @@ export function downloadByData(data: BlobPart, filename: string, mime?: string, | ||
25 | window.URL.revokeObjectURL(blobURL); | 25 | window.URL.revokeObjectURL(blobURL); |
26 | } | 26 | } |
27 | } | 27 | } |
28 | + | ||
28 | /** | 29 | /** |
29 | * 根据文件地址下载文件 | 30 | * 根据文件地址下载文件 |
30 | * @param {*} sUrl | 31 | * @param {*} sUrl |
src/views/demo/feat/download/index.vue
0 → 100644
1 | +<template> | ||
2 | + <div class="m-5 demo-box"> | ||
3 | + <a-alert message="根据后台接口文件流下载" /> | ||
4 | + <a-button type="primary" class="my-4" @click="handleDownByData"> 文件流下载 </a-button> | ||
5 | + | ||
6 | + <a-alert message="根据文件地址下载文件" /> | ||
7 | + | ||
8 | + <a-button type="primary" class="my-4" @click="handleDownloadByUrl"> 文件地址下载 </a-button> | ||
9 | + </div> | ||
10 | +</template> | ||
11 | +<script lang="ts"> | ||
12 | + import { defineComponent } from 'vue'; | ||
13 | + import { downloadByUrl, downloadByData } from '/@/utils/file/FileDownload'; | ||
14 | + | ||
15 | + export default defineComponent({ | ||
16 | + setup() { | ||
17 | + function handleDownByData() { | ||
18 | + downloadByData('text content', 'testName.txt'); | ||
19 | + } | ||
20 | + function handleDownloadByUrl() { | ||
21 | + downloadByUrl({ | ||
22 | + url: 'https://codeload.github.com/anncwb/vue-vben-admin-doc/zip/master', | ||
23 | + target: '_self', | ||
24 | + }); | ||
25 | + } | ||
26 | + return { | ||
27 | + handleDownloadByUrl, | ||
28 | + handleDownByData, | ||
29 | + }; | ||
30 | + }, | ||
31 | + }); | ||
32 | +</script> |