Energy.vue 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  1. <template>
  2. <div class="home">
  3. <div class="home_flex">
  4. <transition
  5. name="custom-up"
  6. enter-active-class="animate__animated animate__fadeInLeft"
  7. leave-active-class="animate__animated animate__fadeOutLeft"
  8. >
  9. <x-box v-if="show" name="近七天用水监测(全场)">
  10. <div class="chart_content">
  11. <chart-water v-if="waterList.length > 0" :id="0" :list="waterList"></chart-water>
  12. <a-empty v-else :image="Empty.PRESENTED_IMAGE_SIMPLE" description="暂无数据" />
  13. </div>
  14. </x-box>
  15. </transition>
  16. <transition
  17. name="custom-up"
  18. enter-active-class="animate__animated animate__fadeInLeft"
  19. leave-active-class="animate__animated animate__fadeOutLeft"
  20. >
  21. <x-box v-if="show" name="近七天用电监测(全场)">
  22. <div class="chart_content">
  23. <chart-ele v-if="eleList.length > 0" :id="0" :list="eleList"></chart-ele>
  24. <a-empty v-else :image="Empty.PRESENTED_IMAGE_SIMPLE" description="暂无数据" />
  25. </div>
  26. </x-box>
  27. </transition>
  28. <transition
  29. name="custom-up"
  30. enter-active-class="animate__animated animate__fadeInLeft"
  31. leave-active-class="animate__animated animate__fadeOutLeft"
  32. >
  33. <x-box v-if="show" name="近七天用料监测(全场)">
  34. <div class="chart_content">
  35. <chart-feed v-if="feedList.length > 0" :id="0" :list="feedList"></chart-feed>
  36. <a-empty v-else :image="Empty.PRESENTED_IMAGE_SIMPLE" description="暂无数据" />
  37. </div>
  38. </x-box>
  39. </transition>
  40. </div>
  41. <div class="home_center">
  42. <transition
  43. name="custom-up"
  44. enter-active-class="animate__animated animate__fadeInDown"
  45. leave-active-class="animate__animated animate__fadeOutUp"
  46. >
  47. <x-tabs v-if="show"></x-tabs>
  48. </transition>
  49. </div>
  50. <div class="home_flex">
  51. <transition
  52. name="custom-up"
  53. enter-active-class="animate__animated animate__fadeInRight"
  54. leave-active-class="animate__animated animate__fadeOutRight"
  55. >
  56. <x-box v-if="show" name="本月用水TOP5">
  57. <div class="chart_content">
  58. <div class="chart_flex">
  59. <div class="chart_box" v-for="(item, i) in waterRank" :key="i">
  60. <div :class="['icon_box', 'rank' + (i+1)]"></div>
  61. <div class="num_box">
  62. <div class="num_name">{{item.name}}</div>
  63. <div class="num_text">{{item.value}}吨</div>
  64. </div>
  65. </div>
  66. </div>
  67. </div>
  68. </x-box>
  69. </transition>
  70. <transition
  71. name="custom-up"
  72. enter-active-class="animate__animated animate__fadeInRight"
  73. leave-active-class="animate__animated animate__fadeOutRight"
  74. >
  75. <x-box v-if="show" name="本月用电TOP5">
  76. <div class="chart_content">
  77. <div class="chart_flex">
  78. <div class="chart_box" v-for="(item, i) in eleRank" :key="i">
  79. <div :class="['icon_box', 'rank' + (i+1)]"></div>
  80. <div class="num_box">
  81. <div class="num_name">{{item.name}}</div>
  82. <div class="num_text">{{item.value}}kw·h</div>
  83. </div>
  84. </div>
  85. </div>
  86. </div>
  87. </x-box>
  88. </transition>
  89. <transition
  90. name="custom-up"
  91. enter-active-class="animate__animated animate__fadeInRight"
  92. leave-active-class="animate__animated animate__fadeOutRight"
  93. >
  94. <x-box v-show="show" name="能耗预警">
  95. <div class="chart_content">
  96. <div class="warn_scroll" ref="scroll">
  97. <template v-if="warnList.length > 0">
  98. <div class="warn_item" v-for="(item, i) in warnList" :key="i">
  99. <div class="warn_icon"></div>
  100. <div class="warn_text">{{item.warningTime}} {{item.buildName}} {{item.warningContent}}</div>
  101. </div>
  102. </template>
  103. <template v-else>
  104. <a-empty :image="Empty.PRESENTED_IMAGE_SIMPLE" description="暂无数据" />
  105. </template>
  106. </div>
  107. </div>
  108. </x-box>
  109. </transition>
  110. </div>
  111. </div>
  112. </template>
  113. <script>
  114. export default {
  115. name: "Energy"
  116. }
  117. </script>
  118. <script setup>
  119. import { Empty } from "ant-design-vue";
  120. import {ref, onMounted, getCurrentInstance, onBeforeUnmount} from 'vue'
  121. import {getWaterRank, getSevenWater, getSevenEle, getEleRank, getWarnList, getFeedSeven} from "../../utils/api";
  122. import XBox from "../../components/XBox.vue";
  123. import XTabs from '../../components/XTabs.vue';
  124. import ChartWater from "./charts/ChartWater.vue";
  125. import ChartEle from "./charts/ChartEle.vue";
  126. import ChartFeed from "./charts/ChartFeed.vue";
  127. import { throttle } from "../../utils";
  128. const { proxy } = getCurrentInstance()
  129. const waterList = ref([
  130. ])
  131. const eleList = ref([
  132. ])
  133. const initList = () => {
  134. let params = {
  135. type: 4
  136. }
  137. getSevenWater(params).then(res => {
  138. let arr = []
  139. if(res.data.list.length > 0) {
  140. res.data.list.forEach(item => {
  141. arr.push({ date: proxy.$moment(item.createTime).format('MM-DD'), value: item.waterValue })
  142. })
  143. }
  144. waterList.value = arr;
  145. })
  146. getSevenEle(params).then(res => {
  147. let arr = []
  148. if(res.data.list.length > 0) {
  149. res.data.list.forEach(item => {
  150. arr.push({ date: proxy.$moment(item.createTime).format('MM-DD'), value: item.electricityValue })
  151. })
  152. }
  153. eleList.value = arr;
  154. })
  155. }
  156. const waterRank = ref([])
  157. const eleRank = ref([])
  158. const initRank = () => {
  159. let params = {
  160. type: 2
  161. }
  162. getWaterRank(params).then(res => {
  163. let arr = [];
  164. if(res.data.length >0) {
  165. res.data.forEach((item, i) => {
  166. if(i< 5) {
  167. arr.push({ name: item.location, value: item.energyWaterValue })
  168. }
  169. })
  170. }
  171. waterRank.value = arr;
  172. })
  173. getEleRank(params).then(res => {
  174. let arr = [];
  175. if(res.data.length >0) {
  176. res.data.forEach((item, i) => {
  177. if(i< 5) {
  178. arr.push({ name: item.location, value: item.energyElectricityValue })
  179. }
  180. })
  181. }
  182. eleRank.value = arr;
  183. })
  184. }
  185. const scroll = ref()
  186. const warnList = ref([])
  187. const current = ref(1)
  188. const size = ref(10)
  189. const fished = ref(false)
  190. const initWarn = () => {
  191. if(fished.value) {
  192. return
  193. } else {
  194. let params = {
  195. current: current.value,
  196. size: size.value,
  197. type: 2
  198. }
  199. getWarnList(params).then(res => {
  200. warnList.value = warnList.value.concat(res.data.records);
  201. if(res.data.records.length < size.value) {
  202. fished.value = true
  203. }
  204. current.value++
  205. })
  206. }
  207. }
  208. const handlerScroll = throttle(() => {
  209. let clientHeight = scroll.value.clientHeight;
  210. let scrollHeight = scroll.value.scrollHeight;
  211. let scrollTop = scroll.value.scrollTop;
  212. if(clientHeight + scrollTop >= scrollHeight) {
  213. initWarn()
  214. }
  215. }, 100)
  216. const feedList = ref([])
  217. const initFeed = () => {
  218. getFeedSeven({}).then(res => {
  219. let arr = []
  220. res.data.forEach(item => {
  221. arr.push({ date: proxy.$moment(item.createDate).format('MM-DD'), value: item.value })
  222. })
  223. feedList.value = arr
  224. })
  225. }
  226. const show = ref(false)
  227. onMounted(() => {
  228. scroll.value.addEventListener('scroll', handlerScroll)
  229. initList()
  230. initRank()
  231. initWarn()
  232. initFeed()
  233. show.value = true
  234. })
  235. onBeforeUnmount(() => {
  236. scroll.value.removeEventListener('scroll', handlerScroll)
  237. })
  238. </script>
  239. <style scoped>
  240. .home {
  241. width: 100%;
  242. height: 100%;
  243. position: relative;
  244. box-sizing: border-box;
  245. padding: 0 25px;
  246. display: flex;
  247. justify-content: space-between;
  248. }
  249. .home_flex {
  250. width: 480px;
  251. height: 100%;
  252. display: flex;
  253. flex-direction: column;
  254. justify-content: space-between;
  255. }
  256. .home_center {
  257. width: 840px;
  258. height: 100%;
  259. display: flex;
  260. flex-direction: column;
  261. justify-content: space-between;
  262. }
  263. .chart_content {
  264. width: 100%;
  265. height: 100%;
  266. box-sizing: border-box;
  267. padding: 14px;
  268. }
  269. .chart_flex {
  270. width: 100%;
  271. height: 100%;
  272. display: flex;
  273. flex-direction: column;
  274. justify-content: space-between;
  275. align-items: center;
  276. }
  277. .chart_box {
  278. width: 100%;
  279. height: 34px;
  280. display: flex;
  281. justify-content: space-between;
  282. align-items: center;
  283. }
  284. .icon_box {
  285. width: 32px;
  286. height: 34px;
  287. }
  288. .num_box {
  289. margin-left: 10px;
  290. flex: 1;
  291. height: 100%;
  292. line-height: 34px;
  293. display: flex;
  294. justify-content: space-between;
  295. background: rgba(0, 30, 61, .68);
  296. box-shadow: inset 0 0 30px rgba(0, 90, 137, .5);
  297. box-sizing: border-box;
  298. padding: 0 10px;
  299. color: #BBD6FF;
  300. cursor: pointer;
  301. border: 1px solid #00668D;
  302. }
  303. .rank1 {
  304. background: url("../../assets/tabs/top1.png") no-repeat;
  305. background-size: 100% 100%;
  306. }
  307. .rank2 {
  308. background: url("../../assets/tabs/top2.png") no-repeat;
  309. background-size: 100% 100%;
  310. }
  311. .rank3 {
  312. background: url("../../assets/tabs/top3.png") no-repeat;
  313. background-size: 100% 100%;
  314. }
  315. .rank4 {
  316. background: url("../../assets/tabs/top4.png") no-repeat;
  317. background-size: 100% 100%;
  318. }
  319. .rank5 {
  320. background: url("../../assets/tabs/top5.png") no-repeat;
  321. background-size: 100% 100%;
  322. }
  323. .warn_scroll {
  324. width: 100%;
  325. height: 100%;
  326. overflow: auto;
  327. }
  328. .warn_scroll::-webkit-scrollbar {
  329. display: none;
  330. }
  331. .warn_item {
  332. width: 100%;
  333. height: 40px;
  334. line-height: 40px;
  335. background: rgba(0, 30, 61, .68);
  336. box-shadow: inset 0 0 30px rgba(0, 90, 137, .5);
  337. display: flex;
  338. align-items: center;
  339. padding: 0 10px;
  340. color: #BBD6FF;
  341. cursor: pointer;
  342. border: 1px solid #00668D;
  343. margin-bottom: 6px;
  344. }
  345. .warn_icon {
  346. width: 24px;
  347. height: 24px;
  348. background: url('../../assets/images/warnOrgin.png') no-repeat;
  349. background-size: 100% 100%;
  350. margin-right: 10px;
  351. }
  352. .warn_text {
  353. flex: 1;
  354. white-space: nowrap; /* 防止文本换行 */
  355. overflow: hidden; /* 隐藏溢出的文本 */
  356. text-overflow: ellipsis;
  357. }
  358. </style>