天波h5前端应用
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

199 Zeilen
7.1KB

  1. <template>
  2. <div class="psychological-main-container">
  3. <van-nav-bar title="今日情绪" :border="true" @click-left="onNavBack">
  4. <template #left>
  5. <div v-show="isShowLeft" class="nav-bar-title">
  6. <van-icon name="arrow-left" size="23"/><span>返回</span>
  7. </div>
  8. </template>
  9. <template #title>
  10. <span>今日情绪</span>
  11. </template>
  12. </van-nav-bar>
  13. <div class="main">
  14. <div class="list">
  15. <div v-for="(item,index) in healhtList" :key="index" :class="['item', item.class]" @click="onClick(item)">
  16. <p class="health-value" :style="{ color: calcColor(item.value) }">
  17. {{ item.value || '--' }}
  18. </p>
  19. <p class="health-name">
  20. {{ item.name || '--'}}
  21. </p>
  22. <div class="health-result">
  23. <div :class="['left', item.class]">
  24. <p class="result">
  25. {{ item.result || '暂无数据'}}
  26. </p>
  27. </div>
  28. <div class="right">
  29. <!-- img -->
  30. <img :src="item.img" alt="">
  31. </div>
  32. </div>
  33. <div class="health-time">
  34. <p class="time">{{ item.time || '--' }}</p>
  35. </div>
  36. </div>
  37. </div>
  38. </div>
  39. </div>
  40. </template>
  41. <script>
  42. import axios from "axios";
  43. import { isNotNull } from "@/utils/index";
  44. import { PsyBaseUrl } from "@/config/models";
  45. import APICore from "@/api/core";
  46. export default {
  47. name: 'psychologicalMain',
  48. data(){
  49. return {
  50. healhtList: [
  51. /* { value: 40, name: '抑郁倾向', class: 'depression',result: '无抑郁倾向', time: '17:52', img: require('@/assets/img/regardless.png') },
  52. { value: 55, name: '压力', class: 'stress', result: '轻度压力', time: '17:52', img: require('@/assets/img/regardless.png') },
  53. { value: 75, name: '疲劳', class: 'tiredness', result: '中度疲劳', time: '17:52', img: require('@/assets/img/moderate.png') }, */
  54. ],
  55. uid: '',
  56. routeDate: '',
  57. params: {}
  58. }
  59. },
  60. computed: {
  61. isShowLeft() {
  62. return isNotNull(this.$route.query.fromUrl);
  63. }
  64. },
  65. mounted() {
  66. this.loadParams();
  67. window.document.title = '心理监测';
  68. },
  69. methods: {
  70. // 获取b端token
  71. getAuth() {
  72. let manufactorId = "5bf13062-a41e-4d00-ba14-1101aad12650";
  73. let that = this;
  74. return new Promise((resolve, reject) => {
  75. APICore.getAuth({ manufactorId: manufactorId }).then(res => {
  76. let data = res.data;
  77. if(data.code === 0) {
  78. resolve(res.data.data);
  79. } else {
  80. this.$toast.fail(`${data.message}`);
  81. reject('');
  82. }
  83. })
  84. })
  85. },
  86. // 加载路由参数
  87. async loadParams() {
  88. let params = this.$route.query;
  89. if (params) {
  90. this.uid = params.uid;
  91. this.routeDate = params.date;
  92. this.params = params;
  93. if(!params.accessToken) {
  94. let authToken = await this.getAuth();
  95. this.$store.commit('ssjlToken', authToken);
  96. } else {
  97. this.$store.commit('ssjlToken', params.accessToken);
  98. }
  99. this.getHomeData();
  100. }
  101. },
  102. // 获取首页数据
  103. getHomeData() {
  104. this.$toast.loading('数据加载中');
  105. let reqUrl = `${PsyBaseUrl}/api/Data/GetHomeData`;
  106. let reqParams = {
  107. uid: this.uid,
  108. date: this.routeDate || this.$dayjs(new Date()).format('YYYY-MM-DD')
  109. };
  110. axios.get(reqUrl, {
  111. params: { ...reqParams },
  112. headers: { 'AccessToken': this.$store.getters.ssjlToken }
  113. }).then(res => {
  114. console.log("res", res);
  115. const data = res.data.response;
  116. if(!data) {
  117. return this.$toast.fail(res.data.msg);
  118. }
  119. this.healhtList = [
  120. // 抑郁
  121. { value: data.DepScore, name: '抑郁倾向', class: 'depression', result: data.DepDesc, time: data.DepMeasureTime ? this.$dayjs(data.DepMeasureTime).format('HH:mm'): '', level: data.DepLevel, img: data.DepScore ? this.calcImg(data.DepLevel, 'depression') : ''},
  122. // 压力
  123. { value: data.StressScore, name: '压力', class: 'stress', result: data.StressDesc, time: data.StressMeasureTime ? this.$dayjs(data.StressMeasureTime).format('HH:mm') : '', level: data.StressLevel, img: data.StressScore ? this.calcImg(data.StressLevel, 'stress') : ''},
  124. // 疲劳
  125. { value: data.TirScore, name: '疲劳', class: 'tiredness', result: data.TirDesc, time: data.TirMeasureTime ? this.$dayjs(data.TirMeasureTime).format('HH:mm') : '', level: data.TirLevel, img: data.TirScore ? this.calcImg(data.TirLevel, 'tiredness') : '' },
  126. ];
  127. this.$toast.success('数据加载完成');
  128. }).catch(() =>{}).finally(() => { })
  129. },
  130. onClick(item) {
  131. this.params.name = item.class;
  132. this.$router.replace({
  133. name: 'psychological',
  134. query: {
  135. name: item.class,
  136. uid: this.uid,
  137. date: this.routeDate,
  138. ...this.params
  139. }
  140. })
  141. },
  142. onNavBack() {
  143. if(this.isShowLeft) {
  144. window.location.href = `${this.$route.query.fromUrl}/#/device`;
  145. } else {
  146. this.$router.go(-1);
  147. }
  148. },
  149. // 计算表情
  150. calcImg(level, name) {
  151. let imgUrl = '';
  152. /* imgUrl = require(`@/assets/img/psychological/${name}_${level}.png`); */
  153. let numLevel = Number(level);
  154. console.log(`@/assets/img/psychological/${name}_${numLevel}.png`);
  155. imgUrl = require(`@/assets/img/psychological/${name}_${numLevel + 1}.png`);
  156. /* switch(level) {
  157. case '0':
  158. imgUrl = require(`@/assets/img/psychological/${name}_${numLevel + 1}.png`);
  159. break;
  160. case '1':
  161. imgUrl = require('@/assets/img/regardless.png');
  162. break;
  163. case '2':
  164. imgUrl = require('@/assets/img/moderate.png');
  165. break;
  166. case '3':
  167. imgUrl = require('@/assets/img/moderate.png');
  168. break;
  169. } */
  170. return imgUrl;
  171. },
  172. // 计算颜色
  173. calcColor(value) {
  174. let color = "";
  175. if (value <= 40) {
  176. color = "#62BD48";
  177. } else if (value > 40 && value <= 65) {
  178. color = "#FEC350";
  179. } else if (value > 65 && value <= 80) {
  180. color = "#F86825";
  181. } else if (value > 80) {
  182. color = "#EB1D15";
  183. } else {
  184. color = "";
  185. }
  186. return color;
  187. }
  188. }
  189. }
  190. </script>
  191. <style scoped lang="scss">
  192. @import "./index.scss";
  193. </style>