Browse Source

新增导出功能

tbphp 2 years ago
parent
commit
1601d739a3

+ 24 - 0
api/controller/Data.php

@@ -78,6 +78,30 @@ class Data extends Base
             success('执行完成');
         }
         error('语句执行完成,但是SVM系统数据更新失败,请联系管理员修复');
+    }
+
+    public function export()
+    {
+        check('eid', 'get');
+
+        // 获取需要执行的sql
+        $data = Db::query('SELECT `remark`, `sql` FROM `data` WHERE `eids` LIKE "%[' . $_GET['eid'] . ']%" ORDER BY `id` ASC');
+        $sql  = '';
+        foreach ($data as $d) {
+            if ($d['sql']) {
+                if (!empty($sql)) {
+                    $sql .= PHP_EOL;
+                }
+                $sql .= '-- ' . trim($d['remark']) . PHP_EOL;
+                $sql .= rtrim($d['sql'], ';') . ';' . PHP_EOL;
+            }
+        }
 
+        // 下载文件
+        $filename = 'svm_' . date('YmdHi') . '.sql';
+        header('Content-type: application/octet-stream');
+        header('Content-Disposition: attachment; filename=' . $filename);
+        echo $sql;
+        exit;
     }
 }

+ 1 - 1
index.html

@@ -1 +1 @@
-<!DOCTYPE html><html><head><meta charset=utf-8><title>SVM - Sql Version Manager</title><link href=/vue/dist/static/css/app.ae61827cc34dd8c73645548979e071cd.css rel=stylesheet></head><body><div id=app></div><script type=text/javascript src=/vue/dist/static/js/manifest.8b3b6907fb64a12e6b9e.js></script><script type=text/javascript src=/vue/dist/static/js/vendor.e99c9851abf986b84b02.js></script><script type=text/javascript src=/vue/dist/static/js/app.1502be62eb13969384cd.js></script></body></html>
+<!DOCTYPE html><html><head><meta charset=utf-8><title>SVM - Sql Version Manager</title><link href=/vue/dist/static/css/app.ae61827cc34dd8c73645548979e071cd.css rel=stylesheet></head><body><div id=app></div><script type=text/javascript src=/vue/dist/static/js/manifest.63869f19f30d1fb1eecc.js></script><script type=text/javascript src=/vue/dist/static/js/vendor.1dad3d0f754daa9c89cb.js></script><script type=text/javascript src=/vue/dist/static/js/app.1502be62eb13969384cd.js></script></body></html>

File diff suppressed because it is too large
+ 1 - 0
vue/dist/static/js/0.2ad0e0802917f9d62d85.js


File diff suppressed because it is too large
+ 0 - 1
vue/dist/static/js/0.776cafea8deda6a663b2.js


File diff suppressed because it is too large
+ 1 - 1
vue/dist/static/js/manifest.8b3b6907fb64a12e6b9e.js


vue/dist/static/js/vendor.e99c9851abf986b84b02.js → vue/dist/static/js/vendor.1dad3d0f754daa9c89cb.js


+ 1 - 1
vue/package.json

@@ -55,7 +55,7 @@
     "vue-loader": "^13.0.0",
     "vue-style-loader": "^3.0.1",
     "vue-template-compiler": "^2.4.1",
-    "webpack": "^3.2.0",
+    "webpack": "^3.3.0",
     "webpack-bundle-analyzer": "^2.8.3",
     "webpack-dev-middleware": "^1.11.0",
     "webpack-hot-middleware": "^2.18.2",

+ 11 - 0
vue/src/cpt/Index.vue

@@ -28,6 +28,8 @@
             <el-button type="danger" size="small" icon="caret-right" :disabled="total == 0 || selEnv == null || selEnv.type != 1" @click="run">执行</el-button>
             <el-button type="primary" size="small" icon="check" :disabled="total == 0" @click="confirm">确认</el-button>
           </el-button-group>
+          <el-button v-if="total == 0" size="small" icon="upload2" :disabled="true">导出</el-button>
+          <a v-else class="el-button el-button--small export" :href="export_url"><i class="el-icon-upload2"></i><span>导出</span></a>
         </el-form-item>
       </el-form>
     </div>
@@ -112,6 +114,7 @@
       load () {
         if (this.selEnv === null) {
           this.listData = null
+          this.total = 0
         } else {
           this.$http.get('data', {params: {eid: this.selEnv.id, page: this.page}}).then(({total, list}) => {
             this.total = total
@@ -145,6 +148,13 @@
         }, () => {})
       }
     },
+    computed: {
+      export_url () {
+        if (this.selEnv) {
+          return process.env.API_URL + 'data/export?eid=' + this.selEnv.id
+        }
+      }
+    },
     created () {
       this.loadProject()
     },
@@ -154,4 +164,5 @@
 
 <style scoped>
   .sql{font-size: 12px;line-height: 16px;white-space: pre-wrap}
+  .export{text-decoration: none;}
 </style>