|
| 1 | +<template> |
| 2 | + <Modal |
| 3 | + v-model="show" |
| 4 | + class="results-export" |
| 5 | + width="450"> |
| 6 | + <div slot="header"> |
| 7 | + <span>结果集导出</span> |
| 8 | + </div> |
| 9 | + <div class="results-export-content"> |
| 10 | + <Form |
| 11 | + ref="resultsExport" |
| 12 | + :model="exportOption" |
| 13 | + :rules="rules" |
| 14 | + :label-width="80"> |
| 15 | + <FormItem |
| 16 | + label="导出名称" |
| 17 | + prop="name"> |
| 18 | + <Input |
| 19 | + v-model="exportOption.name" |
| 20 | + placeholder="请输入导出名称……" |
| 21 | + style="width: 320px;"></Input> |
| 22 | + <Icon |
| 23 | + title="导出后缀可在管理台-常用功能-设置-应用级-pipeline中设置!" |
| 24 | + type="md-help-circle" |
| 25 | + class="results-export-content-help" |
| 26 | + ></Icon> |
| 27 | + </FormItem> |
| 28 | + <FormItem |
| 29 | + label="存储路径" |
| 30 | + prop="path"> |
| 31 | + <directory-dialog |
| 32 | + :filter-node="filterNode" |
| 33 | + :path="exportOption.path" |
| 34 | + :tree="fileTree" |
| 35 | + :load-data-fn="loadDataFn" |
| 36 | + fs-type="script" |
| 37 | + title="结果集导出" |
| 38 | + @set-node="setNode"/> |
| 39 | + </FormItem> |
| 40 | + </Form> |
| 41 | + </div> |
| 42 | + <div slot="footer"> |
| 43 | + <Button |
| 44 | + type="primary" |
| 45 | + @click="submit">确定</Button> |
| 46 | + </div> |
| 47 | + </Modal> |
| 48 | +</template> |
| 49 | +<script> |
| 50 | +import _ from 'lodash'; |
| 51 | +import module from '../index'; |
| 52 | +import storage from '@/js/helper/storage'; |
| 53 | +import util from '@/js/util'; |
| 54 | +import directoryDialog from '@js/component/directoryDialog/index.vue'; |
| 55 | +export default { |
| 56 | + name: 'ResultsExport', |
| 57 | + components: { |
| 58 | + directoryDialog, |
| 59 | + }, |
| 60 | + mixins: [module.mixin], |
| 61 | + props: { |
| 62 | + currentPath: { |
| 63 | + type: String, |
| 64 | + default: '', |
| 65 | + }, |
| 66 | + script: [Object], |
| 67 | + }, |
| 68 | + data() { |
| 69 | + return { |
| 70 | + show: false, |
| 71 | + exportOption: { |
| 72 | + name: '', |
| 73 | + path: '', |
| 74 | + }, |
| 75 | + fileTree: [], |
| 76 | + hdfsComponent: null, |
| 77 | + loadDataFn: () => {}, |
| 78 | + rules: { |
| 79 | + name: [ |
| 80 | + { required: true, message: '请输入名称', trigger: 'blur' }, |
| 81 | + { min: 1, max: 200, message: '长度在1到200个字符', trigger: 'change' }, |
| 82 | + { type: 'string', pattern: /^[\w\u4e00-\u9fa5]+$/, message: '仅支持中文、大小写字母、数字和下划线', trigger: 'change' }, |
| 83 | + ], |
| 84 | + path: [ |
| 85 | + { required: true, message: '请选择导出路径!', trigger: 'change' }, |
| 86 | + ], |
| 87 | + }, |
| 88 | + }; |
| 89 | + }, |
| 90 | + methods: { |
| 91 | + open() { |
| 92 | + this.show = true; |
| 93 | + this.reset(); |
| 94 | + const fileName = this.script.fileName.replace(/\./g, '_'); |
| 95 | + this.exportOption.name = `${fileName}__${Date.now()}`; |
| 96 | + this.setFileTree(); |
| 97 | + }, |
| 98 | + setFileTree() { |
| 99 | + if (_.isEmpty(this.fileTree)) { |
| 100 | + const tmpTree = storage.get('scriptTree', 'SESSION'); |
| 101 | + if (!tmpTree || (tmpTree && _.isEmpty(tmpTree))) { |
| 102 | + this.dispatch('WorkSidebar:showTree', { |
| 103 | + type: 'work', |
| 104 | + }, (f) => { |
| 105 | + this.hdfsComponent = f; |
| 106 | + f.getRootPath((flag) => { |
| 107 | + f.getTree((tree) => { |
| 108 | + if (tree) { |
| 109 | + this.fileTree.push(tree); |
| 110 | + this.loadDataFn = f.loadDataFn; |
| 111 | + } |
| 112 | + }); |
| 113 | + }); |
| 114 | + }); |
| 115 | + } else { |
| 116 | + this.fileTree = _.cloneDeep(tmpTree); |
| 117 | + if (this.hdfsComponent) { |
| 118 | + this.loadDataFn = this.hdfsComponent.loadDataFn; |
| 119 | + } else { |
| 120 | + this.dispatch('WorkSidebar:showTree', { |
| 121 | + type: 'work', |
| 122 | + }, (f) => { |
| 123 | + this.hdfsComponent = f; |
| 124 | + this.loadDataFn = f.loadDataFn; |
| 125 | + }); |
| 126 | + } |
| 127 | + } |
| 128 | + } |
| 129 | + }, |
| 130 | + filterNode(node) { |
| 131 | + return !node.isLeaf; |
| 132 | + }, |
| 133 | + setNode(node, fsType) { |
| 134 | + this.exportOption.path = node.path; |
| 135 | + }, |
| 136 | + submit() { |
| 137 | + this.$refs.resultsExport.validate((valid) => { |
| 138 | + if (!valid) return false; |
| 139 | + this.show = false; |
| 140 | + this.exportConfirm(); |
| 141 | + }); |
| 142 | + }, |
| 143 | + exportConfirm() { |
| 144 | + const tabName = `new_stor_${Date.now()}.out`; |
| 145 | + const code = `from ${this.currentPath} to ${this.exportOption.path}/${this.exportOption.name}`; |
| 146 | + const md5Path = util.md5(tabName); |
| 147 | + this.dispatch('Workbench:add', { |
| 148 | + id: md5Path, |
| 149 | + filename: tabName, |
| 150 | + filepath: '', |
| 151 | + // saveAs表示临时脚本,需要关闭或保存时另存 |
| 152 | + saveAs: true, |
| 153 | + code, |
| 154 | + }, (f) => { |
| 155 | + if (!f) { |
| 156 | + return; |
| 157 | + } |
| 158 | + this.$nextTick(() => { |
| 159 | + this.dispatch('Workbench:run', { id: md5Path }); |
| 160 | + }); |
| 161 | + }); |
| 162 | + }, |
| 163 | + reset() { |
| 164 | + this.exportOption = { |
| 165 | + name: '', |
| 166 | + path: '', |
| 167 | + }; |
| 168 | + this.fileTree = []; |
| 169 | + }, |
| 170 | + }, |
| 171 | +}; |
| 172 | +</script> |
| 173 | +<style lang="scss" src="../index.scss"> |
| 174 | +
|
| 175 | +</style> |
0 commit comments