DeviceEcharts.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. <template>
  2. <div class="charts-container">
  3. <a-select ref="select" v-model:value="chartsType" style="position: absolute; z-index: 99; top: 2px; left: 2px; width: 98px">
  4. <a-select-option value="listMonitor">实时监测</a-select-option>
  5. <a-select-option value="detail">详情监测</a-select-option>
  6. <a-select-option value="history">历史记录</a-select-option>
  7. </a-select>
  8. <div class="charts-box" v-if="chartsType === 'listMonitor'" style="position: absolute; top: 20px;">
  9. <BarAndLine
  10. :chartsColumnsType="chartsColumnsType"
  11. :xAxisPropType="xAxisPropType"
  12. :dataSource="dataSource"
  13. height="100%"
  14. chartsType="listMonitor"
  15. :option="echartsOption"
  16. />
  17. </div>
  18. <div class="charts-box" v-else-if="chartsType === 'detail' && deviceListApi">
  19. <Select
  20. :options="options"
  21. :fieldNames="{ label: 'strname', value: 'id' }"
  22. v-model:value="deviceId"
  23. placeholder="请选择查看的设备"
  24. size="small"
  25. style="position: absolute; z-index: 99; left: 102px; width: 150px; top: 2px"
  26. />
  27. <BarAndLine
  28. :chartsColumnsType="chartsColumnsType"
  29. :xAxisPropType="resultXAxisPropType"
  30. :dataSource="detailDataSource"
  31. height="100%"
  32. chartsType="detail"
  33. />
  34. </div>
  35. <div class="charts-box" v-else-if="chartsType === 'history'">
  36. <Select
  37. :options="options"
  38. :fieldNames="{ label: 'strname', value: 'id' }"
  39. v-model:value="deviceId"
  40. placeholder="请选择查看的设备"
  41. style="position: absolute; z-index: 99; left: 102px; width: 150px; top: 2px"
  42. />
  43. <a-date-picker
  44. v-model:value="historyParams.tData"
  45. valueFormat="YYYY-MM-DD"
  46. placeholder="请选择查询日期"
  47. style="position: absolute; z-index: 99; left: 254px; width: 150px; top: 2px"
  48. />
  49. <a-time-range-picker
  50. v-model:value="historyParams.ttime"
  51. valueFormat="HH:mm:ss"
  52. style="position: absolute; z-index: 99; left: 406px; width: 200px; top: 2px"
  53. />
  54. <a-select
  55. ref="select"
  56. v-model:value="historyParams.skip"
  57. placeholder="请选择间隔时间"
  58. style="position: absolute; z-index: 99; top: 2px; left: 608px; width: 150px"
  59. >
  60. <a-select-option value="1">5秒</a-select-option>
  61. <a-select-option value="2">10秒</a-select-option>
  62. <a-select-option value="3">1分钟</a-select-option>
  63. <a-select-option value="4">5分钟</a-select-option>
  64. <a-select-option value="5">10分钟</a-select-option>
  65. </a-select>
  66. <Pagination
  67. size="small"
  68. v-model:current="currentPage"
  69. v-model:page-size="pageSize"
  70. :total="total"
  71. :show-total="(total) => `共 ${total} 条`"
  72. style="position: absolute; z-index: 99; top: 2px; right: 30px"
  73. />
  74. <BarAndLine
  75. :chartsColumnsType="chartsColumnsType"
  76. :xAxisPropType="resultXAxisPropType"
  77. :dataSource="resultDataSource"
  78. height="100%"
  79. :option="echartsOption1"
  80. chartsType="history"
  81. style="margin-top: 20px;"
  82. />
  83. </div>
  84. </div>
  85. </template>
  86. <script lang="ts">
  87. import { ref, defineComponent, watch, reactive, onMounted, watchEffect } from 'vue';
  88. import BarAndLine from '/@/components/chart/BarAndLine.vue';
  89. import dayjs from 'dayjs';
  90. import { defHttp } from '/@/utils/http/axios';
  91. import { Select, Pagination } from 'ant-design-vue';
  92. export default defineComponent({
  93. name: 'DeviceEcharts',
  94. components: { BarAndLine, Select, Pagination },
  95. props: {
  96. chartsColumns: {
  97. type: Array,
  98. default: () => [],
  99. },
  100. chartsColumnsType: {
  101. type: String,
  102. required: true,
  103. },
  104. dataSource: {
  105. type: Array,
  106. default: () => [],
  107. },
  108. deviceListApi: {
  109. type: Function,
  110. required: true,
  111. },
  112. deviceType: {
  113. type: String,
  114. required: true,
  115. },
  116. option: {
  117. type: Object,
  118. default: () => ({}),
  119. },
  120. xAxisPropType: {
  121. type: String,
  122. required: true,
  123. },
  124. },
  125. setup(props) {
  126. const historyList = (params) => defHttp.get({ url: '/safety/ventanalyMonitorData/list', params });
  127. const chartsType = ref('listMonitor');
  128. const deviceId = ref('');
  129. const options = ref([]);
  130. const historyParams = reactive({
  131. tData: dayjs(),
  132. ttime: ['', ''],
  133. ttime_begin: null,
  134. ttime_end: null,
  135. skip: null,
  136. });
  137. const resultXAxisPropType = ref('');
  138. const resultDataSource = ref<any[]>([]);
  139. const detailDataSource = ref<any[]>([]);
  140. const currentPage = ref<number>(1);
  141. const pageSize = ref<number>(20);
  142. const total = ref(0);
  143. const echartsOption = {
  144. grid: {
  145. top: '60px',
  146. left: '10px',
  147. right: '5px',
  148. bottom: '5%',
  149. containLabel: true,
  150. },
  151. toolbox: {
  152. feature: {},
  153. },
  154. };
  155. const echartsOption1 = {
  156. grid: {
  157. top: '60px',
  158. left: '10px',
  159. right: '5px',
  160. bottom: '10%',
  161. containLabel: true,
  162. },
  163. toolbox: {
  164. feature: {},
  165. },
  166. };
  167. const onChange = (pageNumber: number) => {
  168. console.log('Page: ', pageNumber);
  169. };
  170. watch(
  171. [chartsType, deviceId, historyParams, pageSize, currentPage,],
  172. async (
  173. [newChartsType, newDeviceId, newHistoryParams, newPageSize, newCurrentPage],
  174. [oldChartsType, oldDeviceId, oldHistoryParams, oldPageSize, oldCurrentPage]
  175. ) => {
  176. console.log('[ historyParams ] >', historyParams.ttime, dayjs(historyParams.ttime).format('HH:mm:ss'));
  177. if (newChartsType === 'listMonitor') {
  178. // 实时监测所有
  179. resultDataSource.value = props.dataSource;
  180. } else if (newChartsType === 'history') {
  181. // 历史
  182. resultXAxisPropType.value = 'gcreatetime';
  183. if (newChartsType !== oldChartsType || newDeviceId !== oldDeviceId) {
  184. currentPage.value = 1;
  185. }
  186. const res = await historyList({
  187. ttime_begin: historyParams.ttime[0] ? historyParams.ttime[0] : null,
  188. ttime_end: historyParams.ttime[1] ? historyParams.ttime[1] : null,
  189. tData: dayjs(historyParams.tData).format('YYYY-MM-DD'),
  190. strtype: props.deviceType + '*',
  191. gdeviceid: newDeviceId,
  192. skip: historyParams.skip,
  193. pageSize: pageSize.value,
  194. pageNo: currentPage.value,
  195. });
  196. resultDataSource.value = res.datalist.records.map((item) => Object.assign(item, item.readData));
  197. total.value = res.datalist.total;
  198. } else if (newChartsType === 'detail') {
  199. // 设备详情
  200. resultXAxisPropType.value = 'readTime';
  201. if (newDeviceId !== oldDeviceId) {
  202. detailDataSource.value = [];
  203. }
  204. }
  205. }
  206. );
  207. watchEffect(() => {
  208. if (chartsType.value === 'detail') {
  209. const currentData = props.dataSource.find((item: any) => item.deviceID === deviceId.value);
  210. if (currentData) {
  211. const isHas = detailDataSource.value.find((item) => item[resultXAxisPropType.value] === currentData[resultXAxisPropType.value]);
  212. if (!isHas) {
  213. if (detailDataSource.value.length < 15) {
  214. detailDataSource.value.push(currentData);
  215. } else {
  216. detailDataSource.value.shift();
  217. detailDataSource.value.push(currentData);
  218. }
  219. }
  220. }
  221. }
  222. });
  223. onMounted(async () => {
  224. const res = await props.deviceListApi();
  225. if(res && res.records){
  226. options.value = res.records;
  227. deviceId.value = options.value[0]['id'];
  228. }
  229. });
  230. return {
  231. chartsType,
  232. deviceId,
  233. resultDataSource,
  234. historyParams,
  235. options,
  236. resultXAxisPropType,
  237. detailDataSource,
  238. currentPage,
  239. pageSize,
  240. total,
  241. echartsOption,
  242. echartsOption1,
  243. onChange,
  244. };
  245. },
  246. });
  247. </script>
  248. <style lang="less" scoped>
  249. @import '/@/design/vent/color.less';
  250. .charts-container {
  251. position: relative;
  252. height: 100%;
  253. .charts-box {
  254. width: 100%;
  255. height: 100%;
  256. position: absolute;
  257. bottom: 0;
  258. top: 0px;
  259. }
  260. .@{ventSpace}-picker,
  261. .@{ventSpace}-select-selector {
  262. background: #00000017 !important;
  263. border: 1px solid @vent-form-item-boder !important;
  264. input,
  265. .@{ventSpace}-select-selection-item,
  266. .@{ventSpace}-picker-suffix {
  267. color: #fff !important;
  268. }
  269. .@{ventSpace}-select-selection-placeholder {
  270. color: #b7b7b7 !important;
  271. }
  272. }
  273. .@{ventSpace}-select-arrow,
  274. .@{ventSpace}-picker-separator {
  275. color: #fff !important;
  276. }
  277. }
  278. </style>