index.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. <script setup name="prepare">
  2. import searchCop from './components/search.vue'
  3. import excelCop from '@/components/excel.vue'
  4. import treeCop from '@/components/tree.vue'
  5. import tableCop from './components/table.vue'
  6. import { ElMessage } from 'element-plus';
  7. import { onMounted, ref, onActivated } from 'vue'
  8. import CurrentScatterChart from './components/current-scatter-chart.vue'
  9. import request from '@/api/axios.js'
  10. import {baseURL, socketURL} from '@/api/axios.js'
  11. import dayjs from 'dayjs';
  12. /**配置参数 */
  13. const tableHeight = ref(window.innerHeight - 214 + 'px')
  14. const treeHeight = ref(window.innerHeight - 160 + 'px') //tree高度
  15. const excelHeight = ref(window.innerHeight - 160 + 'px') //excel高度
  16. /**excel 开始 */
  17. const excelList = ref([])
  18. const excelCheckIds = ref([])
  19. const excelCheckData = ref([]) //选中后的所有对象数组
  20. const funExcelChange = async (obj) => { //点击excel项时
  21. return false
  22. }
  23. const funExcelCheckChange = ({ checkArr, data }) => { //bug
  24. if(!checkArr.length){
  25. excelCheckIds.value = []
  26. excelCheckData.value = []
  27. }else{
  28. excelCheckIds.value = checkArr
  29. excelCheckData.value = data.filter(o => checkArr.includes(o.id))
  30. }
  31. funSubmit() // check 后进行操作
  32. }
  33. /**tree 开始 */
  34. const treeData = ref([])
  35. const actTreeNode = ref(null)
  36. const funRepeatMap = (arr) => {
  37. return arr.map(o => {
  38. if (o.children) {
  39. const findIndex = o.children.findIndex(p => !!p.path)
  40. if (findIndex !== -1) {
  41. o.childs = o.children
  42. o.children = []
  43. if(!actTreeNode.value){ //判断当且仅有process获取tree时 赋值
  44. actTreeNode.value = o
  45. }
  46. }
  47. }
  48. return {
  49. ...o,
  50. children: o.children?.length ? funRepeatMap(o.children) : []
  51. }
  52. })
  53. }
  54. const funGetTree = async () => {
  55. actTreeNode.value = null
  56. excelCheckIds.value = []
  57. excelCheckData.value = []
  58. const res = await request.get("/new/photovol/allfilelist")
  59. treeData.value = funRepeatMap(res.data)
  60. excelList.value = []
  61. if(actTreeNode.value){
  62. funCurrentChange({current: actTreeNode.value, currentNode: null})
  63. }
  64. }
  65. const funCurrentChange = ({ current, currentNode }) => {
  66. excelCheckIds.value = []
  67. excelCheckData.value = []
  68. if (current.childs) {
  69. excelList.value = current.childs.map(o => {
  70. return {
  71. id: o.path,
  72. interval: o.interval,
  73. path: o.path,
  74. station: o.station,
  75. time: o.time,
  76. type: o.type,
  77. windturbineId: o.windturbineId,
  78. name: o.path
  79. }
  80. })
  81. } else {
  82. excelList.value = []
  83. }
  84. }
  85. /**table 开始 */
  86. const tableShowId = ref('')
  87. const tableName = ref('')
  88. const tableColumn = ref([])
  89. const tableLoading = ref(false)
  90. const tableData = ref([])
  91. const funExport = async () => {
  92. const a = document.createElement('a')
  93. a.href = baseURL + '/power/prepare/download?id=' + tableShowId.value
  94. a.download = ''
  95. a.click()
  96. }
  97. /**tab */
  98. const activeTab = ref('1')
  99. /**chart Data */
  100. const xAxisData = ref([])
  101. const chartRef = ref() //chart 的ref
  102. const seriesData = ref([])
  103. const dataSet = ref('')
  104. const funChartSelect = async (batch) => {
  105. return false
  106. }
  107. /**submit */
  108. const funSubmit = async () => {
  109. if (!excelCheckIds.value.length) {
  110. ElMessage.error('请勾选要执行的项')
  111. return false
  112. }
  113. const params = {
  114. filelist: excelCheckIds.value.join()
  115. }
  116. tableShowId.value = '1'
  117. tableName.value = params.filelist
  118. tableLoading.value = true
  119. const res = await request.get('/new/photovol/analysis/powertimefile', { params })
  120. if(res.code !== 200){
  121. tableLoading.value = false
  122. return false
  123. }
  124. tableColumn.value = res.data.title.map(o => {
  125. return {
  126. prop: o.key,
  127. label: o.des,
  128. width: o.des==='时间'? 100: 80,
  129. }
  130. })
  131. const wtIds = excelCheckData.value.map(o => o.windturbineId)
  132. const xAxis = []
  133. const series = []
  134. if(!res.data.data || !wtIds.length){ tableLoading.value = false; return false}
  135. if (wtIds && wtIds.length>0) {
  136. for(const index in wtIds){
  137. const llgl = []
  138. const sjgl = []
  139. // console.log(wtIds[index],res.data.data[wtIds[index]])
  140. for(const o of res.data.data[wtIds[index]]){
  141. if(index === '0'){
  142. xAxis.push(o.datetime)
  143. }
  144. tableData.value.push(o)
  145. llgl.push(o.ideaP)
  146. sjgl.push(o.actualP)
  147. }
  148. series.push(
  149. {
  150. name: wtIds[index] + "\n实际功率",
  151. type: "line",
  152. symbol: "line", //设定为实心点
  153. symbolSize: 0, //设定实心点的大小
  154. smooth: false, //这个是把线变成曲线
  155. data: sjgl,
  156. xAxisIndex: 0,
  157. }
  158. )
  159. series.push(
  160. {
  161. name: wtIds[index] + "\n理论功率",
  162. type: "line",
  163. symbol: "line", //设定为实心点
  164. symbolSize: 0, //设定实心点的大小
  165. smooth: false, //这个是把线变成曲线
  166. data: llgl,
  167. xAxisIndex: 0,
  168. }
  169. )
  170. }
  171. }
  172. xAxisData.value = xAxis
  173. seriesData.value = series
  174. tableLoading.value = false
  175. activeTab.value = '2'
  176. }
  177. /**created */
  178. // funGetTree()
  179. /**mounted */
  180. onMounted(() => {
  181. tableHeight.value = window.innerHeight - 214 + 'px'
  182. excelHeight.value = window.innerHeight - 160 + 'px'
  183. treeHeight.value = window.innerHeight - 160 + 'px'
  184. window.addEventListener('resize', () => {
  185. tableHeight.value = window.innerHeight - 214 + 'px'
  186. excelHeight.value = window.innerHeight - 160 + 'px'
  187. treeHeight.value = window.innerHeight - 160 + 'px'
  188. })
  189. })
  190. /**activated */
  191. onActivated(() => {
  192. funGetTree()
  193. // funSubmit()
  194. })
  195. </script>
  196. <template>
  197. <div class="bg-white py-[10px] px-[10px] relative">
  198. <!-- <search-cop class="mb-[20px] shadow rounded-[6px] shadow-blue-500" @submit="funSubmit">
  199. </search-cop> -->
  200. <div class="relative shadow rounded-[6px] shadow-blue-500 px-[10px] pt-[20px] pb-[10px]">
  201. <div class="text-[14px] absolute top-[-7px] text-[#838383] left-[20px]">数据展示</div>
  202. <el-row :gutter="10">
  203. <el-col :span="4">
  204. <tree-cop :data="treeData" type="light" :height="treeHeight" @currentChange="funCurrentChange" @refresh="funGetTree">
  205. </tree-cop>
  206. </el-col>
  207. <el-col :span="4">
  208. <excel-cop :data="excelList" :checkIds="excelCheckIds" :height="excelHeight" showCheckbox @excelChange="funExcelChange" @checkChange="funExcelCheckChange"></excel-cop>
  209. </el-col>
  210. <el-col :span="16">
  211. <div class="px-[10px] shadow rounded-[6px] shadow-blue-500 ">
  212. <el-tabs v-model="activeTab">
  213. <el-tab-pane label="表格数据" name="1">
  214. </el-tab-pane>
  215. <el-tab-pane label="图表展示" name="2">
  216. </el-tab-pane>
  217. <table-cop v-show="activeTab === '1'" :data="tableData" :loading="tableLoading" :column="tableColumn"
  218. :height="tableHeight" :tableId="tableShowId" :tableName="tableName"></table-cop>
  219. <div v-show="activeTab === '2'"
  220. :style="{ height: typeof tableHeight === 'string' ? tableHeight : tableHeight + 'px' }"
  221. class="p-[10px]">
  222. <CurrentScatterChart ref="chartRef" width="100%" :height="`calc( ${tableHeight} - 20px )`" :chartTitle="''"
  223. :xAxisData="xAxisData" :seriesData="seriesData"
  224. :showLegend="true" :brushSelected="false" :dataSet="dataSet" @getSelected="funChartSelect" />
  225. </div>
  226. </el-tabs>
  227. </div>
  228. </el-col>
  229. </el-row>
  230. </div>
  231. </div>
  232. </template>