Skip to content

Commit

Permalink
feat: add file download demo
Browse files Browse the repository at this point in the history
  • Loading branch information
anncwb committed Nov 12, 2020
1 parent 1d45617 commit db3092d
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- 菜单新增 tag 显示,支持 4 中类型颜色及 dot 圆点显示
- 新增菜单及顶栏颜色选择配色
- 增加示例结果页
- 新增文件下载示例

### ⚡ Wip

Expand Down
2 changes: 2 additions & 0 deletions src/components/registerGlobComp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {

// Optional
Select,
Alert,
Checkbox,
DatePicker,
Radio,
Expand Down Expand Up @@ -48,6 +49,7 @@ export function registerGlobComp() {
// If you don’t need it, you can delete it
getApp()
.use(Select)
.use(Alert)
.use(Checkbox)
.use(DatePicker)
.use(Radio)
Expand Down
10 changes: 10 additions & 0 deletions src/router/menus/modules/demo/feat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ const menu: MenuModule = {
menu: {
name: '功能',
path: '/feat',
tag: {
dot: true,
},
children: [
{
path: 'icon',
Expand All @@ -17,6 +20,13 @@ const menu: MenuModule = {
path: 'context-menu',
name: '右键菜单',
},
{
path: 'download',
name: '文件下载',
tag: {
content: 'new',
},
},
{
path: 'click-out-side',
name: 'ClickOutSide',
Expand Down
8 changes: 8 additions & 0 deletions src/router/routes/modules/demo/feat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ const feat: AppRouteModule = {
title: '右键菜单',
},
},
{
path: '/download',
name: 'DownLoadDemo',
component: () => import('/@/views/demo/feat/download/index.vue'),
meta: {
title: '文件下载',
},
},
{
path: '/click-out-side',
name: 'ClickOutSideDemo',
Expand Down
1 change: 1 addition & 0 deletions src/utils/file/FileDownload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export function downloadByData(data: BlobPart, filename: string, mime?: string,
window.URL.revokeObjectURL(blobURL);
}
}

/**
* 根据文件地址下载文件
* @param {*} sUrl
Expand Down
32 changes: 32 additions & 0 deletions src/views/demo/feat/download/index.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<template>
<div class="m-5 demo-box">
<a-alert message="根据后台接口文件流下载" />
<a-button type="primary" class="my-4" @click="handleDownByData"> 文件流下载 </a-button>

<a-alert message="根据文件地址下载文件" />

<a-button type="primary" class="my-4" @click="handleDownloadByUrl"> 文件地址下载 </a-button>
</div>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
import { downloadByUrl, downloadByData } from '/@/utils/file/FileDownload';
export default defineComponent({
setup() {
function handleDownByData() {
downloadByData('text content', 'testName.txt');
}
function handleDownloadByUrl() {
downloadByUrl({
url: 'https://codeload.github.com/anncwb/vue-vben-admin-doc/zip/master',
target: '_self',
});
}
return {
handleDownloadByUrl,
handleDownByData,
};
},
});
</script>

0 comments on commit db3092d

Please sign in to comment.