zant-admin 1.0.4 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +414 -25
- package/README.md +460 -285
- package/bin/cli.js +3 -3
- package/bin/generator.js +502 -502
- package/bin/prompts.js +158 -158
- package/bin/utils.js +133 -133
- package/package.json +2 -2
- package/public/logo.png +0 -0
- package/src/App.vue +16 -16
- package/src/api/methods/department.js +36 -0
- package/src/api/methods/employee.js +22 -0
- package/src/api/methods/logError.js +8 -8
- package/src/api/methods/logOperation.js +8 -8
- package/src/api/methods/login.js +6 -6
- package/src/api/methods/position.js +26 -0
- package/src/api/methods/quartz.js +36 -36
- package/src/api/methods/region.js +16 -16
- package/src/api/methods/sysAccount.js +29 -29
- package/src/api/methods/sysDict.js +29 -29
- package/src/api/methods/sysDictItem.js +26 -26
- package/src/api/methods/sysMenu.js +42 -42
- package/src/api/methods/sysRole.js +35 -35
- package/src/api/methods/sysUser.js +25 -25
- package/src/api/methods/system.js +15 -15
- package/src/api/request.js +225 -225
- package/src/assets/css/style.css +2 -2
- package/src/assets/css/zcui.css +1023 -1023
- package/src/assets/imgs/logo.png +0 -0
- package/src/assets/imgs/md/console.png +0 -0
- package/src/assets/imgs/md/login.png +0 -0
- package/src/assets/imgs/md/menu.png +0 -0
- package/src/assets/imgs/md/serviceMonitoring.png +0 -0
- package/src/assets/imgs/md/statistics.png +0 -0
- package/src/components/FormTable.vue +5 -19
- package/src/components/IconPicker.vue +351 -351
- package/src/components/MainPage.vue +838 -838
- package/src/components/details/logErrorDetails.vue +58 -58
- package/src/components/details/logOperationDetails.vue +76 -76
- package/src/components/edit/QuartzEdit.vue +221 -221
- package/src/components/edit/SysAccountEdit.vue +185 -185
- package/src/components/edit/SysDictEdit.vue +116 -116
- package/src/components/edit/SysDictItemEdit.vue +136 -136
- package/src/components/edit/SysRoleEdit.vue +111 -111
- package/src/components/edit/organizationalStructure/DepartmentEdit.vue +162 -0
- package/src/components/edit/organizationalStructure/EmployeeEdit.vue +295 -0
- package/src/components/edit/organizationalStructure/PositionEdit.vue +166 -0
- package/src/components/edit/sysMenuEdit.vue +2 -1
- package/src/config/index.js +74 -74
- package/src/directives/permission.js +49 -49
- package/src/main.js +37 -37
- package/src/router/index.js +4 -6
- package/src/stores/config.js +43 -43
- package/src/stores/dict.js +33 -33
- package/src/stores/menu.js +81 -81
- package/src/stores/user.js +21 -21
- package/src/utils/baseEcharts.js +661 -661
- package/src/utils/dictTemplate.js +26 -26
- package/src/utils/regionUtils.js +173 -173
- package/src/utils/useFormCRUD.js +59 -59
- package/src/views/baiscstatis/center.vue +474 -474
- package/src/views/baiscstatis/iframePage.vue +29 -29
- package/src/views/baiscstatis/notFound.vue +192 -192
- package/src/views/console.vue +821 -821
- package/src/views/demo/button.vue +269 -269
- package/src/views/demo/importexport.vue +119 -119
- package/src/views/demo/region.vue +322 -322
- package/src/views/demo/statistics.vue +214 -214
- package/src/views/home.vue +6 -6
- package/src/views/login.vue +264 -149
- package/src/views/operations/log/logError.vue +78 -78
- package/src/views/operations/log/logLogin.vue +66 -66
- package/src/views/operations/log/logOperation.vue +103 -103
- package/src/views/operations/log/logQuartz.vue +56 -56
- package/src/views/operations/quartz.vue +179 -179
- package/src/views/operations/serviceMonitoring.vue +134 -134
- package/src/views/organizationalStructure/department.vue +194 -0
- package/src/views/organizationalStructure/employee.vue +234 -0
- package/src/views/organizationalStructure/position.vue +196 -0
- package/src/views/system/sysAccount.vue +128 -128
- package/src/views/system/sysDict.vue +159 -159
- package/src/views/system/sysDictItem.vue +118 -118
- package/src/views/system/sysMenu.vue +225 -225
- package/src/views/system/sysRole.vue +207 -207
- package/src/assets/imgs/md/1.png +0 -0
- package/src/assets/imgs/md/10.png +0 -0
- package/src/assets/imgs/md/11.png +0 -0
- package/src/assets/imgs/md/2.png +0 -0
- package/src/assets/imgs/md/3.png +0 -0
- package/src/assets/imgs/md/4.png +0 -0
- package/src/assets/imgs/md/5.png +0 -0
- package/src/assets/imgs/md/6.png +0 -0
- package/src/assets/imgs/md/7.png +0 -0
- package/src/assets/imgs/md/8.png +0 -0
- package/src/assets/imgs/md/9.png +0 -0
package/src/utils/baseEcharts.js
CHANGED
|
@@ -1,661 +1,661 @@
|
|
|
1
|
-
import * as echarts from 'echarts'
|
|
2
|
-
// 定义柱状图颜色调色板
|
|
3
|
-
export const barColorPalette = [
|
|
4
|
-
'#025DF4',
|
|
5
|
-
'#DB6BCF',
|
|
6
|
-
'#2498D1',
|
|
7
|
-
'#BBBDE6',
|
|
8
|
-
'#4045B2',
|
|
9
|
-
'#21A97A',
|
|
10
|
-
'#FF745A',
|
|
11
|
-
'#007E99',
|
|
12
|
-
'#FFA8A8',
|
|
13
|
-
'#2391FF',
|
|
14
|
-
]
|
|
15
|
-
const createNoDataGraphic = (text = '暂无数据') => ({
|
|
16
|
-
graphic: {
|
|
17
|
-
type: 'text',
|
|
18
|
-
left: 'center',
|
|
19
|
-
top: 'center',
|
|
20
|
-
z: 100, // 确保在最上层
|
|
21
|
-
silent: true,
|
|
22
|
-
invisible: true, // 默认隐藏
|
|
23
|
-
style: {
|
|
24
|
-
text,
|
|
25
|
-
fontSize: 20,
|
|
26
|
-
fontWeight: 'normal',
|
|
27
|
-
fill: '#999',
|
|
28
|
-
align: 'center',
|
|
29
|
-
},
|
|
30
|
-
},
|
|
31
|
-
})
|
|
32
|
-
/**
|
|
33
|
-
* 初始化饼图
|
|
34
|
-
* @param {HTMLElement} chartRef 图表DOM元素引用
|
|
35
|
-
* @returns {echarts.ECharts} 图表实例
|
|
36
|
-
*/
|
|
37
|
-
export const initPieChart = (chartRef, seriesName = '标题') => {
|
|
38
|
-
if (!chartRef) return null
|
|
39
|
-
const chartInstance = echarts.init(chartRef)
|
|
40
|
-
const defaultOptions = {
|
|
41
|
-
...createNoDataGraphic(), // 添加暂无数据图形
|
|
42
|
-
tooltip: {
|
|
43
|
-
trigger: 'item',
|
|
44
|
-
formatter: function (params) {
|
|
45
|
-
return `<span style="display:inline-block;margin-right:5px;
|
|
46
|
-
border-radius:50%;width:10px;height:10px;
|
|
47
|
-
background-color:${params.color}"></span>
|
|
48
|
-
${params.seriesName}<br/>${params.name}: ${params.value} (${params.percent}%)`
|
|
49
|
-
},
|
|
50
|
-
},
|
|
51
|
-
legend: {
|
|
52
|
-
top: 0,
|
|
53
|
-
left: 'center',
|
|
54
|
-
type: 'scroll', // 改为滚动式图例
|
|
55
|
-
pageTextStyle: {
|
|
56
|
-
color: '#333',
|
|
57
|
-
},
|
|
58
|
-
},
|
|
59
|
-
color: barColorPalette,
|
|
60
|
-
series: [
|
|
61
|
-
{
|
|
62
|
-
name: seriesName,
|
|
63
|
-
type: 'pie',
|
|
64
|
-
radius: '55%',
|
|
65
|
-
center: ['50%', '60%'],
|
|
66
|
-
avoidLabelOverlap: true,
|
|
67
|
-
itemStyle: {
|
|
68
|
-
borderRadius: 3,
|
|
69
|
-
borderColor: '#fff',
|
|
70
|
-
borderWidth: 2,
|
|
71
|
-
},
|
|
72
|
-
label: {
|
|
73
|
-
show: true, // 显示标签
|
|
74
|
-
formatter: function (params) {
|
|
75
|
-
// 自定义格式化函数,实现多行显示
|
|
76
|
-
return [`${params.name}`, `${params.percent}%`].join('\n')
|
|
77
|
-
},
|
|
78
|
-
fontSize: 12, // 调整字体大小
|
|
79
|
-
color: '#333', // 标签颜色
|
|
80
|
-
lineHeight: 14, // 行高
|
|
81
|
-
},
|
|
82
|
-
emphasis: {},
|
|
83
|
-
labelLine: {
|
|
84
|
-
show: true,
|
|
85
|
-
},
|
|
86
|
-
data: [],
|
|
87
|
-
},
|
|
88
|
-
],
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
chartInstance.setOption(defaultOptions)
|
|
92
|
-
return chartInstance
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* 更新饼图数据
|
|
96
|
-
* @param {echarts.ECharts} chartInstance 图表实例
|
|
97
|
-
* @param {Array} data 图表数据
|
|
98
|
-
*/
|
|
99
|
-
export const updatePieChart = ({ chartInstance, data }) => {
|
|
100
|
-
hideChartLoading(chartInstance)
|
|
101
|
-
if (!chartInstance) return
|
|
102
|
-
const isEmpty = !data || data.length === 0
|
|
103
|
-
// 更新配置
|
|
104
|
-
const updateOptions = {
|
|
105
|
-
tooltip: {
|
|
106
|
-
show: !isEmpty,
|
|
107
|
-
},
|
|
108
|
-
legend: {
|
|
109
|
-
show: !isEmpty,
|
|
110
|
-
},
|
|
111
|
-
series: [
|
|
112
|
-
{
|
|
113
|
-
data: isEmpty
|
|
114
|
-
? []
|
|
115
|
-
: data.map(item => ({
|
|
116
|
-
...item,
|
|
117
|
-
name: `${item.name} (${item.value})`,
|
|
118
|
-
})),
|
|
119
|
-
silent: isEmpty,
|
|
120
|
-
},
|
|
121
|
-
],
|
|
122
|
-
graphic: {
|
|
123
|
-
invisible: !isEmpty, // 有数据时隐藏,无数据时显示
|
|
124
|
-
},
|
|
125
|
-
}
|
|
126
|
-
// 合并自定义配置
|
|
127
|
-
chartInstance.setOption(updateOptions)
|
|
128
|
-
}
|
|
129
|
-
/**
|
|
130
|
-
* 初始化柱状图
|
|
131
|
-
* @param {HTMLElement} chartRef 图表DOM元素引用
|
|
132
|
-
* @returns {echarts.ECharts} 图表实例
|
|
133
|
-
*/
|
|
134
|
-
export const initBarChart = (chartRef, yAxisName = '单位') => {
|
|
135
|
-
if (!chartRef) return null
|
|
136
|
-
const chartInstance = echarts.init(chartRef)
|
|
137
|
-
const defaultOptions = {
|
|
138
|
-
...createNoDataGraphic(), // 添加暂无数据图形
|
|
139
|
-
tooltip: {
|
|
140
|
-
trigger: 'axis',
|
|
141
|
-
axisPointer: {
|
|
142
|
-
type: 'shadow',
|
|
143
|
-
},
|
|
144
|
-
},
|
|
145
|
-
grid: {
|
|
146
|
-
left: '3%',
|
|
147
|
-
right: '4%',
|
|
148
|
-
bottom: '1%', // 增加底部间距为滑动条留出空间
|
|
149
|
-
top: '15%',
|
|
150
|
-
containLabel: true,
|
|
151
|
-
},
|
|
152
|
-
legend: {
|
|
153
|
-
top: 'top', // 设置图例位于顶部
|
|
154
|
-
data: [],
|
|
155
|
-
},
|
|
156
|
-
xAxis: {
|
|
157
|
-
type: 'category',
|
|
158
|
-
data: [],
|
|
159
|
-
axisLabel: {
|
|
160
|
-
rotate: 0, // 保持水平
|
|
161
|
-
interval: 0,
|
|
162
|
-
},
|
|
163
|
-
axisTick: {
|
|
164
|
-
show: false,
|
|
165
|
-
},
|
|
166
|
-
},
|
|
167
|
-
yAxis: {
|
|
168
|
-
type: 'value',
|
|
169
|
-
name: yAxisName,
|
|
170
|
-
axisLabel: {
|
|
171
|
-
formatter: function (value) {
|
|
172
|
-
// 只显示整数值
|
|
173
|
-
return value % 1 === 0 ? value : ''
|
|
174
|
-
},
|
|
175
|
-
},
|
|
176
|
-
nameTextStyle: {
|
|
177
|
-
padding: [0, 30, 15, 0],
|
|
178
|
-
},
|
|
179
|
-
splitLine: {
|
|
180
|
-
lineStyle: {
|
|
181
|
-
type: 'dashed',
|
|
182
|
-
},
|
|
183
|
-
},
|
|
184
|
-
},
|
|
185
|
-
// 默认启用内置滑动条,但隐藏(超过12列时显示)
|
|
186
|
-
dataZoom: [
|
|
187
|
-
{
|
|
188
|
-
type: 'inside', // 内置型数据区域缩放
|
|
189
|
-
start: 0,
|
|
190
|
-
end: 100,
|
|
191
|
-
zoomOnMouseWheel: false, // 禁用鼠标滚轮缩放
|
|
192
|
-
moveOnMouseMove: true, // 允许拖拽滑动
|
|
193
|
-
moveOnMouseWheel: true, // 允许鼠标滚轮滑动
|
|
194
|
-
},
|
|
195
|
-
{
|
|
196
|
-
type: 'slider', // 滑动条型数据区域缩放
|
|
197
|
-
show: false, // 默认隐藏
|
|
198
|
-
start: 0,
|
|
199
|
-
end: 100,
|
|
200
|
-
bottom: '0%',
|
|
201
|
-
height: 15,
|
|
202
|
-
handleSize: '100%',
|
|
203
|
-
handleStyle: {
|
|
204
|
-
color: '#025DF4',
|
|
205
|
-
},
|
|
206
|
-
fillerColor: 'rgba(2, 93, 244, 0.2)',
|
|
207
|
-
borderColor: '#ddd',
|
|
208
|
-
backgroundColor: '#f5f5f5',
|
|
209
|
-
showDetail: false,
|
|
210
|
-
},
|
|
211
|
-
],
|
|
212
|
-
series: [],
|
|
213
|
-
}
|
|
214
|
-
chartInstance.setOption(defaultOptions)
|
|
215
|
-
return chartInstance
|
|
216
|
-
}
|
|
217
|
-
/**
|
|
218
|
-
* 更新柱状图数据
|
|
219
|
-
* @param {echarts.ECharts} chartInstance 图表实例
|
|
220
|
-
* @param {Object} data 图表数据 {xAxis: {data: []}, series: []}
|
|
221
|
-
*/
|
|
222
|
-
export const updateBarChart = ({
|
|
223
|
-
chartInstance,
|
|
224
|
-
data,
|
|
225
|
-
shouldShowSlider = false,
|
|
226
|
-
shouldShowSliderNumber = 12,
|
|
227
|
-
}) => {
|
|
228
|
-
hideChartLoading(chartInstance)
|
|
229
|
-
if (!chartInstance) return
|
|
230
|
-
|
|
231
|
-
const isEmpty =
|
|
232
|
-
!data || !data.xAxis || !data.xAxis.data || data.xAxis.data.length === 0
|
|
233
|
-
const dataLength = isEmpty ? 0 : data.xAxis.data.length
|
|
234
|
-
|
|
235
|
-
// 提取图例数据(公司名称)
|
|
236
|
-
const legendData = isEmpty ? [] : data.series.map(item => item.name)
|
|
237
|
-
|
|
238
|
-
// 构建系列配置
|
|
239
|
-
const series = isEmpty
|
|
240
|
-
? []
|
|
241
|
-
: data.series.map((companyData, index) => {
|
|
242
|
-
// 获取当前线条的颜色
|
|
243
|
-
const baseColor = barColorPalette[index % barColorPalette.length]
|
|
244
|
-
return {
|
|
245
|
-
name: companyData.name,
|
|
246
|
-
type: 'bar',
|
|
247
|
-
barMaxWidth: 40,
|
|
248
|
-
barCategoryGap: shouldShowSlider ? '15%' : '30%', // 有滑动条时减小间距
|
|
249
|
-
data: companyData.data,
|
|
250
|
-
itemStyle: {
|
|
251
|
-
color: {
|
|
252
|
-
// 线性渐变,方向从底部到顶部
|
|
253
|
-
type: 'linear',
|
|
254
|
-
x: 0,
|
|
255
|
-
y: 0,
|
|
256
|
-
x2: 0,
|
|
257
|
-
y2: 1,
|
|
258
|
-
colorStops: [
|
|
259
|
-
{
|
|
260
|
-
offset: 0,
|
|
261
|
-
color: baseColor, // 0% 处的颜色 - 原始颜色
|
|
262
|
-
},
|
|
263
|
-
{
|
|
264
|
-
offset: 1,
|
|
265
|
-
color: getLighterColor(baseColor, 0.7), // 100% 处的颜色 - 更浅的颜色
|
|
266
|
-
},
|
|
267
|
-
],
|
|
268
|
-
global: false, // 全局使用默认值
|
|
269
|
-
},
|
|
270
|
-
borderRadius: [5, 5, 0, 0],
|
|
271
|
-
shadowColor: 'rgba(0, 0, 0, 0.1)',
|
|
272
|
-
shadowBlur: 5,
|
|
273
|
-
shadowOffsetY: 3,
|
|
274
|
-
},
|
|
275
|
-
label: {
|
|
276
|
-
show: true,
|
|
277
|
-
position: 'top',
|
|
278
|
-
formatter: '{c}',
|
|
279
|
-
color: '#333',
|
|
280
|
-
fontSize: 12,
|
|
281
|
-
},
|
|
282
|
-
emphasis: {
|
|
283
|
-
itemStyle: {
|
|
284
|
-
shadowColor: 'rgba(0, 0, 0, 0.3)',
|
|
285
|
-
shadowBlur: 10,
|
|
286
|
-
shadowOffsetY: 5,
|
|
287
|
-
},
|
|
288
|
-
},
|
|
289
|
-
}
|
|
290
|
-
})
|
|
291
|
-
|
|
292
|
-
// x轴配置 - 保持水平显示,不旋转
|
|
293
|
-
const xAxisConfig = {
|
|
294
|
-
data: isEmpty ? [] : data.xAxis.data,
|
|
295
|
-
axisLabel: {
|
|
296
|
-
rotate: 0, // 保持水平,不旋转
|
|
297
|
-
interval: 0,
|
|
298
|
-
margin: 8,
|
|
299
|
-
fontSize: 12, // 统一字体大小
|
|
300
|
-
// 如果文字过长可以自动换行
|
|
301
|
-
formatter: function (value) {
|
|
302
|
-
if (value.length > 6) {
|
|
303
|
-
// 超过6个字符换行
|
|
304
|
-
return value.substring(0, 6) + '\n' + value.substring(6)
|
|
305
|
-
}
|
|
306
|
-
return value
|
|
307
|
-
},
|
|
308
|
-
},
|
|
309
|
-
axisTick: {
|
|
310
|
-
show: false,
|
|
311
|
-
},
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
// 滑动条配置
|
|
315
|
-
const dataZoomConfig = [
|
|
316
|
-
{
|
|
317
|
-
type: 'inside',
|
|
318
|
-
start: 0,
|
|
319
|
-
end: shouldShowSlider
|
|
320
|
-
? Math.min(100, (shouldShowSliderNumber / dataLength) * 100)
|
|
321
|
-
: 100, // 初始显示12列
|
|
322
|
-
zoomOnMouseWheel: false,
|
|
323
|
-
moveOnMouseMove: true,
|
|
324
|
-
moveOnMouseWheel: true,
|
|
325
|
-
},
|
|
326
|
-
{
|
|
327
|
-
type: 'slider',
|
|
328
|
-
show: shouldShowSlider, // 根据数据长度决定是否显示
|
|
329
|
-
start: 0,
|
|
330
|
-
end: shouldShowSlider
|
|
331
|
-
? Math.min(100, (shouldShowSliderNumber / dataLength) * 100)
|
|
332
|
-
: 100,
|
|
333
|
-
bottom: '0%',
|
|
334
|
-
height: 15,
|
|
335
|
-
handleSize: '100%',
|
|
336
|
-
handleStyle: {
|
|
337
|
-
color: '#025DF4',
|
|
338
|
-
},
|
|
339
|
-
fillerColor: 'rgba(2, 93, 244, 0.2)',
|
|
340
|
-
borderColor: '#ddd',
|
|
341
|
-
backgroundColor: '#f5f5f5',
|
|
342
|
-
showDetail: false,
|
|
343
|
-
},
|
|
344
|
-
]
|
|
345
|
-
|
|
346
|
-
// 构建最终配置
|
|
347
|
-
const defaultOptions = {
|
|
348
|
-
tooltip: {
|
|
349
|
-
show: !isEmpty,
|
|
350
|
-
},
|
|
351
|
-
grid: {
|
|
352
|
-
bottom: shouldShowSlider ? '6%' : '1%', // 增加底部间距为滑动条留出空间
|
|
353
|
-
},
|
|
354
|
-
xAxis: xAxisConfig,
|
|
355
|
-
legend: {
|
|
356
|
-
data: legendData,
|
|
357
|
-
},
|
|
358
|
-
series: series,
|
|
359
|
-
dataZoom: dataZoomConfig,
|
|
360
|
-
graphic: {
|
|
361
|
-
invisible: !isEmpty, // 有数据时隐藏,无数据时显示
|
|
362
|
-
},
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
// 更新图表配置
|
|
366
|
-
chartInstance.setOption(defaultOptions, {
|
|
367
|
-
replaceMerge: ['series'], // 关键修改:替换而非合并
|
|
368
|
-
})
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
/**
|
|
372
|
-
* 初始化折线图
|
|
373
|
-
* @param {HTMLElement} chartRef 图表DOM元素引用
|
|
374
|
-
* @returns {echarts.ECharts} 图表实例
|
|
375
|
-
*/
|
|
376
|
-
export const initLineChart = (chartRef, yAxisName = '单位') => {
|
|
377
|
-
if (!chartRef) return null
|
|
378
|
-
const chartInstance = echarts.init(chartRef)
|
|
379
|
-
const defaultOptions = {
|
|
380
|
-
...createNoDataGraphic(), // 添加暂无数据图形
|
|
381
|
-
tooltip: {
|
|
382
|
-
trigger: 'axis',
|
|
383
|
-
axisPointer: {
|
|
384
|
-
type: 'shadow',
|
|
385
|
-
},
|
|
386
|
-
},
|
|
387
|
-
grid: {
|
|
388
|
-
left: '3%',
|
|
389
|
-
right: '4%',
|
|
390
|
-
bottom: '1%', // 增加底部间距为滑动条留出空间
|
|
391
|
-
top: '15%',
|
|
392
|
-
containLabel: true,
|
|
393
|
-
},
|
|
394
|
-
legend: {
|
|
395
|
-
top: 'top', // 设置图例位于顶部
|
|
396
|
-
data: [],
|
|
397
|
-
},
|
|
398
|
-
xAxis: {
|
|
399
|
-
type: 'category',
|
|
400
|
-
boundaryGap: false,
|
|
401
|
-
data: [],
|
|
402
|
-
axisLabel: {
|
|
403
|
-
rotate: 0, // 保持水平
|
|
404
|
-
interval: 0,
|
|
405
|
-
},
|
|
406
|
-
axisTick: {
|
|
407
|
-
show: false,
|
|
408
|
-
},
|
|
409
|
-
},
|
|
410
|
-
yAxis: {
|
|
411
|
-
type: 'value',
|
|
412
|
-
name: yAxisName,
|
|
413
|
-
axisLabel: {
|
|
414
|
-
formatter: function (value) {
|
|
415
|
-
// 只显示整数值
|
|
416
|
-
return value % 1 === 0 ? value : ''
|
|
417
|
-
},
|
|
418
|
-
},
|
|
419
|
-
nameTextStyle: {
|
|
420
|
-
padding: [0, 30, 15, 0],
|
|
421
|
-
},
|
|
422
|
-
splitLine: {
|
|
423
|
-
lineStyle: {
|
|
424
|
-
type: 'dashed',
|
|
425
|
-
},
|
|
426
|
-
},
|
|
427
|
-
},
|
|
428
|
-
// 默认启用内置滑动条,但隐藏(超过12列时显示)
|
|
429
|
-
dataZoom: [
|
|
430
|
-
{
|
|
431
|
-
type: 'inside', // 内置型数据区域缩放
|
|
432
|
-
start: 0,
|
|
433
|
-
end: 100,
|
|
434
|
-
zoomOnMouseWheel: false, // 禁用鼠标滚轮缩放
|
|
435
|
-
moveOnMouseMove: true, // 允许拖拽滑动
|
|
436
|
-
moveOnMouseWheel: true, // 允许鼠标滚轮滑动
|
|
437
|
-
},
|
|
438
|
-
{
|
|
439
|
-
type: 'slider', // 滑动条型数据区域缩放
|
|
440
|
-
show: false, // 默认隐藏
|
|
441
|
-
start: 0,
|
|
442
|
-
end: 100,
|
|
443
|
-
bottom: '5%', // 滑动条位置
|
|
444
|
-
height: 15,
|
|
445
|
-
handleSize: '100%',
|
|
446
|
-
handleStyle: {
|
|
447
|
-
color: '#025DF4',
|
|
448
|
-
},
|
|
449
|
-
fillerColor: 'rgba(2, 93, 244, 0.2)',
|
|
450
|
-
borderColor: '#ddd',
|
|
451
|
-
backgroundColor: '#f5f5f5',
|
|
452
|
-
showDetail: false,
|
|
453
|
-
},
|
|
454
|
-
],
|
|
455
|
-
series: [],
|
|
456
|
-
}
|
|
457
|
-
|
|
458
|
-
chartInstance.setOption(defaultOptions)
|
|
459
|
-
return chartInstance
|
|
460
|
-
}
|
|
461
|
-
|
|
462
|
-
/**
|
|
463
|
-
* 更新折线图数据
|
|
464
|
-
* @param {echarts.ECharts} chartInstance 图表实例
|
|
465
|
-
* @param {Object} data 图表数据 {xAxis: {data: []}, series: []}
|
|
466
|
-
*/
|
|
467
|
-
export const updateLineChart = ({
|
|
468
|
-
chartInstance,
|
|
469
|
-
data,
|
|
470
|
-
shouldShowSlider = false,
|
|
471
|
-
shouldShowSliderNumber = 12,
|
|
472
|
-
}) => {
|
|
473
|
-
hideChartLoading(chartInstance)
|
|
474
|
-
if (!chartInstance) return
|
|
475
|
-
|
|
476
|
-
const isEmpty =
|
|
477
|
-
!data || !data.xAxis || !data.xAxis.data || data.xAxis.data.length === 0
|
|
478
|
-
const dataLength = isEmpty ? 0 : data.xAxis.data.length
|
|
479
|
-
|
|
480
|
-
// 提取图例数据
|
|
481
|
-
const legendData = isEmpty ? [] : data.series.map(item => item.name)
|
|
482
|
-
|
|
483
|
-
// 构建系列配置
|
|
484
|
-
const series = isEmpty
|
|
485
|
-
? []
|
|
486
|
-
: data.series.map((lineData, index) => {
|
|
487
|
-
// 获取当前线条的颜色
|
|
488
|
-
const baseColor = barColorPalette[index % barColorPalette.length]
|
|
489
|
-
|
|
490
|
-
return {
|
|
491
|
-
name: lineData.name,
|
|
492
|
-
type: 'line',
|
|
493
|
-
smooth: true, // 平滑曲线
|
|
494
|
-
symbol: 'circle',
|
|
495
|
-
symbolSize: 5,
|
|
496
|
-
data: lineData.data,
|
|
497
|
-
itemStyle: {
|
|
498
|
-
color: baseColor,
|
|
499
|
-
},
|
|
500
|
-
lineStyle: {
|
|
501
|
-
width: 2,
|
|
502
|
-
shadowColor: 'rgba(0, 0, 0, 0.1)',
|
|
503
|
-
shadowBlur: 5,
|
|
504
|
-
shadowOffsetY: 3,
|
|
505
|
-
},
|
|
506
|
-
areaStyle: {
|
|
507
|
-
color: {
|
|
508
|
-
type: 'linear',
|
|
509
|
-
x: 0,
|
|
510
|
-
y: 0,
|
|
511
|
-
x2: 0,
|
|
512
|
-
y2: 1,
|
|
513
|
-
colorStops: [
|
|
514
|
-
{
|
|
515
|
-
offset: 0,
|
|
516
|
-
color: getLighterColor(baseColor, 0.1), // 区域顶部颜色,较浅
|
|
517
|
-
},
|
|
518
|
-
{
|
|
519
|
-
offset: 1,
|
|
520
|
-
color: getLighterColor(baseColor, 0.9), // 区域底部颜色,更浅
|
|
521
|
-
},
|
|
522
|
-
],
|
|
523
|
-
global: false,
|
|
524
|
-
},
|
|
525
|
-
opacity: 0.3, // 轻微区域填充
|
|
526
|
-
},
|
|
527
|
-
label: {
|
|
528
|
-
show: true,
|
|
529
|
-
position: 'top',
|
|
530
|
-
formatter: '{c}',
|
|
531
|
-
color: '#333',
|
|
532
|
-
fontSize: 12,
|
|
533
|
-
},
|
|
534
|
-
emphasis: {
|
|
535
|
-
focus: 'series',
|
|
536
|
-
},
|
|
537
|
-
}
|
|
538
|
-
})
|
|
539
|
-
|
|
540
|
-
// x轴配置 - 保持水平显示,不旋转
|
|
541
|
-
const xAxisConfig = {
|
|
542
|
-
data: isEmpty ? [] : data.xAxis.data,
|
|
543
|
-
axisLabel: {
|
|
544
|
-
rotate: 0, // 保持水平,不旋转
|
|
545
|
-
interval: 0,
|
|
546
|
-
margin: 8,
|
|
547
|
-
fontSize: 12, // 统一字体大小
|
|
548
|
-
// 如果文字过长可以自动换行
|
|
549
|
-
formatter: function (value) {
|
|
550
|
-
if (value.length > 6) {
|
|
551
|
-
// 超过6个字符换行
|
|
552
|
-
return value.substring(0, 6) + '\n' + value.substring(6)
|
|
553
|
-
}
|
|
554
|
-
return value
|
|
555
|
-
},
|
|
556
|
-
},
|
|
557
|
-
axisTick: {
|
|
558
|
-
show: false,
|
|
559
|
-
},
|
|
560
|
-
}
|
|
561
|
-
|
|
562
|
-
// 滑动条配置
|
|
563
|
-
const dataZoomConfig = [
|
|
564
|
-
{
|
|
565
|
-
type: 'inside',
|
|
566
|
-
start: 0,
|
|
567
|
-
end: shouldShowSlider
|
|
568
|
-
? Math.min(100, (shouldShowSliderNumber / dataLength) * 100)
|
|
569
|
-
: 100, // 初始显示12列
|
|
570
|
-
zoomOnMouseWheel: false,
|
|
571
|
-
moveOnMouseMove: true,
|
|
572
|
-
moveOnMouseWheel: true,
|
|
573
|
-
},
|
|
574
|
-
{
|
|
575
|
-
type: 'slider',
|
|
576
|
-
show: shouldShowSlider, // 根据数据长度决定是否显示
|
|
577
|
-
start: 0,
|
|
578
|
-
end: shouldShowSlider
|
|
579
|
-
? Math.min(100, (shouldShowSliderNumber / dataLength) * 100)
|
|
580
|
-
: 100,
|
|
581
|
-
bottom: '0%',
|
|
582
|
-
height: 15,
|
|
583
|
-
handleSize: '100%',
|
|
584
|
-
handleStyle: {
|
|
585
|
-
color: '#025DF4',
|
|
586
|
-
},
|
|
587
|
-
fillerColor: 'rgba(2, 93, 244, 0.2)',
|
|
588
|
-
borderColor: '#ddd',
|
|
589
|
-
backgroundColor: '#f5f5f5',
|
|
590
|
-
showDetail: false,
|
|
591
|
-
},
|
|
592
|
-
]
|
|
593
|
-
|
|
594
|
-
// 构建最终配置
|
|
595
|
-
const defaultOptions = {
|
|
596
|
-
tooltip: {
|
|
597
|
-
show: !isEmpty,
|
|
598
|
-
},
|
|
599
|
-
grid: {
|
|
600
|
-
bottom: shouldShowSlider ? '6%' : '1%', // 增加底部间距为滑动条留出空间
|
|
601
|
-
},
|
|
602
|
-
xAxis: xAxisConfig,
|
|
603
|
-
legend: {
|
|
604
|
-
data: legendData,
|
|
605
|
-
},
|
|
606
|
-
series: series,
|
|
607
|
-
dataZoom: dataZoomConfig,
|
|
608
|
-
graphic: {
|
|
609
|
-
invisible: !isEmpty, // 有数据时隐藏,无数据时显示
|
|
610
|
-
},
|
|
611
|
-
}
|
|
612
|
-
|
|
613
|
-
// 更新图表配置
|
|
614
|
-
chartInstance.setOption(defaultOptions, {
|
|
615
|
-
replaceMerge: ['series'], // 关键修改:替换而非合并
|
|
616
|
-
})
|
|
617
|
-
}
|
|
618
|
-
|
|
619
|
-
/**
|
|
620
|
-
* 显示图表加载状态
|
|
621
|
-
* @param {echarts.ECharts} chartInstance 图表实例
|
|
622
|
-
*/
|
|
623
|
-
export const showChartLoading = chartInstance => {
|
|
624
|
-
if (!chartInstance) return
|
|
625
|
-
|
|
626
|
-
chartInstance.showLoading({
|
|
627
|
-
text: '数据加载中...',
|
|
628
|
-
color: '#1677ff',
|
|
629
|
-
maskColor: 'rgba(255, 255, 255, 0.8)',
|
|
630
|
-
textColor: '#000',
|
|
631
|
-
zlevel: 0,
|
|
632
|
-
})
|
|
633
|
-
}
|
|
634
|
-
/**
|
|
635
|
-
* 隐藏图表加载状态
|
|
636
|
-
* @param {echarts.ECharts} chartInstance 图表实例
|
|
637
|
-
*/
|
|
638
|
-
export const hideChartLoading = chartInstance => {
|
|
639
|
-
if (!chartInstance) return
|
|
640
|
-
chartInstance.hideLoading()
|
|
641
|
-
}
|
|
642
|
-
|
|
643
|
-
/**
|
|
644
|
-
* 获取更亮颜色的函数
|
|
645
|
-
* @param {string} color - 基础颜色
|
|
646
|
-
* @param {number} lum - 亮度系数 (0 <= lum <= 1)
|
|
647
|
-
*/
|
|
648
|
-
function getLighterColor(color, lum) {
|
|
649
|
-
// 将十六进制颜色转换为RGB
|
|
650
|
-
let rgb = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(color)
|
|
651
|
-
let r = parseInt(rgb[1], 16)
|
|
652
|
-
let g = parseInt(rgb[2], 16)
|
|
653
|
-
let b = parseInt(rgb[3], 16)
|
|
654
|
-
|
|
655
|
-
// 调整亮度
|
|
656
|
-
r = Math.floor(Math.min(255, Math.max(0, r + (255 - r) * lum)))
|
|
657
|
-
g = Math.floor(Math.min(255, Math.max(0, g + (255 - g) * lum)))
|
|
658
|
-
b = Math.floor(Math.min(255, Math.max(0, b + (255 - b) * lum)))
|
|
659
|
-
|
|
660
|
-
return `rgb(${r},${g},${b})`
|
|
661
|
-
}
|
|
1
|
+
import * as echarts from 'echarts'
|
|
2
|
+
// 定义柱状图颜色调色板
|
|
3
|
+
export const barColorPalette = [
|
|
4
|
+
'#025DF4',
|
|
5
|
+
'#DB6BCF',
|
|
6
|
+
'#2498D1',
|
|
7
|
+
'#BBBDE6',
|
|
8
|
+
'#4045B2',
|
|
9
|
+
'#21A97A',
|
|
10
|
+
'#FF745A',
|
|
11
|
+
'#007E99',
|
|
12
|
+
'#FFA8A8',
|
|
13
|
+
'#2391FF',
|
|
14
|
+
]
|
|
15
|
+
const createNoDataGraphic = (text = '暂无数据') => ({
|
|
16
|
+
graphic: {
|
|
17
|
+
type: 'text',
|
|
18
|
+
left: 'center',
|
|
19
|
+
top: 'center',
|
|
20
|
+
z: 100, // 确保在最上层
|
|
21
|
+
silent: true,
|
|
22
|
+
invisible: true, // 默认隐藏
|
|
23
|
+
style: {
|
|
24
|
+
text,
|
|
25
|
+
fontSize: 20,
|
|
26
|
+
fontWeight: 'normal',
|
|
27
|
+
fill: '#999',
|
|
28
|
+
align: 'center',
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
})
|
|
32
|
+
/**
|
|
33
|
+
* 初始化饼图
|
|
34
|
+
* @param {HTMLElement} chartRef 图表DOM元素引用
|
|
35
|
+
* @returns {echarts.ECharts} 图表实例
|
|
36
|
+
*/
|
|
37
|
+
export const initPieChart = (chartRef, seriesName = '标题') => {
|
|
38
|
+
if (!chartRef) return null
|
|
39
|
+
const chartInstance = echarts.init(chartRef)
|
|
40
|
+
const defaultOptions = {
|
|
41
|
+
...createNoDataGraphic(), // 添加暂无数据图形
|
|
42
|
+
tooltip: {
|
|
43
|
+
trigger: 'item',
|
|
44
|
+
formatter: function (params) {
|
|
45
|
+
return `<span style="display:inline-block;margin-right:5px;
|
|
46
|
+
border-radius:50%;width:10px;height:10px;
|
|
47
|
+
background-color:${params.color}"></span>
|
|
48
|
+
${params.seriesName}<br/>${params.name}: ${params.value} (${params.percent}%)`
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
legend: {
|
|
52
|
+
top: 0,
|
|
53
|
+
left: 'center',
|
|
54
|
+
type: 'scroll', // 改为滚动式图例
|
|
55
|
+
pageTextStyle: {
|
|
56
|
+
color: '#333',
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
color: barColorPalette,
|
|
60
|
+
series: [
|
|
61
|
+
{
|
|
62
|
+
name: seriesName,
|
|
63
|
+
type: 'pie',
|
|
64
|
+
radius: '55%',
|
|
65
|
+
center: ['50%', '60%'],
|
|
66
|
+
avoidLabelOverlap: true,
|
|
67
|
+
itemStyle: {
|
|
68
|
+
borderRadius: 3,
|
|
69
|
+
borderColor: '#fff',
|
|
70
|
+
borderWidth: 2,
|
|
71
|
+
},
|
|
72
|
+
label: {
|
|
73
|
+
show: true, // 显示标签
|
|
74
|
+
formatter: function (params) {
|
|
75
|
+
// 自定义格式化函数,实现多行显示
|
|
76
|
+
return [`${params.name}`, `${params.percent}%`].join('\n')
|
|
77
|
+
},
|
|
78
|
+
fontSize: 12, // 调整字体大小
|
|
79
|
+
color: '#333', // 标签颜色
|
|
80
|
+
lineHeight: 14, // 行高
|
|
81
|
+
},
|
|
82
|
+
emphasis: {},
|
|
83
|
+
labelLine: {
|
|
84
|
+
show: true,
|
|
85
|
+
},
|
|
86
|
+
data: [],
|
|
87
|
+
},
|
|
88
|
+
],
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
chartInstance.setOption(defaultOptions)
|
|
92
|
+
return chartInstance
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* 更新饼图数据
|
|
96
|
+
* @param {echarts.ECharts} chartInstance 图表实例
|
|
97
|
+
* @param {Array} data 图表数据
|
|
98
|
+
*/
|
|
99
|
+
export const updatePieChart = ({ chartInstance, data }) => {
|
|
100
|
+
hideChartLoading(chartInstance)
|
|
101
|
+
if (!chartInstance) return
|
|
102
|
+
const isEmpty = !data || data.length === 0
|
|
103
|
+
// 更新配置
|
|
104
|
+
const updateOptions = {
|
|
105
|
+
tooltip: {
|
|
106
|
+
show: !isEmpty,
|
|
107
|
+
},
|
|
108
|
+
legend: {
|
|
109
|
+
show: !isEmpty,
|
|
110
|
+
},
|
|
111
|
+
series: [
|
|
112
|
+
{
|
|
113
|
+
data: isEmpty
|
|
114
|
+
? []
|
|
115
|
+
: data.map(item => ({
|
|
116
|
+
...item,
|
|
117
|
+
name: `${item.name} (${item.value})`,
|
|
118
|
+
})),
|
|
119
|
+
silent: isEmpty,
|
|
120
|
+
},
|
|
121
|
+
],
|
|
122
|
+
graphic: {
|
|
123
|
+
invisible: !isEmpty, // 有数据时隐藏,无数据时显示
|
|
124
|
+
},
|
|
125
|
+
}
|
|
126
|
+
// 合并自定义配置
|
|
127
|
+
chartInstance.setOption(updateOptions)
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* 初始化柱状图
|
|
131
|
+
* @param {HTMLElement} chartRef 图表DOM元素引用
|
|
132
|
+
* @returns {echarts.ECharts} 图表实例
|
|
133
|
+
*/
|
|
134
|
+
export const initBarChart = (chartRef, yAxisName = '单位') => {
|
|
135
|
+
if (!chartRef) return null
|
|
136
|
+
const chartInstance = echarts.init(chartRef)
|
|
137
|
+
const defaultOptions = {
|
|
138
|
+
...createNoDataGraphic(), // 添加暂无数据图形
|
|
139
|
+
tooltip: {
|
|
140
|
+
trigger: 'axis',
|
|
141
|
+
axisPointer: {
|
|
142
|
+
type: 'shadow',
|
|
143
|
+
},
|
|
144
|
+
},
|
|
145
|
+
grid: {
|
|
146
|
+
left: '3%',
|
|
147
|
+
right: '4%',
|
|
148
|
+
bottom: '1%', // 增加底部间距为滑动条留出空间
|
|
149
|
+
top: '15%',
|
|
150
|
+
containLabel: true,
|
|
151
|
+
},
|
|
152
|
+
legend: {
|
|
153
|
+
top: 'top', // 设置图例位于顶部
|
|
154
|
+
data: [],
|
|
155
|
+
},
|
|
156
|
+
xAxis: {
|
|
157
|
+
type: 'category',
|
|
158
|
+
data: [],
|
|
159
|
+
axisLabel: {
|
|
160
|
+
rotate: 0, // 保持水平
|
|
161
|
+
interval: 0,
|
|
162
|
+
},
|
|
163
|
+
axisTick: {
|
|
164
|
+
show: false,
|
|
165
|
+
},
|
|
166
|
+
},
|
|
167
|
+
yAxis: {
|
|
168
|
+
type: 'value',
|
|
169
|
+
name: yAxisName,
|
|
170
|
+
axisLabel: {
|
|
171
|
+
formatter: function (value) {
|
|
172
|
+
// 只显示整数值
|
|
173
|
+
return value % 1 === 0 ? value : ''
|
|
174
|
+
},
|
|
175
|
+
},
|
|
176
|
+
nameTextStyle: {
|
|
177
|
+
padding: [0, 30, 15, 0],
|
|
178
|
+
},
|
|
179
|
+
splitLine: {
|
|
180
|
+
lineStyle: {
|
|
181
|
+
type: 'dashed',
|
|
182
|
+
},
|
|
183
|
+
},
|
|
184
|
+
},
|
|
185
|
+
// 默认启用内置滑动条,但隐藏(超过12列时显示)
|
|
186
|
+
dataZoom: [
|
|
187
|
+
{
|
|
188
|
+
type: 'inside', // 内置型数据区域缩放
|
|
189
|
+
start: 0,
|
|
190
|
+
end: 100,
|
|
191
|
+
zoomOnMouseWheel: false, // 禁用鼠标滚轮缩放
|
|
192
|
+
moveOnMouseMove: true, // 允许拖拽滑动
|
|
193
|
+
moveOnMouseWheel: true, // 允许鼠标滚轮滑动
|
|
194
|
+
},
|
|
195
|
+
{
|
|
196
|
+
type: 'slider', // 滑动条型数据区域缩放
|
|
197
|
+
show: false, // 默认隐藏
|
|
198
|
+
start: 0,
|
|
199
|
+
end: 100,
|
|
200
|
+
bottom: '0%',
|
|
201
|
+
height: 15,
|
|
202
|
+
handleSize: '100%',
|
|
203
|
+
handleStyle: {
|
|
204
|
+
color: '#025DF4',
|
|
205
|
+
},
|
|
206
|
+
fillerColor: 'rgba(2, 93, 244, 0.2)',
|
|
207
|
+
borderColor: '#ddd',
|
|
208
|
+
backgroundColor: '#f5f5f5',
|
|
209
|
+
showDetail: false,
|
|
210
|
+
},
|
|
211
|
+
],
|
|
212
|
+
series: [],
|
|
213
|
+
}
|
|
214
|
+
chartInstance.setOption(defaultOptions)
|
|
215
|
+
return chartInstance
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* 更新柱状图数据
|
|
219
|
+
* @param {echarts.ECharts} chartInstance 图表实例
|
|
220
|
+
* @param {Object} data 图表数据 {xAxis: {data: []}, series: []}
|
|
221
|
+
*/
|
|
222
|
+
export const updateBarChart = ({
|
|
223
|
+
chartInstance,
|
|
224
|
+
data,
|
|
225
|
+
shouldShowSlider = false,
|
|
226
|
+
shouldShowSliderNumber = 12,
|
|
227
|
+
}) => {
|
|
228
|
+
hideChartLoading(chartInstance)
|
|
229
|
+
if (!chartInstance) return
|
|
230
|
+
|
|
231
|
+
const isEmpty =
|
|
232
|
+
!data || !data.xAxis || !data.xAxis.data || data.xAxis.data.length === 0
|
|
233
|
+
const dataLength = isEmpty ? 0 : data.xAxis.data.length
|
|
234
|
+
|
|
235
|
+
// 提取图例数据(公司名称)
|
|
236
|
+
const legendData = isEmpty ? [] : data.series.map(item => item.name)
|
|
237
|
+
|
|
238
|
+
// 构建系列配置
|
|
239
|
+
const series = isEmpty
|
|
240
|
+
? []
|
|
241
|
+
: data.series.map((companyData, index) => {
|
|
242
|
+
// 获取当前线条的颜色
|
|
243
|
+
const baseColor = barColorPalette[index % barColorPalette.length]
|
|
244
|
+
return {
|
|
245
|
+
name: companyData.name,
|
|
246
|
+
type: 'bar',
|
|
247
|
+
barMaxWidth: 40,
|
|
248
|
+
barCategoryGap: shouldShowSlider ? '15%' : '30%', // 有滑动条时减小间距
|
|
249
|
+
data: companyData.data,
|
|
250
|
+
itemStyle: {
|
|
251
|
+
color: {
|
|
252
|
+
// 线性渐变,方向从底部到顶部
|
|
253
|
+
type: 'linear',
|
|
254
|
+
x: 0,
|
|
255
|
+
y: 0,
|
|
256
|
+
x2: 0,
|
|
257
|
+
y2: 1,
|
|
258
|
+
colorStops: [
|
|
259
|
+
{
|
|
260
|
+
offset: 0,
|
|
261
|
+
color: baseColor, // 0% 处的颜色 - 原始颜色
|
|
262
|
+
},
|
|
263
|
+
{
|
|
264
|
+
offset: 1,
|
|
265
|
+
color: getLighterColor(baseColor, 0.7), // 100% 处的颜色 - 更浅的颜色
|
|
266
|
+
},
|
|
267
|
+
],
|
|
268
|
+
global: false, // 全局使用默认值
|
|
269
|
+
},
|
|
270
|
+
borderRadius: [5, 5, 0, 0],
|
|
271
|
+
shadowColor: 'rgba(0, 0, 0, 0.1)',
|
|
272
|
+
shadowBlur: 5,
|
|
273
|
+
shadowOffsetY: 3,
|
|
274
|
+
},
|
|
275
|
+
label: {
|
|
276
|
+
show: true,
|
|
277
|
+
position: 'top',
|
|
278
|
+
formatter: '{c}',
|
|
279
|
+
color: '#333',
|
|
280
|
+
fontSize: 12,
|
|
281
|
+
},
|
|
282
|
+
emphasis: {
|
|
283
|
+
itemStyle: {
|
|
284
|
+
shadowColor: 'rgba(0, 0, 0, 0.3)',
|
|
285
|
+
shadowBlur: 10,
|
|
286
|
+
shadowOffsetY: 5,
|
|
287
|
+
},
|
|
288
|
+
},
|
|
289
|
+
}
|
|
290
|
+
})
|
|
291
|
+
|
|
292
|
+
// x轴配置 - 保持水平显示,不旋转
|
|
293
|
+
const xAxisConfig = {
|
|
294
|
+
data: isEmpty ? [] : data.xAxis.data,
|
|
295
|
+
axisLabel: {
|
|
296
|
+
rotate: 0, // 保持水平,不旋转
|
|
297
|
+
interval: 0,
|
|
298
|
+
margin: 8,
|
|
299
|
+
fontSize: 12, // 统一字体大小
|
|
300
|
+
// 如果文字过长可以自动换行
|
|
301
|
+
formatter: function (value) {
|
|
302
|
+
if (value.length > 6) {
|
|
303
|
+
// 超过6个字符换行
|
|
304
|
+
return value.substring(0, 6) + '\n' + value.substring(6)
|
|
305
|
+
}
|
|
306
|
+
return value
|
|
307
|
+
},
|
|
308
|
+
},
|
|
309
|
+
axisTick: {
|
|
310
|
+
show: false,
|
|
311
|
+
},
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
// 滑动条配置
|
|
315
|
+
const dataZoomConfig = [
|
|
316
|
+
{
|
|
317
|
+
type: 'inside',
|
|
318
|
+
start: 0,
|
|
319
|
+
end: shouldShowSlider
|
|
320
|
+
? Math.min(100, (shouldShowSliderNumber / dataLength) * 100)
|
|
321
|
+
: 100, // 初始显示12列
|
|
322
|
+
zoomOnMouseWheel: false,
|
|
323
|
+
moveOnMouseMove: true,
|
|
324
|
+
moveOnMouseWheel: true,
|
|
325
|
+
},
|
|
326
|
+
{
|
|
327
|
+
type: 'slider',
|
|
328
|
+
show: shouldShowSlider, // 根据数据长度决定是否显示
|
|
329
|
+
start: 0,
|
|
330
|
+
end: shouldShowSlider
|
|
331
|
+
? Math.min(100, (shouldShowSliderNumber / dataLength) * 100)
|
|
332
|
+
: 100,
|
|
333
|
+
bottom: '0%',
|
|
334
|
+
height: 15,
|
|
335
|
+
handleSize: '100%',
|
|
336
|
+
handleStyle: {
|
|
337
|
+
color: '#025DF4',
|
|
338
|
+
},
|
|
339
|
+
fillerColor: 'rgba(2, 93, 244, 0.2)',
|
|
340
|
+
borderColor: '#ddd',
|
|
341
|
+
backgroundColor: '#f5f5f5',
|
|
342
|
+
showDetail: false,
|
|
343
|
+
},
|
|
344
|
+
]
|
|
345
|
+
|
|
346
|
+
// 构建最终配置
|
|
347
|
+
const defaultOptions = {
|
|
348
|
+
tooltip: {
|
|
349
|
+
show: !isEmpty,
|
|
350
|
+
},
|
|
351
|
+
grid: {
|
|
352
|
+
bottom: shouldShowSlider ? '6%' : '1%', // 增加底部间距为滑动条留出空间
|
|
353
|
+
},
|
|
354
|
+
xAxis: xAxisConfig,
|
|
355
|
+
legend: {
|
|
356
|
+
data: legendData,
|
|
357
|
+
},
|
|
358
|
+
series: series,
|
|
359
|
+
dataZoom: dataZoomConfig,
|
|
360
|
+
graphic: {
|
|
361
|
+
invisible: !isEmpty, // 有数据时隐藏,无数据时显示
|
|
362
|
+
},
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
// 更新图表配置
|
|
366
|
+
chartInstance.setOption(defaultOptions, {
|
|
367
|
+
replaceMerge: ['series'], // 关键修改:替换而非合并
|
|
368
|
+
})
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
/**
|
|
372
|
+
* 初始化折线图
|
|
373
|
+
* @param {HTMLElement} chartRef 图表DOM元素引用
|
|
374
|
+
* @returns {echarts.ECharts} 图表实例
|
|
375
|
+
*/
|
|
376
|
+
export const initLineChart = (chartRef, yAxisName = '单位') => {
|
|
377
|
+
if (!chartRef) return null
|
|
378
|
+
const chartInstance = echarts.init(chartRef)
|
|
379
|
+
const defaultOptions = {
|
|
380
|
+
...createNoDataGraphic(), // 添加暂无数据图形
|
|
381
|
+
tooltip: {
|
|
382
|
+
trigger: 'axis',
|
|
383
|
+
axisPointer: {
|
|
384
|
+
type: 'shadow',
|
|
385
|
+
},
|
|
386
|
+
},
|
|
387
|
+
grid: {
|
|
388
|
+
left: '3%',
|
|
389
|
+
right: '4%',
|
|
390
|
+
bottom: '1%', // 增加底部间距为滑动条留出空间
|
|
391
|
+
top: '15%',
|
|
392
|
+
containLabel: true,
|
|
393
|
+
},
|
|
394
|
+
legend: {
|
|
395
|
+
top: 'top', // 设置图例位于顶部
|
|
396
|
+
data: [],
|
|
397
|
+
},
|
|
398
|
+
xAxis: {
|
|
399
|
+
type: 'category',
|
|
400
|
+
boundaryGap: false,
|
|
401
|
+
data: [],
|
|
402
|
+
axisLabel: {
|
|
403
|
+
rotate: 0, // 保持水平
|
|
404
|
+
interval: 0,
|
|
405
|
+
},
|
|
406
|
+
axisTick: {
|
|
407
|
+
show: false,
|
|
408
|
+
},
|
|
409
|
+
},
|
|
410
|
+
yAxis: {
|
|
411
|
+
type: 'value',
|
|
412
|
+
name: yAxisName,
|
|
413
|
+
axisLabel: {
|
|
414
|
+
formatter: function (value) {
|
|
415
|
+
// 只显示整数值
|
|
416
|
+
return value % 1 === 0 ? value : ''
|
|
417
|
+
},
|
|
418
|
+
},
|
|
419
|
+
nameTextStyle: {
|
|
420
|
+
padding: [0, 30, 15, 0],
|
|
421
|
+
},
|
|
422
|
+
splitLine: {
|
|
423
|
+
lineStyle: {
|
|
424
|
+
type: 'dashed',
|
|
425
|
+
},
|
|
426
|
+
},
|
|
427
|
+
},
|
|
428
|
+
// 默认启用内置滑动条,但隐藏(超过12列时显示)
|
|
429
|
+
dataZoom: [
|
|
430
|
+
{
|
|
431
|
+
type: 'inside', // 内置型数据区域缩放
|
|
432
|
+
start: 0,
|
|
433
|
+
end: 100,
|
|
434
|
+
zoomOnMouseWheel: false, // 禁用鼠标滚轮缩放
|
|
435
|
+
moveOnMouseMove: true, // 允许拖拽滑动
|
|
436
|
+
moveOnMouseWheel: true, // 允许鼠标滚轮滑动
|
|
437
|
+
},
|
|
438
|
+
{
|
|
439
|
+
type: 'slider', // 滑动条型数据区域缩放
|
|
440
|
+
show: false, // 默认隐藏
|
|
441
|
+
start: 0,
|
|
442
|
+
end: 100,
|
|
443
|
+
bottom: '5%', // 滑动条位置
|
|
444
|
+
height: 15,
|
|
445
|
+
handleSize: '100%',
|
|
446
|
+
handleStyle: {
|
|
447
|
+
color: '#025DF4',
|
|
448
|
+
},
|
|
449
|
+
fillerColor: 'rgba(2, 93, 244, 0.2)',
|
|
450
|
+
borderColor: '#ddd',
|
|
451
|
+
backgroundColor: '#f5f5f5',
|
|
452
|
+
showDetail: false,
|
|
453
|
+
},
|
|
454
|
+
],
|
|
455
|
+
series: [],
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
chartInstance.setOption(defaultOptions)
|
|
459
|
+
return chartInstance
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
/**
|
|
463
|
+
* 更新折线图数据
|
|
464
|
+
* @param {echarts.ECharts} chartInstance 图表实例
|
|
465
|
+
* @param {Object} data 图表数据 {xAxis: {data: []}, series: []}
|
|
466
|
+
*/
|
|
467
|
+
export const updateLineChart = ({
|
|
468
|
+
chartInstance,
|
|
469
|
+
data,
|
|
470
|
+
shouldShowSlider = false,
|
|
471
|
+
shouldShowSliderNumber = 12,
|
|
472
|
+
}) => {
|
|
473
|
+
hideChartLoading(chartInstance)
|
|
474
|
+
if (!chartInstance) return
|
|
475
|
+
|
|
476
|
+
const isEmpty =
|
|
477
|
+
!data || !data.xAxis || !data.xAxis.data || data.xAxis.data.length === 0
|
|
478
|
+
const dataLength = isEmpty ? 0 : data.xAxis.data.length
|
|
479
|
+
|
|
480
|
+
// 提取图例数据
|
|
481
|
+
const legendData = isEmpty ? [] : data.series.map(item => item.name)
|
|
482
|
+
|
|
483
|
+
// 构建系列配置
|
|
484
|
+
const series = isEmpty
|
|
485
|
+
? []
|
|
486
|
+
: data.series.map((lineData, index) => {
|
|
487
|
+
// 获取当前线条的颜色
|
|
488
|
+
const baseColor = barColorPalette[index % barColorPalette.length]
|
|
489
|
+
|
|
490
|
+
return {
|
|
491
|
+
name: lineData.name,
|
|
492
|
+
type: 'line',
|
|
493
|
+
smooth: true, // 平滑曲线
|
|
494
|
+
symbol: 'circle',
|
|
495
|
+
symbolSize: 5,
|
|
496
|
+
data: lineData.data,
|
|
497
|
+
itemStyle: {
|
|
498
|
+
color: baseColor,
|
|
499
|
+
},
|
|
500
|
+
lineStyle: {
|
|
501
|
+
width: 2,
|
|
502
|
+
shadowColor: 'rgba(0, 0, 0, 0.1)',
|
|
503
|
+
shadowBlur: 5,
|
|
504
|
+
shadowOffsetY: 3,
|
|
505
|
+
},
|
|
506
|
+
areaStyle: {
|
|
507
|
+
color: {
|
|
508
|
+
type: 'linear',
|
|
509
|
+
x: 0,
|
|
510
|
+
y: 0,
|
|
511
|
+
x2: 0,
|
|
512
|
+
y2: 1,
|
|
513
|
+
colorStops: [
|
|
514
|
+
{
|
|
515
|
+
offset: 0,
|
|
516
|
+
color: getLighterColor(baseColor, 0.1), // 区域顶部颜色,较浅
|
|
517
|
+
},
|
|
518
|
+
{
|
|
519
|
+
offset: 1,
|
|
520
|
+
color: getLighterColor(baseColor, 0.9), // 区域底部颜色,更浅
|
|
521
|
+
},
|
|
522
|
+
],
|
|
523
|
+
global: false,
|
|
524
|
+
},
|
|
525
|
+
opacity: 0.3, // 轻微区域填充
|
|
526
|
+
},
|
|
527
|
+
label: {
|
|
528
|
+
show: true,
|
|
529
|
+
position: 'top',
|
|
530
|
+
formatter: '{c}',
|
|
531
|
+
color: '#333',
|
|
532
|
+
fontSize: 12,
|
|
533
|
+
},
|
|
534
|
+
emphasis: {
|
|
535
|
+
focus: 'series',
|
|
536
|
+
},
|
|
537
|
+
}
|
|
538
|
+
})
|
|
539
|
+
|
|
540
|
+
// x轴配置 - 保持水平显示,不旋转
|
|
541
|
+
const xAxisConfig = {
|
|
542
|
+
data: isEmpty ? [] : data.xAxis.data,
|
|
543
|
+
axisLabel: {
|
|
544
|
+
rotate: 0, // 保持水平,不旋转
|
|
545
|
+
interval: 0,
|
|
546
|
+
margin: 8,
|
|
547
|
+
fontSize: 12, // 统一字体大小
|
|
548
|
+
// 如果文字过长可以自动换行
|
|
549
|
+
formatter: function (value) {
|
|
550
|
+
if (value.length > 6) {
|
|
551
|
+
// 超过6个字符换行
|
|
552
|
+
return value.substring(0, 6) + '\n' + value.substring(6)
|
|
553
|
+
}
|
|
554
|
+
return value
|
|
555
|
+
},
|
|
556
|
+
},
|
|
557
|
+
axisTick: {
|
|
558
|
+
show: false,
|
|
559
|
+
},
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
// 滑动条配置
|
|
563
|
+
const dataZoomConfig = [
|
|
564
|
+
{
|
|
565
|
+
type: 'inside',
|
|
566
|
+
start: 0,
|
|
567
|
+
end: shouldShowSlider
|
|
568
|
+
? Math.min(100, (shouldShowSliderNumber / dataLength) * 100)
|
|
569
|
+
: 100, // 初始显示12列
|
|
570
|
+
zoomOnMouseWheel: false,
|
|
571
|
+
moveOnMouseMove: true,
|
|
572
|
+
moveOnMouseWheel: true,
|
|
573
|
+
},
|
|
574
|
+
{
|
|
575
|
+
type: 'slider',
|
|
576
|
+
show: shouldShowSlider, // 根据数据长度决定是否显示
|
|
577
|
+
start: 0,
|
|
578
|
+
end: shouldShowSlider
|
|
579
|
+
? Math.min(100, (shouldShowSliderNumber / dataLength) * 100)
|
|
580
|
+
: 100,
|
|
581
|
+
bottom: '0%',
|
|
582
|
+
height: 15,
|
|
583
|
+
handleSize: '100%',
|
|
584
|
+
handleStyle: {
|
|
585
|
+
color: '#025DF4',
|
|
586
|
+
},
|
|
587
|
+
fillerColor: 'rgba(2, 93, 244, 0.2)',
|
|
588
|
+
borderColor: '#ddd',
|
|
589
|
+
backgroundColor: '#f5f5f5',
|
|
590
|
+
showDetail: false,
|
|
591
|
+
},
|
|
592
|
+
]
|
|
593
|
+
|
|
594
|
+
// 构建最终配置
|
|
595
|
+
const defaultOptions = {
|
|
596
|
+
tooltip: {
|
|
597
|
+
show: !isEmpty,
|
|
598
|
+
},
|
|
599
|
+
grid: {
|
|
600
|
+
bottom: shouldShowSlider ? '6%' : '1%', // 增加底部间距为滑动条留出空间
|
|
601
|
+
},
|
|
602
|
+
xAxis: xAxisConfig,
|
|
603
|
+
legend: {
|
|
604
|
+
data: legendData,
|
|
605
|
+
},
|
|
606
|
+
series: series,
|
|
607
|
+
dataZoom: dataZoomConfig,
|
|
608
|
+
graphic: {
|
|
609
|
+
invisible: !isEmpty, // 有数据时隐藏,无数据时显示
|
|
610
|
+
},
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
// 更新图表配置
|
|
614
|
+
chartInstance.setOption(defaultOptions, {
|
|
615
|
+
replaceMerge: ['series'], // 关键修改:替换而非合并
|
|
616
|
+
})
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
/**
|
|
620
|
+
* 显示图表加载状态
|
|
621
|
+
* @param {echarts.ECharts} chartInstance 图表实例
|
|
622
|
+
*/
|
|
623
|
+
export const showChartLoading = chartInstance => {
|
|
624
|
+
if (!chartInstance) return
|
|
625
|
+
|
|
626
|
+
chartInstance.showLoading({
|
|
627
|
+
text: '数据加载中...',
|
|
628
|
+
color: '#1677ff',
|
|
629
|
+
maskColor: 'rgba(255, 255, 255, 0.8)',
|
|
630
|
+
textColor: '#000',
|
|
631
|
+
zlevel: 0,
|
|
632
|
+
})
|
|
633
|
+
}
|
|
634
|
+
/**
|
|
635
|
+
* 隐藏图表加载状态
|
|
636
|
+
* @param {echarts.ECharts} chartInstance 图表实例
|
|
637
|
+
*/
|
|
638
|
+
export const hideChartLoading = chartInstance => {
|
|
639
|
+
if (!chartInstance) return
|
|
640
|
+
chartInstance.hideLoading()
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
/**
|
|
644
|
+
* 获取更亮颜色的函数
|
|
645
|
+
* @param {string} color - 基础颜色
|
|
646
|
+
* @param {number} lum - 亮度系数 (0 <= lum <= 1)
|
|
647
|
+
*/
|
|
648
|
+
function getLighterColor(color, lum) {
|
|
649
|
+
// 将十六进制颜色转换为RGB
|
|
650
|
+
let rgb = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(color)
|
|
651
|
+
let r = parseInt(rgb[1], 16)
|
|
652
|
+
let g = parseInt(rgb[2], 16)
|
|
653
|
+
let b = parseInt(rgb[3], 16)
|
|
654
|
+
|
|
655
|
+
// 调整亮度
|
|
656
|
+
r = Math.floor(Math.min(255, Math.max(0, r + (255 - r) * lum)))
|
|
657
|
+
g = Math.floor(Math.min(255, Math.max(0, g + (255 - g) * lum)))
|
|
658
|
+
b = Math.floor(Math.min(255, Math.max(0, b + (255 - b) * lum)))
|
|
659
|
+
|
|
660
|
+
return `rgb(${r},${g},${b})`
|
|
661
|
+
}
|