first commit
This commit is contained in:
@@ -0,0 +1,554 @@
|
||||
<!--#
|
||||
layout("/layouts/platform.html"){
|
||||
#-->
|
||||
<style>
|
||||
#app {
|
||||
display: flex;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
background-color: #f0f2f5;
|
||||
}
|
||||
|
||||
.box-card {
|
||||
width: calc(100% - 20px);
|
||||
height: calc(100% - 20px);
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.box-card .el-card__body {
|
||||
height: calc(100% - 67px - 20px);
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.box-card-title {
|
||||
font-size: 20px;
|
||||
}
|
||||
|
||||
.card-body {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
height: 100%;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.card-body-center {
|
||||
width: 60%;
|
||||
min-width: 800px;
|
||||
height: 100%;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.card-body-center-bottom {
|
||||
position: absolute;
|
||||
left: 0;
|
||||
bottom: 0;
|
||||
width: 100%;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.card-body-center-bottom button {
|
||||
margin: 0 10px;
|
||||
}
|
||||
|
||||
.card-body-center > .el-carousel {
|
||||
height: calc(100% - 120px);
|
||||
position: relative;
|
||||
overflow-y: hidden;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.card-body-center > .el-carousel > .el-carousel__container {
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.carousel-table-item {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
padding: 10px 0;
|
||||
}
|
||||
|
||||
.carousel-table-item-center {
|
||||
height: 100%;
|
||||
width: 90%;
|
||||
min-width: 800px;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.carousel-table-item-center .card-body {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.checkGroup {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
overflow-y: scroll;
|
||||
padding-right: 10px;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.checkGroup .el-radio, .checkGroup .el-checkbox {
|
||||
padding: 12px;
|
||||
margin: 0 !important;
|
||||
margin-top: 15px !important;
|
||||
}
|
||||
|
||||
.checkGroup .el-checkbox__label {
|
||||
width: calc(100% - 16px);
|
||||
}
|
||||
|
||||
.carousel-table-item-relation .el-card__body {
|
||||
position: relative;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.carousel-table-item-form .el-card__body {
|
||||
position: relative;
|
||||
height: 100%;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
</style>
|
||||
<div id="app" v-cloak>
|
||||
<el-card class="box-card" shadow="never">
|
||||
<div slot="header" class="clearfix">
|
||||
<span class="box-card-title">DataKid</span>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="card-body-center">
|
||||
<el-steps :active="active" align-center>
|
||||
<el-step title="选择数据表" icon="el-icon-document-copy"></el-step>
|
||||
<el-step title="选择数据列" icon="el-icon-s-unfold"></el-step>
|
||||
<el-step title="数据列对应" icon="el-icon-s-operation"></el-step>
|
||||
<el-step title="提交数据" icon="el-icon-upload"></el-step>
|
||||
<el-step title="导入结果" icon="el-icon-bell"></el-step>
|
||||
</el-steps>
|
||||
|
||||
<el-carousel indicator-position="none" :autoplay="false" arrow="never" ref="carousel"
|
||||
direction="vertical">
|
||||
<!--表选择-->
|
||||
<el-carousel-item class="carousel-table-item">
|
||||
<el-card class="carousel-table-item-center">
|
||||
<div slot="header" class="clearfix">
|
||||
<el-input style="width: 200px" v-model="tableNameKeyWord" placeholder="请输入关键字查询"
|
||||
clearable></el-input>
|
||||
<el-button type="primary" icon="el-icon-search" @click="tableNameSearch"></el-button>
|
||||
<el-button v-if="formData.tableName" style="float: right; padding: 10px 0" type="text">
|
||||
当前选中:{{formData.tableName}}
|
||||
</el-button>
|
||||
</div>
|
||||
|
||||
<el-radio-group class="checkGroup" v-model="formData.tableName">
|
||||
<el-radio v-for="item in tableOptionsClone" :key="item.table_name"
|
||||
:label="item.table_name" border>
|
||||
{{item.table_name}}{{item.table_comment?' ( '+item.table_comment+' )':''}}<span
|
||||
style="float: right;color: #F56C6C">rows: {{item.table_rows}}</span>
|
||||
</el-radio>
|
||||
</el-radio-group>
|
||||
</el-card>
|
||||
</el-carousel-item>
|
||||
|
||||
<!--列选择-->
|
||||
<el-carousel-item class="carousel-table-item">
|
||||
<el-card class="carousel-table-item-center">
|
||||
<div slot="header" class="clearfix">
|
||||
<el-input style="width: 200px" v-model="columnNameKeyWord" placeholder="请输入关键字查询"
|
||||
clearable></el-input>
|
||||
<el-button type="primary" icon="el-icon-search" @click="columnSearch"></el-button>
|
||||
|
||||
<el-button style="float: right; padding: 10px 0" type="text">
|
||||
{{formData.tableName}}
|
||||
</el-button>
|
||||
</div>
|
||||
<el-checkbox-group class="checkGroup" v-model="formData.columns">
|
||||
<el-checkbox v-for="item in columnOptionsClone" :key="item.column_name"
|
||||
:label="item.column_name" border>
|
||||
{{item.column_name}}{{item.column_comment?' ( '+item.column_comment+' )':''}}<span
|
||||
style="float: right;color: #F56C6C">{{item.column_type}}</span>
|
||||
</el-checkbox>
|
||||
</el-checkbox-group>
|
||||
</el-card>
|
||||
</el-carousel-item>
|
||||
|
||||
<!--列对应-->
|
||||
<el-carousel-item style="padding: 10px" class="carousel-table-item">
|
||||
<el-card style="width: 100%" class="carousel-table-item-relation">
|
||||
<el-table
|
||||
:data="relation" height="100%"
|
||||
style="width: 100%" border size="medium">
|
||||
<el-table-column
|
||||
prop="column_name"
|
||||
label="列名">
|
||||
</el-table-column>
|
||||
<el-table-column
|
||||
prop="column_comment"
|
||||
label="描述" show-overflow-tooltip="true">
|
||||
</el-table-column>
|
||||
<el-table-column
|
||||
prop="is_nullable"
|
||||
label="可为空">
|
||||
</el-table-column>
|
||||
<el-table-column
|
||||
prop="column_type"
|
||||
label="类型">
|
||||
</el-table-column>
|
||||
<el-table-column
|
||||
prop="column_key"
|
||||
label="key">
|
||||
</el-table-column>
|
||||
<el-table-column min-width="200px">
|
||||
<template slot="header" slot-scope="scope">
|
||||
目标列
|
||||
<el-popover
|
||||
placement="top-start"
|
||||
title="提示"
|
||||
trigger="hover"
|
||||
content="excel对应的表头名称,用于和表数据列对应">
|
||||
<i slot="reference" class="el-icon-question"></i>
|
||||
</el-popover>
|
||||
</template>
|
||||
<template slot-scope="{row}">
|
||||
<el-input
|
||||
v-model="row.relation"
|
||||
size="medium"
|
||||
placeholder="目标列"/>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</el-card>
|
||||
</el-carousel-item>
|
||||
|
||||
|
||||
<!--提交-->
|
||||
<el-carousel-item style="padding: 10px" class="carousel-table-item">
|
||||
<el-card style="width: 100%" class="carousel-table-item-form">
|
||||
<el-form label-width="120px" :model="formData" ref="form" :rules="formRules">
|
||||
<el-form-item label=" " label-width="135px" class="view-header">
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item prop="method" label="导入方式">
|
||||
<el-radio-group v-model="formData.method">
|
||||
<el-radio-button :label="1">追加或更新</el-radio-button>
|
||||
<el-radio-button :label="2">仅追加</el-radio-button>
|
||||
<el-radio-button :label="3">仅更新</el-radio-button>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item v-if="[1,3].includes(formData.method)" prop="field" label="关键字段">
|
||||
<el-select v-model="formData.field" placeholder="请选择" style="width:50%">
|
||||
<el-option
|
||||
v-for="item in relation"
|
||||
:key="item.column_name"
|
||||
:label="item.column_name"
|
||||
:value="item.column_name">
|
||||
</el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item prop="plugins" label="可选插件">
|
||||
<el-checkbox-group v-model="formData.plugins">
|
||||
<el-checkbox v-for="v in plugins" :label="v.name" border>{{v.description}}
|
||||
</el-checkbox>
|
||||
</el-checkbox-group>
|
||||
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="文  件" class="is-required">
|
||||
<el-upload
|
||||
drag
|
||||
name="file"
|
||||
ref="upload"
|
||||
action="****"
|
||||
:on-remove="handleRemove"
|
||||
:on-change="handleChange"
|
||||
:auto-upload="false"
|
||||
:limit="1"
|
||||
:file-list="fileList">
|
||||
<i class="el-icon-upload"></i>
|
||||
<div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
|
||||
<div class="el-upload__tip" slot="tip" style="color: #F56C6C">
|
||||
只能上传 xls/xlsx 文件
|
||||
</div>
|
||||
</el-upload>
|
||||
</el-form-item>
|
||||
|
||||
</el-form>
|
||||
</el-card>
|
||||
</el-carousel-item>
|
||||
|
||||
<!--结果-->
|
||||
<el-carousel-item style="padding: 10px">
|
||||
<el-card style="width: 100%">
|
||||
<div style="display: flex;justify-content: center;align-items: center;flex-direction:column ">
|
||||
<el-progress type="circle" :percentage="result.success/result.total*100"
|
||||
status="success"></el-progress>
|
||||
<div style="font-size: 12px;color: rgb(100,100,100);margin-top: 20px">总记录数
|
||||
{{result.total}} 条,成功
|
||||
{{result.success}} 条!
|
||||
</div>
|
||||
<div style="margin-top: 5px" v-if="result.cacheKey">
|
||||
<el-link type="primary" style="font-size: 12px;"
|
||||
:href="loc()+'/exportErrors?cacheKey='+result.cacheKey">下载错误记录
|
||||
</el-link>
|
||||
</div>
|
||||
</div>
|
||||
</el-card>
|
||||
</el-carousel-item>
|
||||
</el-carousel>
|
||||
|
||||
|
||||
<div class="card-body-center-bottom">
|
||||
<el-button size="medium" @click="prev" :disabled="active==0||loading">上一步</el-button>
|
||||
<el-button type="primary" size="medium" :loading="loading" @click="active<4?next():carry()">
|
||||
{{active<4?'下一步':'完成'}}
|
||||
</el-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</el-card>
|
||||
</div>
|
||||
<script>
|
||||
var vue = new Vue({
|
||||
el: '#app',
|
||||
data() {
|
||||
return {
|
||||
active: 0,
|
||||
result: {success: 0, total: 0},
|
||||
loading: false,
|
||||
|
||||
/*提交数据*/
|
||||
/*start*/
|
||||
fileList: [],
|
||||
plugins: {},
|
||||
formRules: {
|
||||
method: [{required: true, message: '必填', trigger: ['blur', 'change']}],
|
||||
field: [{required: true, message: '必填', trigger: ['blur', 'change']}],
|
||||
},
|
||||
/*end*/
|
||||
|
||||
/*列对应*/
|
||||
/*start*/
|
||||
relation: [],
|
||||
/*end*/
|
||||
|
||||
/*tableColumn*/
|
||||
/*start*/
|
||||
columnOptions: [],
|
||||
columnOptionsClone: [],
|
||||
columnNameKeyWord: '',
|
||||
/*end*/
|
||||
|
||||
/*tableName*/
|
||||
/*start*/
|
||||
tableNameKeyWord: '',
|
||||
tableOptions: [],
|
||||
tableOptionsClone: [],
|
||||
cacheTableName: '',
|
||||
/*end*/
|
||||
|
||||
formData: {
|
||||
tableName: '',
|
||||
columns: [],
|
||||
method: 1,
|
||||
plugins: [],
|
||||
}
|
||||
}
|
||||
},
|
||||
components: {},
|
||||
filters: {},
|
||||
methods: {
|
||||
carry() {
|
||||
this.formData = {
|
||||
tableName: '',
|
||||
columns: [],
|
||||
method: 1,
|
||||
plugins: [],
|
||||
}
|
||||
this.relation = []
|
||||
this.fileList = []
|
||||
this.active = 0
|
||||
this.$refs.carousel.next()
|
||||
},
|
||||
async next() {
|
||||
const {active} = this
|
||||
if (active == 0) {
|
||||
if (!this.formData.tableName) {
|
||||
this.$notify({
|
||||
title: '警告',
|
||||
message: '请选择数据表',
|
||||
type: 'warning'
|
||||
});
|
||||
return
|
||||
}
|
||||
if (this.cacheTableName != this.formData.tableName) {
|
||||
this.loadColumn()
|
||||
this.formData.columns = []
|
||||
this.cacheTableName = this.formData.tableName
|
||||
}
|
||||
} else if (active == 1) {
|
||||
if (!this.formData.columns || !this.formData.columns.length) {
|
||||
this.$notify({
|
||||
title: '警告',
|
||||
message: '请选择数据列',
|
||||
type: 'warning'
|
||||
});
|
||||
return
|
||||
}
|
||||
this.genRelation()
|
||||
} else if (active == 2) {
|
||||
if (this.relation.find(v => !v.relation)) {
|
||||
this.$notify({
|
||||
title: '警告',
|
||||
message: '存在未填写的目标列',
|
||||
type: 'warning'
|
||||
});
|
||||
return
|
||||
}
|
||||
} else if (active == 3) {
|
||||
await this.doSubmit()
|
||||
}
|
||||
|
||||
this.$refs.carousel.next()
|
||||
this.active++
|
||||
},
|
||||
prev() {
|
||||
this.$refs.carousel.prev()
|
||||
this.active--
|
||||
},
|
||||
|
||||
async doSubmit() {
|
||||
let Break = false
|
||||
this.$refs["form"].validate((valid) => {
|
||||
if (!valid || !this.fileList.length) {
|
||||
this.$notify({
|
||||
title: '警告',
|
||||
message: '存在未填写的必填项',
|
||||
type: 'warning'
|
||||
});
|
||||
Break = true
|
||||
return
|
||||
}
|
||||
})
|
||||
if (Break) return
|
||||
|
||||
this.loading = true
|
||||
|
||||
let formData = new FormData()
|
||||
for (let key in this.formData) {
|
||||
formData.append(key, this.formData[key])
|
||||
}
|
||||
formData.append("relation", JSON.stringify(this.relation))
|
||||
this.fileList.forEach((val) => {
|
||||
formData.append("file", val.raw, val.raw.name);
|
||||
});
|
||||
|
||||
const {code, data, msg} = await $.ajax({
|
||||
url: loc() + "/importData",
|
||||
type: "post",
|
||||
data: formData,
|
||||
processData: false,
|
||||
contentType: false,
|
||||
});
|
||||
|
||||
this.loading = false
|
||||
|
||||
if (code) {
|
||||
this.$notify.error({
|
||||
title: '错误',
|
||||
message: msg
|
||||
});
|
||||
|
||||
this.result = {success: 0, total: 0}
|
||||
return
|
||||
}
|
||||
|
||||
this.result = data
|
||||
|
||||
},
|
||||
|
||||
/*提交数据*/
|
||||
/*start*/
|
||||
handleRemove(file, fileList) {
|
||||
this.fileList = fileList;
|
||||
},
|
||||
handleChange(file, fileList) {
|
||||
|
||||
const remove = () => {
|
||||
for (let i = 0; i < fileList.length; i++) {
|
||||
if (file == fileList[i]) {
|
||||
fileList.splice(i, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (file.size == 0) {
|
||||
this.$message.warning("您选择的是空文件!");
|
||||
remove()
|
||||
}
|
||||
|
||||
const type = ['xls', 'xlsx'].includes(file.name.split('.').pop().toLowerCase())
|
||||
if (!type) {
|
||||
this.$message.warning('上传文件只能是' + ['xls', 'xlsx'].map(v => v.toLowerCase()).join("/") + '格式!');
|
||||
remove()
|
||||
}
|
||||
|
||||
this.fileList = fileList;
|
||||
},
|
||||
async loadPlugins() {
|
||||
this.plugins = await getEnumOptions("DataImportPluginHandle")
|
||||
},
|
||||
/*end*/
|
||||
|
||||
/*数据列对应*/
|
||||
/*start*/
|
||||
genRelation() {
|
||||
this.relation = this.columnOptions.filter(v => this.formData.columns.includes(v.column_name))
|
||||
},
|
||||
/*end*/
|
||||
|
||||
/*tableName*/
|
||||
/*start*/
|
||||
columnSearch() {
|
||||
if (!this.columnNameKeyWord) {
|
||||
this.columnOptionsClone = clone(this.columnOptions)
|
||||
return
|
||||
}
|
||||
this.columnOptionsClone = this.columnOptions.filter(v => v.column_name.toLowerCase().indexOf(this.columnNameKeyWord.toLowerCase()) != -1 || v.column_comment.toLowerCase().indexOf(this.columnNameKeyWord.toLowerCase()) != -1)
|
||||
},
|
||||
async loadColumn() {
|
||||
const {tableName} = this.formData
|
||||
const {data} = await $.get(loc() + '/columns', {tableName})
|
||||
this.columnOptions = data
|
||||
this.columnOptionsClone = clone(data)
|
||||
},
|
||||
/*end*/
|
||||
|
||||
/*tableName*/
|
||||
/*start*/
|
||||
tableNameSearch() {
|
||||
if (!this.tableNameKeyWord) {
|
||||
this.tableOptionsClone = clone(this.tableOptions)
|
||||
return
|
||||
}
|
||||
this.tableOptionsClone = this.tableOptions.filter(v => v.table_name.toLowerCase().indexOf(this.tableNameKeyWord.toLowerCase()) != -1 || v.table_comment.toLowerCase().indexOf(this.tableNameKeyWord.toLowerCase()) != -1)
|
||||
},
|
||||
async loadTableName() {
|
||||
const {data} = await $.get(loc() + '/tableNames')
|
||||
this.tableOptions = data
|
||||
this.tableOptionsClone = clone(data)
|
||||
}
|
||||
/*end*/
|
||||
},
|
||||
created() {
|
||||
this.loadTableName()
|
||||
this.loadPlugins()
|
||||
}
|
||||
})
|
||||
</script>
|
||||
<!--#
|
||||
}
|
||||
#-->
|
||||
Reference in New Issue
Block a user