vben
2020-11-13 db3092db2eb7d5346778847757adb2b9c4041ed5
feat: add file download demo
1个文件已添加
5个文件已修改
54 ■■■■■ 已修改文件
CHANGELOG.zh_CN.md 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/components/registerGlobComp.ts 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/router/menus/modules/demo/feat.ts 10 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/router/routes/modules/demo/feat.ts 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/utils/file/FileDownload.ts 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/demo/feat/download/index.vue 32 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
CHANGELOG.zh_CN.md
@@ -12,6 +12,7 @@
- 菜单新增 tag 显示,支持 4 中类型颜色及 dot 圆点显示
- 新增菜单及顶栏颜色选择配色
- 增加示例结果页
- 新增文件下载示例
### ⚡ Wip
src/components/registerGlobComp.ts
@@ -6,6 +6,7 @@
  // Optional
  Select,
  Alert,
  Checkbox,
  DatePicker,
  Radio,
@@ -48,6 +49,7 @@
  // If you don’t need it, you can delete it
  getApp()
    .use(Select)
    .use(Alert)
    .use(Checkbox)
    .use(DatePicker)
    .use(Radio)
src/router/menus/modules/demo/feat.ts
@@ -4,6 +4,9 @@
  menu: {
    name: '功能',
    path: '/feat',
    tag: {
      dot: true,
    },
    children: [
      {
        path: 'icon',
@@ -18,6 +21,13 @@
        name: '右键菜单',
      },
      {
        path: 'download',
        name: '文件下载',
        tag: {
          content: 'new',
        },
      },
      {
        path: 'click-out-side',
        name: 'ClickOutSide',
      },
src/router/routes/modules/demo/feat.ts
@@ -41,6 +41,14 @@
      },
    },
    {
      path: '/download',
      name: 'DownLoadDemo',
      component: () => import('/@/views/demo/feat/download/index.vue'),
      meta: {
        title: '文件下载',
      },
    },
    {
      path: '/click-out-side',
      name: 'ClickOutSideDemo',
      component: () => import('/@/views/demo/feat/click-out-side/index.vue'),
src/utils/file/FileDownload.ts
@@ -25,6 +25,7 @@
    window.URL.revokeObjectURL(blobURL);
  }
}
/**
 * 根据文件地址下载文件
 * @param {*} sUrl
src/views/demo/feat/download/index.vue
New file
@@ -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>