首页设计-echrats

效果展示

代码展示

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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
<template>
<div>
<div class="home-page">
<h2>欢迎{{ username }}, 使用医学影像系统-数据文件存储软件</h2>
</div>
<div class="container">
<div class="box" id="area1"></div>
<div class="box" id="area2">区域 2</div>
<div class="box" id="area3">
<div class="table-title">今日就诊患者</div>
<el-table :data="tableData" style="width: 100%; height: 100%;" border>
<el-table-column prop="patientNumber" label="患者编号" min-width="150">
</el-table-column>
<el-table-column prop="patientName" label="患者姓名" min-width="150">
</el-table-column>
<el-table-column prop="gender" label="患者性别" min-width="150">
<template slot-scope="scope">
<dict-tag :options="dict.type.sys_user_sex" :value="scope.row.gender" />
</template>
</el-table-column>
<el-table-column prop="surgeryType" label="手术类型" min-width="150">
<template slot-scope="scope">
<dict-tag :options="dict.type.surgery_type" :value="scope.row.surgeryType" />
</template>
</el-table-column>
</el-table>
</div>
<div class="box" id="area4">
<div class="table-title">公告栏</div>
<el-table :data="noticeList" style="width: 100%; height: 100%;" border>
<el-table-column label="公告标题" align="center" prop="noticeTitle" min-width="150"
:show-overflow-tooltip="true" />
<el-table-column label="公告类型" align="center" prop="noticeType" min-width="150">
<template slot-scope="scope">
<dict-tag :options="dict.type.sys_notice_type" :value="scope.row.noticeType" />
</template>
</el-table-column>
<el-table-column label="公告内容" align="center" prop="noticeContent" min-width="150"
:show-overflow-tooltip="true" />
</el-table>
</div>
</div>
</div>


</template>

<script>
import { getHomePageInfo } from '@/api/menu';
import { listNotice } from "@/api/system/notice";
export default {
name: 'HomePage',
dicts: ['sys_user_sex', 'surgery_type', 'sys_notice_type'],
data () {
return {
username: '',
source: [], //患者来源
growthXAxisData: [], //患者增长
growthSeriesData: [], //患者增长
tableData: [], //当日就诊
noticeList: [], //系统公告
dictArr: {} // 存储字典数据,使用对象保存多个字典
};
},
created () {
this.getInfo();
},
mounted () {
this.initArea1();
this.initArea2()
},
methods: {
async getInfo () {
this.username = this.$store.state.user.name;
try {
//获取系统通知
let notice = await listNotice()
this.noticeList = notice.rows
// 获取首页数据
const res = await getHomePageInfo();
//获取今日就诊
this.tableData = res.data.todayPatient
//获取增长日期数据
let growthData = res.data.growth || []
this.growthXAxisData = growthData.map(item => item.date);
this.growthSeriesData = growthData.map(item => parseInt(item.count, 10)); // 确保将 count 转换为数字
// 获取字典数据并处理 source 数据
const patientSource = await this.getDicts('patient_source');
this.dictArr['patient_source'] = Array.isArray(patientSource.data) ? patientSource.data : []; // 存储字典数据
// 处理 source 数据
this.source = this.mapNamesToDictLabels(res.data.source, 'patient_source');
this.$nextTick(() => {
this.initArea1(); // 初始化图表
this.initArea2()
});
} catch (error) {
console.error('获取数据失败', error);
}
},
mapNamesToDictLabels (source, dictType) {
// 确保 dictArr 中的字典数据存在
const dictData = this.dictArr[dictType] || [];
// 创建 dictMap 映射
const dictMap = dictData.reduce((acc, item) => {
if (item.dictValue && item.dictLabel) {
acc[item.dictValue] = item.dictLabel;
}
return acc;
}, {});
// 使用字典映射替换 source 的 name
const mappedSource = source.map(item => {
const newItem = { ...item };
if (dictMap[item.name]) {
newItem.name = dictMap[item.name]; // 替换 name 为 dictLabel
}
return newItem;
});
return mappedSource;
},
initArea1 () {
let area1 = this.$echarts.init(document.getElementById('area1'));
let option = {
title: {
text: '患者来源统计',
left: 'center'
},
tooltip: {
trigger: 'item'
},
legend: {
orient: 'vertical',
left: 'left'
},
series: [
{
name: '来源信息',
type: 'pie',
radius: '50%',
data: this.source,
emphasis: {
itemStyle: {
shadowBlur: 10,
shadowOffsetX: 0,
shadowColor: 'rgba(0, 0, 0, 0.5)'
}
}
}
]
};
area1.setOption(option);
},
initArea2 () {
let area2 = this.$echarts.init(document.getElementById('area2'));
let option = {
title: {
text: '患者新增趋势', // 设置标题内容
left: 'center', // 标题居中
top: 'top', // 标题在顶部
textStyle: {
fontSize: 18, // 设置字体大小
fontWeight: 'bold' // 设置字体粗细
}
},
tooltip: {
trigger: 'axis',
axisPointer: {
type: 'shadow'
}
},
grid: {
left: '3%',
right: '4%',
bottom: '3%',
containLabel: true
},
xAxis: [
{
type: 'category',
data: this.growthXAxisData,
axisTick: {
alignWithLabel: true
}
}
],
yAxis: [
{
type: 'value'
}
],
series: [
{
type: 'bar',
data: this.growthSeriesData
}
]
};
area2.setOption(option);
}
}
};
</script>

<style scoped>
.home-page {
padding: 20px;
text-align: center;
}

.container {
display: grid;
grid-template-columns: repeat(2, 1fr);
grid-template-rows: repeat(2, 300px);
gap: 10px;
padding: 20px;
height: 100vh;
box-sizing: border-box;
}

.box {
background-color: #ffffff;
/* 纯白色背景 */
border: 1px solid #e0e0e0;
/* 淡灰色边框,增加轻微的边界 */
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
/* 添加轻微阴影 */
display: flex;
flex-direction: column;
/* 让内容垂直排列 */
align-items: center;
padding: 20px;
/* 添加内边距 */
font-size: 20px;
color: #333;
}

.table-title {
font-size: 22px;
font-weight: bold;
color: #333;
margin-bottom: 20px;
text-align: center;
}

.el-table {
width: 100%;
/* 使表格宽度适应容器 */
height: 100%;
/* 使表格高度适应容器 */
border: 1px solid #ddd;
border-radius: 4px;
}

.el-table th,
.el-table td {
text-align: center;
/* Center align text */
}

.el-table th {
background-color: #f5f5f5;
color: #333;
font-weight: bold;
}

.el-table td {
font-size: 14px;
}

.el-table-column {
padding: 10px;
}
</style>

1.实现思路

后端返回值

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
{
"msg": "返回信息测试",
"code": 200,
"data": {
"source": [
{
"name": "2",
"value": "4"
},
{
"name": "1",
"value": "4"
},
{
"name": "3",
"value": "3"
},
{
"name": "4",
"value": "2"
}
]
}
}

把前端页面划分为四个区域,页面初始化

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
initArea1 () {	//饼状图
let area1 = this.$echarts.init(document.getElementById('area1'));
let option = {
title: {
text: '患者来源统计',
left: 'center'
},
tooltip: {
trigger: 'item'
},
legend: {
orient: 'vertical',
left: 'left'
},
series: [
{
name: '来源信息',
type: 'pie',
radius: '50%',
data: this.source,
emphasis: {
itemStyle: {
shadowBlur: 10,
shadowOffsetX: 0,
shadowColor: 'rgba(0, 0, 0, 0.5)'
}
}
}
]
};
area1.setOption(option);
},
initArea2 () { //柱状图
let area2 = this.$echarts.init(document.getElementById('area2'));
let option = {
title: {
text: '患者新增趋势', // 设置标题内容
left: 'center', // 标题居中
top: 'top', // 标题在顶部
textStyle: {
fontSize: 18, // 设置字体大小
fontWeight: 'bold' // 设置字体粗细
}
},
tooltip: {
trigger: 'axis',
axisPointer: {
type: 'shadow'
}
},
grid: {
left: '3%',
right: '4%',
bottom: '3%',
containLabel: true
},
xAxis: [
{
type: 'category',
data: this.growthXAxisData,
axisTick: {
alignWithLabel: true
}
}
],
yAxis: [
{
type: 'value'
}
],
series: [
{
type: 'bar',
data: this.growthSeriesData
}
]
};
area2.setOption(option);
}
}

1.1 患者来源统计

关键点在于字典的使用

1
const patientSource = await this.getDicts('patient_source');	//系统自带默认方法
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
source: [], //患者来源
dictArr: {} // 存储字典数据,使用对象保存多个字典
//存在页面加载顺序问题
created () {
this.getInfo();
},
mounted () {
this.initArea1();
this.initArea2()
}, //优先加载数据,然后再渲染echarts表格
async getInfo () {
try {
// 获取首页数据
const res = await getHomePageInfo();
// 获取字典数据并处理 source 数据
const patientSource = await this.getDicts('patient_source');
this.dictArr['patient_source'] = Array.isArray(patientSource.data) ? patientSource.data : []; // 存储字典数据
// 处理 source 数据
this.source = this.mapNamesToDictLabels(res.data.source, 'patient_source');
this.$nextTick(() => {
this.initArea1(); // 初始化图表
this.initArea2()
});
} catch (error) {
console.error('获取数据失败', error);
}
},
mapNamesToDictLabels (source, dictType) {
// 确保 dictArr 中的字典数据存在
const dictData = this.dictArr[dictType] || [];
// 创建 dictMap 映射
const dictMap = dictData.reduce((acc, item) => {
if (item.dictValue && item.dictLabel) {
acc[item.dictValue] = item.dictLabel;
}
return acc;
}, {});
// 使用字典映射替换 source 的 name
const mappedSource = source.map(item => {
const newItem = { ...item };
if (dictMap[item.name]) {
newItem.name = dictMap[item.name]; // 替换 name 为 dictLabel
}
return newItem;
});
return mappedSource;
},

1.2 患者新增趋势

返回值

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
 
"growth": [
{
"date": "2024-08-12",
"count": "2"
},
{
"date": "2024-08-15",
"count": "2"
},
{
"date": "2024-08-16",
"count": "2"
},
{
"date": "2024-08-17",
"count": "1"
}
],

实现思路,后端是查询本周内新增的患者数据,无论是在哪一天

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
public List<Map<String, Object>> getGrowth(DocPatientInfo docPatientInfo) {
LocalDate today = LocalDate.now();
LocalDate startOfWeek = today.with(DayOfWeek.MONDAY);
LocalDate endOfWeek = today.with(DayOfWeek.SUNDAY);

// 将 LocalDate 转换为字符串
DateTimeFormatter formatter = DateTimeFormatter.ISO_DATE;
String startDate = startOfWeek.atStartOfDay().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
String endDate = endOfWeek.atTime(23, 59, 59).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
docPatientInfo.setStartDate(startDate);
docPatientInfo.setEndDate(endDate);
List<Map<String, Object>> allData = docPatientInfoMapper.getPatientGrowth(docPatientInfo);
// 格式化结果
List<Map<String, Object>> result = new ArrayList<>();
for (Map<String, Object> entry : allData) {
Map<String, Object> resultEntry = new HashMap<>();
resultEntry.put("date", entry.get("date")); // date 是日期字段
resultEntry.put("count", entry.get("count")); // count 是每日新增数量
result.add(resultEntry);
}
return result;
}

前端代码:

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
growthXAxisData: [],  //患者增长x轴,代表日期
growthSeriesData: [], //患者增长,数量
async getInfo () {
try {
//获取增长日期数据
let growthData = res.data.growth || []
this.growthXAxisData = growthData.map(item => item.date);
this.growthSeriesData = growthData.map(item => parseInt(item.count, 10)); // 确保将 count 转换为数字
} catch (error) {
console.error('获取数据失败', error);
}
},

initArea2 () {
let area2 = this.$echarts.init(document.getElementById('area2'));
let option = {
title: {
text: '患者新增趋势', // 设置标题内容
left: 'center', // 标题居中
top: 'top', // 标题在顶部
textStyle: {
fontSize: 18, // 设置字体大小
fontWeight: 'bold' // 设置字体粗细
}
},
tooltip: {
trigger: 'axis',
axisPointer: {
type: 'shadow'
}
},
grid: {
left: '3%',
right: '4%',
bottom: '3%',
containLabel: true
},
xAxis: [
{
type: 'category',
data: this.growthXAxisData,
axisTick: {
alignWithLabel: true
}
}
],
yAxis: [
{
type: 'value'
}
],
series: [
{
type: 'bar',
data: this.growthSeriesData
}
]
};
area2.setOption(option);
}

1.3 今日就诊名单

返回值:

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
"todayPatient": [
{
"createBy": null,
"createTime": null,
"updateBy": null,
"updateTime": null,
"remark": null,
"id": null,
"patientNumber": "F001",
"patientName": "jack",
"photoUrl": null,
"gender": "0",
"dateOfBirth": null,
"surgeryDate": null,
"surgeryType": "4",
"source": null,
"notes": null,
"loginAssociation": null,
"delFlag": null,
"userId": null,
"deptId": null,
"startDate": null,
"endDate": null
},
{
"createBy": null,
"createTime": null,
"updateBy": null,
"updateTime": null,
"remark": null,
"id": null,
"patientNumber": "F002",
"patientName": "rose",
"photoUrl": null,
"gender": "1",
"dateOfBirth": null,
"surgeryDate": null,
"surgeryType": "5",
"source": null,
"notes": null,
"loginAssociation": null,
"delFlag": null,
"userId": null,
"deptId": null,
"startDate": null,
"endDate": null
},
{
"createBy": null,
"createTime": null,
"updateBy": null,
"updateTime": null,
"remark": null,
"id": null,
"patientNumber": "F003",
"patientName": "david",
"photoUrl": null,
"gender": "2",
"dateOfBirth": null,
"surgeryDate": null,
"surgeryType": "4",
"source": null,
"notes": null,
"loginAssociation": null,
"delFlag": null,
"userId": null,
"deptId": null,
"startDate": null,
"endDate": null
},
{
"createBy": null,
"createTime": null,
"updateBy": null,
"updateTime": null,
"remark": null,
"id": null,
"patientNumber": "H001",
"patientName": "测试1",
"photoUrl": null,
"gender": "0",
"dateOfBirth": null,
"surgeryDate": null,
"surgeryType": "1",
"source": null,
"notes": null,
"loginAssociation": null,
"delFlag": null,
"userId": null,
"deptId": null,
"startDate": null,
"endDate": null
}
],

前端使用表格展示

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<div class="box" id="area3">
<div class="table-title">今日就诊患者</div>
<el-table :data="tableData" style="width: 100%; height: 100%;" border>
<el-table-column prop="patientNumber" label="患者编号" min-width="150">
</el-table-column>
<el-table-column prop="patientName" label="患者姓名" min-width="150">
</el-table-column>
<el-table-column prop="gender" label="患者性别" min-width="150">
<template slot-scope="scope">
<dict-tag :options="dict.type.sys_user_sex" :value="scope.row.gender" />
</template>
</el-table-column>
<el-table-column prop="surgeryType" label="手术类型" min-width="150">
<template slot-scope="scope">
<dict-tag :options="dict.type.surgery_type" :value="scope.row.surgeryType" />
</template>
</el-table-column>
</el-table>
</div>

直接使用字典

1
2
3
4
dicts: ['sys_user_sex', 'surgery_type', 'sys_notice_type'],
tableData: [],
//获取今日就诊
this.tableData = res.data.todayPatient

1.4 公告栏

使用系统自带api

1
import { listNotice } from "@/api/system/notice";

返回值

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
{
"total": "3",
"rows": [
{
"createBy": "admin",
"createTime": "2024-07-05 22:44:00",
"updateBy": "",
"updateTime": null,
"remark": "管理员",
"noticeId": "1",
"noticeTitle": "温馨提醒:2018-07-01 若依新版本发布啦",
"noticeType": "2",
"noticeContent": "新版本内容",
"status": "0"
},
{
"createBy": "admin",
"createTime": "2024-07-05 22:44:00",
"updateBy": "",
"updateTime": null,
"remark": "管理员",
"noticeId": "2",
"noticeTitle": "维护通知:2018-07-01 若依系统凌晨维护",
"noticeType": "1",
"noticeContent": "维护内容",
"status": "0"
},
{
"createBy": "admin",
"createTime": "2024-08-16 15:01:59",
"updateBy": "",
"updateTime": null,
"remark": null,
"noticeId": "10",
"noticeTitle": "测试公告",
"noticeType": "2",
"noticeContent": "<p>1111</p>",
"status": "0"
}
],
"code": 200,
"msg": "查询成功"
}

前端

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<div class="box" id="area4">
<div class="table-title">公告栏</div>
<el-table :data="noticeList" style="width: 100%; height: 100%;" border>
<el-table-column label="公告标题" align="center" prop="noticeTitle" min-width="150"
:show-overflow-tooltip="true" />
<el-table-column label="公告类型" align="center" prop="noticeType" min-width="150">
<template slot-scope="scope">
<dict-tag :options="dict.type.sys_notice_type" :value="scope.row.noticeType" />
</template>
</el-table-column>
<el-table-column label="公告内容" align="center" prop="noticeContent" min-width="150"
:show-overflow-tooltip="true" />
</el-table>
</div>
1
2
3
4
noticeList: [], //系统公告
//获取系统通知
let notice = await listNotice()
this.noticeList = notice.rows