deviceDetails.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. <template>
  2. <scroll-view class="scroll-height" :scroll-y="true" :data-theme="'theme-' + proxy.$settingStore.themeColor.name">
  3. <view class="deviceDetails-container">
  4. <view class="flex bg-white p15 mb15">
  5. <image style="width: 40px; height: 40px; margin: auto 15px auto 0" :src="'/static/images/404.png'" mode="aspectFill"></image>
  6. <view style="margin: auto auto auto 0">
  7. <view style="font-size: 15px"> {{ commonStore.$state.deviceDetailsArray.deviceName }} </view>
  8. </view>
  9. <view style="margin: auto 0 auto 0">
  10. <view :style="{ fontSize: '15px', color: commonStore.$state.deviceDetailsArray.deviceStatus == 1 ? '#16bf00' : 'red' }">
  11. {{ commonStore.$state.deviceDetailsArray.deviceStatus == 1 ? "在线" : "离线" }}
  12. </view>
  13. </view>
  14. </view>
  15. <view class="bg-white p15 mb15">
  16. <uni-section class="block mb10" title="基本信息" type="line"></uni-section>
  17. <view class="tableType3 p0">
  18. <u-empty v-if="dataList.length <= 0" text="暂无数据" mode="data" icon="http://cdn.uviewui.com/uview/empty/data.png"> </u-empty>
  19. <u-row v-for="po in dataList" :key="po">
  20. <u-col span="4">
  21. <view style="text-align: right; padding: 0px 5px 0px 5px">{{ po.title }}</view>
  22. </u-col>
  23. <u-col span="8">
  24. <view style="text-align: left; padding: 0px 5px 0px 5px">{{ po.value }}</view>
  25. </u-col>
  26. </u-row>
  27. </view>
  28. </view>
  29. <view class="bg-white p15 mb15">
  30. <!-- 分段器组件 -->
  31. <view class="app-subsection">
  32. <u-subsection :list="list" :current="tabPosition" inactiveColor="#303133" :activeColor="proxy.$settingStore.themeColor.color" @change="tabPositionChange" style="width: 100%"></u-subsection>
  33. </view>
  34. <view v-if="tabPosition == 1">
  35. <view class="flex" :style="{ color: proxy.$settingStore.themeColor.color }">
  36. <view class="ml10" style="margin-left: auto" @click="open">选择时间</view>
  37. <view class="ml10" @click="modalShow = true">筛选</view>
  38. </view>
  39. <chart :currentDateList="currentDateList"></chart>
  40. <!-- <view class="tableType1">
  41. <u-row>
  42. <u-col span="12">
  43. <view>指数</view>
  44. </u-col>
  45. </u-row>
  46. <u-row v-for="(co, index) in content4" :key="index">
  47. <u-col span="12">
  48. <view>{{ co.name1 }}</view>
  49. </u-col>
  50. </u-row>
  51. </view> -->
  52. </view>
  53. <!-- -->
  54. <view v-else>
  55. <view class="flex" style="flex-wrap: wrap; line-height: 36px">
  56. <view style="width: 50%" v-for="realTime in realTimeDataList" :key="realTime">
  57. {{ realTime.attributeName + ":" }}
  58. {{ realTime.value }}
  59. {{ realTime.attributeUnit ? realTime.attributeUnit : "" }}
  60. </view>
  61. </view>
  62. </view>
  63. </view>
  64. <u-modal :show="modalShow" @confirm="modalShow = false" @close="modalShow = false" :closeOnClickOverlay="true">
  65. <view class="slot-content">
  66. <u-checkbox-group
  67. v-model="checkboxValueList"
  68. @change="
  69. (val) => {
  70. checkboxChange(val);
  71. }
  72. "
  73. :activeColor="proxy.$settingStore.themeColor.color"
  74. >
  75. <u-checkbox class="mb10" v-for="option in checkboxDataList" :key="option" :label="option.attributeName" :name="option.attributeCode"> </u-checkbox>
  76. </u-checkbox-group>
  77. </view>
  78. </u-modal>
  79. <uni-calendar ref="calendar" class="uni-calendar--hook" :clearDate="false" :insert="false" :lunar="false" :range="true" @confirm="calendarConfirm" />
  80. </view>
  81. </scroll-view>
  82. </template>
  83. <script setup>
  84. import { onLoad, onShow, onReady, onHide, onLaunch, onNavigationBarButtonTap, onPageScroll } from "@dcloudio/uni-app";
  85. import { ref, reactive, computed, getCurrentInstance, toRefs, inject } from "vue";
  86. import { useStores, commonStores } from "@/store/modules/index";
  87. import chart from "./chart.vue";
  88. import { dmpProductAttribute, historyMetrics, last } from "@/api/business/fireIot/deviceManage.js";
  89. const { proxy } = getCurrentInstance();
  90. const commonStore = commonStores();
  91. const dataList = ref([
  92. {
  93. title: "设备类型",
  94. value: commonStore.$state.deviceDetailsArray.productName,
  95. },
  96. {
  97. title: "设备编号",
  98. value: commonStore.$state.deviceDetailsArray.deviceId,
  99. },
  100. {
  101. title: "物联网卡号",
  102. value: commonStore.$state.deviceDetailsArray.simCode,
  103. },
  104. {
  105. title: "安装位置",
  106. value: commonStore.$state.deviceDetailsArray.installAddress,
  107. },
  108. {
  109. title: "添加时间",
  110. value: commonStore.$state.deviceDetailsArray.createdTime ? commonStore.$state.deviceDetailsArray.createdTime.replace("T", " ") : "",
  111. },
  112. ]);
  113. const checkboxDataList = ref([]); //复选框渲染数据存储
  114. const checkboxValueList = ref([]); //复选框值数据存储
  115. const realTimeDataList = ref([]); //实时数据存储
  116. const tableDataList = ref([]); //表格数据存储
  117. const currentDateList = ref([]); //图表数据存储
  118. const modalShow = ref(false); //模态框显示隐藏
  119. const calendar = ref(null);
  120. const calendarStartTime = ref(""); //日历开始时间
  121. const calendarEndTime = ref(""); //日历结束时间
  122. function open() {
  123. calendar.value.open();
  124. }
  125. /**
  126. * @初始化
  127. */
  128. function init() {
  129. dmpProductAttribute({
  130. current: 1,
  131. size: 100,
  132. attributeName: "",
  133. productId: commonStore.$state.deviceDetailsArray.productId,
  134. }).then((requset) => {
  135. if (requset.status === "SUCCESS") {
  136. checkboxDataList.value = requset.data.records;
  137. realTimeDataList.value = requset.data.records;
  138. var array = [];
  139. requset.data.records.forEach((el) => {
  140. array.push(el.attributeCode);
  141. });
  142. last({
  143. deviceId: commonStore.$state.deviceDetailsArray.deviceId,
  144. metrics: array,
  145. }).then((requsets) => {
  146. if (requsets.status === "SUCCESS") {
  147. realTimeDataList.value.forEach((el) => {
  148. el.value = 0;
  149. requsets.data.forEach((e) => {
  150. if (el.attributeCode === e.metric) {
  151. el.value = e.value;
  152. }
  153. });
  154. });
  155. }
  156. });
  157. }
  158. });
  159. }
  160. /**
  161. * @tabs切换change事件
  162. */
  163. const list = ref(["实时数据", "历史数据"]);
  164. const tabPosition = ref(0);
  165. function tabPositionChange(index) {
  166. tabPosition.value = index;
  167. }
  168. /**
  169. * @checkbox选中change事件
  170. */
  171. function checkboxChange(value) {
  172. checkboxValueList.value = value;
  173. historyMetricsApi();
  174. }
  175. /**
  176. * @日历确认事件
  177. */
  178. function calendarConfirm(e) {
  179. calendarStartTime.value = e.range.before;
  180. calendarEndTime.value = e.range.after ? e.range.after : e.range.before;
  181. historyMetricsApi();
  182. }
  183. /**
  184. * @设备多属性历史数据请求
  185. * @api接口请求
  186. */
  187. function historyMetricsApi() {
  188. historyMetrics({
  189. startTime: calendarStartTime.value,
  190. endTime: calendarEndTime.value,
  191. deviceId: commonStore.$state.deviceDetailsArray.deviceId,
  192. deviceType: commonStore.$state.deviceDetailsArray.deviceType,
  193. metrics: checkboxValueList.value,
  194. }).then((requset) => {
  195. if (requset.status === "SUCCESS") {
  196. currentDateList.value = requset.data;
  197. checkboxDataList.value.forEach((el) => {
  198. currentDateList.value.forEach((e) => {
  199. if (el.attributeCode == e.metric) {
  200. e.attributeName = el.attributeName;
  201. }
  202. });
  203. });
  204. currentDateList.value.forEach((el) => {
  205. if (el.metricItems.length > 0) {
  206. el.data = [];
  207. el.metricItems.forEach((e) => {
  208. el.data.push([e.timestamp, e.value]);
  209. });
  210. } else {
  211. el.data = [];
  212. }
  213. });
  214. }
  215. });
  216. }
  217. onReady(() => {});
  218. onShow(() => {
  219. //调用系统主题颜色
  220. proxy.$settingStore.systemThemeColor([1]);
  221. });
  222. onLoad((options) => {
  223. init();
  224. });
  225. </script>
  226. <style lang="scss" scoped>
  227. .app-subsection {
  228. display: flex;
  229. margin-bottom: 10px;
  230. padding: 0px 5rem;
  231. }
  232. </style>