rjy 4 years ago
parent
commit
a1d99c0af8
2 changed files with 36 additions and 3 deletions
  1. 3 1
      package.json
  2. 33 2
      src/views/new-plan/detail.vue

+ 3 - 1
package.json

@@ -18,6 +18,7 @@
     "core-js": "^3.4.4",
     "echarts": "^4.8.0",
     "element-ui": "^2.13.0",
+    "file-saver": "^2.0.2",
     "lodash": "^4.17.15",
     "moment": "^2.27.0",
     "naf-core": "^0.1.2",
@@ -26,7 +27,8 @@
     "vue-meta": "^2.4.0",
     "vue-router": "^3.3.4",
     "vuex": "^3.1.2",
-    "wangeditor": "^3.1.1"
+    "wangeditor": "^3.1.1",
+    "xlsx": "^0.16.5"
   },
   "devDependencies": {
     "@vue/cli-plugin-babel": "^4.1.0",

+ 33 - 2
src/views/new-plan/detail.vue

@@ -1,7 +1,19 @@
 <template>
   <div id="detail">
     <list-frame :title="pageTitle" returns="./index" :needFilter="false" :needPag="false" :needAdd="false">
-      <data-table :fields="fields" :data="list" :opera="opera" :usePage="false" @namelist="toNamelist" @view="toView" :toFormat="toFormat"></data-table>
+      <el-col class="mb">
+        <el-button type="primary" @click="exportExcel()">下载上传名单模板</el-button>
+      </el-col>
+      <data-table
+        id="out-table"
+        :fields="fields"
+        :data="list"
+        :opera="opera"
+        :usePage="false"
+        @namelist="toNamelist"
+        @view="toView"
+        :toFormat="toFormat"
+      ></data-table>
     </list-frame>
     <el-dialog :visible.sync="dialog" title="上传名单" width="30%">
       <el-form size="mini">
@@ -23,6 +35,8 @@
 
 <script>
 import _ from 'lodash';
+import FileSaver from 'file-saver';
+import XLSX from 'xlsx';
 import listFrame from '@frame/layout/admin/list-frame';
 import dataTable from '@frame/components/filter-page-table';
 import { mapState, createNamespacedHelpers } from 'vuex';
@@ -79,6 +93,19 @@ export default {
     ...imports(['create']),
     ...schPlan(['update']),
     ...util(['fetch']),
+    // 导出功能
+    exportExcel() {
+      /* generate workbook object from table */
+      var wb = XLSX.utils.table_to_book(document.querySelector('#out-table'));
+      /* get binary string as output */
+      var wbout = XLSX.write(wb, { bookType: 'xlsx', bookSST: true, type: 'array' });
+      try {
+        FileSaver.saveAs(new Blob([wbout], { type: 'application/octet-stream' }), 'sheetjs.xlsx');
+      } catch (e) {
+        if (typeof console !== 'undefined') console.log(e, wbout);
+      }
+      return wbout;
+    },
     async search() {
       let tp = await this.getTrainplan(this.id);
       if (this.$checkRes(tp)) {
@@ -160,4 +187,8 @@ export default {
 };
 </script>
 
-<style lang="less" scoped></style>
+<style lang="less" scoped>
+.mb {
+  margin: 0 0 10px 1576px;
+}
+</style>