dataDetail_graph.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. <template>
  2. <div>
  3. <div style="margin-top:8px">
  4. <span style="font-size: 10px;">搜索:</span>
  5. <el-select style="width: 200px" v-model="currentSubEquipnameId" placeholder="请选择"
  6. @change="selectCurrentpoint()">
  7. <el-option v-for="item in options" :key="item.id" :label="item.name" :value="item.id">
  8. </el-option>
  9. </el-select>
  10. </div>
  11. <el-card class="box-card" v-for="(item,index) in mpArray">
  12. <mpGraph2 :beforeData='item.before' :afterData='item.after'
  13. :xTime='item.time' :title='item.name'></mpGraph2>
  14. </el-card>
  15. </div>
  16. </template>
  17. <script>
  18. import {
  19. pinyin
  20. } from 'pinyin-pro';
  21. import mpGraph2 from '../../components/mpGraph/mpGraph.vue'
  22. import {
  23. closeSync
  24. } from 'fs';
  25. export default {
  26. name: "dataDetail_graph",
  27. data() {
  28. return {
  29. start: 1,
  30. showReject: false,
  31. before: [1, 2, 3, 4],
  32. page: 1, //当前第几页
  33. size: 10, //当前每页页数
  34. currentSubEquipnameId: '',
  35. currentEquipId: 0,
  36. // 父组件向子组件传递的值
  37. // mpArray: [
  38. // {
  39. // before: [1,2,3,4],
  40. // after:[5,6,7,8],
  41. // name:'电流',
  42. // time:[1,2,3,4]
  43. // }
  44. // ],
  45. mpArray:[],
  46. hbasetablename: '',
  47. options: [],
  48. mpName: [],
  49. // 根据子设备id获取到的测点个数
  50. mpHeaderLength: [],
  51. timer: null
  52. }
  53. },
  54. components: {
  55. mpGraph2,
  56. },
  57. mounted() {
  58. console.log("#####");
  59. console.log(pinyin('功率', {
  60. toneType: 'none'
  61. }).replace(/\s*/g, ''));
  62. this.currentEquipId = this.$route.query.equipmentId
  63. // this.currentEquipId = window.sessionStorage.getItem("dataList_currentEquipId");
  64. // 获取子设备选项
  65. this.getSubEquipOption();
  66. // console.log("here1")
  67. // this.initData();
  68. // console.log("here2")
  69. // this.timer = setInterval(() => {
  70. // this.initData1();
  71. // }, 5000)
  72. },
  73. beforeDestroy() {
  74. clearInterval(this.timer)
  75. this.timer = null
  76. console.log("graph kill")
  77. },
  78. methods: {
  79. // 改变当前子设备选项
  80. selectCurrentpoint() {
  81. if (this.timer !== null) {
  82. clearInterval(this.timer)
  83. this.timer = null
  84. }
  85. for (let i in this.options) {
  86. if (this.options[i].id == this.currentSubEquipnameId) {
  87. this.subEuipname = this.options[i].name;
  88. this.hbasetablename = this.options[i].hbasetablename;
  89. // console.log("this.hbasetablename"+this.hbasetablename);
  90. break;
  91. }
  92. }
  93. this.initData();
  94. // this.getHbaseData1()
  95. },
  96. // 根据传来的设备currentEquipId找到对应的子设备选项
  97. getSubEquipOption() {
  98. this.getRequest('/subEquipmentManage/getSubEquipmentInfoByEquipmentId/?equipmentId=' + this.currentEquipId).then(
  99. resp => {
  100. if (resp.data) {
  101. console.log(resp.data)
  102. this.options = resp.data.data;
  103. this.currentSubEquipname = this.options[0].name; //将当前子系统与id设置为下拉框第一个
  104. this.currentSubEquipnameId = this.options[0].id;
  105. this.subEuipname = this.options[0].name;
  106. this.hbasetablename = this.options[0].hbasetablename;
  107. // this.hbasetablename = this.options[0].hbasetablename;
  108. // console.log("options");
  109. // console.log(this.options);
  110. this.initData();
  111. }
  112. });
  113. },
  114. initData() {
  115. // this.currentSubEquipnameId = parseInt(this.currentSubEquipnameId);
  116. this.getRequest('/dataQualityMeasurePoint/getMeasurePointBySubEquipmentId/?subEquipmentId=' + this
  117. .currentSubEquipnameId + '&page=' + this.page + '&size=' + this.size).then(resp => {
  118. if (resp.data) {
  119. this.mpHeaderLength = resp.data.data.length;
  120. // 所有测点名字的数组
  121. var mpNames = [];
  122. for (let i = 0; i < resp.data.data.length; i++) {
  123. mpNames.push(resp.data.data[i].name);
  124. }
  125. this.mpName = mpNames;
  126. this.total = resp.data.total;
  127. // var mpLength = this.mpName.length;
  128. // var arr = [];
  129. this.startGetData()
  130. // for (let mpName of mpNames) {
  131. // arr.push(this.getHbaseData(mpName));
  132. // }
  133. // console.log(arr)
  134. // Promise.all(arr).then(resp => {
  135. // this.showReject = true;
  136. // var mpInfo = [];
  137. // console.log("333")
  138. // console.log(resp)
  139. // console.log(resp[0].data)
  140. // // console.log(resp.data.legth)
  141. // // 取到某一个测点的治理前,后的数组
  142. // // for (let i in resp.data) {
  143. // for (var i = 0; i < resp.length; i++) {
  144. // // 每个测点有20个数据
  145. // var o = {
  146. // name: '',
  147. // before: [],
  148. // after: [],
  149. // time: []
  150. // };
  151. // for (var j = 0; j < resp[i].data.length; j++) {
  152. // o.name = this.mpName[i];
  153. // o.time.push(resp[i].data[j].date);
  154. // for (var key in resp[i].data[j]) {
  155. // if (key.indexOf("before") !== -1) {
  156. // console.log(eval("resp[i].data[j]." + key));
  157. // o.before.push(eval("resp[i].data[j]." + key));
  158. // }
  159. // if (key.indexOf("after") !== -1) {
  160. // o.after.push(eval("resp[i].data[j]." + key));
  161. // }
  162. // }
  163. // }
  164. // mpInfo.push(o);
  165. //
  166. // }
  167. // console.log('mpInfo');
  168. // console.log(mpInfo);
  169. // this.mpArray = mpInfo;
  170. //
  171. // })
  172. }
  173. })
  174. },
  175. handleHbaseSearch() {
  176. let arr = [];
  177. for (let mpName of this.mpName) {
  178. console.log(mpName)
  179. arr.push(this.getHbaseData(mpName));
  180. }
  181. console.log(arr)
  182. Promise.all(arr).then(resp => {
  183. this.showReject = true;
  184. var mpInfo = [];
  185. console.log("333")
  186. console.log(resp)
  187. console.log(resp[0].data)
  188. // console.log(resp.data.legth)
  189. // 取到某一个测点的治理前,后的数组
  190. // for (let i in resp.data) {
  191. for (var i = 0; i < resp.length; i++) {
  192. // 每个测点有20个数据
  193. var o = {
  194. name: '',
  195. before: [],
  196. after: [],
  197. time: []
  198. };
  199. for (var j = 0; j < resp[i].data.length; j++) {
  200. o.name = this.mpName[i];
  201. o.time.push(resp[i].data[j].date);
  202. for (var key in resp[i].data[j]) {
  203. if (key.indexOf("before") !== -1) {
  204. console.log(eval("resp[i].data[j]." + key));
  205. o.before.push(eval("resp[i].data[j]." + key));
  206. }
  207. if (key.indexOf("after") !== -1) {
  208. o.after.push(eval("resp[i].data[j]." + key));
  209. }
  210. }
  211. }
  212. mpInfo.push(o);
  213. }
  214. console.log('mpInfo');
  215. console.log(mpInfo);
  216. this.mpArray = mpInfo;
  217. })
  218. },
  219. getHbaseData(mpName) {
  220. // 测点名字个数
  221. return this.getRequest('/hbase/getMeasurePointByname/?hbasetablename=' + this.hbasetablename +
  222. '&qualifier=' +
  223. pinyin(mpName, {
  224. toneType: 'none'
  225. }).replace(/\s*/g, '') + '&page=' + this.page + '&size=' + this.size)
  226. },
  227. startGetData() {
  228. this.timer = setInterval(() => {
  229. this.handleHbaseSearch()
  230. }, 2000)
  231. }
  232. }
  233. }
  234. </script>
  235. <style>
  236. .el-card {
  237. margin-top: 10px;
  238. margin-left: 35px;
  239. margin-right: 35px;
  240. }
  241. </style>