导入数据

openf12
yujialong 2 years ago
parent 1d2b7098d1
commit 520feb1396
  1. 5
      package-lock.json
  2. 1
      package.json
  3. BIN
      src/assets/images/dataforward.png
  4. 13
      src/components/TestPanel.vue
  5. 6
      src/components/codemirror.vue
  6. 379
      src/views/Data.vue

5
package-lock.json generated

@ -5422,6 +5422,11 @@
"schema-utils": "^2.5.0"
}
},
"file-saver": {
"version": "2.0.5",
"resolved": "https://registry.npmjs.org/file-saver/-/file-saver-2.0.5.tgz",
"integrity": "sha512-P9bmyZ3h/PRG+Nzga+rbdI4OEpNDzAVyy74uVO9ATgzLK6VtAsYybF/+TOCvrc0MO793d6+42lLyZTw7/ArVzA=="
},
"filesize": {
"version": "3.6.1",
"resolved": "https://registry.npmjs.org/filesize/-/filesize-3.6.1.tgz",

@ -12,6 +12,7 @@
"clipboard": "^2.0.10",
"core-js": "^3.19.3",
"element-ui": "^2.15.6",
"file-saver": "^2.0.5",
"jquery": "^3.6.0",
"js-cookie": "^3.0.1",
"lib-flexible": "^0.3.2",

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

@ -463,7 +463,20 @@ export default {
type: 'warning',
center: true
}).then(() => {
//
if (!pointList.find(e => e.codeId)) {
this.$post(this.api.runPythonCode, {
code: '',
bcId: pointList[0].judgmentId,
cid: this.courseId,
projectId: this.projectId
}).then(({ codeId }) => {
this.$parent.workbench[0].codeId = codeId
this.submit()
}).catch(err => {})
} else {
this.submit()
}
}).catch(() => {})
},
//

@ -43,6 +43,7 @@
</div>
<div class="result-right t-color" v-show="isError">
<img :src="require(`@/assets/images/system/${$config.defaultSystem}/yes.png`)" alt />运行成功
<el-button class="tips-btn" @click="exportResult">导出结果</el-button>
</div>
<div class="result-wrong" v-show="isError === 0">
<img src="@/assets/images/error.png" alt />
@ -479,6 +480,11 @@ export default {
downloadPic(i) {
this.$refs['picLink' + i][0].click()
},
exportResult() {
var FileSaver = require('file-saver');
var blob = new Blob([this.runResult], {type: "text/plain;charset=utf-8"});
FileSaver.saveAs(blob, 'result.csv')
},
//
getTips() {
this.tipsVisible = true

@ -5,9 +5,7 @@
<div class="tool">
<el-input style="width: 250px" placeholder="请输入文件名称" v-model="keyword" suffix-icon="el-icon-search" clearable size="small"></el-input>
<div class="action">
<el-upload :headers="{token}" :action="api.fileUpload" name="file" :limit="1000" :show-file-list="false" :before-upload="beforeImport" :on-success="successImport">
<el-button class="cus-btn" type="primary" size="small">导入数据</el-button>
</el-upload>
<el-button class="cus-btn" type="primary" size="small" @click="sourceVisible = true">导入数据</el-button>
<el-button class="cus-btn" style="margin-left: 10px;" type="primary" size="small" @click="delAll">批量删除</el-button>
</div>
</div>
@ -40,6 +38,55 @@
<div class="pagination">
<el-pagination background layout="total,prev, pager, next" :current-page="page" @current-change="handleCurrentChange" :total="total"></el-pagination>
</div>
<el-dialog title="请选择数据源" :visible.sync="sourceVisible" width="400px" :close-on-click-modal="false">
<ul class="source-list">
<li style="width: 48%" @click="showData">
<img src="@/assets/images/dataforward.png" alt="">
</li>
<el-upload class="upload" :headers="{token}" :action="api.fileUpload" name="file" :limit="1000" :show-file-list="false" :before-upload="beforeImport" :on-success="successImport">
<li style="width: 100%;">本地上传</li>
</el-upload>
</ul>
</el-dialog>
<!-- 导入数据 -->
<el-dialog title="导入" :visible.sync="importVisible" width="80%" center @close="closeImport" class="dialog" :close-on-click-modal="false">
<el-container style="padding: 20px 0 20px 20px;background-color: #f0f0f0;">
<div style="overflow:auto;height: 558px;width:330px;padding:15px;background:#fff" ref="typeTreeWrap" @scroll="loadType">
<el-tree v-loading="importLoading"
ref="typeTree"
:data="importTypeList"
node-key="id"
accordion
:default-expanded-keys="defaultTypeActive"
:default-checked-keys="defaultTypeChecked"
:current-node-key="curId"
show-checkbox
highlight-current
@node-click="importTypeClick"
@node-expand="importTypeExpand"
>
</el-tree>
</div>
<el-main style="padding-top: 0;padding-bottom: 0;">
<el-card shadow="hover">
<div class="flex-center mgb20">
<p class="hr_tag"></p>
<span>预览</span>
</div>
<el-table :data="fieldData" stripe header-align="center" v-if="fieldHead.length">
<el-table-column type="index" width="100" label="序号" align="center"></el-table-column>
<el-table-column v-for="(item,index) in fieldHead" :prop="item.field" :key="index" :label="item.comment" align="center"></el-table-column>
</el-table>
</el-card>
</el-main>
</el-container>
<span slot="footer" class="dialog-footer">
<el-button @click="importVisible = false"> </el-button>
<el-button type="primary" :loading="submited" @click="confirmImport"> </el-button>
</span>
</el-dialog>
</div>
</div>
</template>
@ -58,7 +105,21 @@ export default {
keyword: '',
page: 1,
pageSize: 10,
total: 0
total: 0,
sourceVisible: false,
importVisible: false,
defaultTypeActive: [],
defaultTypeChecked: [],
importLoading: false,
tablePromises: [],
importTypeList: [],
fieldData: [],
fieldHead: [],
tableName: '',
curId: '',
curExpand: '',
submited: false,
};
},
components: {
@ -119,6 +180,7 @@ export default {
ossFileName: file.ossFileName
}).then(res => {
this.$message.success('导入成功')
this.sourceVisible = false
this.getData()
}).catch(res => {})
},
@ -177,6 +239,287 @@ export default {
},
handleSelectionChange(val) {
this.multipleSelection = val
},
//
getMoreTable(list,id){
list.map(n => {
if(n.id == id){
this.getTable(n,1)
}else if(n.children && n.children.length){
this.getMoreTable(n.children,id)
}
})
},
// ,,id
renderChecked(){
let result = []
let list = this.$refs.typeTree.getCheckedNodes()
list.map((n,i) => {
if(n.tableLen && n.tableLen > n.children.length){
result = [...result,...n.children.map(n => n.id)]
}else{
result.push(n.id)
}
})
this.$refs.typeTree.setCheckedKeys(result)
},
// ,dom,
loadType(e){
clearTimeout(this.typeTimer)
let typeTree = this.$refs.typeTreeWrap
//
this.typeTimer = setTimeout(() => {
this.typeTreeScrollTop = typeTree.scrollTop - this.typeTreeScrollTop
// ,
if(this.typeTreeScrollTop > 0 && typeTree.scrollHeight - (typeTree.clientHeight + parseInt(typeTree.scrollTop)) < 10){
this.getMoreTable(this.importTypeList,this.curExpand)
Promise.all(this.tablePromises).then(_ => {
this.renderChecked()
})
}
},50)
},
//
getTable(n,isConcat){
this.tablePromises.push(new Promise((resolve,reject) => {
this.$post(`${this.api.originalListById}?categoryId=${n.realId}&pageNum=${n.typeTreePage ? n.typeTreePage : 1}&pageSize=${this.typeTreeUnit}`).then(res => {
let list = res.list.records
list.map(n => {
n.label = n.showName
n.id = String(n.id)
// ,
if(this.defaultTypeChecked.includes(n.id)){
n.disabled = true
}
})
// ,
if(isConcat){
n.children = n.children.concat(list)
}else{
n.children = list
n.tableLen = res.list.total
}
// ,+1
n.typeTreePage++
resolve()
}).catch(res => {
reject()
})
}))
},
//
showData(){
this.importLoading = true
this.importVisible = true
//
this.$post(this.api.originalList).then(res => {
// idlabelnamekeylabelnamekey
function handleId(data){
data.map(n => {
n.realId = n.id
// ididuuid
n.id = uuid.v4()
n.label = n.categoryName
if(n.children.length){
handleId(n.children)
}
})
}
handleId(res)
// pageSize300020
this.$post(`${this.api.getIdQueryTable}?categoryId=${this.categoryId}&showName=${this.keyword}&pageNum=1&pageSize=3000&updateTime=${this.updateTime ? this.updateTime : ''}`).then(res1 => {
let list = res1.pageList.records
this.defaultTypeChecked = list.map(n => n.copyId) // copyIdidid
//
const handleId = data => {
data.map(n => {
if(n.children.length){
handleId(n.children)
}else{
// 1
n.typeTreePage = 1
this.getTable(n)
}
})
}
handleId(res)
//
function handleDisabled (list) {
list.map(e => {
if (e.children && e.children.length) {
if (e.children.every(e => e.disabled)) e.disabled = true
handleDisabled(e.children)
}
})
}
Promise.all(this.tablePromises).then(_ => {
handleDisabled(res)
this.importTypeList = res
this.importLoading = false
})
}).catch(res => {
this.importLoading = false
})
}).catch(res => {
this.importLoading = false
})
},
//
getFields(){
this.$get(`${this.api.staticPreview}?tableName=${this.tableName}`).then(res => {
let comment = res.comment
let fieldHead = []
// id
comment.map(n => {
n.field != 'id' && n.field != 'operation_time' && fieldHead.push(n)
})
this.fieldHead = fieldHead
let data = res.data
data.map(n => {
for(let i in n){
// +0000,,
if(typeof n[i] == 'string' && n[i].endsWith('+0000')) n[i] = this.formatDate('yyyy-MM-dd hh:mm:ss',new Date(n[i]))
}
})
this.fieldData = data
}).catch(res => {})
this.importVisible = true
},
//
importTypeClick(data){
// ,,
if(data.name){
this.tableName = data.name
this.curId = data.id
this.getFields()
}
},
//
importTypeExpand(obj,node,com){
this.curExpand = obj.id
this.renderChecked()
},
//
closeImport(){
this.$refs.typeTree.setCheckedKeys([])
this.categorys = []
},
// id
getNames(list){
const categoryId = Number(this.categoryId)
return new Promise((resolve,reject) => {
this.$get(`${this.api.getAllTableInfoByCategoryId}?categoryId=${list.join()}`).then(res => {
const list = res.tableInfo
list.map(e => {
delete e.id // id
e.categoryId = categoryId
})
this.categorys = list
resolve()
}).catch(res => {})
})
},
//
saveSuccess() {
this.$message.success('导入成功')
this.getData()
this.importVisible = false
setTimeout(() => {
this.submited = false
},1000)
},
//
confirmImport(){
if(this.submited) return false //
const checked = this.$refs.typeTree.getCheckedNodes().filter(e => !e.disabled) //
//
if(!checked.length) return this.$message.warning('请选择数据')
this.submited = true
// ididid
const typeIds = checked.filter(e => !e.name).map(e => e.realId) // idnamenameididididrealIdid
const tableIds = checked.filter(e => e.name) //
const categoryId = Number(this.categoryId) //
// categoryId
tableIds.map(e => {
delete e.id
e.categoryId = categoryId
})
/**
* 根据某个值给数组对象去重
* @param arr 要处理的数组
* @param val 去重依据的值
*/
function uniq (arr, val) {
const res = new Map()
return arr.filter(e => !res.has(e[val]) && res.set(e[val], 1))
}
// ididid
if (typeIds.length) {
this.getNames(typeIds).then(() => {
const allIds = [...this.categorys, ...tableIds] // idid
const data = uniq(allIds, 'name')
const dataList = []
// 2000
for (let i = 0, len = data.length; i < len; i += 2000) {
dataList.push(data.slice(i, i + 2000))
}
const promiseList = []
// 2000item6item6item2000item6item6item2000666
if (dataList.length > 6) {
dataList.slice(0, 6).map(e => {
promiseList.push(new Promise((resolve,reject) => {
this.$post(this.api.saveTable, e).then(res => {
resolve()
}).catch(res => {
reject()
})
}))
})
Promise.all(promiseList).then(res => {
dataList.slice(6).map(e => {
promiseList.push(new Promise((resolve,reject) => {
this.$post(this.api.saveTable, e).then(res => {
resolve()
}).catch(res => {
reject()
})
}))
})
Promise.all(promiseList).then(res => {
this.saveSuccess()
}).catch(err => {
this.submited = false
})
}).catch(err => {
this.submited = false
})
} else {
dataList.map(e => {
promiseList.push(new Promise((resolve,reject) => {
this.$post(this.api.saveTable, e).then(res => {
resolve()
}).catch(res => {
reject()
})
}))
})
Promise.all(promiseList).then(res => {
this.saveSuccess()
}).catch(err => {
this.submited = false
})
}
})
} else { //
this.$post(this.api.saveTable, tableIds).then(res => {
this.saveSuccess()
}).catch(res => {
this.submited = false
})
}
}
}
};
@ -211,4 +554,32 @@ export default {
cursor: pointer;
}
}
/deep/.source-list {
display: flex;
justify-content: space-between;
li {
display: inline-flex;
justify-content: center;
align-items: center;
height: 100px;
border: 1px solid #ccc;
border-radius: 8px;
cursor: pointer;
img {
width: 90%;
}
&:hover {
border-color: #007eff;
}
}
.upload {
width: 48%;
.el-upload {
width: 100%;
&:focus {
color: #007eff;
}
}
}
}
</style>
Loading…
Cancel
Save