stationPowerContro.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. <template>
  2. <div class="stationPowerContro" :class="!theme ? 'themeDark' : 'themeLight'">
  3. <div class="stationPowerControSeach">
  4. <div class="seach_top">
  5. <div class="exceed">
  6. <span class="exceedName">时间:</span>
  7. <el-date-picker v-model="pickerTime" @change="changeTime" format="YYYY-MM-DD" type="date"
  8. placeholder="选择时间" />
  9. </div>
  10. <el-button type="primary" @click="seachData">计 算</el-button>
  11. <el-button @click="exportExcel">导 出</el-button>
  12. </div>
  13. </div>
  14. <div class="stationPowerControTable">
  15. <p class="tableTitle">{{titelMonth}}场站中长期电量未来40天预测</p>
  16. <span class="tableUnit">单位:m/s,万kwh</span>
  17. <div :style="tableHeight">
  18. <div class="tablestyle warn-table" style="margin-top: 10px">
  19. <!-- :span-method="mergeSameCells" -->
  20. <el-table :data="tableData" v-loading="loading" border style="width: 100%"
  21. :max-height="tableMainHeight" ref="stationPowerTable"
  22. element-loading-background="rgba(0,0,0,.5)" :header-cell-style="{ 'text-align': 'center' }">
  23. <el-table-column prop="name" label="名称" width="200" align="center" fixed>
  24. </el-table-column>
  25. <el-table-column prop="time" label="周期" width="73" align="center" fixed>
  26. </el-table-column>
  27. <el-table-column label="日期" align="center">
  28. <el-table-column :prop="item.value" :label="item.label" align="center"
  29. v-for="(item, index) in tableColumn" :key="index">
  30. <template #default="scope">
  31. {{scope.row[scope.row.nameEn+(index+1)]}}
  32. </template>
  33. </el-table-column>
  34. </el-table-column>
  35. </el-table>
  36. </div>
  37. </div>
  38. </div>
  39. </div>
  40. </template>
  41. <script>
  42. import {
  43. apiGetallStationPower
  44. } from "../../api/api";
  45. import jsonData from "./component/stationPowerControl.json";
  46. import dayjs from "dayjs";
  47. import * as XLSX from 'xlsx'
  48. import {
  49. saveAs
  50. } from 'file-saver'
  51. import * as XLSXD from 'xlsx-js-style'
  52. export default {
  53. data() {
  54. return {
  55. loading: false,
  56. pickerTime: "",
  57. titelMonth: "",
  58. tableData: [],
  59. tableColumn: [],
  60. echartsTheme: "",
  61. theme: null,
  62. };
  63. },
  64. watch: {
  65. "$store.state.theme": {
  66. handler: function (newVal, oldVal) {
  67. this.theme = newVal;
  68. this.echartsTheme = !newVal ? "dark" : "";
  69. // this.getStationData();
  70. },
  71. immediate: true,
  72. },
  73. },
  74. created() {
  75. this.pickerTime = dayjs(new Date()).format("YYYY-MM-DD")
  76. this.titelMonth = this.pickerTime.split("-")[0] + "年" + this.pickerTime.split("-")[1] + "月" + this
  77. .pickerTime.split("-")[2] + "日"
  78. this.getStationData();
  79. },
  80. computed: {
  81. tableHeight() {
  82. let height = (document.documentElement.clientHeight - 190) / 2 + "px";
  83. return {
  84. width: "100%",
  85. height: height,
  86. };
  87. },
  88. tableMainHeight() {
  89. let height = (document.documentElement.clientHeight - 180) + "px";
  90. return height
  91. },
  92. },
  93. methods: {
  94. getStationData() {
  95. let that = this;
  96. that.loading = true
  97. let params = {
  98. date: that.pickerTime
  99. }
  100. apiGetallStationPower(params).then(res => {
  101. that.loading = false
  102. if (res && res.data) {
  103. // that.tableData = res.data.power
  104. res.data.power.forEach(iv => {
  105. let obj = {
  106. name: iv.name,
  107. nameEn: iv.nameEn,
  108. time: iv.time
  109. }
  110. iv.power.forEach((ic, idx) => {
  111. (obj[obj.nameEn + (idx + 1)]) = ic.toFixed(2)
  112. })
  113. that.tableData.push(obj)
  114. })
  115. console.log("table=====>>>>", that.tableData)
  116. res.data.title.forEach((it, index) => {
  117. let obj = {
  118. label: it,
  119. value: index
  120. }
  121. that.tableColumn.push(obj)
  122. })
  123. }
  124. }).catch(e => {
  125. that.loading = false
  126. let tableColumn = [...Array(40).keys()].map(i => i + 1)
  127. tableColumn.forEach((it, index) => {
  128. let obj = {
  129. label: it,
  130. value: index
  131. }
  132. that.tableColumn.push(obj)
  133. })
  134. that.tableData = jsonData.data
  135. })
  136. },
  137. changeTime(val) {
  138. },
  139. seachData() {
  140. let str = dayjs(this.pickerTime).format("YYYY-MM")
  141. this.titelMonth = str.split("-")[0] + "年" + str.split("-")[1] + "月"
  142. this.getStationData()
  143. },
  144. exportExcel() {
  145. let $e = this.$refs.stationPowerTable.$el
  146. try {
  147. let $table = $e.querySelector('.el-table__fixed')
  148. if (!$table) {
  149. $table = $e
  150. }
  151. const wb = XLSX.utils.table_to_book($table, {
  152. raw: true
  153. })
  154. const wbout = XLSXD.write(wb, {
  155. bookType: 'xlsx',
  156. bookSST: true,
  157. type: 'array'
  158. })
  159. saveAs(
  160. new Blob([wbout], {
  161. type: 'application/octet-stream'
  162. }),
  163. `场站中长期电量预测数据导出.xlsx`,
  164. )
  165. } catch (e) {
  166. if (typeof console !== 'undefined') console.error(e)
  167. }
  168. },
  169. mergeSameCells({
  170. row,
  171. column,
  172. rowIndex,
  173. columnIndex
  174. }) {
  175. if (columnIndex === 0) {
  176. const prevRow = this.tableData[rowIndex];
  177. if (prevRow && this.tableData[rowIndex + 1] && this.tableData[rowIndex + 1].name === prevRow.name) {
  178. if (row.name.indexOf('风速') !== -1) {
  179. return {
  180. rowspan: 2,
  181. colspan: 1,
  182. }
  183. } else {
  184. return {
  185. rowspan: 3,
  186. colspan: 1,
  187. }
  188. }
  189. }
  190. }
  191. // if (columnIndex === 0) {
  192. // if (rowIndex % 2 === 0) {
  193. // return {
  194. // rowspan: 2,
  195. // colspan: 1,
  196. // }
  197. // } else {
  198. // return {
  199. // rowspan: 0,
  200. // colspan: 0,
  201. // }
  202. // }
  203. // }
  204. }
  205. },
  206. };
  207. </script>
  208. <style lang="less">
  209. .stationPowerContro {
  210. padding: 0 20px 0 20px;
  211. .stationPowerControSeach {
  212. margin-top: 20px;
  213. .seach_top {
  214. display: flex;
  215. .exceed {
  216. .exceedName {
  217. margin-top: 7px;
  218. font-size: 14px;
  219. margin-left: 10px;
  220. }
  221. display: flex;
  222. margin-right: 20px;
  223. .el-select,
  224. .el-select__wrapper {
  225. height: 32px;
  226. }
  227. .el-date-editor {
  228. height: 32px;
  229. .el-input__icon,
  230. .el-range-separator {
  231. line-height: 30px;
  232. }
  233. }
  234. .select-trigger {
  235. .el-input {
  236. .el-input__wrapper {
  237. height: 30px;
  238. }
  239. }
  240. .el-input__suffix {
  241. .el-input__icon {
  242. line-height: 30px;
  243. }
  244. }
  245. }
  246. }
  247. .el-button {
  248. height: 30px;
  249. padding: 0 20px;
  250. line-height: 5px;
  251. }
  252. }
  253. }
  254. .stationPowerControTable {
  255. .tableTitle {
  256. display: flex;
  257. justify-content: center;
  258. font-size: 18px;
  259. font-weight: 600;
  260. }
  261. .tableUnit {
  262. font-size: 14px;
  263. }
  264. }
  265. }
  266. .themeDark {
  267. background-image: none;
  268. .stationPowerControSeach {
  269. .exceedName {
  270. color: #fff;
  271. }
  272. }
  273. .stationPowerControTable {
  274. .tableTitle,
  275. .tableUnit {
  276. color: #fff;
  277. }
  278. }
  279. }
  280. .themeLight {
  281. .stationPowerControSeach {
  282. .exceedName {
  283. color: #000;
  284. }
  285. }
  286. .stationPowerControTable {
  287. .tableTitle,
  288. .tableUnit {
  289. color: #000;
  290. }
  291. }
  292. }
  293. </style>