Heartrate.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449
  1. <template>
  2. <div>
  3. <div class="box-header">
  4. <div class="box-title boldtext">
  5. 心率 <span style="margin-left: 14px">{{ currentDate }}</span>
  6. </div>
  7. <div>
  8. <el-button @click="exportData" size="small" style="margin-right: 20px"
  9. >导出</el-button
  10. >
  11. <el-date-picker
  12. size="small"
  13. v-model="currentDatePicker"
  14. type="date"
  15. placeholder="选择日期"
  16. value-format="yyyy-MM-dd"
  17. @change="datePickerchange"
  18. >
  19. </el-date-picker>
  20. </div>
  21. </div>
  22. <!-- 根据 detailsType 控制图表或列表的展示 -->
  23. <div v-show="!detailsType" style="min-width: 841px; height: 320px; width: 100%;">
  24. <!-- 图表展示 -->
  25. <div ref="heartrateChart" style="width: 100%; height: 100%;"></div>
  26. <div class="heartrate-data">
  27. <div class="heartrate-data-item" style="background-color: #f8fbff">
  28. <div class="heartrate-data-imgbox">
  29. <img src="@/assets/images/watchApi/xl.png" />
  30. </div>
  31. <div class="heartrate-data-right">
  32. <!-- <div class="heartrate-data-num">-</div> -->
  33. <div class="heartrate-data-num" style="color: #00bc98;">{{ avgBpm || '-'}} </div>
  34. <div>平均心率(bpm)</div>
  35. </div>
  36. </div>
  37. <div class="heartrate-data-item" style="background-color: #ffefef">
  38. <div class="heartrate-data-imgbox">
  39. <img src="@/assets/images/watchApi/xl.png" />
  40. </div>
  41. <div class="heartrate-data-right">
  42. <div class="heartrate-data-num">{{ maxBpm || '-'}}</div>
  43. <div>最大心率(bpm)</div>
  44. </div>
  45. </div>
  46. <div class="heartrate-data-item" style="background-color: #fff8f7">
  47. <div class="heartrate-data-imgbox">
  48. <img src="@/assets/images/watchApi/xl.png" />
  49. </div>
  50. <div class="heartrate-data-right">
  51. <div class="heartrate-data-num">{{ minBpm || '-'}}</div>
  52. <div>最小心率(bpm)</div>
  53. </div>
  54. </div>
  55. </div>
  56. </div>
  57. <div v-show="detailsType" class="heartrate-data">
  58. <!-- 列表展示 -->
  59. <el-table v-loading="loading" :data="dataList">
  60. <el-table-column type="index" label="序号" align="center"/>
  61. <el-table-column label="平均心率" align="center" prop="avgBpm" />
  62. <el-table-column label="最大心率" align="center" prop="maxBpm" />
  63. <el-table-column label="最小心率" align="center" prop="minBpm" />
  64. <el-table-column label="状态" align="center" prop="status" :formatter="statusFormatter"/>
  65. <el-table-column label="时间" align="center" prop="createTime" />
  66. <template #empty>
  67. <div>
  68. 今日暂无数据,请选择其他日期
  69. </div>
  70. </template>
  71. </el-table>
  72. </div>
  73. <pagination
  74. v-show="(total>0) && detailsType"
  75. :total="total"
  76. :page.sync="queryParams.pageNum"
  77. :limit.sync="queryParams.pageSize"
  78. @pagination="getDataPage"
  79. />
  80. </div>
  81. </template>
  82. <script>
  83. import * as echarts from "echarts";
  84. import { queryByDate, exportHeartDate,queryPageByDate } from "@/api/watch/deviceInfo";
  85. export default {
  86. props: {
  87. deviceId: {
  88. type: String || Number,
  89. default: "",
  90. },
  91. detailsType: { type: Boolean, default: false }, // 接收 detailsType 作为 prop
  92. },
  93. data() {
  94. return {
  95. // 总条数
  96. total: 0,
  97. queryParams:{
  98. pageNum: 1,
  99. pageSize: 10,
  100. deviceId:"",
  101. startTime:"",
  102. endTime:""
  103. },
  104. loading: false,// 遮罩层
  105. dataList:[],
  106. avgBpm:'',
  107. maxBpm:'',
  108. minBpm:'',
  109. currentDate: this.parseTime(new Date(), "{y}-{m}-{d}"),
  110. currentDatePicker: "",
  111. exportLoading: false,
  112. chart: null,
  113. chartOptions: {
  114. tooltip: {
  115. trigger: "axis",
  116. axisPointer: {
  117. label: {
  118. backgroundColor: "#FFFFFF",
  119. },
  120. lineStyle: {
  121. color: "#DE5D36",
  122. width: 1,
  123. },
  124. },
  125. backgroundColor: "rgba(255, 140, 106, 1)",
  126. borderColor: "#EC3B2C",
  127. borderWidth: 1,
  128. textStyle: {
  129. color: "#FFFFFF",
  130. },
  131. extraCssText: "box-shadow: 0 0 5px rgba(0, 0, 0, 0.3);",
  132. formatter: (params)=> {
  133. if (params[0].value != undefined) {
  134. return this.parseTime(params[0].value[0], "{h}:{i}") + " " + params[0].value[1] + "bpm";
  135. }
  136. },
  137. },
  138. grid: {
  139. bottom: "10%",
  140. left: "8%",
  141. top: "10",
  142. },
  143. xAxis: {
  144. type: "time",
  145. // min: new Date(this.currentDate + " 00:00:00").getTime(),
  146. // max: new Date(this.currentDate + " 23:59:59").getTime(),
  147. splitNumber: 6,
  148. // interval: 1000 * 60 * 60 * 4, // 每4小时一个标签
  149. axisLine: {
  150. show: false,
  151. },
  152. axisTick: {
  153. show: false,
  154. },
  155. splitLine: {
  156. show: false,
  157. },
  158. axisLabel: {
  159. color: "#999999",
  160. margin: 20,
  161. // fontSize: 14,
  162. fontWeight: "bold",
  163. formatter: (value) => {
  164. return this.parseTime(value, "{h}:{i}");
  165. },
  166. },
  167. },
  168. yAxis: {
  169. type: "value",
  170. min: 0,
  171. max: 200,
  172. splitNumber: 10,
  173. axisLine: {
  174. show: false,
  175. },
  176. splitLine: {
  177. show: true,
  178. lineStyle: {
  179. type: "dashed",
  180. },
  181. },
  182. axisTick: {
  183. show: false,
  184. },
  185. axisLabel: {
  186. color: "#999999",
  187. verticalAlign: "middle",
  188. align: "left",
  189. margin: 30,
  190. // fontSize: 14,
  191. fontWeight: "bold",
  192. },
  193. },
  194. series: [
  195. {
  196. data: [],
  197. type: "line",
  198. smooth: true,
  199. symbol: "none",
  200. lineStyle: {
  201. color: "#de5d36", //改变折线颜色
  202. },
  203. areaStyle: {
  204. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
  205. { offset: 0, color: "rgba(255, 148, 113, 1)" },
  206. { offset: 1, color: "rgba(255, 252, 251, 1)" },
  207. ]),
  208. },
  209. emphasis: {
  210. focus: "series",
  211. },
  212. },
  213. ],
  214. },
  215. sportChart: null,
  216. sportChartOption: {
  217. tooltip: {
  218. trigger: "item",
  219. },
  220. series: [
  221. {
  222. name: "运动心率",
  223. type: "pie",
  224. radius: ["40%", "60%"],
  225. avoidLabelOverlap: false,
  226. padAngle: 2,
  227. label: {
  228. show: false,
  229. position: "center",
  230. },
  231. emphasis: {
  232. label: {
  233. show: true,
  234. fontSize: 20,
  235. fontWeight: "bold",
  236. color: ""
  237. },
  238. },
  239. labelLine: {
  240. show: false,
  241. },
  242. data: [
  243. { value: 1048, name: "常规",itemStyle: {color:"#00bc98"}},
  244. { value: 735, name: "热身",itemStyle: {color:"#0286ff"} },
  245. { value: 580, name: "燃脂",itemStyle: {color:"#20fef5"} },
  246. { value: 484, name: "有氧",itemStyle: {color:"#8e80f2"} },
  247. { value: 300, name: "无氧",itemStyle: {color:"#fe9b52"} },
  248. ],
  249. },
  250. ],
  251. },
  252. };
  253. },
  254. methods: {
  255. getDataPage(){
  256. this.loading = true;
  257. this.queryParams.deviceId = this.deviceId;
  258. this.queryParams.startTime = this.currentDate + " 00:00:00";
  259. this.queryParams.endTime = this.currentDate + " 23:59:59";
  260. queryPageByDate(this.queryParams)
  261. .then((response) => {
  262. if (response) {
  263. this.dataList = response.rows;
  264. this.total = response.total;
  265. this.loading = false;
  266. } else {
  267. console.warn("心率分页数据返回为空或格式不正确:", response);
  268. }
  269. })
  270. .catch((error) => {
  271. console.error("获取心率分页数据失败:", error);
  272. });
  273. },
  274. statusFormatter(row, column, cellValue) {
  275. // 如果状态为0,则显示"正常",否则显示其他状态
  276. return cellValue === 0 ? '正常' : '异常'; // 你可以根据需求修改 "异常" 为其他状态
  277. },
  278. datePickerchange() {
  279. this.currentDate = this.currentDatePicker || this.parseTime(new Date(), "{y}-{m}-{d}");
  280. if(this.detailsType){
  281. this.getDataPage();
  282. } else{
  283. this.getDetailsData();
  284. }
  285. },
  286. initChart() {
  287. const chartElement = this.$refs.heartrateChart;
  288. const sportChartElement = this.$refs.sportHeartrate;
  289. if (chartElement) {
  290. this.chart = echarts.init(chartElement);
  291. this.chartOptions.xAxis.min = this.currentDate + ' 00:00:00'
  292. this.chartOptions.xAxis.max = this.currentDate + ' 23:59:59'
  293. this.chart.setOption(this.chartOptions);
  294. }
  295. if (sportChartElement) {
  296. this.sportChart = echarts.init(sportChartElement);
  297. this.sportChart.setOption(this.sportChartOption);
  298. }
  299. },
  300. // 获取心率折线图
  301. getDetailsData() {
  302. queryByDate(this.currentDate, this.deviceId)
  303. .then((response) => {
  304. if (response && response.data) {
  305. // this.dataList = response.data.list
  306. //更新平均最大最小心率
  307. this.avgBpm = response.data.avg;
  308. this.maxBpm = response.data.max;
  309. this.minBpm = response.data.min;
  310. const data = response.data.list.map((item) => ({
  311. name: item.createTime,
  312. value: [
  313. new Date(item.createTime).getTime(), // 确保时间为毫秒时间戳
  314. item.avgBpm,
  315. ],
  316. }));
  317. // 更新 chartOptions.series 数据
  318. this.chartOptions.series[0].data = data;
  319. // 更新图表
  320. if (this.detailsType == false) {
  321. this.initChart()
  322. }
  323. } else {
  324. console.warn("心率数据返回为空或格式不正确:", response);
  325. }
  326. })
  327. .catch((error) => {
  328. console.error("获取心率数据失败:", error);
  329. });
  330. },
  331. // 导出数据逻辑
  332. exportData() {
  333. this.$confirm("是否确认导出所有用户数据项?", "警告", {
  334. confirmButtonText: "确定",
  335. cancelButtonText: "取消",
  336. type: "warning",
  337. })
  338. .then(() => {
  339. this.exportLoading = true;
  340. return exportHeartDate(this.currentDate, this.deviceId);
  341. })
  342. .then((response) => {
  343. this.download(response.msg);
  344. this.exportLoading = false;
  345. })
  346. .catch(() => {});
  347. },
  348. },
  349. };
  350. </script>
  351. <style lang="scss" scoped>
  352. @mixin u-flex($flexD, $alignI, $justifyC) {
  353. display: flex;
  354. flex-direction: $flexD;
  355. align-items: $alignI;
  356. justify-content: $justifyC;
  357. }
  358. .fz15 {
  359. font-size: 15px !important;
  360. }
  361. .boldtext {
  362. font-size: 16px;
  363. color: #292929;
  364. line-height: 30px;
  365. font-weight: 700;
  366. }
  367. .box-header {
  368. padding: 0 15px;
  369. @include u-flex(row, center, space-between);
  370. height: 50px;
  371. }
  372. .box-title {
  373. color: #292929;
  374. font-size: 16px;
  375. font-family: PingFang SC-Medium;
  376. padding-left: 10px;
  377. border-left: 4px solid #2284ff;
  378. line-height: 13px;
  379. }
  380. .heartrate-data {
  381. @include u-flex(row, center, space-around);
  382. margin-top: 30px;
  383. &-item {
  384. height: 60px;
  385. width: 196px;
  386. border-radius: 4px;
  387. box-shadow: 0 0 10px rgba(1, 24, 54, 0.1);
  388. overflow: hidden;
  389. @include u-flex(row, center, flex-start);
  390. img {
  391. height: 41px;
  392. width: 41px;
  393. }
  394. }
  395. &-imgbox {
  396. flex-shrink: 0;
  397. height: 60px;
  398. width: 60px;
  399. @include u-flex(row, center, center);
  400. }
  401. &-right {
  402. flex: 1;
  403. text-align: center;
  404. font-size: 13px;
  405. color: #606165;
  406. font-family: PingFang SC-Medium;
  407. background: #fff;
  408. height: 60px;
  409. }
  410. &-num {
  411. font-size: 22px;
  412. color: #2c2c3b;
  413. line-height: 38px;
  414. }
  415. }
  416. .heartrate-sport {
  417. @include u-flex(row, flex-start, flex-start);
  418. margin-top: 20px;
  419. &-l {
  420. width: 490px;
  421. flex-shrink: 0;
  422. }
  423. &-r {
  424. flex: 1;
  425. max-width: 720px;
  426. }
  427. &-lechart {
  428. width: 490px;
  429. height: 300px;
  430. }
  431. &-rechart {
  432. width: 100%;
  433. @include u-flex(row, center, center);
  434. }
  435. }
  436. </style>