Browse Source

模板导入新增联调

luckysheet_xiaowang
mk 8 months ago
parent
commit
a8c4a6b459
  1. 1
      src/views/modules/base/smartExcel/cpts/excel-upload-data.vue
  2. 69
      src/views/modules/base/smartExcel/cpts/export-view.vue
  3. 2
      src/views/modules/base/smartExcel/filling.vue

1
src/views/modules/base/smartExcel/cpts/excel-upload-data.vue

@ -269,6 +269,7 @@ export default {
} }
this.$emit('handleUploadDataHide', data) this.$emit('handleUploadDataHide', data)
} else { } else {
this.dataListLoading = false;
console.log(msg); console.log(msg);
} }
}, },

69
src/views/modules/base/smartExcel/cpts/export-view.vue

@ -18,7 +18,7 @@
<el-dialog title="数据列表导出" v-if="showUploadData" :visible.sync="showUploadData" width="60%" <el-dialog title="数据列表导出" v-if="showUploadData" :visible.sync="showUploadData" width="60%"
:close-on-click-modal="false"> :close-on-click-modal="false">
<excelUploadData @handleUploadDataHide="handleUploadDataHide" :currentTable="currentTable" <excelUploadData @handleUploadDataHide="handleUploadDataHide" :currentTable="currentTable"
:btnLoading="btnLoading" :pageType='`report`' :workBookId="workBookId" @saveLuckysheetHead="saveLuckysheet"> :btnLoading="btnLoading" :pageType='`report`' :workBookId="workBookId" @saveLuckysheetHead="saveLuckysheetHead">
</excelUploadData> </excelUploadData>
</el-dialog> </el-dialog>
<el-dialog title="数据统计条件" v-if="showCondition" :visible.sync="showCondition" width="60%" <el-dialog title="数据统计条件" v-if="showCondition" :visible.sync="showCondition" width="60%"
@ -27,8 +27,7 @@
</el-dialog> </el-dialog>
<el-dialog title="上传统计模板" v-if="showTemplate" :visible.sync="showTemplate" width="60%" <el-dialog title="上传统计模板" v-if="showTemplate" :visible.sync="showTemplate" width="60%"
:close-on-click-modal="false"> :close-on-click-modal="false">
<el-form :model="dataForm" :rules="dataRule" ref="dataForm" <el-form :model="dataForm" :rules="dataRule" ref="dataForm" :label-width="'120px'">
:label-width="'120px'">
<el-form-item label="报表名称" prop="reportName"> <el-form-item label="报表名称" prop="reportName">
<el-input v-model.trim="dataForm.reportName" placeholder="报表名称"></el-input> <el-input v-model.trim="dataForm.reportName" placeholder="报表名称"></el-input>
</el-form-item> </el-form-item>
@ -73,7 +72,6 @@ export default {
currentTable: null, currentTable: null,
currentId: '', currentId: '',
btnLoading: false, btnLoading: false,
workBookId: '',
infoObj: {}, infoObj: {},
showCondition: false, showCondition: false,
showTemplate: false, showTemplate: false,
@ -81,11 +79,15 @@ export default {
reportType: 1,//01 reportType: 1,//01
reportName: '',// reportName: '',//
workbookId: '', workbookId: '',
formCode: "",
columnsJson: [],
searchForm: {}
}, },
dataRule: { dataRule: {
reportName: [{ required: true, message: this.$t('validate.required'), trigger: 'blur' }] reportName: [{ required: true, message: this.$t('validate.required'), trigger: 'blur' }]
}, },
exportJson:null, exportJson: null,
importType: ''//template list
}; };
}, },
props: { props: {
@ -108,10 +110,11 @@ export default {
}, },
watch: {}, watch: {},
async mounted() { async mounted() {
await this.loadWorkBook()
this.$nextTick(async () => { this.$nextTick(async () => {
if (this.pageType === 'info') { if (this.pageType === 'info') {
await this.loadWorkBook()
await this.getSheetList() await this.getSheetList()
if (this.infoObj.reportType === 0) {
let heading = this.infoObj.columnsJson[0].children.map(item => ({ label: item.label })) let heading = this.infoObj.columnsJson[0].children.map(item => ({ label: item.label }))
for (let i in heading) { for (let i in heading) {
luckysheet.setCellValue(0, i, heading[i].label) luckysheet.setCellValue(0, i, heading[i].label)
@ -129,8 +132,14 @@ export default {
}); });
let bottomRightCorner = this.numberToLetter(Object.keys(list[0]).length)// let bottomRightCorner = this.numberToLetter(Object.keys(list[0]).length)//
luckysheet.setRangeValue(newArray, { luckysheet.setRangeValue(newArray, {
range: `A2:${bottomRightCorner}${2 + list.length}`, range: `A2:${bottomRightCorner}${list.length}`,
}) })
}else{
await this.loadWorkBook(this.infoObj.workbookId)
}
}else{
await this.loadWorkBook()
} }
}) })
}, },
@ -163,12 +172,10 @@ export default {
throw error; throw error;
} }
}, },
uploadExcel(files) { async uploadExcel(files) {
if (!files) return alert('没有文件等待导入'); if (!files) return alert('没有文件等待导入');
let that = this let that = this
LuckyExcel.transformExcelToLucky(files, function (exportJson, luckysheetfile) { LuckyExcel.transformExcelToLucky(files, function (exportJson, luckysheetfile) {
console.log(exportJson, '获取到导入的JSON');
that.exportJson = exportJson
if (exportJson.sheets == null || exportJson.sheets.length == 0) return alert('读取excel文件内容失败, 目前不支持XLS文件!'); if (exportJson.sheets == null || exportJson.sheets.length == 0) return alert('读取excel文件内容失败, 目前不支持XLS文件!');
window.luckysheet.destroy(); window.luckysheet.destroy();
options.container = 'luckysheet-export' options.container = 'luckysheet-export'
@ -179,8 +186,10 @@ export default {
title: exportJson.info.name, title: exportJson.info.name,
hook: {}, hook: {},
}); });
}); });
this.saveLuckysheet() await nextTick(1000)
await this.saveLuckysheetHead()
}, },
beforeExcelUpload(file) { beforeExcelUpload(file) {
this.fullscreenLoading = true; this.fullscreenLoading = true;
@ -200,7 +209,7 @@ export default {
return fileType && isLt1M; return fileType && isLt1M;
}, },
onClickShowCondition() { onClickShowCondition() {
this.showCondition = true this.showCondition = true;
}, },
async getSheetList() { async getSheetList() {
const { data, code } = await requestGet('/actual/base/intellgentizeReport/detail', { id: this.infoIds.id }) const { data, code } = await requestGet('/actual/base/intellgentizeReport/detail', { id: this.infoIds.id })
@ -214,16 +223,17 @@ export default {
// //
async handleClickInspect() { async handleClickInspect() {
this.showTemplate = true; this.showTemplate = true;
this.importType = 'template'
}, },
onClickUplond() { onClickUplond() {
this.showUploadData = true; this.showUploadData = true;
let list = luckysheet.getAllSheets() let list = luckysheet.getAllSheets()
this.currentTable = list.filter(item => item.status == '1') this.currentTable = list.filter(item => item.status == '1')
this.importType = 'list'
}, },
async handleUploadDataHide(val) { async handleUploadDataHide(val) {
let listData = await this.getListData(val.id) const listData = await this.getListData(val.id)
luckysheet.insertRow(this.currentTable[0].data.length, 1) luckysheet.insertRow(this.currentTable[0].data.length, 1)
luckysheet.insertRow(this.currentTable[0].data.length, { number: listData.length }); luckysheet.insertRow(this.currentTable[0].data.length, { number: listData.length });
this.showUploadData = false; this.showUploadData = false;
@ -235,21 +245,34 @@ export default {
}); });
let bottomRightCorner = this.numberToLetter(Object.keys(listData[0]).length)// let bottomRightCorner = this.numberToLetter(Object.keys(listData[0]).length)//
luckysheet.setRangeValue(newArray, { luckysheet.setRangeValue(newArray, {
range: `A2:${bottomRightCorner}${2 + listData.length}`, range: `A2:${bottomRightCorner}${listData.length}`,
}) })
}, },
async saveLuckysheet(head) { async saveLuckysheetHead(head) {
if (this.currentTable[0].data[0].every(item => !item) && head) { // this.currentTable[0].data[0].every(item => !item) &&
if (head && this.importType === 'list') {
let temp = head.map(item => item.children).flat(); let temp = head.map(item => item.children).flat();
for (let i in temp) { for (let i in temp) {
luckysheet.setCellValue(0, i, temp[i].label) luckysheet.setCellValue(0, i, temp[i].label)
} }
} }
let luckysheetJson = luckysheet.getAllSheets() let luckysheetJson = luckysheet.getAllSheets()
const { data, code, msg } = await requestPost(`/actual/base/luckySheet/workbook/createByJson?fileName=`, luckysheetJson) const { data, code, msg } = await requestPost(`/actual/base/luckySheet/workbook/createByJson?fileName=${this.dataForm.reportName}`, luckysheetJson)
if (code === 0) { if (code === 0) {
this.workBookId = data.workbookId; this.dataForm.workbookId = data.workbookId;
if (this.importType === 'template') {
this.createdReport()
}
} else {
console.log(msg);
}
},
//
async createdReport() {
const url = '/actual/base/intellgentizeReport/create'
let { data, code, msg } = await requestPost(url, this.dataForm)
if (code === 0) {
console.log(data);
} else { } else {
console.log(msg); console.log(msg);
} }
@ -271,10 +294,10 @@ export default {
} }
return letter; return letter;
}, },
loadWorkBook() { loadWorkBook(workbookId) {
options.container = 'luckysheet-export' options.container = 'luckysheet-export'
options.gridKey = this.pageType === 'info' ? this.infoIds.workbookId : null; options.gridKey = this.pageType === 'info' ? this.infoIds.workbookId : null;
options.loadUrl = null options.loadUrl = workbookId?`${process.env.VUE_APP_API_SERVER}/actual/base/luckySheet/workbook/load?workbookId=${workbookId}`:null
window.luckysheet.create({ window.luckysheet.create({
...options, ...options,
}); });
@ -321,7 +344,7 @@ export default {
height: calc(100vh - 250px); height: calc(100vh - 250px);
} }
#luckysheet-export{ #luckysheet-export {
width: 100%; width: 100%;
padding: 0px; padding: 0px;
z-index: 2; z-index: 2;

2
src/views/modules/base/smartExcel/filling.vue

@ -50,7 +50,7 @@
</el-form> </el-form>
</div> </div>
<div class="m-table"> <div class="m-table">
<el-table :data="tableData" border class="m-table-item" style="width: 100%" :height="maxTableHeight"> <el-table :data="tableData" border class="m-table-item" style="width: 100%" >
<el-table-column label="" fixed="left" type="selection" align="center" width="50" /> <el-table-column label="" fixed="left" type="selection" align="center" width="50" />
<el-table-column label="序号" fixed="left" type="index" align="center" width="50" /> <el-table-column label="序号" fixed="left" type="index" align="center" width="50" />
<el-table-column prop="agencyName" align="center" label="发布组织" :show-overflow-tooltip="true"> <el-table-column prop="agencyName" align="center" label="发布组织" :show-overflow-tooltip="true">

Loading…
Cancel
Save