|
@@ -1,11 +1,5 @@
|
|
<template>
|
|
<template>
|
|
- <div
|
|
+ <div class="statstics-wrapper">
|
|
- v-loading="loading"
|
|
|
|
- element-loading-text="拼命加载中"
|
|
|
|
- element-loading-spinner="el-icon-loading"
|
|
|
|
- element-loading-background="rgba(0, 0, 0, 0.8)"
|
|
|
|
- class="statstics-wrapper"
|
|
|
|
- >
|
|
|
|
<div
|
|
<div
|
|
ref="headerWrapper"
|
|
ref="headerWrapper"
|
|
class="statstics-header"
|
|
class="statstics-header"
|
|
@@ -13,8 +7,6 @@
|
|
<StatisticsHeader
|
|
<StatisticsHeader
|
|
:title="`${chartsTitle}统计`"
|
|
:title="`${chartsTitle}统计`"
|
|
:custom-items="customFormItems"
|
|
:custom-items="customFormItems"
|
|
- :items="formItems"
|
|
|
|
- :data.sync="formData"
|
|
|
|
@getFormData="getFormData"
|
|
@getFormData="getFormData"
|
|
@export="exportHandler"
|
|
@export="exportHandler"
|
|
/>
|
|
/>
|
|
@@ -43,33 +35,24 @@ export default {
|
|
props: {
|
|
props: {
|
|
chartsTitle: {
|
|
chartsTitle: {
|
|
type: String,
|
|
type: String,
|
|
- required: true,
|
|
+ required: true
|
|
},
|
|
},
|
|
querySettings: {
|
|
querySettings: {
|
|
type: Object,
|
|
type: Object,
|
|
- required: true,
|
|
+ required: true
|
|
},
|
|
},
|
|
customFormItems: {
|
|
customFormItems: {
|
|
type: Array,
|
|
type: Array,
|
|
- default: () => [],
|
|
+ default: () => []
|
|
- },
|
|
+ }
|
|
- formItems: {
|
|
|
|
- type: Array,
|
|
|
|
- },
|
|
|
|
- formData: {
|
|
|
|
- type: Object,
|
|
|
|
- required: true,
|
|
|
|
- },
|
|
|
|
},
|
|
},
|
|
data() {
|
|
data() {
|
|
return {
|
|
return {
|
|
- loading: false,
|
|
|
|
myChart: null,
|
|
myChart: null,
|
|
debounceTime: 300,
|
|
debounceTime: 300,
|
|
chartHeight: '70vh',
|
|
chartHeight: '70vh',
|
|
hasChartData: false,
|
|
hasChartData: false,
|
|
seriesKey: 'seriesData',
|
|
seriesKey: 'seriesData',
|
|
- xAxisKey: 'flight_date',
|
|
|
|
filters: [],
|
|
filters: [],
|
|
tableData: [],
|
|
tableData: [],
|
|
params: [],
|
|
params: [],
|
|
@@ -80,9 +63,9 @@ export default {
|
|
axisPointer: {
|
|
axisPointer: {
|
|
type: 'cross',
|
|
type: 'cross',
|
|
crossStyle: {
|
|
crossStyle: {
|
|
- color: '#999',
|
|
+ color: '#999'
|
|
- },
|
|
+ }
|
|
- },
|
|
+ }
|
|
},
|
|
},
|
|
legend: {
|
|
legend: {
|
|
top: '5%',
|
|
top: '5%',
|
|
@@ -95,37 +78,37 @@ export default {
|
|
data: [
|
|
data: [
|
|
this.chartsTitle.replace('量', '数量'),
|
|
this.chartsTitle.replace('量', '数量'),
|
|
// `${this.chartsTitle}量同比`,
|
|
// `${this.chartsTitle}量同比`,
|
|
- `${this.chartsTitle}环比`,
|
|
+ `${this.chartsTitle}环比`
|
|
],
|
|
],
|
|
textStyle: {
|
|
textStyle: {
|
|
fontFamily: 'Helvetica, "Microsoft YaHei"',
|
|
fontFamily: 'Helvetica, "Microsoft YaHei"',
|
|
- color: '#101116',
|
|
+ color: '#101116'
|
|
- },
|
|
+ }
|
|
},
|
|
},
|
|
grid: {
|
|
grid: {
|
|
top: '15%',
|
|
top: '15%',
|
|
left: '5%',
|
|
left: '5%',
|
|
right: '5%',
|
|
right: '5%',
|
|
- bottom: '5%',
|
|
+ bottom: '5%'
|
|
},
|
|
},
|
|
xAxis: {
|
|
xAxis: {
|
|
data: [],
|
|
data: [],
|
|
axisLine: {
|
|
axisLine: {
|
|
show: true,
|
|
show: true,
|
|
lineStyle: {
|
|
lineStyle: {
|
|
- color: '#000000',
|
|
+ color: '#000000'
|
|
- },
|
|
+ }
|
|
},
|
|
},
|
|
axisTick: {
|
|
axisTick: {
|
|
- show: false, // 隐藏X轴刻度
|
|
+ show: false // 隐藏X轴刻度
|
|
},
|
|
},
|
|
axisLabel: {
|
|
axisLabel: {
|
|
fontFamily: 'Helvetica, "Microsoft YaHei"',
|
|
fontFamily: 'Helvetica, "Microsoft YaHei"',
|
|
- color: '#101116',
|
|
+ color: '#101116'
|
|
},
|
|
},
|
|
axisPointer: {
|
|
axisPointer: {
|
|
- type: 'shadow',
|
|
+ type: 'shadow'
|
|
- },
|
|
+ }
|
|
},
|
|
},
|
|
yAxis: [
|
|
yAxis: [
|
|
{
|
|
{
|
|
@@ -135,18 +118,18 @@ export default {
|
|
lineStyle: {
|
|
lineStyle: {
|
|
type: 'dashed',
|
|
type: 'dashed',
|
|
color: '#B0B3C3',
|
|
color: '#B0B3C3',
|
|
- opacity: 0.5,
|
|
+ opacity: 0.5
|
|
- },
|
|
+ }
|
|
},
|
|
},
|
|
axisPointer: {
|
|
axisPointer: {
|
|
label: {
|
|
label: {
|
|
- formatter: ({ value }) => value.toFixed(),
|
|
+ formatter: ({ value }) => value.toFixed()
|
|
- },
|
|
+ }
|
|
},
|
|
},
|
|
axisLabel: {
|
|
axisLabel: {
|
|
fontFamily: 'Helvetica, "Microsoft YaHei"',
|
|
fontFamily: 'Helvetica, "Microsoft YaHei"',
|
|
- color: '#101116',
|
|
+ color: '#101116'
|
|
- },
|
|
+ }
|
|
},
|
|
},
|
|
{
|
|
{
|
|
min: -0.3,
|
|
min: -0.3,
|
|
@@ -154,17 +137,17 @@ export default {
|
|
axisLabel: {
|
|
axisLabel: {
|
|
formatter: value => (value * 100).toFixed(2) + '%',
|
|
formatter: value => (value * 100).toFixed(2) + '%',
|
|
fontFamily: 'Helvetica, "Microsoft YaHei"',
|
|
fontFamily: 'Helvetica, "Microsoft YaHei"',
|
|
- color: '#101116',
|
|
+ color: '#101116'
|
|
},
|
|
},
|
|
axisPointer: {
|
|
axisPointer: {
|
|
label: {
|
|
label: {
|
|
- formatter: ({ value }) => (value * 100).toFixed(2) + '%',
|
|
+ formatter: ({ value }) => (value * 100).toFixed(2) + '%'
|
|
- },
|
|
+ }
|
|
},
|
|
},
|
|
splitLine: {
|
|
splitLine: {
|
|
- show: false,
|
|
+ show: false
|
|
- },
|
|
+ }
|
|
- },
|
|
+ }
|
|
],
|
|
],
|
|
series: [
|
|
series: [
|
|
{
|
|
{
|
|
@@ -172,14 +155,14 @@ export default {
|
|
type: 'bar',
|
|
type: 'bar',
|
|
z: 2,
|
|
z: 2,
|
|
itemStyle: {
|
|
itemStyle: {
|
|
- color: '#6682B5',
|
|
+ color: '#6682B5'
|
|
},
|
|
},
|
|
barWidth: 40,
|
|
barWidth: 40,
|
|
label: {
|
|
label: {
|
|
show: true,
|
|
show: true,
|
|
- position: 'top',
|
|
+ position: 'top'
|
|
},
|
|
},
|
|
- data: [],
|
|
+ data: []
|
|
},
|
|
},
|
|
{
|
|
{
|
|
name: `${this.chartsTitle}同比`,
|
|
name: `${this.chartsTitle}同比`,
|
|
@@ -190,17 +173,17 @@ export default {
|
|
itemStyle: {
|
|
itemStyle: {
|
|
color: '#F2B849',
|
|
color: '#F2B849',
|
|
borderColor: '#ffffff',
|
|
borderColor: '#ffffff',
|
|
- borderWidth: 4,
|
|
+ borderWidth: 4
|
|
},
|
|
},
|
|
lineStyle: {
|
|
lineStyle: {
|
|
width: 4,
|
|
width: 4,
|
|
- color: '#F2B849',
|
|
+ color: '#F2B849'
|
|
},
|
|
},
|
|
symbolSize: 32,
|
|
symbolSize: 32,
|
|
tooltip: {
|
|
tooltip: {
|
|
- valueFormatter: value => (value * 100).toFixed(2) + '%',
|
|
+ valueFormatter: value => (value * 100).toFixed(2) + '%'
|
|
},
|
|
},
|
|
- data: [],
|
|
+ data: []
|
|
},
|
|
},
|
|
{
|
|
{
|
|
name: `${this.chartsTitle}环比`,
|
|
name: `${this.chartsTitle}环比`,
|
|
@@ -211,25 +194,24 @@ export default {
|
|
itemStyle: {
|
|
itemStyle: {
|
|
color: '#E33D3D',
|
|
color: '#E33D3D',
|
|
borderColor: '#ffffff',
|
|
borderColor: '#ffffff',
|
|
- borderWidth: 4,
|
|
+ borderWidth: 4
|
|
},
|
|
},
|
|
lineStyle: {
|
|
lineStyle: {
|
|
width: 4,
|
|
width: 4,
|
|
- color: '#E33D3D',
|
|
+ color: '#E33D3D'
|
|
},
|
|
},
|
|
symbolSize: 32,
|
|
symbolSize: 32,
|
|
tooltip: {
|
|
tooltip: {
|
|
- valueFormatter: value => (value * 100).toFixed(2) + '%',
|
|
+ valueFormatter: value => (value * 100).toFixed(2) + '%'
|
|
},
|
|
},
|
|
- data: [],
|
|
+ data: []
|
|
- },
|
|
+ }
|
|
- ],
|
|
+ ]
|
|
- },
|
|
+ }
|
|
- admin: {},
|
|
|
|
}
|
|
}
|
|
},
|
|
},
|
|
computed: {
|
|
computed: {
|
|
- ...mapGetters(['sidebar']),
|
|
+ ...mapGetters(['sidebar'])
|
|
},
|
|
},
|
|
watch: {
|
|
watch: {
|
|
// 监听数据变化 重绘图形
|
|
// 监听数据变化 重绘图形
|
|
@@ -238,36 +220,30 @@ export default {
|
|
this.myChart.setOption(obj)
|
|
this.myChart.setOption(obj)
|
|
this.resizeHandler()
|
|
this.resizeHandler()
|
|
},
|
|
},
|
|
- deep: true,
|
|
+ deep: true
|
|
},
|
|
},
|
|
'sidebar.expand'() {
|
|
'sidebar.expand'() {
|
|
this.setChartHeight()
|
|
this.setChartHeight()
|
|
},
|
|
},
|
|
querySettings: {
|
|
querySettings: {
|
|
- handler({ seriesKey, filters, xAxisKey }) {
|
|
+ handler({ seriesKey, filters }) {
|
|
if (seriesKey) {
|
|
if (seriesKey) {
|
|
this.seriesKey = seriesKey
|
|
this.seriesKey = seriesKey
|
|
}
|
|
}
|
|
- if (xAxisKey) {
|
|
|
|
- this.xAxisKey = xAxisKey
|
|
|
|
- }
|
|
|
|
if (filters?.length) {
|
|
if (filters?.length) {
|
|
this.filters = filters
|
|
this.filters = filters
|
|
}
|
|
}
|
|
},
|
|
},
|
|
deep: true,
|
|
deep: true,
|
|
- immediate: true,
|
|
+ immediate: true
|
|
- },
|
|
+ }
|
|
},
|
|
},
|
|
mounted() {
|
|
mounted() {
|
|
this.setChartHeight()
|
|
this.setChartHeight()
|
|
this.myChart = this.$echarts.init(document.getElementById('chart'))
|
|
this.myChart = this.$echarts.init(document.getElementById('chart'))
|
|
this.myChart.setOption(this.options)
|
|
this.myChart.setOption(this.options)
|
|
// 监听页面缩放
|
|
// 监听页面缩放
|
|
- this.debouncedChartHeightSetter = this._.debounce(
|
|
+ this.debouncedChartHeightSetter = this._.debounce(this.setChartHeight, this.debounceTime)
|
|
- this.setChartHeight,
|
|
|
|
- this.debounceTime
|
|
|
|
- )
|
|
|
|
window.addEventListener('resize', this.debouncedChartHeightSetter)
|
|
window.addEventListener('resize', this.debouncedChartHeightSetter)
|
|
},
|
|
},
|
|
beforeDestroy() {
|
|
beforeDestroy() {
|
|
@@ -291,79 +267,98 @@ export default {
|
|
getFormData(formData) {
|
|
getFormData(formData) {
|
|
this.resetDatas()
|
|
this.resetDatas()
|
|
|
|
|
|
- let params = {}
|
|
+ let id
|
|
- params = JSON.parse(JSON.stringify(formData))
|
|
+ let params = []
|
|
- params.fd1 = formData.dateTime[0]
|
|
+ if (formData.range === '基地分公司') {
|
|
- params.fd2 = formData.dateTime[1]
|
|
+ if (formData.flightType === '有行李') {
|
|
- delete params.dateTime
|
|
+ id = this.querySettings.withBaggageByArea
|
|
- this.admin = JSON.parse(JSON.stringify(params))
|
|
+ } else if (formData.baggageType === '不包含DEL') {
|
|
- delete params.timedim
|
|
+ id = this.querySettings.notDelByArea
|
|
- this.getSingleChartsData(this.querySettings.serviceId, params)
|
|
+ } else if (formData.passengerType[0] === '要客类型') {
|
|
- // if (formData.passengerType.length) {
|
|
+ id = this.querySettings.importantByArea
|
|
- // this.filters = [
|
|
+ } else {
|
|
- // {
|
|
+ id = this.querySettings.byArea
|
|
- // key: formData.passengerType[0],
|
|
+ }
|
|
- // value: formData.passengerType[1]
|
|
+ params = [formData.interval, formData.area, formData.inOrOut, formData.dateTime[0], formData.dateTime[1]]
|
|
- // }
|
|
+ } else {
|
|
- // ]
|
|
+ if (formData.flightType === '有行李') {
|
|
- // }
|
|
+ id = this.querySettings.withBaggageByOther
|
|
- // this.params = [...params, ...this.filters.map(({ value }) => value)]
|
|
+ } else if (formData.baggageType === '不包含DEL') {
|
|
- // if (params[2] instanceof Array) {
|
|
+ id = this.querySettings.notDelByOther
|
|
- // const paramsList = params[2].map(param => [...params.slice(0, 2), param, ...params.slice(3)])
|
|
+ } else if (formData.passengerType[0] === '要客类型') {
|
|
- // this.getMultipleChartsData(id, paramsList)
|
|
+ id = this.querySettings.importantByOther
|
|
- // } else {
|
|
+ } else {
|
|
- // this.getSingleChartsData(id, params)
|
|
+ id = this.querySettings.byOther
|
|
- // }
|
|
+ }
|
|
|
|
+ params = [formData.interval, formData.range, formData.inOrOut, formData.dateTime[0], formData.dateTime[1]]
|
|
|
|
+ if (formData.airline.length) {
|
|
|
|
+ params.splice(2, 0, formData.airline)
|
|
|
|
+ } else if (formData.airport.length) {
|
|
|
|
+ params.splice(2, 0, formData.airport)
|
|
|
|
+ } else if (formData.terminal !== '') {
|
|
|
|
+ params.splice(2, 0, formData.terminal)
|
|
|
|
+ } else {
|
|
|
|
+ params.splice(2, 0, '全部')
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (formData.passengerType.length) {
|
|
|
|
+ this.filters = [
|
|
|
|
+ {
|
|
|
|
+ key: formData.passengerType[0],
|
|
|
|
+ value: formData.passengerType[1]
|
|
|
|
+ }
|
|
|
|
+ ]
|
|
|
|
+ }
|
|
|
|
+ this.params = [...params, ...this.filters.map(({ value }) => value)]
|
|
|
|
+ if (params[2] instanceof Array) {
|
|
|
|
+ const paramsList = params[2].map(param => [...params.slice(0, 2), param, ...params.slice(3)])
|
|
|
|
+ this.getMultipleChartsData(id, paramsList)
|
|
|
|
+ } else {
|
|
|
|
+ this.getSingleChartsData(id, params)
|
|
|
|
+ }
|
|
},
|
|
},
|
|
async getMultipleChartsData(id, paramsList) {
|
|
async getMultipleChartsData(id, paramsList) {
|
|
- this.loading = true
|
|
|
|
try {
|
|
try {
|
|
- const listValuesArray = await Promise.all(
|
|
+ const listValuesArray = await Promise.all(paramsList.map(params => this.getChartsData(id, params)))
|
|
- paramsList.map(params => this.getChartsData(id, params))
|
|
+ const listValues = listValuesArray.reduce((preValues, currentValues) => {
|
|
- )
|
|
+ currentValues.forEach(value => {
|
|
- const listValues = listValuesArray.reduce(
|
|
+ const preValue = preValues.find(preValue => preValue.A === value.A)
|
|
- (preValues, currentValues) => {
|
|
+ if (preValue) {
|
|
- currentValues.forEach(value => {
|
|
+ preValue[this.seriesKey] += value[this.seriesKey]
|
|
- const preValue = preValues.find(
|
|
+ } else {
|
|
- preValue => preValue.A === value.A
|
|
+ preValues.push({
|
|
- )
|
|
+ A: value.A,
|
|
- if (preValue) {
|
|
+ [this.seriesKey]: value[this.seriesKey]
|
|
- preValue[this.seriesKey] += value[this.seriesKey]
|
|
+ })
|
|
- } else {
|
|
+ }
|
|
- preValues.push({
|
|
+ })
|
|
- A: value.A,
|
|
+ return preValues
|
|
- [this.seriesKey]: value[this.seriesKey],
|
|
+ }, [])
|
|
- })
|
|
|
|
- }
|
|
|
|
- })
|
|
|
|
- return preValues
|
|
|
|
- },
|
|
|
|
- []
|
|
|
|
- )
|
|
|
|
this.setChartsData(this._.sortBy(listValues, 'A'))
|
|
this.setChartsData(this._.sortBy(listValues, 'A'))
|
|
} catch (error) {
|
|
} catch (error) {
|
|
this.$message.error(error.message)
|
|
this.$message.error(error.message)
|
|
}
|
|
}
|
|
- this.loading = false
|
|
|
|
},
|
|
},
|
|
async getSingleChartsData(id, params) {
|
|
async getSingleChartsData(id, params) {
|
|
- this.loading = true
|
|
|
|
try {
|
|
try {
|
|
const listValues = await this.getChartsData(id, params)
|
|
const listValues = await this.getChartsData(id, params)
|
|
this.setChartsData(listValues)
|
|
this.setChartsData(listValues)
|
|
} catch (error) {
|
|
} catch (error) {
|
|
this.$message.error(error.message)
|
|
this.$message.error(error.message)
|
|
}
|
|
}
|
|
- this.loading = false
|
|
|
|
},
|
|
},
|
|
- async getChartsData(serviceId, params) {
|
|
+ async getChartsData(id, params) {
|
|
try {
|
|
try {
|
|
- const { code, returnData, message } = await TempQuery({
|
|
+ const {
|
|
- serviceId,
|
|
+ code,
|
|
- dataContent: [params],
|
|
+ returnData: { listValues },
|
|
|
|
+ message
|
|
|
|
+ } = await TempQuery({
|
|
|
|
+ id,
|
|
|
|
+ dataContent: params
|
|
})
|
|
})
|
|
if (Number(code) === 0) {
|
|
if (Number(code) === 0) {
|
|
- return returnData.listValues || returnData
|
|
+ return listValues
|
|
} else {
|
|
} else {
|
|
return Promise.reject(message || '失败')
|
|
return Promise.reject(message || '失败')
|
|
}
|
|
}
|
|
@@ -375,42 +370,26 @@ export default {
|
|
const xAxisData = []
|
|
const xAxisData = []
|
|
const yAxisData = [0]
|
|
const yAxisData = [0]
|
|
const seriesDatas = []
|
|
const seriesDatas = []
|
|
- let filteredList = []
|
|
+ const filteredList = listValues.filter(element =>
|
|
- if (listValues && listValues.length) {
|
|
+ this.filters.every((key, value) => {
|
|
- filteredList = listValues.filter(element =>
|
|
+ if (key && value && element[key] !== value) {
|
|
- this.filters.every((key, value) => {
|
|
+ return false
|
|
- if (key && value && element[key] !== value) {
|
|
+ } else {
|
|
- return false
|
|
+ return true
|
|
- } else {
|
|
+ }
|
|
- return true
|
|
+ })
|
|
- }
|
|
+ )
|
|
- })
|
|
|
|
- )
|
|
|
|
- }
|
|
|
|
if (filteredList.length === 0) {
|
|
if (filteredList.length === 0) {
|
|
this.$message.info('未查询到对应数据')
|
|
this.$message.info('未查询到对应数据')
|
|
return
|
|
return
|
|
}
|
|
}
|
|
- // console.log(this.admin)
|
|
|
|
- if (this.admin.io === '进港') {
|
|
|
|
- this.seriesKey = 'in_num'
|
|
|
|
- } else if (this.admin.io === '离港') {
|
|
|
|
- this.seriesKey = 'out_num'
|
|
|
|
- } else if (this.admin.io === '中转') {
|
|
|
|
- this.seriesKey = 'trans_num'
|
|
|
|
- } else if (this.admin.timedim === '正常') {
|
|
|
|
- this.seriesKey = 'bag_num'
|
|
|
|
- } else if (this.admin.timedim === '异常') {
|
|
|
|
- this.seriesKey = 'exception_num'
|
|
|
|
- }
|
|
|
|
for (let i = 0; i < filteredList.length; i++) {
|
|
for (let i = 0; i < filteredList.length; i++) {
|
|
- xAxisData.push(filteredList[i][this.xAxisKey])
|
|
+ xAxisData.push(filteredList[i].A)
|
|
seriesDatas.push(filteredList[i][this.seriesKey])
|
|
seriesDatas.push(filteredList[i][this.seriesKey])
|
|
if (i > 0) {
|
|
if (i > 0) {
|
|
if (filteredList[i - 1][this.seriesKey] > 0) {
|
|
if (filteredList[i - 1][this.seriesKey] > 0) {
|
|
yAxisData.push(
|
|
yAxisData.push(
|
|
- (filteredList[i][this.seriesKey] -
|
|
+ (filteredList[i][this.seriesKey] - filteredList[i - 1][this.seriesKey]) /
|
|
- filteredList[i - 1][this.seriesKey]) /
|
|
|
|
filteredList[i - 1][this.seriesKey]
|
|
filteredList[i - 1][this.seriesKey]
|
|
)
|
|
)
|
|
} else {
|
|
} else {
|
|
@@ -436,11 +415,7 @@ export default {
|
|
const headerHeight = this.$refs['headerWrapper'].offsetHeight
|
|
const headerHeight = this.$refs['headerWrapper'].offsetHeight
|
|
const footerBlankHeight = 24
|
|
const footerBlankHeight = 24
|
|
this.chartHeight = `calc(100vh - ${
|
|
this.chartHeight = `calc(100vh - ${
|
|
- topBarHeight +
|
|
+ topBarHeight + headerBlankHeight + tabsWrapperHeight + headerHeight + footerBlankHeight
|
|
- headerBlankHeight +
|
|
|
|
- tabsWrapperHeight +
|
|
|
|
- headerHeight +
|
|
|
|
- footerBlankHeight
|
|
|
|
}px)`
|
|
}px)`
|
|
this.$nextTick(() => {
|
|
this.$nextTick(() => {
|
|
this.resizeHandler()
|
|
this.resizeHandler()
|
|
@@ -464,18 +439,10 @@ export default {
|
|
// $a.click()
|
|
// $a.click()
|
|
|
|
|
|
// 生成表格数据
|
|
// 生成表格数据
|
|
- const xlsxDatas = [
|
|
+ const xlsxDatas = [['时间', this.chartsTitle.replace('量', '数量'), `${this.chartsTitle}环比`]]
|
|
- [
|
|
|
|
- '时间',
|
|
|
|
- this.chartsTitle.replace('量', '数量'),
|
|
|
|
- `${this.chartsTitle}环比`,
|
|
|
|
- ],
|
|
|
|
- ]
|
|
|
|
const transposition = this.tableData[0].map((col, colIndex) => {
|
|
const transposition = this.tableData[0].map((col, colIndex) => {
|
|
return this.tableData.map((row, rowIndex) => {
|
|
return this.tableData.map((row, rowIndex) => {
|
|
- return rowIndex === 2
|
|
+ return rowIndex === 2 ? (row[colIndex] * 100).toFixed(2) + '%' : row[colIndex]
|
|
- ? (row[colIndex] * 100).toFixed(2) + '%'
|
|
|
|
- : row[colIndex]
|
|
|
|
})
|
|
})
|
|
})
|
|
})
|
|
xlsxDatas.push(...transposition)
|
|
xlsxDatas.push(...transposition)
|
|
@@ -484,20 +451,17 @@ export default {
|
|
const summaryRow = ['合计']
|
|
const summaryRow = ['合计']
|
|
const colNum = xlsxDatas[0].length
|
|
const colNum = xlsxDatas[0].length
|
|
for (let colIndex = 1; colIndex < colNum; colIndex++) {
|
|
for (let colIndex = 1; colIndex < colNum; colIndex++) {
|
|
- summaryRow[colIndex] = xlsxDatas.reduce(
|
|
+ summaryRow[colIndex] = xlsxDatas.reduce((pre, currentRow, rowIndex) => {
|
|
- (pre, currentRow, rowIndex) => {
|
|
+ if (colIndex === 1) {
|
|
- if (colIndex === 1) {
|
|
+ if (rowIndex === 0) {
|
|
- if (rowIndex === 0) {
|
|
+ return 0
|
|
- return 0
|
|
|
|
- } else {
|
|
|
|
- return pre + currentRow[colIndex]
|
|
|
|
- }
|
|
|
|
} else {
|
|
} else {
|
|
- return pre
|
|
+ return pre + currentRow[colIndex]
|
|
}
|
|
}
|
|
- },
|
|
+ } else {
|
|
- ''
|
|
+ return pre
|
|
- )
|
|
+ }
|
|
|
|
+ }, '')
|
|
}
|
|
}
|
|
xlsxDatas.push(summaryRow)
|
|
xlsxDatas.push(summaryRow)
|
|
}
|
|
}
|
|
@@ -517,10 +481,7 @@ export default {
|
|
}, 0)
|
|
}, 0)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
- if (
|
|
+ if ((!columnWidths[columnIndex] && cellWidth > 0) || cellWidth > columnWidths[columnIndex]) {
|
|
- (!columnWidths[columnIndex] && cellWidth > 0) ||
|
|
|
|
- cellWidth > columnWidths[columnIndex]
|
|
|
|
- ) {
|
|
|
|
columnWidths[columnIndex] = cellWidth
|
|
columnWidths[columnIndex] = cellWidth
|
|
}
|
|
}
|
|
})
|
|
})
|
|
@@ -529,26 +490,26 @@ export default {
|
|
const sheet = XLSX.utils.aoa_to_sheet(xlsxDatas)
|
|
const sheet = XLSX.utils.aoa_to_sheet(xlsxDatas)
|
|
// 添加列宽度
|
|
// 添加列宽度
|
|
sheet['!cols'] = columnWidths.map(width => ({
|
|
sheet['!cols'] = columnWidths.map(width => ({
|
|
- wch: width + 2,
|
|
+ wch: width + 2
|
|
}))
|
|
}))
|
|
// 样式
|
|
// 样式
|
|
const borderStyle = {
|
|
const borderStyle = {
|
|
style: 'medium',
|
|
style: 'medium',
|
|
color: {
|
|
color: {
|
|
- rgb: 'FFFFFF',
|
|
+ rgb: 'FFFFFF'
|
|
- },
|
|
+ }
|
|
}
|
|
}
|
|
const reg = /^[A-Z]+([\d]+$)/
|
|
const reg = /^[A-Z]+([\d]+$)/
|
|
for (const key in sheet) {
|
|
for (const key in sheet) {
|
|
- const match = reg.test(key)
|
|
+ const match = key.match(reg)
|
|
if (match) {
|
|
if (match) {
|
|
- const rowIndex = reg.exec(key)[1]
|
|
+ const rowIndex = match[1]
|
|
let cellStyle = {
|
|
let cellStyle = {
|
|
alignment: {
|
|
alignment: {
|
|
horizontal: 'center',
|
|
horizontal: 'center',
|
|
vertical: 'center',
|
|
vertical: 'center',
|
|
- wrapText: true,
|
|
+ wrapText: true
|
|
- },
|
|
+ }
|
|
}
|
|
}
|
|
if (Number(rowIndex) === 1) {
|
|
if (Number(rowIndex) === 1) {
|
|
cellStyle = {
|
|
cellStyle = {
|
|
@@ -557,22 +518,41 @@ export default {
|
|
top: borderStyle,
|
|
top: borderStyle,
|
|
right: borderStyle,
|
|
right: borderStyle,
|
|
bottom: borderStyle,
|
|
bottom: borderStyle,
|
|
- left: borderStyle,
|
|
+ left: borderStyle
|
|
},
|
|
},
|
|
font: {
|
|
font: {
|
|
color: {
|
|
color: {
|
|
- rgb: 'FFFFFF',
|
|
+ rgb: 'FFFFFF'
|
|
- },
|
|
+ }
|
|
},
|
|
},
|
|
fill: {
|
|
fill: {
|
|
fgColor: {
|
|
fgColor: {
|
|
- rgb: '3366FF',
|
|
+ rgb: '3366FF'
|
|
- },
|
|
+ }
|
|
- },
|
|
+ }
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
cellStyle.alignment.horizontal = 'left'
|
|
cellStyle.alignment.horizontal = 'left'
|
|
}
|
|
}
|
|
|
|
+ const cellValue = sheet[key].v
|
|
|
|
+ const isNumber = /^[^0]/.test(cellValue) && !isNaN(parseFloat(cellValue)) && isFinite(cellValue)
|
|
|
|
+ const isPercentage = /^[0-9]+(\.[0-9]+){0,1}\%$/.test(cellValue)
|
|
|
|
+ if (isNumber) {
|
|
|
|
+ sheet[key] = {
|
|
|
|
+ ...sheet[key],
|
|
|
|
+ t: 'n',
|
|
|
|
+ z: '0',
|
|
|
|
+ v: Number(cellValue)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (isPercentage) {
|
|
|
|
+ sheet[key] = {
|
|
|
|
+ ...sheet[key],
|
|
|
|
+ t: 'n',
|
|
|
|
+ z: '0.00%',
|
|
|
|
+ v: parseFloat(cellValue)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
sheet[key].s = cellStyle
|
|
sheet[key].s = cellStyle
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -583,16 +563,13 @@ export default {
|
|
bookType: 'xlsx',
|
|
bookType: 'xlsx',
|
|
bookSST: true,
|
|
bookSST: true,
|
|
type: 'buffer',
|
|
type: 'buffer',
|
|
- cellStyles: true,
|
|
+ cellStyles: true
|
|
})
|
|
})
|
|
// 下载表格
|
|
// 下载表格
|
|
const fileName = `${this.chartsTitle}统计-${this.params.join('-')}.xlsx`
|
|
const fileName = `${this.chartsTitle}统计-${this.params.join('-')}.xlsx`
|
|
- FileSaver.saveAs(
|
|
+ FileSaver.saveAs(new Blob([tableWrite], { type: 'application/octet-stream' }), fileName)
|
|
- new Blob([tableWrite], { type: 'application/octet-stream' }),
|
|
+ }
|
|
- fileName
|
|
+ }
|
|
- )
|
|
|
|
- },
|
|
|
|
- },
|
|
|
|
}
|
|
}
|
|
</script>
|
|
</script>
|
|
|
|
|