Commit bb8f553e by 刘泽志

动态解析模板

parent 8ddee006
......@@ -330,3 +330,17 @@ export function uploadExcel(data) {
}
})
}
/**
* 根据基础模板重置字段
* @param excelId
* @returns {*}
*/
export function resetField(excelId){
return request({
url: `${prefix}/field/reset`,
method: 'get',
params:{excelId}
})
}
......@@ -18,7 +18,7 @@
</el-upload>
</div>
<div slot="footer" class="dialog-footer">
<el-button type="primary" @click="upload">上传</el-button>
<el-button type="primary" @click="upload" :loading="loading">上传</el-button>
<el-button @click="cancel">取 消</el-button>
</div>
</el-dialog>
......@@ -33,6 +33,10 @@ export default {
type: String,
default: ''
},
loading: {
type: Boolean,
default: false
},
width: {
type: String,
default: '400px'
......
......@@ -227,12 +227,15 @@
<el-input v-model="fieldDrawer.queryForm.coordinate"/>
</el-form-item>
<el-form-item label="">
<el-button :loading="fieldDrawer.queryFieldLoading" icon="el-icon-search" plain type="primary"
<el-button :loading="fieldDrawer.queryFieldLoading" icon="el-icon-search" type="primary"
@click="queryFieldList"
>查询
</el-button>
<el-button plain type="primary" @click="openFieldDialog">新增</el-button>
<el-button plain type="primary" @click="openQuicklyBind">快速绑定</el-button>
<el-button type="success" @click="openFieldDialog">新增</el-button>
<el-button type="warning" @click="openQuicklyBind">快速绑定</el-button>
<el-button type="warning" @click="resetField" :loading="fieldDrawer.resetFieldLoading"
:disabled="!fieldDrawer.template.excelId">模板初始化
</el-button>
</el-form-item>
</el-form>
<el-table v-loading="fieldDrawer.queryFieldLoading" :data="fieldDrawer.fieldList"
......@@ -311,6 +314,7 @@
:open.sync="initTemplateDialog.show"
title="初始模板上传"
@upload="initTemplateUpload"
:loading="initTemplateDialog.loading"
/>
</div>
</template>
......@@ -319,10 +323,11 @@
import * as Emport from '@/api/emport/Emport'
import StringUtil from '@/utils/document/StringUtil'
import AutoUpload from '@/views/emport/emport/AutoUpload.vue'
import {resetField} from "@/api/emport/Emport";
export default {
name: 'Emport',
components: { AutoUpload },
components: {AutoUpload},
data() {
return {
// 页面查询字段
......@@ -364,7 +369,7 @@ export default {
fieldId: null
},
fieldDrawer: { // 字段抽屉
template: null,
template: {},
show: false,
fieldList: [],
queryForm: {
......@@ -377,7 +382,8 @@ export default {
pageSize: 10,
total: 0
},
queryFieldLoading: false
queryFieldLoading: false,
resetFieldLoading: false
},
quicklyBindDialog: { // 字段dialog
show: false,
......@@ -386,7 +392,8 @@ export default {
},
initTemplateDialog: {
template: null,
show: false
show: false,
loading: false
},
importLoading: false, // 导入数据loading
queryTemplateLoading: false, // 模板查询loading
......@@ -395,6 +402,7 @@ export default {
}
},
created() {
this.queryTemplateLoading = true
this.initYearDict(() => {
let now = new Date()
this.queryForm.year = now.getFullYear() + ''
......@@ -508,7 +516,7 @@ export default {
// 打开年份字典编辑框
editYearDialog(data) {
this.yearDialog.title = '编辑年份'
this.yearDialog.data = { ...data }
this.yearDialog.data = {...data}
this.yearDialog.show = true
},
// 提交年份dialog
......@@ -532,7 +540,7 @@ export default {
})
},
// 删除年份字典
deleteYear({ id, label }) {
deleteYear({id, label}) {
this.$confirm(`是否删除数据项 ${label} ?`, '删除',
{
type: 'warning',
......@@ -554,13 +562,13 @@ export default {
// 打开机构类型字典新增框
openOrgDialog() {
this.orgDialog.title = '新增机构类型'
this.orgDialog.data = { type: 'org', value: '' }
this.orgDialog.data = {type: 'org', value: ''}
this.orgDialog.show = true
},
// 打开机构类型字典编辑框
editOrgDialog(data) {
this.orgDialog.title = '编辑机构类型'
this.orgDialog.data = { ...data }
this.orgDialog.data = {...data}
this.orgDialog.show = true
},
// 提交机构类型dialog
......@@ -590,7 +598,7 @@ export default {
})
},
// 删除机构类型字典
deleteOrg({ id, label }) {
deleteOrg({id, label}) {
this.$confirm(`是否删除数据项 ${label} ?`, '删除',
{
type: 'warning',
......@@ -626,7 +634,7 @@ export default {
this.queryForm.file = fileList[0]
},
// 文件上传方法
fileUpload({ file, onError, onProgress, onSuccess }) {
fileUpload({file, onError, onProgress, onSuccess}) {
this.importLoading = true
let formData = new FormData()
formData.append('file', file)
......@@ -702,7 +710,7 @@ export default {
// 打开模板编辑框
editTemplateDialog(row) {
this.templateDialog.title = '编辑模板'
this.templateDialog.data = { ...row }
this.templateDialog.data = {...row}
this.templateDialog.show = true
},
// 删除模板
......@@ -747,7 +755,7 @@ export default {
},
// 打开字段抽屉
openFieldDrawer(row) {
this.fieldDrawer.template = { ...row }
this.fieldDrawer.template = {...row}
this.fieldDrawer.queryForm = {
templateId: row.id,
code: '',
......@@ -783,7 +791,7 @@ export default {
// 打开修改字段的dialog
editFieldDialog(row) {
this.fieldDialog.title = '修改字段'
this.fieldDialog.data = { ...row }
this.fieldDialog.data = {...row}
this.fieldDialog.show = true
},
// 删除字段
......@@ -864,13 +872,14 @@ export default {
this.initTemplateDialog.show = true
},
// 初始化模板上上传方法
initTemplateUpload({ file, onSuccess }) {
initTemplateUpload({file, onSuccess}) {
let formData = new FormData()
formData.append('file', file)
formData.append('type', '2')
formData.append('templateId', this.initTemplateDialog.template.id)
formData.append('year', this.initTemplateDialog.template.year)
formData.append('orgName', this.initTemplateDialog.template.orgName)
this.initTemplateDialog.loading = true
Emport.uploadExcel(formData).then(res => {
if (res.code === 200) {
onSuccess()
......@@ -878,6 +887,22 @@ export default {
this.initTemplateDialog.show = false
this.initTemplate()
}
}).finally(_ => this.initTemplateDialog.loading = false)
},
// 重置字段信息
resetField() {
this.$confirm('此操作将覆盖原来设置的字段信息重新生成, 是否继续?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
this.fieldDrawer.resetFieldLoading = true
Emport.resetField(this.fieldDrawer.template.excelId).then(res => {
if (res.code === 200) {
this.$message.success("字段初始化成功")
this.queryFieldList()
}
}).finally(_ => this.fieldDrawer.resetFieldLoading = false)
})
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment