|
@@ -138,7 +138,7 @@
|
|
|
<el-row v-if="btnType == 'showShared'" style="margin: 10px 20px;">
|
|
|
<el-button type="primary" size="mini" icon="el-icon-download" @click="downloadReport">下载</el-button>
|
|
|
<el-button type="warning" size="mini" icon="el-icon-printer" @click="printExcel">打印</el-button>
|
|
|
- <el-button type="info" size="mini" icon="el-icon-document" @click="historyReport">运行记录</el-button>
|
|
|
+ <el-button v-if="chooseMyReport && chooseMyReport.reportTableType != 0" type="info" size="mini" icon="el-icon-document" @click="historyReport">运行记录</el-button>
|
|
|
<el-button type="danger" size="mini" icon="el-icon-circle-close" @click="cancelSaveReport">关闭</el-button>
|
|
|
</el-row>
|
|
|
<el-row v-if="btnType == 'showChild'" style="margin: 10px 20px;">
|
|
@@ -1142,65 +1142,67 @@ export default {
|
|
|
// const optionData = packtable(res, luckysheet.getAllSheets()[0])
|
|
|
// console.log('table2==>', optionData)
|
|
|
setTimeout(() => {
|
|
|
- this.drawTableData(res, p.showType, luckysheet.getAllSheets()[0])
|
|
|
+ // this.drawTableData(res, p.showType, luckysheet.getAllSheets()[0])
|
|
|
}, 500)
|
|
|
})
|
|
|
},
|
|
|
- drawBaseInfo() {
|
|
|
+ /** 初始化表格基础数据项值 */
|
|
|
+ initBaseInfoData(data) {
|
|
|
let currDate = getNowFormatDate('yyyy-MM-dd')
|
|
|
let currDateTime = getNowFormatDate('yyyy-MM-dd HH:mm:ss')
|
|
|
+ data.baseItem = {
|
|
|
+ 'currDate': currDate,
|
|
|
+ 'currDateTime': currDateTime,
|
|
|
+ 'userName': getUsername(),
|
|
|
+ 'winUserName': process.env.VUE_APP_WINNAME
|
|
|
+ }
|
|
|
+ return data
|
|
|
+ },
|
|
|
+ /** 绘制基础数据项布局信息 */
|
|
|
+ drawBaseInfo(baseData) {
|
|
|
+ if (!baseData) return
|
|
|
let option = luckysheet.getAllSheets()[0]
|
|
|
option.celldata.map(item => {
|
|
|
if (item.v.v) {
|
|
|
- item.v.v = String(item.v.v).trim();
|
|
|
+ item.v.v = String(item.v.v).trim()
|
|
|
if (item.v.v.match(/\${([^}]+)}/g)) { // 替换${xxx}内部数据
|
|
|
if (item.v.v.indexOf('${currDate}') > -1) {
|
|
|
let val = item.v.v
|
|
|
- val = val.replace('${currDate}', currDate)
|
|
|
+ val = val.replace('${currDate}', baseData.currDate)
|
|
|
luckysheet.setCellValue(item.r, item.c, val)
|
|
|
}
|
|
|
if (item.v.v.indexOf('${currDateTime}') > -1) {
|
|
|
let val = item.v.v
|
|
|
- val = val.replace('${currDateTime}', currDateTime)
|
|
|
+ val = val.replace('${currDateTime}', baseData.currDateTime)
|
|
|
luckysheet.setCellValue(item.r, item.c, val)
|
|
|
}
|
|
|
if (item.v.v.indexOf('${userName}') > -1) {
|
|
|
let val = item.v.v
|
|
|
- val = val.replace('${userName}', getUsername())
|
|
|
+ val = val.replace('${userName}', baseData.userName)
|
|
|
luckysheet.setCellValue(item.r, item.c, val)
|
|
|
}
|
|
|
if (item.v.v.indexOf('${winUserName}') > -1) {
|
|
|
let val = item.v.v
|
|
|
- val = val.replace('${winUserName}', process.env.VUE_APP_WINNAME)
|
|
|
+ val = val.replace('${winUserName}', baseData.winUserName)
|
|
|
luckysheet.setCellValue(item.r, item.c, val)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
})
|
|
|
},
|
|
|
- drawTableData(sources, type, option) {
|
|
|
- option.celldata.map(item => {
|
|
|
- if (item.v.v) {
|
|
|
- item.v.v = String(item.v.v).trim();
|
|
|
- if (item.v.v.match(/\${([^}]+)}/g)) { // 替换${xxx}内部数据
|
|
|
- sources.forEach(source => {
|
|
|
- let itemName = source.itemName
|
|
|
- itemName = itemName.substring(itemName.lastIndexOf('.') + 1)
|
|
|
- let name = '${' + source.itemGroupId + '.' + itemName + '.' + type.dataId + '}'
|
|
|
- if (item.v.v === name) {
|
|
|
- let dataList = source.dataList
|
|
|
- // for (let i = 0; i < dataList.length; i++) {
|
|
|
- for (let i = 0; i < type.valLine; i++) {
|
|
|
- let p_r = parseInt(item.r)
|
|
|
- let p_c = parseInt(item.c)
|
|
|
- if (type.valType == '2') p_r += i
|
|
|
- else p_c += i
|
|
|
- luckysheet.setCellValue(p_r, p_c, (dataList[i] != null && dataList[i] != undefined) ? dataList[i] : cqcyCode['invalidData'])
|
|
|
- }
|
|
|
- }
|
|
|
- })
|
|
|
- }
|
|
|
- }
|
|
|
+ /** 绘制表格数据 */
|
|
|
+ drawTableData(tableItemList) {
|
|
|
+ if (!tableItemList || tableItemList.length == 0) return
|
|
|
+ tableItemList.forEach((tableItem, i) => {
|
|
|
+ // console.log(tableItem)
|
|
|
+ let standby = tableItem.standby ? JSON.parse(tableItem.standby) : {}
|
|
|
+ let dataIndex = standby.index != null ? standby.index : -1
|
|
|
+ let valueList = tableItem.valueList ? tableItem.valueList.split(',') : []
|
|
|
+ let val = (dataIndex == -1 || (dataIndex + 1) > valueList.length)
|
|
|
+ ? cqcyCode['invalidData'] : valueList[dataIndex]
|
|
|
+ let xAxis = tableItem.xaxis
|
|
|
+ let yAxis = tableItem.yaxis
|
|
|
+ luckysheet.setCellValue(xAxis, yAxis, val)
|
|
|
})
|
|
|
},
|
|
|
/** 向 Excel 插入图表 */
|
|
@@ -1473,39 +1475,40 @@ export default {
|
|
|
}
|
|
|
const loading = showLoading(this, '加载中,请稍候···')
|
|
|
getReportTableById(data.id).then(res => {
|
|
|
- loading.close()
|
|
|
- if (!res.data) {
|
|
|
+ let _data = res.data
|
|
|
+ if (!_data) {
|
|
|
+ loading.close()
|
|
|
showAlertMsgWin(this, null, '选择的报表不存在!')
|
|
|
return
|
|
|
}
|
|
|
this.showMainView = true
|
|
|
- this.breadcrumbList = [res.data.reportTableName]
|
|
|
- let reportTableData = res.data.reportTableData
|
|
|
- this.reportForm.valueCondition = res.data.valueCondition
|
|
|
- this.reportForm.reportValueFormat = res.data.reportValueFormat
|
|
|
- let luckyData = JSON.parse(reportTableData)
|
|
|
- console.log(luckyData)
|
|
|
- // 只读
|
|
|
+ this.breadcrumbList = [_data.reportTableName]
|
|
|
+ // 判断是否运行记录
|
|
|
if (type === 'history') {
|
|
|
this.dialogHistoryReportVisible = false
|
|
|
this.btnType = 'showChild'
|
|
|
- } else if (type === 'deny') {
|
|
|
- this.chooseMyReport = res.data
|
|
|
- this.dialogHistoryReportVisible = false
|
|
|
- this.btnType = 'showShared'
|
|
|
} else {
|
|
|
this.chooseMyReport = res.data
|
|
|
- this.btnType = 'show'
|
|
|
+ console.log(this.chooseMyReport)
|
|
|
+ this.btnType = 'showShared'
|
|
|
}
|
|
|
- this.setLuckysheetStatus(luckyData, type === 'history' || type === 'deny', type)
|
|
|
+ this.setLuckysheetStatus(_data, true, type, loading)
|
|
|
}).catch((e) => {
|
|
|
loading.close()
|
|
|
showAlertWin(this, null, e)
|
|
|
})
|
|
|
},
|
|
|
/** 设置工作表状态 */
|
|
|
- setLuckysheetStatus(luckyData, isReadOnly, type) {
|
|
|
+ setLuckysheetStatus(dataInfo, isReadOnly, type, loading) {
|
|
|
let _this = this
|
|
|
+ // 报表数据
|
|
|
+ let reportTableData = dataInfo.reportTableData
|
|
|
+ let luckyData = JSON.parse(reportTableData)
|
|
|
+ // 基础数据项值
|
|
|
+ let baseItem = luckyData.baseItem
|
|
|
+ // 数据项
|
|
|
+ let reportTableItemList = dataInfo.reportTableItemList
|
|
|
+
|
|
|
luckysheet.destroy()
|
|
|
let option = luckyData.option
|
|
|
if (!option) option = JSON.parse(JSON.stringify(this.luckysheetOption))
|
|
@@ -1547,9 +1550,8 @@ export default {
|
|
|
// 钩子函数
|
|
|
option.hook = {
|
|
|
workbookCreateAfter() {
|
|
|
+ // 图表操作
|
|
|
let charts = luckyData.charts
|
|
|
- let tables = luckyData.tables
|
|
|
- let eventTables = luckyData.eventTables
|
|
|
option.data.forEach((data, i) => {
|
|
|
if (data.chart && data.chart.length > 0) {
|
|
|
data.chart.forEach((chart, j) => {
|
|
@@ -1559,38 +1561,31 @@ export default {
|
|
|
})
|
|
|
}
|
|
|
})
|
|
|
- if (type == 'deny') {
|
|
|
- for (let i in charts) {
|
|
|
- _this.insertEChartInfo(charts[i])
|
|
|
- }
|
|
|
- for (let i in tables) {
|
|
|
- _this.insertTableInfo(tables[i])
|
|
|
- }
|
|
|
- _this.drawBaseInfo()
|
|
|
+ for (let i in charts) {
|
|
|
+ _this.insertEChartInfo(charts[i])
|
|
|
}
|
|
|
- _this.drawAutoReportData(luckyData.tables)
|
|
|
- // 事件驱动报表信息
|
|
|
- _this.drawEventReportData(eventTables)
|
|
|
+ // 绘制基础数据项
|
|
|
+ _this.drawBaseInfo(baseItem)
|
|
|
+ // 绘制数据值
|
|
|
+ _this.drawTableData(reportTableItemList)
|
|
|
luckysheet.setRangeShow('BH1')
|
|
|
+ if (loading) loading.close()
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
|
let charts = luckyData.charts
|
|
|
- let tables = luckyData.tables
|
|
|
- let eventTables = luckyData.eventTables
|
|
|
// 钩子函数
|
|
|
option.hook = {
|
|
|
workbookCreateAfter() {
|
|
|
for (let i in charts) {
|
|
|
_this.insertEChartInfo(charts[i])
|
|
|
}
|
|
|
- for (let i in tables) {
|
|
|
- _this.insertTableInfo(tables[i])
|
|
|
- }
|
|
|
- _this.drawBaseInfo()
|
|
|
- // 事件驱动报表信息
|
|
|
- _this.drawEventReportData(eventTables)
|
|
|
+ // 绘制基础数据项
|
|
|
+ _this.drawBaseInfo(baseItem)
|
|
|
+ // 绘制数据值
|
|
|
+ _this.drawTableData(reportTableItemList)
|
|
|
luckysheet.setRangeShow('BH1')
|
|
|
+ if (loading) loading.close()
|
|
|
},
|
|
|
cellUpdated(r, c, newV, oldV) {
|
|
|
if (!(r === 49 && c === 0)) {
|
|
@@ -1805,7 +1800,8 @@ export default {
|
|
|
/** 保存报表信息 */
|
|
|
saveReportInfo(loading, dataInfo) {
|
|
|
if (!loading) loading = showLoading(this, '保存中,请稍候···')
|
|
|
- this.reportForm.reportTableData = JSON.stringify(dataInfo)
|
|
|
+ let _excelData = this.initBaseInfoData(dataInfo)
|
|
|
+ this.reportForm.reportTableData = JSON.stringify(_excelData)
|
|
|
saveReport(this.reportForm).then(res => {
|
|
|
loading.close()
|
|
|
let msg = res.data ? '保存成功!' : '保存失败!'
|