index.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  1. <template>
  2. <div class="system-monitor-container">
  3. <!-- 左侧导航树 -->
  4. <el-card class="tree-card">
  5. <h3>系统层级</h3>
  6. <el-tree
  7. :data="systemTree"
  8. node-key="id"
  9. default-expand-all
  10. highlight-current
  11. @node-click="handleNodeClick"
  12. >
  13. <template #default="{ node, data }">
  14. <span class="custom-tree-node">
  15. <span>{{ node.label }}</span>
  16. <el-tag v-if="data.type === 'system'" size="small" type="primary">系统</el-tag>
  17. <el-tag v-if="data.type === 'subsystem'" size="small" type="success">子系统</el-tag>
  18. </span>
  19. </template>
  20. </el-tree>
  21. </el-card>
  22. <!-- 右侧监控展示 -->
  23. <el-card class="monitor-card">
  24. <h3>监控组态图</h3>
  25. <div class="config-info" v-if="currentSystem.config">
  26. <h4>组态配置</h4>
  27. <pre>{{ currentSystem.config }}</pre>
  28. <el-button type="primary" @click="editConfig">编辑配置</el-button>
  29. </div>
  30. <div class="chart-container" v-if="currentSystem.data">
  31. <h4>实时监控数据</h4>
  32. <div ref="chart" class="chart"></div>
  33. </div>
  34. </el-card>
  35. <!-- 组态编辑对话框 -->
  36. <el-dialog v-model="dialogVisible" title="编辑组态配置" width="50%">
  37. <el-form :model="configForm" label-width="120px">
  38. <el-form-item label="设备列表">
  39. <el-input v-model="configForm.devices" placeholder="逗号分隔的设备列表" />
  40. </el-form-item>
  41. <el-form-item label="布局">
  42. <el-select v-model="configForm.layout" placeholder="选择布局">
  43. <el-option label="网格" value="grid" />
  44. <el-option label="列表" value="list" />
  45. <el-option label="自定义" value="custom" />
  46. </el-select>
  47. </el-form-item>
  48. </el-form>
  49. <template #footer>
  50. <span class="dialog-footer">
  51. <el-button @click="dialogVisible = false">取消</el-button>
  52. <el-button type="primary" @click="saveConfig">保存</el-button>
  53. </span>
  54. </template>
  55. </el-dialog>
  56. </div>
  57. </template>
  58. <script setup>
  59. import { ref, onMounted, nextTick } from 'vue'
  60. import * as echarts from 'echarts'
  61. import { ElMessage } from 'element-plus'
  62. // 模拟系统层级数据
  63. const systemTree = ref([
  64. {
  65. id: 'sys1',
  66. label: '暖通空调系统',
  67. type: 'system',
  68. children: [
  69. { id: 'subsys1', label: '空调机组', type: 'subsystem' },
  70. { id: 'subsys2', label: '末端设备', type: 'subsystem' }
  71. ]
  72. },
  73. {
  74. id: 'sys2',
  75. label: '新风系统',
  76. type: 'system',
  77. children: [
  78. { id: 'subsys3', label: '新风机', type: 'subsystem' },
  79. { id: 'subsys4', label: '空气过滤器', type: 'subsystem' }
  80. ]
  81. },
  82. {
  83. id: 'sys3',
  84. label: '制冷机房',
  85. type: 'system',
  86. children: [
  87. { id: 'subsys5', label: '冷水机组', type: 'subsystem' },
  88. { id: 'subsys6', label: '冷却塔', type: 'subsystem' }
  89. ]
  90. },
  91. {
  92. id: 'sys4',
  93. label: '水系统',
  94. type: 'system',
  95. children: [
  96. { id: 'subsys7', label: '水泵', type: 'subsystem' },
  97. { id: 'subsys8', label: '水箱', type: 'subsystem' }
  98. ]
  99. },
  100. {
  101. id: 'sys5',
  102. label: '电梯系统',
  103. type: 'system',
  104. children: [
  105. { id: 'subsys9', label: '电梯A', type: 'subsystem' },
  106. { id: 'subsys10', label: '电梯B', type: 'subsystem' }
  107. ]
  108. },
  109. {
  110. id: 'sys6',
  111. label: '配电系统',
  112. type: 'system',
  113. children: [
  114. { id: 'subsys11', label: '配电柜', type: 'subsystem' },
  115. { id: 'subsys12', label: '断路器', type: 'subsystem' }
  116. ]
  117. },
  118. {
  119. id: 'sys7',
  120. label: '照明系统',
  121. type: 'system',
  122. children: [
  123. { id: 'subsys13', label: '照明A', type: 'subsystem' },
  124. { id: 'subsys14', label: '照明B', type: 'subsystem' }
  125. ]
  126. }
  127. ])
  128. // 当前选中的系统
  129. const currentSystem = ref({
  130. config: null,
  131. data: null
  132. })
  133. // 组态配置映射(模拟数据)
  134. const systemConfigMap = {
  135. 'subsys1': {
  136. config: { devices: ['ac_unit1', 'fan1'], layout: 'grid' },
  137. data: {
  138. temperature: [22, 23, 21, 24, 22, 23, 21],
  139. humidity: [45, 50, 55, 48, 49, 47, 50]
  140. }
  141. },
  142. 'subsys2': {
  143. config: { devices: ['end_device1', 'end_device2'], layout: 'list' },
  144. data: {
  145. temperature: [20, 21, 22, 20, 21, 22, 20],
  146. humidity: [55, 60, 65, 62, 63, 61, 64]
  147. }
  148. },
  149. 'subsys3': {
  150. config: { devices: ['ventilator1', 'filter1'], layout: 'custom' },
  151. data: {
  152. airflow: [100, 110, 120, 105, 115, 125, 110]
  153. }
  154. },
  155. 'subsys4': {
  156. config: { devices: ['filter2', 'filter3'], layout: 'grid' },
  157. data: {
  158. airflow: [90, 95, 100, 92, 97, 102, 95]
  159. }
  160. },
  161. 'subsys5': {
  162. config: { devices: ['chiller1', 'chiller2'], layout: 'list' },
  163. data: {
  164. temperature: [18, 19, 17, 18, 19, 17, 18]
  165. }
  166. },
  167. 'subsys6': {
  168. config: { devices: ['cooling_tower1', 'cooling_tower2'], layout: 'custom' },
  169. data: {
  170. temperature: [25, 26, 24, 25, 26, 24, 25]
  171. }
  172. },
  173. 'subsys7': {
  174. config: { devices: ['pump1', 'pump2'], layout: 'grid' },
  175. data: {
  176. flow_rate: [50, 55, 60, 52, 57, 62, 55]
  177. }
  178. },
  179. 'subsys8': {
  180. config: { devices: ['tank1', 'tank2'], layout: 'list' },
  181. data: {
  182. water_level: [80, 85, 90, 82, 87, 92, 85]
  183. }
  184. },
  185. 'subsys9': {
  186. config: { devices: ['elevator_a1', 'elevator_a2'], layout: 'custom' },
  187. data: {
  188. status: ['正常', '正常', '正常', '正常', '正常', '正常', '正常']
  189. }
  190. },
  191. 'subsys10': {
  192. config: { devices: ['elevator_b1', 'elevator_b2'], layout: 'grid' },
  193. data: {
  194. status: ['正常', '正常', '正常', '正常', '正常', '正常', '正常']
  195. }
  196. },
  197. 'subsys11': {
  198. config: { devices: ['switchboard1', 'switchboard2'], layout: 'list' },
  199. data: {
  200. voltage: [220, 225, 230, 222, 227, 232, 225]
  201. }
  202. },
  203. 'subsys12': {
  204. config: { devices: ['breaker1', 'breaker2'], layout: 'custom' },
  205. data: {
  206. current: [10, 12, 11, 10, 12, 11, 10]
  207. }
  208. },
  209. 'subsys13': {
  210. config: { devices: ['light_a1', 'light_a2'], layout: 'grid' },
  211. data: {
  212. power_usage: [50, 55, 60, 52, 57, 62, 55]
  213. }
  214. },
  215. 'subsys14': {
  216. config: { devices: ['light_b1', 'light_b2'], layout: 'list' },
  217. data: {
  218. power_usage: [40, 45, 50, 42, 47, 52, 45]
  219. }
  220. }
  221. }
  222. // 组态编辑对话框显示控制
  223. const dialogVisible = ref(false)
  224. // 当前编辑的配置
  225. const configForm = ref({
  226. devices: '',
  227. layout: ''
  228. })
  229. // ECharts 实例
  230. const chart = ref(null)
  231. let chartInstance = null
  232. // 处理树节点点击事件
  233. const handleNodeClick = (data) => {
  234. if (data.type === 'subsystem') {
  235. // 加载对应子系统的组态配置和监控数据
  236. const systemData = systemConfigMap[data.id]
  237. if (systemData) {
  238. currentSystem.value = systemData
  239. configForm.value.devices = systemData.config.devices.join(', ')
  240. configForm.value.layout = systemData.config.layout
  241. nextTick(() => {
  242. initChart(systemData.data)
  243. })
  244. } else {
  245. currentSystem.value = { config: null, data: null }
  246. }
  247. } else {
  248. // 如果是系统节点,清空监控数据
  249. currentSystem.value = { config: null, data: null }
  250. }
  251. }
  252. // 初始化 ECharts 图表
  253. const initChart = (data) => {
  254. if (chartInstance) {
  255. chartInstance.dispose()
  256. }
  257. chartInstance = echarts.init(chart.value)
  258. const option = {
  259. tooltip: {
  260. trigger: 'axis'
  261. },
  262. legend: {
  263. data: Object.keys(data)
  264. },
  265. xAxis: {
  266. type: 'category',
  267. data: ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
  268. },
  269. yAxis: {
  270. type: 'value'
  271. },
  272. series: Object.keys(data).map(key => ({
  273. name: key,
  274. type: 'line',
  275. data: data[key]
  276. }))
  277. }
  278. chartInstance.setOption(option)
  279. }
  280. // 编辑配置
  281. const editConfig = () => {
  282. if (currentSystem.value.config) {
  283. dialogVisible.value = true
  284. } else {
  285. ElMessage.warning('请先选择一个子系统以编辑配置')
  286. }
  287. }
  288. // 保存配置
  289. const saveConfig = () => {
  290. if (currentSystem.value.config) {
  291. currentSystem.value.config.devices = configForm.value.devices.split(',').map(device => device.trim())
  292. currentSystem.value.config.layout = configForm.value.layout
  293. ElMessage.success('配置保存成功')
  294. dialogVisible.value = false
  295. }
  296. }
  297. // 页面加载时初始化图表
  298. onMounted(() => {
  299. // 可以在这里加载默认的子系统数据
  300. // 例如:handleNodeClick(systemTree.value[0].children[0])
  301. })
  302. </script>
  303. <style scoped lang="scss">
  304. .system-monitor-container {
  305. display: flex;
  306. height: 100vh;
  307. padding: 20px;
  308. .tree-card {
  309. width: 300px;
  310. margin-right: 20px;
  311. h3 {
  312. margin-bottom: 10px;
  313. font-size: 18px;
  314. color: #333;
  315. }
  316. .custom-tree-node {
  317. display: flex;
  318. justify-content: space-between;
  319. align-items: center;
  320. width: 100%;
  321. }
  322. }
  323. .monitor-card {
  324. flex: 1;
  325. h3 {
  326. margin-bottom: 10px;
  327. font-size: 18px;
  328. color: #333;
  329. }
  330. .config-info {
  331. pre {
  332. background-color: #f5f5f5;
  333. padding: 10px;
  334. border-radius: 5px;
  335. font-size: 14px;
  336. overflow-x: auto;
  337. }
  338. .el-button {
  339. margin-top: 10px;
  340. }
  341. }
  342. .chart-container {
  343. margin-top: 20px;
  344. .chart {
  345. width: 100%;
  346. height: 400px;
  347. }
  348. }
  349. }
  350. }
  351. </style>