Commit 12f2ed43 by 刘泽志

文档上传

parent bb8f553e
......@@ -332,6 +332,44 @@ export function uploadExcel(data) {
}
/**
* 下载模板
* @param excelId
* @returns {*}
*/
export function downloadTemplate(excelId) {
return request({
url: `${prefix}/template/download`,
method: 'get',
params:{excelId},
headers: { "Content-Type": "application/x-www-form-urlencoded" },
responseType: "blob",
})
}
/**
* 下载模板
* @param excelId
* @returns {*}
*/
export function getTemplateFileName(excelId) {
return request({
url: `${prefix}/template/download/filename`,
method: 'get',
params:{excelId}
})
}
export async function blobValidate(data) {
try {
const text = await data.text();
JSON.parse(text);
return false;
} catch (error) {
return true;
}
}
/**
* 根据基础模板重置字段
* @param excelId
* @returns {*}
......@@ -344,3 +382,29 @@ export function resetField(excelId){
})
}
/**
* 创建物理表
* @param tableName
* @param templateId
* @returns {*}
*/
export function createTable(tableName,templateId){
return request({
url: `${prefix}/table/create`,
method: 'get',
params:{tableName,templateId}
})
}
/**
* 数据分析并导出
* @param templateId
* @returns {*}
*/
export function analyzeExport(templateId){
return request({
url: `${prefix}/analyze/export`,
method: 'get',
params:{templateId}
})
}
<template>
<el-dialog :close-on-click-modal="false"
:show-close="false"
:visible="loading" :width="width"
append-to-body center
class="dialog-loading"
custom-class="dialog-loading-custom"
>
<div v-loading="loading"
:element-loading-text="content"
:style="{height: height}"
element-loading-spinner="el-icon-loading"
></div>
</el-dialog>
</template>
<script>
export default {
name: 'AutoLoading',
props: {
loading: {
type: Boolean,
default: false
},
content: {
type: String,
default: ''
},
width: {
type: String,
default: '300px'
},
height: {
type: String,
default: '200px'
}
}
}
</script>
<style lang="scss" scoped>
.dialog-loading {
::v-deep {
.el-dialog__header {
display: none;
}
.el-loading-mask {
border-radius: 16px;
background-color: transparent;
}
.dialog-loading-custom {
border-radius: 16px;
background-color: rgba(255, 255, 255,0.5);
}
.el-dialog__body {
padding: 0;
}
}
}
</style>
......@@ -45,7 +45,9 @@
<el-divider class="divider1"></el-divider>
<el-form inline size="small">
<el-form-item>
<el-button style="margin-left:6px;" size="small" icon="el-icon-pie-chart" plain>分析并导出</el-button>
<el-button icon="el-icon-pie-chart" plain
size="small"
style="margin-left:6px;" @click="analyzeExport">分析并导出</el-button>
<el-button size="small" icon="el-icon-set-up" plain>设置机构字典</el-button>
<el-button size="small" icon="el-icon-refresh" plain>清空数据</el-button>
<el-button icon="el-icon-folder-add" plain size="small" @click="openTemplateDialog">添加模板</el-button>
......@@ -78,7 +80,10 @@
<el-dropdown-item icon="el-icon-upload2" @click.native="openUploadTemplate(scope.row)">
模板上传
</el-dropdown-item>
<el-dropdown-item icon="el-icon-download">模板下载</el-dropdown-item>
<el-dropdown-item :disabled="!scope.row.excelId" icon="el-icon-download"
@click.native="downloadTemplate(scope.row)"
>模板下载
</el-dropdown-item>
<el-dropdown-item icon="el-icon-view" @click.native="openFieldDrawer(scope.row)">查看字段
</el-dropdown-item>
</el-dropdown-menu>
......@@ -197,10 +202,12 @@
<el-input-number v-model="fieldDialog.data.sort" :min="0" :precision="0"/>
</el-form-item>
<el-form-item label="数据库字段" prop="field">
<el-select v-model="fieldDialog.data.field" :popper-append-to-body="false">
<el-select v-if="false" v-model="fieldDialog.data.field" :popper-append-to-body="false">
<el-option v-for="item in fieldDict" :key="item.id" :label="item.label" :value="item.value"
></el-option>
</el-select>
<el-autocomplete v-model="fieldDialog.data.field" :fetch-suggestions="fetchSuggestions">
</el-autocomplete>
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
......@@ -227,14 +234,17 @@
<el-input v-model="fieldDrawer.queryForm.coordinate"/>
</el-form-item>
<el-form-item label="">
<el-button :loading="fieldDrawer.queryFieldLoading" icon="el-icon-search" type="primary"
<el-button :loading="fieldDrawer.queryFieldLoading" icon="el-icon-search" style="margin-left: 8px" type="primary"
@click="queryFieldList"
>查询
</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">模板初始化
:disabled="!fieldDrawer.template.excelId"
>模板初始化
</el-button>
<el-button type="info" @click="createTable">物理表生成
</el-button>
</el-form-item>
</el-form>
......@@ -316,6 +326,10 @@
@upload="initTemplateUpload"
:loading="initTemplateDialog.loading"
/>
<!-- 分析loading -->
<AutoLoading
:content="analyzeData.content"
:loading="analyzeData.loading" />
</div>
</template>
......@@ -323,11 +337,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";
import AutoLoading from '@/views/emport/emport/AutoLoading.vue'
export default {
name: 'Emport',
components: {AutoUpload},
components: { AutoLoading, AutoUpload },
data() {
return {
// 页面查询字段
......@@ -398,7 +412,11 @@ export default {
importLoading: false, // 导入数据loading
queryTemplateLoading: false, // 模板查询loading
queryTableLoading: false, // 查询数据表loading
templateList: [] // 模板列表
templateList: [], // 模板列表
analyzeData:{
loading: false,
content: ""
}
}
},
created() {
......@@ -516,7 +534,7 @@ export default {
// 打开年份字典编辑框
editYearDialog(data) {
this.yearDialog.title = '编辑年份'
this.yearDialog.data = {...data}
this.yearDialog.data = { ...data }
this.yearDialog.show = true
},
// 提交年份dialog
......@@ -540,7 +558,7 @@ export default {
})
},
// 删除年份字典
deleteYear({id, label}) {
deleteYear({ id, label }) {
this.$confirm(`是否删除数据项 ${label} ?`, '删除',
{
type: 'warning',
......@@ -562,13 +580,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
......@@ -598,7 +616,7 @@ export default {
})
},
// 删除机构类型字典
deleteOrg({id, label}) {
deleteOrg({ id, label }) {
this.$confirm(`是否删除数据项 ${label} ?`, '删除',
{
type: 'warning',
......@@ -634,10 +652,15 @@ 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)
let template = this.templateList.find(item=>item.orgName === this.queryForm.orgName)
formData.append("type","1")
formData.append("templateId",template.id)
formData.append("year",template.year)
formData.append("orgName",template.orgName)
//formData.append("templateId", this.checkTemplate.id);
Emport.uploadExcel(formData)
.then((res) => {
......@@ -710,7 +733,7 @@ export default {
// 打开模板编辑框
editTemplateDialog(row) {
this.templateDialog.title = '编辑模板'
this.templateDialog.data = {...row}
this.templateDialog.data = { ...row }
this.templateDialog.show = true
},
// 删除模板
......@@ -755,7 +778,7 @@ export default {
},
// 打开字段抽屉
openFieldDrawer(row) {
this.fieldDrawer.template = {...row}
this.fieldDrawer.template = { ...row }
this.fieldDrawer.queryForm = {
templateId: row.id,
code: '',
......@@ -791,7 +814,7 @@ export default {
// 打开修改字段的dialog
editFieldDialog(row) {
this.fieldDialog.title = '修改字段'
this.fieldDialog.data = {...row}
this.fieldDialog.data = { ...row }
this.fieldDialog.show = true
},
// 删除字段
......@@ -872,7 +895,7 @@ export default {
this.initTemplateDialog.show = true
},
// 初始化模板上上传方法
initTemplateUpload({file, onSuccess}) {
initTemplateUpload({ file, onSuccess }) {
let formData = new FormData()
formData.append('file', file)
formData.append('type', '2')
......@@ -899,12 +922,68 @@ export default {
this.fieldDrawer.resetFieldLoading = true
Emport.resetField(this.fieldDrawer.template.excelId).then(res => {
if (res.code === 200) {
this.$message.success("字段初始化成功")
this.$message.success('字段初始化成功')
this.queryFieldList()
}
}).finally(_ => this.fieldDrawer.resetFieldLoading = false)
})
}
},
// 模板下载
downloadTemplate(row) {
Emport.downloadTemplate(row.excelId)
.then(async res => {
const isFile = await Emport.blobValidate(res)
if (isFile) {
const { data } = await Emport.getTemplateFileName(row.excelId)
//const blob = new Blob([res])
saveAs(res, data.fileName)
}
})
},
// 物理表生成
createTable() {
let template = this.fieldDrawer.template
this.$prompt('请输入要生成的表名(表名会自动转成大写形式)', '物理表生成',
{
confirmButtonText: '确定',
cancelButtonText: '取消',
beforeClose: (action, instance, done) => {
if (action === 'confirm') {
instance.confirmButtonLoading = true
Emport.createTable(instance.inputValue, template.id).then(res => {
if (res.code === 200) {
this.$message.success({
message: '物理表创建成功',
duration: 1000 * 5
})
done()
}
}).finally(_ => instance.confirmButtonLoading = false)
} else {
done()
}
}
}
)
},
// 字段输入建议
fetchSuggestions(qs, callback) {
if (!this.fieldDict) {
callback([])
return
}
if (qs) {
let result = this.fieldDict.filter(item => item.label.toUpperCase().includes(qs.toUpperCase()))
callback(result)
} else {
callback(this.fieldDict)
}
},
// 数据分析并导出
analyzeExport(){
this.analyzeData.content="正在分析导入数据"
this.analyzeData.loading = true
},
}
}
</script>
......
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