index.vue 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  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 - 314 + 'px')
  14. const treeHeight = ref(window.innerHeight - 260 + 'px') //tree高度
  15. const excelHeight = ref(window.innerHeight - 260 + 'px') //excel高度
  16. /**excel 开始 */
  17. const excelList = ref([])
  18. const funExcelChange = async (obj) => { //点击excel项时
  19. activeTab.value = '1'
  20. tableShowId.value = obj.id
  21. tableName.value = obj.name
  22. tableLoading.value = true
  23. const res = await request.get('/power/prepare/show', { params: { id: obj.id } })
  24. if(res.code === 200){
  25. tableColumn.value = res.data.title.map(o => {
  26. return {
  27. prop: o.key,
  28. label: o.des,
  29. width: o.des==='时间'? 100: 80,
  30. }
  31. })
  32. tableData.value = res.data.data
  33. tableLoading.value = false
  34. }else{
  35. tableLoading.value = false
  36. }
  37. }
  38. /**tree 开始 */
  39. const treeData = ref([])
  40. const funRepeatMap = (arr) => {
  41. return arr.map(o => {
  42. if (o.children) {
  43. const findIndex = o.children.findIndex(p => !!p.type)
  44. if (findIndex !== -1) {
  45. o.childs = o.children
  46. o.children = []
  47. }
  48. }
  49. return {
  50. ...o,
  51. children: o.children?.length ? funRepeatMap(o.children) : []
  52. }
  53. })
  54. }
  55. const funGetTree = async () => {
  56. const res = await request.get("/power/prepare/tree")
  57. treeData.value = funRepeatMap(res.data)
  58. excelList.value = []
  59. }
  60. const funCurrentChange = ({ current, currentNode }) => {
  61. if (current.childs) {
  62. excelList.value = current.childs.map(o => {
  63. return {
  64. id: o.id,
  65. interval: o.interval,
  66. path: o.path,
  67. prepareid: o.prepareid,
  68. station: o.station,
  69. time: o.time,
  70. type: o.type,
  71. windturbine: o.windturbine,
  72. name: o.path.substring(o.path.indexOf(o.station + '_') + (o.station + '_').length)
  73. }
  74. })
  75. } else {
  76. excelList.value = []
  77. }
  78. }
  79. /**table 开始 */
  80. const tableShowId = ref('')
  81. const tableName = ref('')
  82. const tableColumn = ref([])
  83. const tableLoading = ref(false)
  84. const tableData = ref([])
  85. const funExport = async () => {
  86. const a = document.createElement('a')
  87. a.href = baseURL + '/power/prepare/download?id=' + tableShowId.value
  88. a.download = ''
  89. a.click()
  90. }
  91. /**tab */
  92. const activeTab = ref('1')
  93. /**chart Data */
  94. const xAxisData = ref([])
  95. const chartRef = ref() //chart 的ref
  96. const seriesData = ref([])
  97. const dataSet = ref('')
  98. const funChartSelect = async (batch) => {
  99. return false
  100. }
  101. /**submit */
  102. const funSubmit = async (params) => {
  103. activeTab.value = '2'
  104. tableShowId.value = 1
  105. tableName.value = ''
  106. tableLoading.value = true
  107. const res = await request.get('/agc/deviate', { params: params })
  108. tableColumn.value = [
  109. {
  110. prop: 'ts',
  111. label: '时间',
  112. width: 100,
  113. },
  114. {
  115. prop: 'ygsdxz',
  116. label: '有功设定限值',
  117. width: 80,
  118. },
  119. {
  120. prop: 'sfyg',
  121. label: '实发有功',
  122. width: 80,
  123. },
  124. {
  125. prop: 'llgl',
  126. label: '理论功率',
  127. width: 80,
  128. },
  129. {
  130. prop: 'pcsx',
  131. label: '偏差上限',
  132. width: 80,
  133. },
  134. {
  135. prop: 'pcxx',
  136. label: '偏差下限',
  137. width: 100,
  138. },
  139. ]
  140. const tableArr = []
  141. const tsArr = []
  142. const ygsdxz = []
  143. const sfyg = []
  144. const llgl = []
  145. const pcsx = []
  146. const pcxx = []
  147. res['有功设定限值'].values.map((o, index) => {
  148. tsArr.push(dayjs(o.ts).format('YYYY-MM-DD HH:mm:ss'))
  149. ygsdxz.push(Number(o.value).toFixed(2))
  150. sfyg.push(Number(res['实发有功'].values[index].value).toFixed(2))
  151. llgl.push(Number(res['理论功率'].values[index].value).toFixed(2))
  152. pcsx.push(Number(res['偏差上限'].values[index].value).toFixed(2))
  153. pcxx.push(Number(res['偏差下限'].values[index].value).toFixed(2))
  154. tableArr.push({
  155. ts: dayjs(o.ts).format('YYYY-MM-DD HH:mm:ss'),
  156. ygsdxz: Number(o.value).toFixed(2),
  157. sfyg: Number(res['实发有功'].values[index].value).toFixed(2),
  158. llgl: Number(res['理论功率'].values[index].value).toFixed(2),
  159. pcsx: Number(res['偏差上限'].values[index].value).toFixed(2),
  160. pcxx: Number(res['偏差下限'].values[index].value).toFixed(2),
  161. })
  162. })
  163. xAxisData.value = tableArr.map(o => o.ts)
  164. seriesData.value = [
  165. {
  166. name: "有功设定限值",
  167. type: "line",
  168. symbol: "line", //设定为实心点
  169. symbolSize: 0, //设定实心点的大小
  170. smooth: false, //这个是把线变成曲线
  171. data: ygsdxz,
  172. xAxisIndex: 0,
  173. },
  174. {
  175. name: "实发有功",
  176. type: "line",
  177. symbol: "line", //设定为实心点
  178. symbolSize: 0, //设定实心点的大小
  179. smooth: false, //这个是把线变成曲线
  180. data: sfyg,
  181. xAxisIndex: 0,
  182. },
  183. {
  184. name: "理论功率",
  185. type: "line",
  186. symbol: "line", //设定为实心点
  187. symbolSize: 0, //设定实心点的大小
  188. smooth: false, //这个是把线变成曲线
  189. data: llgl,
  190. xAxisIndex: 0,
  191. },
  192. {
  193. name: "偏差上限",
  194. type: "line",
  195. symbol: "line", //设定为实心点
  196. symbolSize: 0, //设定实心点的大小
  197. smooth: false, //这个是把线变成曲线
  198. data: pcsx,
  199. xAxisIndex: 0,
  200. lineStyle: {
  201. opacity: 0
  202. },
  203. areaStyle: {
  204. color: '#ccc',
  205. },
  206. symbol: 'none'
  207. },
  208. {
  209. name: "偏差下限",
  210. type: "line",
  211. symbol: "line", //设定为实心点
  212. symbolSize: 0, //设定实心点的大小
  213. smooth: false, //这个是把线变成曲线
  214. data: pcxx,
  215. xAxisIndex: 0,
  216. lineStyle: {
  217. opacity: 0
  218. },
  219. areaStyle: {
  220. color: '#fff',
  221. opacity: 1
  222. },
  223. symbol: 'none'
  224. },
  225. ]
  226. tableData.value = tableArr
  227. tableLoading.value = false
  228. // if (res.code === 200) {
  229. // if(res.data.sjgl?.length){
  230. // for(const wtObj of res.data.sjgl){
  231. // seriesData.value.push(
  232. // {
  233. // name: wtObj.obj.windturbine + "\n实际功率",
  234. // type: "line",
  235. // symbol: "line", //设定为实心点
  236. // symbolSize: 0, //设定实心点的大小
  237. // smooth: true, //这个是把线变成曲线
  238. // data: wtObj.sjgl || [],
  239. // xAxisIndex: 0,
  240. // },
  241. // )
  242. // wtData.value.push(wtObj.obj)
  243. // }
  244. // }
  245. // }
  246. }
  247. /**created */
  248. // funGetTree()
  249. /**mounted */
  250. onMounted(() => {
  251. tableHeight.value = window.innerHeight - 314 + 'px'
  252. excelHeight.value = window.innerHeight - 260 + 'px'
  253. treeHeight.value = window.innerHeight - 260 + 'px'
  254. window.addEventListener('resize', () => {
  255. tableHeight.value = window.innerHeight - 314 + 'px'
  256. excelHeight.value = window.innerHeight - 260 + 'px'
  257. treeHeight.value = window.innerHeight - 260 + 'px'
  258. })
  259. })
  260. /**activated */
  261. onActivated(() => {
  262. // funGetTree()
  263. // funSubmit()
  264. })
  265. </script>
  266. <template>
  267. <div class="bg-white py-[10px] px-[10px] relative">
  268. <search-cop class="mb-[20px] shadow rounded-[6px] shadow-blue-500" @submit="funSubmit">
  269. </search-cop>
  270. <div class="relative shadow rounded-[6px] shadow-blue-500 px-[10px] pt-[20px] pb-[10px]">
  271. <div class="text-[14px] absolute top-[-7px] text-[#838383] left-[20px]">数据展示</div>
  272. <el-row :gutter="10">
  273. <!-- <el-col :span="5">
  274. <tree-cop :data="treeData" :height="treeHeight" @currentChange="funCurrentChange" @refresh="funGetTree">
  275. </tree-cop>
  276. </el-col>
  277. <el-col :span="3">
  278. <excel-cop :data="excelList" :height="excelHeight" @excelChange="funExcelChange"></excel-cop>
  279. </el-col> -->
  280. <el-col :span="24">
  281. <div class="px-[10px] shadow rounded-[6px] shadow-blue-500 ">
  282. <el-tabs v-model="activeTab">
  283. <el-tab-pane label="表格数据" name="1">
  284. </el-tab-pane>
  285. <el-tab-pane label="图表展示" name="2">
  286. </el-tab-pane>
  287. <table-cop v-show="activeTab === '1'" :data="tableData" :loading="tableLoading" :column="tableColumn"
  288. :height="tableHeight" :tableId="tableShowId" :tableName="tableName"></table-cop>
  289. <div v-show="activeTab === '2'"
  290. :style="{ height: typeof tableHeight === 'string' ? tableHeight : tableHeight + 'px' }"
  291. class="p-[10px]">
  292. <CurrentScatterChart ref="chartRef" width="100%" :height="`calc( ${tableHeight} - 20px )`" :chartTitle="''"
  293. :xAxisData="xAxisData" :yAxisData="{ splitLine: { show: false } }" :seriesData="seriesData"
  294. :showLegend="true" :brushSelected="false" :dataSet="dataSet" @getSelected="funChartSelect" />
  295. </div>
  296. </el-tabs>
  297. </div>
  298. </el-col>
  299. </el-row>
  300. </div>
  301. </div>
  302. </template>