index.vue 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  1. <template>
  2. <view>
  3. <!-- <van-tabs v-model="active">
  4. <van-tab title="日"> -->
  5. <view class="top-box">
  6. <view class="container-top" @click="showDayPicker = true">
  7. <view class="top-left">
  8. <view class="word">今日</view>
  9. <text>{{formatDate(dayValue)}}</text>
  10. </view>
  11. <!-- <view class="top-right" @click.stop="fullscreenFn">
  12. <image src="/static/image/full.png" mode=""></image>
  13. </view> -->
  14. </view>
  15. <view class="chartsMain" v-if="dayArea.categories.length">
  16. <canvas canvas-id="canvasArea" id="canvasArea" class="charts"></canvas>
  17. </view>
  18. <view class="chartsMain" v-else>
  19. <image src="/static/image/none.png" mode=""></image>
  20. </view>
  21. </view>
  22. <content-page :dayInfo="dayInfo"></content-page>
  23. <!-- </van-tab>
  24. <van-tab title="月">
  25. <view class="top-box">
  26. <view class="container-top" @click="showMonthPicker = true">
  27. <view class="top-left">
  28. <view class="word">月份</view>
  29. <text>{{formatMonth(monthValue)}}</text>
  30. </view>
  31. <view class="top-right">
  32. <image src="/static/image/full.png" mode=""></image>
  33. </view>
  34. </view>
  35. <view class="chartsMain">
  36. <canvas canvas-id="canvasMonthArea" id="canvasMonthArea" class="charts"
  37. @touchstart="touchArea"></canvas>
  38. </view>
  39. </view>
  40. <content-page></content-page>
  41. </van-tab>
  42. <van-tab title="年">
  43. <view class="top-box">
  44. <view class="container-top" @click="showYearPicker = true">
  45. <view class="top-left">
  46. <view class="word">年份</view>
  47. <text>{{formatYear(yearValue)}}</text>
  48. </view>
  49. <view class="top-right">
  50. <image src="/static/image/full.png" mode=""></image>
  51. </view>
  52. </view>
  53. <view class="chartsMain">
  54. <canvas canvas-id="canvasYearArea" id="canvasYearArea" class="charts"
  55. @touchstart="touchArea"></canvas>
  56. </view>
  57. </view>
  58. <content-page></content-page>
  59. </van-tab>
  60. </van-tabs> -->
  61. <van-popup :show="showDayPicker" position="bottom">
  62. <van-datetime-picker @cancel="showDayPicker=false" @confirm="onConfirm" :value="currentDay" type="date" />
  63. </van-popup>
  64. <van-popup :show="showMonthPicker" position="bottom">
  65. <van-datetime-picker @cancel="showMonthPicker=false" @confirm="onMonthConfirm" type="year-month"
  66. :value="currentMonth" />
  67. </van-popup>
  68. <van-popup :show="showYearPicker" position="bottom">
  69. <van-datetime-picker @cancel="showYearPicker=false" @confirm="onYearConfirm" type="year"
  70. :value="currentYear" />
  71. </van-popup>
  72. </view>
  73. </template>
  74. <script>
  75. import * as infoApi from '@/api/info/index.js';
  76. import dayjs from "@/plugin/dayjs/dayjs.min.js";
  77. import contentPage from './components/content.vue'
  78. import {
  79. mapGetters
  80. } from "vuex";
  81. // 图表
  82. import uCharts from "@/components/ucharts/ucharts.js";
  83. // import uCharts from "@/components/u-charts/u-charts.js";
  84. var _self;
  85. var canvaRing = null;
  86. var canvaArea = null;
  87. var canvaGauge = null;
  88. var canvaPie = null;
  89. var canvaColumn = null;
  90. var canvaFunnel = null;
  91. var canvaWord = null;
  92. export default {
  93. components: {
  94. contentPage
  95. },
  96. data() {
  97. return {
  98. active: 2,
  99. cWidth: '',
  100. cHeight: '',
  101. pixelRatio: 1,
  102. dayValue: new Date(),
  103. monthValue: new Date(),
  104. yearValue: new Date(),
  105. showDayPicker: false, //日
  106. showMonthPicker: false, //月
  107. showYearPicker: false, //年
  108. // minDate:new Date().getTime(),
  109. currentDay: new Date().getTime(),
  110. currentMonth: new Date().getTime(),
  111. currentYear: new Date().getTime(),
  112. fullscreen: false,
  113. dayInfo: {}, //日数据
  114. dayTimeList: [], //日X轴数据
  115. dayDataList: [], //日图表数据
  116. // 日折线图
  117. dayArea: {
  118. categories: [],
  119. // categories: ['08:22','08:22','08:22','08:22'],
  120. series: [{
  121. name: '低压',
  122. data: [],
  123. // data: [68,89,66,79],
  124. color: '#39C1F6'
  125. }, {
  126. name: '高压',
  127. data: [],
  128. // data: [68,89,66,79],
  129. color: '#F35546'
  130. }]
  131. },
  132. // 月折线图
  133. monthArea: {
  134. categories: ['6月', '7月', '8月', ],
  135. series: [{
  136. name: '学习前端',
  137. data: [100, 80, 95, ],
  138. color: '#F35546'
  139. }]
  140. },
  141. // 年折线图
  142. yearArea: {
  143. categories: ['6月', '7月'],
  144. series: [{
  145. name: '学习前端',
  146. data: [100, 80, ],
  147. color: '#F35546'
  148. }]
  149. },
  150. };
  151. },
  152. computed: mapGetters(['deviceId']),
  153. async onLoad() {
  154. _self = this;
  155. this.cWidth = uni.upx2px(680);
  156. this.cHeight = uni.upx2px(400);
  157. await this.getData()
  158. this.getServerData();
  159. },
  160. mounted() {
  161. console.log(this.formatDate(this.currentDate), 333);
  162. },
  163. methods: {
  164. getData() {
  165. let data = this.formatDate(this.dayValue).split("-"); // ["2023", "10", "18"]
  166. let params = {
  167. deviceId: this.deviceId,
  168. year: data[0],
  169. month: data[1],
  170. day: data[2],
  171. // day:"17",
  172. }
  173. return infoApi.getBloodPressure(params).then(res => {
  174. console.log(res, 44);
  175. if (res.data === null) {
  176. this.dayInfo = {}
  177. this.dayInfo.list = []
  178. this.dayArea.categories = []
  179. }
  180. if (res.code === 0 && res.data.list.length) {
  181. this.dayInfo = res.data
  182. // 组装接口数据。上方折线图若超过10条,截取10条
  183. let categoriesArr = res.data.list.map(item => this.formatHHmm(item.createTime))
  184. let seriesArr1 = res.data.list.map(item => item.hypotension)
  185. let seriesArr2 = res.data.list.map(item => item.hypertension)
  186. this.dayArea.categories = categoriesArr.length > 10 ? categoriesArr.slice(-10) :
  187. categoriesArr
  188. this.dayArea.series[0].data = seriesArr1.length > 10 ? seriesArr1.slice(-10) : seriesArr1
  189. this.dayArea.series[1].data = seriesArr2.length > 10 ? seriesArr2.slice(-10) : seriesArr2
  190. }
  191. })
  192. .catch(err => {
  193. return this.$util.Tips({
  194. title: err,
  195. // icon: 'error'
  196. });
  197. });
  198. },
  199. fullscreenFn() {
  200. wx.requestFullScreen({
  201. success: (res) => {
  202. console.log(res, 666);
  203. this.fullscreen = true
  204. }
  205. });
  206. },
  207. formatter(type, val) {
  208. if (type === 'year') {
  209. return `${val}年`;
  210. } else if (type === 'month') {
  211. return `${val}月`;
  212. }
  213. return val;
  214. },
  215. onYearConfirm(value) {
  216. console.log(value, 444);
  217. this.yearValue = value.detail
  218. this.showYearPicker = false
  219. },
  220. onMonthConfirm(value) {
  221. this.monthValue = value.detail
  222. this.showMonthPicker = false;
  223. console.log(this.formatMonth(this.monthValue), 777);
  224. },
  225. async onConfirm(value) {
  226. this.dayValue = value.detail;
  227. await this.getData()
  228. this.getServerData();
  229. this.showDayPicker = false;
  230. },
  231. formatHHmm: function(date) {
  232. return dayjs(date).format("HH:mm");
  233. },
  234. formatDate: function(date) {
  235. return dayjs(date).format("YYYY-MM-DD");
  236. },
  237. formatMonth: function(date) {
  238. return dayjs(date).format("YYYY-MM");
  239. },
  240. formatYear: function(date) {
  241. return dayjs(date).format("YYYY");
  242. },
  243. changeDay() {
  244. this.showDayPicker = true
  245. },
  246. getServerData() {
  247. console.log('是否先执行');
  248. _self.showArea("canvasArea", this.chartData, 'day');
  249. _self.showArea("canvasMonthArea", this.chartData, 'month');
  250. _self.showArea("canvasYearArea", this.chartData, 'year');
  251. },
  252. // 折线图
  253. showArea(canvasId, chartData, type) {
  254. const categories = type == 'day' ? _self.dayArea.categories : type == 'month' ? _self.monthArea
  255. .categories : _self.yearArea.categories
  256. const series = type == 'day' ? _self.dayArea.series : type == 'month' ? _self.monthArea.series : _self
  257. .yearArea.series
  258. canvaArea = new uCharts({
  259. $this: _self,
  260. canvasId: canvasId,
  261. type: 'area',
  262. fontSize: 11,
  263. legend: false,
  264. dataLabel: true,
  265. dataPointShape: true,
  266. background: '#FFFFFF',
  267. pixelRatio: _self.pixelRatio,
  268. categories: categories,
  269. series: series,
  270. animation: true,
  271. padding: [20, 10, 10, 10],
  272. xAxis: {
  273. type: 'grid',
  274. gridColor: '#CCCCCC',
  275. gridType: 'solid',
  276. dashLength: 8,
  277. disableGrid: true,
  278. rotateLabel: true,
  279. rotateAngle: -50,
  280. },
  281. yAxis: {
  282. gridType: 'solid',
  283. gridColor: '#CCCCCC',
  284. dashLength: 8,
  285. splitNumber: 5,
  286. min: 0,
  287. max: 200,
  288. },
  289. width: _self.cWidth * _self.pixelRatio,
  290. height: _self.cHeight * _self.pixelRatio,
  291. extra: {
  292. area: {
  293. type: 'straight',
  294. // type: 'curve',
  295. opacity: 0.2,
  296. addLine: true,
  297. width: 2
  298. }
  299. }
  300. });
  301. },
  302. touchArea(e) {
  303. canvaArea.showToolTip(e, {
  304. format: function(item, category) {
  305. return item.name + ' ' + category + ' ' + ':' + item.data
  306. }
  307. });
  308. },
  309. }
  310. };
  311. </script>
  312. <style lang="scss" scoped>
  313. // ::v-deep .van-tab__pane--active{
  314. // width: 100%;
  315. // }
  316. .top-box {
  317. padding: 28rpx 32rpx 19rpx;
  318. background-color: #fff;
  319. .container-top {
  320. display: flex;
  321. align-items: center;
  322. justify-content: space-between;
  323. margin-bottom: 28rpx;
  324. .top-left {
  325. .word {
  326. font-size: 36rpx;
  327. font-weight: 500;
  328. color: #000000;
  329. }
  330. text {
  331. font-size: 24rpx;
  332. font-weight: 500;
  333. color: #777777;
  334. line-height: 33rpx;
  335. }
  336. }
  337. .top-right {
  338. width: 32rpx;
  339. height: 32rpx;
  340. image {
  341. width: 32rpx;
  342. height: 32rpx;
  343. }
  344. }
  345. }
  346. .chartsMain {
  347. width: 100%;
  348. // height: 450rpx;
  349. // box-sizing: border-box;
  350. background: #fff;
  351. border-top: 2rpx solid #f2f2f2;
  352. text-align: center;
  353. image {
  354. width: 70%;
  355. // height: 100%;
  356. }
  357. .charts {
  358. width: 680rpx;
  359. height: 400rpx;
  360. box-sizing: border-box;
  361. }
  362. }
  363. }
  364. </style>