ソースを参照

添加导出新功能

lex-xin 5 年 前
コミット
fa4cc3039d
3 ファイル変更104 行追加5 行削除
  1. 0 1
      src/api/user.js
  2. 100 2
      src/views/dashboard/index.vue
  3. 4 2
      vue.config.js

+ 0 - 1
src/api/user.js

@@ -1,7 +1,6 @@
 import request from '@/utils/request'
 
 export function login(data) {
-  console.log(data)
   return request({
     url: '/user/login',
     method: 'post',

+ 100 - 2
src/views/dashboard/index.vue

@@ -77,11 +77,14 @@
         <!--  v-if="majorStatus == 1" -->
         <el-button type='danger'
                    icon='el-icon-position'
+                   v-show="paymentStatus"
                    @click="getMoney">开启缴费</el-button>
         <el-button type='warning'
                    icon="el-icon-news"
                    v-if='this.majorId'
                    @click='openUrl'>打开二维码</el-button>
+        <el-button plain
+                 @click="exportis">导出</el-button>
       </el-form>
       <!-- 提示语 -->
       <p class="subMsg"
@@ -91,6 +94,7 @@
            v-if="majorId">
         <el-table :data="tableData"
                   style="width: 100%"
+                  id='tableid'
                   @selection-change="handleSelectionChange">
           <el-table-column type="selection"
                            :selectable='checkboxT'
@@ -243,6 +247,7 @@ export default {
   name: "dashboard",
   data () {
     return {
+      paymentStatus: false, // 开启缴费开关
       topForm: {
         team: "",
         status: "",
@@ -345,6 +350,10 @@ export default {
       if (status == 3 || status == 4) {
         this.disabled = false;
       }
+      // 判断乐团是否已经开启缴费
+      if (status == 2 || status == 3 || status == 4) {
+          this.paymentStatus = true
+      }
       this.majorId = id;
       // 发请求 获取学生列表数据
       this.getstudentList();
@@ -509,8 +518,97 @@ export default {
       }
 
     },
-    // hidecode () {
-    // }
+    exportis () {
+      // var curTbl = document.getElementById('tableid');
+      // this.tableId = curTbl;
+      // console.log(curTbl);
+      console.log(this.tableData)
+      if(this.tableData.length <= 0) {
+          return false
+      }
+      this.method5('tableid');
+    },
+
+    // 导出
+    getExplorer () {
+      var explorer = window.navigator.userAgent;
+      //ie
+      if (explorer.indexOf("MSIE") >= 0) {
+        return 'ie';
+      }
+      //firefox
+      else if (explorer.indexOf("Firefox") >= 0) {
+        return 'Firefox';
+      }
+      //Chrome
+      else if (explorer.indexOf("Chrome") >= 0) {
+        return 'Chrome';
+      }
+      //Opera
+      else if (explorer.indexOf("Opera") >= 0) {
+        return 'Opera';
+      }
+      //Safari
+      else if (explorer.indexOf("Safari") >= 0) {
+        return 'Safari';
+      }
+    },
+    method5 (tableid) {
+
+      if (this.getExplorer() == 'ie') {
+        var curTbl = document.getElementById(tableid);
+        var oXL = new ActiveXObject("Excel.Application");
+        var oWB = oXL.Workbooks.Add();
+        var xlsheet = oWB.Worksheets(1);
+        var sel = document.body.createTextRange();
+        sel.moveToElementText(curTbl);
+        sel.select();
+        sel.execCommand("Copy");
+        xlsheet.Paste();
+        oXL.Visible = true;
+        try {
+
+          var fname = oXL.Application.GetSaveAsFilename("哈哈哈.xls", "Excel Spreadsheets (*.xls), *.xls");
+        } catch (e) {
+          print("Nested catch caught " + e);
+        } finally {
+          oWB.SaveAs(fname);
+          oWB.Close(savechanges = false);
+          oXL.Quit();
+          oXL = null;
+          this.idTmr = window.setInterval("Cleanup();", 1);
+        }
+
+      }
+      else {
+        this.tableToExcel();
+      }
+    },
+    Cleanup () {
+      window.clearInterval(this.idTmr);
+      this.CollectGarbage();
+    },
+    tableToExcel () {
+
+      (function () {
+        var uri = 'data:application/vnd.ms-excel;base64,',
+          template = '<html><head><meta charset="UTF-8"></head><body><table>{table}</table></body></html>',
+          base64 = function (s) { return window.btoa(unescape(encodeURIComponent(s))) },
+          format = function (s, c) {
+            return s.replace(/{(\w+)}/g,
+              function (m, p) { return c[p]; })          }
+        // table name
+        let table = document.getElementById('tableid')
+        // || name
+        var ctx = { worksheet: 'Worksheet', table: table.innerHTML }
+        window.location.href = uri + base64(format(template, ctx))
+        // 
+        // return function () {
+
+
+        // }
+      })()
+    },
   },
   watch: {
     radio (val) {

+ 4 - 2
vue.config.js

@@ -44,14 +44,16 @@ module.exports = {
       // http://192.168.3.28:8005
       // 192.168.3.38:8088
       '/order': {
-        target: `http://192.168.3.38:9000`,
+        target: 'http://testpay.dayaedu.com',
+        // target: `http://192.168.3.38:9000`,
         changeOrigin: true,
         pathRewrite: {
           "^order": ''
         }
       },
       '/user': {
-        target: `http://192.168.3.38:9000`,
+        target: 'http://testpay.dayaedu.com',
+        // target: `http://192.168.3.38:9000`,
         changeOrigin: true,
         pathRewrite: {
           "^user": ''