FlowChartEdit.vue
5.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
<template>
<div class="fullheight">
<ht-sidebar-dialog
:visible.sync="dialogVisible"
v-if="dialogVisible"
:show-close="false"
width="100%"
:close-on-click-modal="false"
v-loading="loading"
>
<el-page-header @back="back" content="视图列表" />
<div style="margin: 10px 0">
<ht-input v-model="data.name" />
<el-button @click="edit()">添加报表</el-button>
<el-button type="primary" @click="save">保存</el-button>
<el-button v-if="data.type !== '1' && data.id" @click="publish"
>发布</el-button
>
</div>
<div v-for="(option, index) in options" :key="index" v-cloak>
<el-button size="mini" type="primary" @click="edit(option.id, index)"
>编辑</el-button
>
<el-button size="mini" type="danger" @click="remove(option.id)"
>删除</el-button
>
<el-button size="mini" type="warning" @click="refresh(option.id, index)"
>刷新</el-button
>
<el-button size="mini" type="info" @click="exportData(index)"
>导出</el-button
>
<chart
v-if="dialogVisible"
:option="option"
:index="index"
:is-convert-option="true"
/>
</div>
</ht-sidebar-dialog>
<report-setting
ref="reportSetting"
:id="selectedId"
v-if="dialogVisible"
:report="selectedReport"
@after-save="afterSave"
/>
</div>
</template>
<script>
import flow from '@/api/flow.js'
const chart = () => import('@/components/form/chart/Chart.vue')
const reportSetting = () => import('@/components/form/chart/ReportSetting.vue')
import { export_json_to_excel } from '@/vendor/Export2Excel.js'
export default {
components: {
chart,
reportSetting
},
data() {
return {
reportChartId: '',
dialogVisible: false,
data: {},
options: [],
selectedId: '',
index: '',
selectedReport: {},
loading: true
}
},
methods: {
//返回
back() {
this.$emit('save-report')
this.dialogVisible = false
},
handleOpen(id) {
this.loading = true
this.reportChartId = id
this.dialogVisible = true
this.options = []
this.getReportChartData()
},
async getReportChartData() {
if (this.reportChartId) {
await flow.getReportList(this.reportChartId).then(data => {
if (data) {
this.data = data
} else {
this.data = {}
}
})
await flow.getEchartsData(this.reportChartId).then(data => {
if (this.options) {
this.options = data.value
} else {
this.options = []
}
})
} else {
this.data = {}
this.options = []
}
setTimeout(() => {
this.loading = false
}, 50)
},
edit(id, index) {
this.selectedReport = {
id: this.data.id,
name: this.data.name,
alias: this.data.alias
}
if (id) {
this.index = index
this.selectedId = id
} else {
this.selectedId = ''
this.index = ''
}
this.$refs.reportSetting.handleOpen()
},
remove(id) {
this.$confirm('确定删除吗?')
.then(() => {
flow.removeAct(id).then(data => {
this.$message.success('删除成功')
this.getReportChartData(this.reportChartId)
})
})
.catch(() => {})
},
afterSave() {
this.getReportChartData()
},
save() {
if (this.data.name.length == 0) {
this.$message('视图列表名称必填!')
return
}
let data = {
name: this.data.name,
alias: this.data.alias,
type: this.data.type,
id: this.data.id,
createBy: this.data.createBy,
createName: this.data.createName,
createOrgId: this.data.createOrgId,
orgName: this.data.orgName
}
flow.saveReport(data).then(data => {
if (data.state) {
this.data.id = data.value
this.$message.success(data.message)
this.$emit('save-report')
this.dialogVisible = false
} else {
this.$message.error(data.message)
}
})
},
publish() {
flow.publishReport(this.data.id).then(data => {
if (data.state) {
this.$message.success('发布成功')
this.data.type = '1'
this.$emit('after-save', {})
} else {
this.$message.error(data.message)
}
})
},
refresh(id, index) {
flow.getSingleEchartsData(id).then(data => {
this.options.splice(index, 1)
this.options.splice(index, 0, data.value)
})
},
/**
* 导出图表数据
* @param index 多个图表的索引
* @returns {ElMessageComponent}
*/
exportData(index) {
if (!this.options.length) {
return this.$message.warning('未获取到流程图表信息,请核对后再试!')
}
const option = this.options[index]
//头部,第一格放入空行占位
const header = ['类型', ...option['xAxis']]
const series = option['series']
const body = []
if (series && series.length) {
series.forEach((item) => {
if (item.name && item.data && item.data.length) {
body.push([ item.name, ...item.data ])
}
})
}
//导出参数
if (!body.length) {
return this.$message.warning('未获取到流程图表数据!')
}
const exportParam = { header, data: body, filename: option['subtext'], sheetName: option['name'] }
export_json_to_excel(exportParam)
}
}
}
</script>
<style lang="scss" scoped>
.fullheight {
overflow: auto;
}
[v-cloak] {
display: none;
}
</style>