Pulse.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  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. <div v-show="!detailsType" ref="heartrateChart" style="width: 841px; height: 320px"></div>
  23. <!-- <div class="heartrate-data">
  24. <div class="heartrate-data-item" style="background-color: #f8fbff">
  25. <div class="heartrate-data-imgbox">
  26. <img src="@/assets/images/watchApi/xl.png" />
  27. </div>
  28. <div class="heartrate-data-right">
  29. <div class="heartrate-data-num" style="color: #00bc98;">{{ avgBpm || '-'}} </div>
  30. <div>平均心率(bpm)</div>
  31. </div>
  32. </div>
  33. <div class="heartrate-data-item" style="background-color: #ffefef">
  34. <div class="heartrate-data-imgbox">
  35. <img src="@/assets/images/watchApi/xl.png" />
  36. </div>
  37. <div class="heartrate-data-right">
  38. <div class="heartrate-data-num">{{ maxBpm || '-'}}</div>
  39. <div>最大心率(bpm)</div>
  40. </div>
  41. </div>
  42. <div class="heartrate-data-item" style="background-color: #fff8f7">
  43. <div class="heartrate-data-imgbox">
  44. <img src="@/assets/images/watchApi/xl.png" />
  45. </div>
  46. <div class="heartrate-data-right">
  47. <div class="heartrate-data-num">{{ minBpm || '-'}}</div>
  48. <div>最小心率(bpm)</div>
  49. </div>
  50. </div>
  51. </div> -->
  52. <!-- <div class="heartrate-sport">
  53. <div class="heartrate-sport-l" style="margin-left: 15px">
  54. <div class="box-title fz15">运动心率</div>
  55. <div class="heartrate-sport-lechart">
  56. <div ref="sportHeartrate" style="width: 100%;height: 100%;"></div>
  57. </div>
  58. </div>
  59. <div class="heartrate-sport-r" style="margin-left: 15px">
  60. <div class="box-title fz15">异常心率</div>
  61. <div class="heartrate-sport-rechart">
  62. <el-empty description="暂无数据" image-size="70" v-if="sportChartOption.series[0].data.length == 0"></el-empty>
  63. <div v-else>tu</div>
  64. </div>
  65. </div>
  66. </div> -->
  67. <!-- 列表展示 -->
  68. <div v-show="detailsType">
  69. <el-table :data="dataList">
  70. <el-table-column type="index" label="序号" align="center"/>
  71. <el-table-column label="时间" align="center" prop="time" />
  72. <el-table-column label="脉搏" align="center" prop="pulseRate" />
  73. </el-table>
  74. <pagination v-show="(dataListTotal > 0) && detailsType" :total="dataListTotal" :page.sync="tqueryParams.pageNum" :limit.sync="tqueryParams.pageSize" @pagination="getTableList"/>
  75. </div>
  76. </div>
  77. </template>
  78. <script>
  79. import * as echarts from "echarts";
  80. import { queryPulseDate } from "@/api/watch/deviceInfo";
  81. export default {
  82. props: {
  83. deviceId: {
  84. type: String || Number,
  85. default: "",
  86. },
  87. detailsType: {
  88. type: Boolean,
  89. default: false
  90. }
  91. },
  92. data() {
  93. return {
  94. dataList:[],
  95. tqueryParams: {
  96. pageNum: 1,
  97. pageSize: 10,
  98. },
  99. dataListTotal: 0,
  100. avgBpm:'',
  101. maxBpm:'',
  102. minBpm:'',
  103. currentDate: this.parseTime(new Date(), "{y}-{m}-{d}"),
  104. currentDatePicker: "",
  105. exportLoading: false,
  106. chart: null,
  107. chartOptions: {
  108. tooltip: {
  109. trigger: "axis",
  110. axisPointer: {
  111. type: "line",
  112. },
  113. },
  114. grid: {
  115. top: "5%",
  116. left: "7%",
  117. bottom: "10%",
  118. right: "7%"
  119. },
  120. xAxis: {
  121. type: "time",
  122. // min: new Date(this.currentDate + " 00:00:00").getTime(),
  123. // max: new Date(this.currentDate + " 23:59:59").getTime(),
  124. splitNumber: 6,
  125. // interval: 1000 * 60 * 60 * 4, // 每4小时一个标签
  126. axisLine: {
  127. show: false,
  128. },
  129. axisTick: {
  130. show: false,
  131. },
  132. splitLine: {
  133. show: false,
  134. },
  135. axisLabel: {
  136. fontWeight: "bold",
  137. color: "#999999",
  138. formatter: (value) => {
  139. return this.parseTime(value, "{h}:{i}");
  140. },
  141. },
  142. },
  143. yAxis: {
  144. type: "value",
  145. min: 0,
  146. max: 200,
  147. interval: 20,
  148. axisLine: {
  149. show: false,
  150. },
  151. splitLine: {
  152. show: true,
  153. lineStyle: {
  154. type: "dashed",
  155. },
  156. },
  157. axisTick: {
  158. show: false,
  159. },
  160. axisLabel: {
  161. color: "#999999",
  162. fontWeight: "bold",
  163. },
  164. },
  165. series: [
  166. {
  167. data: [],
  168. type: "line",
  169. smooth: true,
  170. symbol: "none",
  171. lineStyle: {
  172. color: "#de5d36", //改变折线颜色
  173. },
  174. areaStyle: {
  175. opacity: 0.8,
  176. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
  177. {
  178. offset: 0,
  179. color: "#ffd2c3",
  180. },
  181. {
  182. offset: 1,
  183. color: "#fff",
  184. },
  185. ]),
  186. },
  187. },
  188. ],
  189. },
  190. sportChart: null,
  191. sportChartOption: {
  192. tooltip: {
  193. trigger: "item",
  194. },
  195. series: [
  196. {
  197. name: "运动心率",
  198. type: "pie",
  199. radius: ["40%", "60%"],
  200. avoidLabelOverlap: false,
  201. padAngle: 2,
  202. label: {
  203. show: false,
  204. position: "center",
  205. },
  206. emphasis: {
  207. label: {
  208. show: true,
  209. fontSize: 20,
  210. fontWeight: "bold",
  211. color: ""
  212. },
  213. },
  214. labelLine: {
  215. show: false,
  216. },
  217. data: [
  218. { value: 1048, name: "常规",itemStyle: {color:"#00bc98"}},
  219. { value: 735, name: "热身",itemStyle: {color:"#0286ff"} },
  220. { value: 580, name: "燃脂",itemStyle: {color:"#20fef5"} },
  221. { value: 484, name: "有氧",itemStyle: {color:"#8e80f2"} },
  222. { value: 300, name: "无氧",itemStyle: {color:"#fe9b52"} },
  223. ],
  224. },
  225. ],
  226. },
  227. };
  228. },
  229. methods: {
  230. datePickerchange() {
  231. this.currentDate = this.currentDatePicker || this.parseTime(new Date(), "{y}-{m}-{d}");
  232. this.getDetailsData()
  233. },
  234. initChart() {
  235. const chartElement = this.$refs.heartrateChart;
  236. const sportChartElement = this.$refs.sportHeartrate;
  237. if (chartElement) {
  238. this.chart = echarts.init(chartElement);
  239. this.seChartOptions()
  240. }
  241. if (sportChartElement) {
  242. this.sportChart = echarts.init(sportChartElement);
  243. this.sportChart.setOption(this.sportChartOption);
  244. }
  245. },
  246. seChartOptions() {
  247. this.chartOptions.xAxis.min = this.currentDate + ' 00:00:00'
  248. this.chartOptions.xAxis.max = this.currentDate + ' 23:59:59'
  249. this.chart.setOption(this.chartOptions);
  250. },
  251. // 获取脉搏折线图
  252. getDetailsData() {
  253. queryPulseDate(this.currentDate, this.deviceId)
  254. .then((response) => {
  255. if (response && response.data) {
  256. // console.log("------------------" + JSON.stringify(response.data, null, 2) )
  257. const data = response.data.map((item) => ({
  258. name: item.time,
  259. value: [
  260. new Date(item.time).getTime(), // 确保时间为毫秒时间戳
  261. item.pulseRate,
  262. ],
  263. }));
  264. // 更新 chartOptions.series 数据
  265. this.chartOptions.series[0].data = data;
  266. this.getTableList()
  267. // 更新图表
  268. if (this.detailsType == false) {
  269. this.initChart()
  270. }
  271. } else {
  272. console.warn("心率数据返回为空或格式不正确:", response);
  273. }
  274. })
  275. .catch((error) => {
  276. console.error("获取心率数据失败:", error);
  277. });
  278. },
  279. getTableList() {
  280. let list = this.chartOptions.series[0].data.map(item=>({
  281. time: item.name,
  282. pulseRate: item.value[1]
  283. }))
  284. this.dataListTotal = list.length
  285. const start = (this.tqueryParams.pageNum - 1) * this.tqueryParams.pageSize;
  286. const end = start + this.tqueryParams.pageSize;
  287. this.dataList = list.slice(start, end);
  288. },
  289. },
  290. };
  291. </script>
  292. <style lang="scss" scoped>
  293. @mixin u-flex($flexD, $alignI, $justifyC) {
  294. display: flex;
  295. flex-direction: $flexD;
  296. align-items: $alignI;
  297. justify-content: $justifyC;
  298. }
  299. .fz15 {
  300. font-size: 15px !important;
  301. }
  302. .boldtext {
  303. font-size: 16px;
  304. color: #292929;
  305. line-height: 30px;
  306. font-weight: 700;
  307. }
  308. .box-header {
  309. padding: 0 15px;
  310. @include u-flex(row, center, space-between);
  311. height: 50px;
  312. }
  313. .box-title {
  314. color: #292929;
  315. font-size: 16px;
  316. font-family: PingFang SC-Medium;
  317. padding-left: 10px;
  318. border-left: 4px solid #2284ff;
  319. line-height: 13px;
  320. }
  321. .heartrate-data {
  322. @include u-flex(row, center, space-around);
  323. margin-top: 30px;
  324. &-item {
  325. height: 60px;
  326. width: 196px;
  327. border-radius: 4px;
  328. box-shadow: 0 0 10px rgba(1, 24, 54, 0.1);
  329. overflow: hidden;
  330. @include u-flex(row, center, flex-start);
  331. img {
  332. height: 41px;
  333. width: 41px;
  334. }
  335. }
  336. &-imgbox {
  337. flex-shrink: 0;
  338. height: 60px;
  339. width: 60px;
  340. @include u-flex(row, center, center);
  341. }
  342. &-right {
  343. flex: 1;
  344. text-align: center;
  345. font-size: 13px;
  346. color: #606165;
  347. font-family: PingFang SC-Medium;
  348. background: #fff;
  349. height: 60px;
  350. }
  351. &-num {
  352. font-size: 22px;
  353. color: #2c2c3b;
  354. line-height: 38px;
  355. }
  356. }
  357. .heartrate-sport {
  358. @include u-flex(row, flex-start, flex-start);
  359. margin-top: 20px;
  360. &-l {
  361. width: 490px;
  362. flex-shrink: 0;
  363. }
  364. &-r {
  365. flex: 1;
  366. }
  367. &-lechart {
  368. width: 490px;
  369. height: 300px;
  370. }
  371. &-rechart {
  372. width: 100%;
  373. @include u-flex(row, center, center);
  374. }
  375. }
  376. </style>