<template>
|
<zt-dialog ref="dialog" title="导入字典" :hasConfirm="false" append-to-body>
|
<el-form>
|
<zt-form-item style="width:100%;" label="" prop="remark">
|
<el-upload
|
style="width: 600px"
|
class="upload-demo"
|
ref="upload"
|
:action="apiURL"
|
:on-success="succ"
|
:on-exceed="uploadExceed"
|
:on-error="err"
|
:limit="1"
|
:file-list="fileList"
|
:auto-upload="false">
|
<div style="display:inline-block;font-size: 14px;" class="el-upload__tip"> 只能上传.xlsx或.xls的文件,且不超过2G</div>
|
<el-button slot="trigger" size="small" type="primary" style="font-size: 15px">选取文件</el-button>
|
<el-button type="primary" size="small" style="margin-left:20px;font-size: 15px" @click="submitUpload()">提 交
|
</el-button>
|
</el-upload>
|
</zt-form-item>
|
<el-progress :text-inside="true" :stroke-width="30" :percentage="progress.speed"></el-progress>
|
<zt-form-item style="width:100%;" label="导入信息提示:" prop="text">
|
<el-input style="width:80%;color:#000000;" v-model="dataForm.text" type="textarea" :rows="1" placeholder="导入信息提示" readOnly></el-input>
|
</zt-form-item>
|
<el-table ref="table" v-adaptive="{bottomOffset:220}" height="100px" :resizable="false" :data="resultData" highlight-current-row :default-sort ="{prop:'errCause',order:'ascending'}">
|
<el-table-column prop="sheetName" label="excel工作表" width="150"/>
|
<el-table-column :sortable="true" prop="errCause" label="错误原因" width="300"/>
|
<el-table-column prop="lineNumber" label="错误行数" />
|
</el-table>
|
</el-form>
|
<!--<template slot="footer">-->
|
<!--<zt-button type="primary" style="float:left" @click="exportExcelModel()">导出Excel导入模板</zt-button>-->
|
<!--</template>-->
|
</zt-dialog>
|
</template>
|
|
<script>
|
import Cookies from 'js-cookie'
|
import qs from 'qs'
|
import {guid} from "../../../../src/commonJS/common";
|
|
export default {
|
props: {
|
projectId: {
|
type: String,
|
required: true
|
}
|
},
|
data() {
|
return {
|
dataForm: {
|
result: ''
|
},
|
progress: {
|
id: null,
|
speed: 0,
|
text: '',
|
start: false,
|
timer: null
|
},
|
fileType: ['xlsx', 'xls'],
|
apiURL: '',
|
start: 0,
|
dialogVisible: false,
|
dialogMsg: '',
|
fileList: [],
|
resultData: []
|
}
|
},
|
computed: {
|
importparam() {
|
return {}
|
}
|
},
|
created() {
|
this.fileList = []
|
this.resultData = []
|
},
|
methods: {
|
|
// Array.sort(function(obj1, obj2) {
|
// let val1 = obj1.key
|
// let val2 = obj2.key
|
// return val1 - val2
|
// }),
|
init() {
|
this.fileList = []
|
this.resultData = []
|
this.progress.id = guid()
|
let params = qs.stringify({
|
token: Cookies.get('token'),
|
progressId:this.progress.id
|
})
|
this.apiURL = `${window.SITE_CONFIG['apiURL']}/sys/dict/type/importDataDictExcel?${params}`
|
},
|
uploadExceed(files, fileList) {
|
this.$set(fileList[0], 'raw', files[0])
|
this.$set(fileList[0], 'name', files[0].name)
|
this.$refs.upload.clearFiles()
|
this.$refs.upload.handleStart(files[0])
|
},
|
succ(res, file, fileList) {
|
clearInterval(this.timer)
|
this.dataForm.speed = 100
|
this.$refs.upload.clearFiles()
|
this.fileList = []
|
if (res.code === 0) {
|
this.dataForm.text = res.msg
|
}
|
if (res.code === 501) {
|
this.dataForm.text = res.msg
|
if (res.data) {
|
this.resultData = res.data
|
}
|
}
|
this.$emit('refreshDataList')
|
},
|
err(res, file, fileList) {
|
clearInterval(this.timer)
|
this.dataForm.speed = 0
|
this.dataForm.text = '导入数据包格式有误'
|
this.$tip.error(res.msg)
|
},
|
submitUpload() {
|
this.dataForm.speed = 0
|
this.dataForm.text = ''
|
this.progress.speed = 0
|
this.progress.start = true
|
this.progress.timer = window.setInterval(this.getStroke, 1000)
|
this.uploadQuery()
|
},
|
uploadQuery() {
|
if (this.$refs.upload.uploadFiles.length === 1) {
|
this.start = 1
|
this.$refs.upload.submit()
|
} else {
|
this.$tip.error('请选择需要上传的.xlsx或.xls的文件')
|
}
|
//clearInterval(this.timers)
|
},
|
getStroke() {
|
//console.log('getStroke:',this.progress.start,",",this.progress.speed)
|
if (this.progress.start && this.progress.speed < 100) {
|
//console.log('getStroke2')
|
this.$http.get(`sys/common/stroke?progressId=${this.progress.id}`).then(
|
res=>{
|
if (res.success) {
|
this.progress.speed = parseFloat(res.data.speed)
|
this.progress.text = res.data.text
|
}
|
}
|
)
|
} else {
|
}
|
}
|
}
|
}
|
</script>
|
|
<style scoped>
|
|
</style>
|