Sports.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  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">导出</el-button>
  9. <el-date-picker size="small" v-model="currentDatePicker" type="date" placeholder="选择日期"
  10. value-format="yyyy-MM-dd" @change="datePickerchange">
  11. </el-date-picker>
  12. </div>
  13. </div>
  14. <!-- 展示 -->
  15. <div v-show="!detailsType">
  16. <div class="sports-echarts">
  17. <div class="sports-echarts-title">
  18. <span class="sports-echarts-num">{{ stepTotal || '-' }}</span>步
  19. </div>
  20. <div class="sports-echarts-box">
  21. <div ref="sportCharts" style="width: 100%;height: 100%;min-width: 783px;"></div>
  22. </div>
  23. </div>
  24. </div>
  25. <div v-show="detailsType">
  26. <el-table :data="dataList" style="width: 100%">
  27. <el-table-column prop="stepTotal" label="运动步数" />
  28. <el-table-column prop="distanceTotal" label="运动里程" />
  29. <el-table-column prop="sportTime" label="运动时长(min)" />
  30. <el-table-column prop="startTime" label="开始时间" />
  31. <el-table-column prop="type" label="运动类型" />
  32. <template #empty>
  33. <div>
  34. 今日暂无数据,请选择其他日期
  35. </div>
  36. </template>
  37. </el-table>
  38. <pagination v-show="(total > 0) && detailsType" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getDataPage"/>
  39. </div>
  40. </div>
  41. </template>
  42. <script>
  43. import { querySportData,exportSporttDate,querySportPageByDate } from "@/api/watch/deviceInfo";
  44. export default {
  45. props: {
  46. deviceId: {
  47. type: String || Number,
  48. default: "",
  49. },
  50. detailsType: {
  51. type: Boolean,
  52. default: false
  53. }
  54. },
  55. data() {
  56. return {
  57. loading: false,// 遮罩层
  58. dataList:[],
  59. total: 0,
  60. queryParams:{
  61. pageNum: 1,
  62. pageSize: 10,
  63. deviceId:"",
  64. startTime:"",
  65. endTime:""
  66. },
  67. stepTotal: '',
  68. currentDate: this.parseTime(new Date(), "{y}-{m}-{d}"),
  69. currentDatePicker: "",
  70. tableData: [],
  71. total: 0,
  72. queryParams: {
  73. pageNum: 1,
  74. pageSize: 10,
  75. },
  76. max_y: 40,
  77. chart: null,
  78. chartOptions: {
  79. grid: {
  80. top: "18%",
  81. left: "10%",
  82. bottom: "10%",
  83. right: "7%"
  84. },
  85. title: {
  86. subtext: "单位:步",
  87. left: 7,
  88. top: "0%",
  89. },
  90. xAxis: {
  91. type: "category",
  92. data: [
  93. "00:00",
  94. "01:00",
  95. "02:00",
  96. "03:00",
  97. "04:00",
  98. "05:00",
  99. "06:00",
  100. "07:00",
  101. "08:00",
  102. "09:00",
  103. "10:00",
  104. "11:00",
  105. "12:00",
  106. "13:00",
  107. "14:00",
  108. "15:00",
  109. "16:00",
  110. "17:00",
  111. "18:00",
  112. "19:00",
  113. "20:00",
  114. "21:00",
  115. "22:00",
  116. "23:00"
  117. ],
  118. axisLabel: {
  119. show: true,
  120. fontSize: 12,
  121. color: "#999999",
  122. interval: function (index, name) {
  123. if (index % 6 == 0 || index == 23) return true;
  124. else return false;
  125. }
  126. }
  127. },
  128. yAxis: {
  129. type: "value",
  130. axisTick: {
  131. show: false
  132. },
  133. splitLine: {
  134. lineStyle: {
  135. type: "dashed"
  136. }
  137. },
  138. axisLabel: {
  139. fontSize: 12,
  140. color: "#999999",
  141. formatter: (value) => {
  142. if (value >= this.max_y) {
  143. return value;
  144. } else return value;
  145. }
  146. }
  147. },
  148. series: [
  149. {
  150. data: [],
  151. type: 'bar',
  152. barWidth: 8,
  153. color: '#65a9ff'
  154. }
  155. ]
  156. }
  157. };
  158. },
  159. methods: {
  160. getDataPage(){
  161. this.loading = true;
  162. this.queryParams.deviceId = this.deviceId;
  163. this.queryParams.startTime = this.currentDate + " 00:00:00";
  164. this.queryParams.endTime = this.currentDate + " 23:59:59";
  165. querySportPageByDate(this.queryParams)
  166. .then((response) => {
  167. if (response) {
  168. this.dataList = response.rows;
  169. this.total = response.total;
  170. this.loading = false;
  171. } else {
  172. console.warn("运动分页数据返回为空或格式不正确:", response);
  173. }
  174. })
  175. .catch((error) => {
  176. console.error("获取运动分页数据失败:", error);
  177. });
  178. },
  179. getDetailsData() {
  180. querySportData(this.currentDate, this.deviceId)
  181. .then((response) => {
  182. if (response && response.data) {
  183. this.stepTotal = response.data.stepTotal;
  184. this.chartOptions.series[0].data = response.data.steps;
  185. // console.log("-----------------------" + JSON.stringify(this.chartOptions.series[0].data, null, 2))
  186. // 更新图表
  187. if(this.detailsType == false) {
  188. this.initChart();
  189. }
  190. } else {
  191. console.warn("心率数据返回为空或格式不正确:", response);
  192. }
  193. })
  194. .catch((error) => {
  195. console.error("获取心率数据失败:", error);
  196. });
  197. },
  198. datePickerchange() {
  199. this.currentDate = this.currentDatePicker || this.parseTime(new Date(), "{y}-{m}-{d}");
  200. if(this.detailsType){
  201. this.getDataPage();
  202. } else{
  203. this.getDetailsData();
  204. }
  205. },
  206. initChart() {
  207. const chartElement = this.$refs.sportCharts;
  208. if (chartElement) {
  209. this.chart = this.echarts.init(chartElement);
  210. this.chartOptions.xAxis.min = this.currentDate + ' 00:00:00'
  211. this.chartOptions.xAxis.max = this.currentDate + ' 23:59:59'
  212. this.chart.setOption(this.chartOptions);
  213. }
  214. },
  215. exportData() {
  216. this.$confirm("是否确认导出所有用户数据项?", "警告", {
  217. confirmButtonText: "确定",
  218. cancelButtonText: "取消",
  219. type: "warning",
  220. })
  221. .then(() => {
  222. this.exportLoading = true;
  223. return exportSporttDate(this.currentDate, this.deviceId);
  224. })
  225. .then((response) => {
  226. this.download(response.msg);
  227. this.exportLoading = false;
  228. })
  229. .catch(() => {});
  230. },
  231. },
  232. };
  233. </script>
  234. <style lang="scss" scoped>
  235. @mixin u-flex($flexD, $alignI, $justifyC) {
  236. display: flex;
  237. flex-direction: $flexD;
  238. align-items: $alignI;
  239. justify-content: $justifyC;
  240. }
  241. .boldtext {
  242. font-size: 16px;
  243. color: #292929;
  244. line-height: 30px;
  245. font-weight: 700;
  246. }
  247. .box-header {
  248. width: 100%;
  249. box-sizing: border-box;
  250. padding: 0 15px;
  251. @include u-flex(row, center, space-between);
  252. height: 50px;
  253. }
  254. .box-title {
  255. color: #292929;
  256. font-size: 16px;
  257. font-family: PingFang SC-Medium;
  258. padding-left: 10px;
  259. border-left: 4px solid #2284ff;
  260. line-height: 13px;
  261. }
  262. .sports-echarts {
  263. &-title {
  264. padding: 12px;
  265. font-size: 12px;
  266. color: #727272;
  267. }
  268. &-num {
  269. font-weight: 700;
  270. font-size: 16px;
  271. color: #292929;
  272. }
  273. &-box {
  274. min-width: 783px;
  275. width: 100%;
  276. max-width: 1200px;
  277. height: 300px;
  278. }
  279. }
  280. </style>