index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548
  1. <template>
  2. <div class="app-container page-nesting" style="position: relative">
  3. <!-- 树形组件start -->
  4. <div class="grid-content treeDom">
  5. <div style="text-align: center" class="mb-20">
  6. <el-button
  7. v-if="treeLevel == 3 || groupingId == 0 || treeLevel == 1"
  8. disabled
  9. >
  10. 添加分组
  11. </el-button>
  12. <el-button v-else type="primary" @click="addGroup()">
  13. 添加分组
  14. </el-button>
  15. <el-button
  16. v-if="treeLevel == 3 || groupingId == 0 || treeLevel == 1"
  17. disabled
  18. >
  19. 添加站点
  20. </el-button>
  21. <el-button v-else type="primary" @click="addSite()">添加站点</el-button>
  22. </div>
  23. <el-input
  24. placeholder="输入关键字进行过滤"
  25. v-model="filterText"
  26. class="mb-20 searchInput"
  27. >
  28. <template>
  29. <i class="el-icon-search el-input__icon"></i>
  30. </template>
  31. </el-input>
  32. <!-- <el-scrollbar> -->
  33. <!-- <el-tree
  34. :data="data2"
  35. show-checkbox
  36. node-key="id"
  37. :default-expanded-keys="[1]"
  38. :default-checked-keys="[368]"
  39. :props="defaultProps2"
  40. /> -->
  41. <el-tree
  42. class="filter-tree siteTree"
  43. ref="tree"
  44. :data="data"
  45. node-key="id"
  46. :props="defaultProps"
  47. :filter-node-method="filterNode"
  48. @node-click="handleNodeClick"
  49. :expand-on-click-node="false"
  50. :highlight-current="showTree"
  51. default-expand-all
  52. :current-node-key="defaultExpand"
  53. >
  54. <template #default="{ node, data }">
  55. <span
  56. class="custom-tree-node"
  57. style="width: 100%"
  58. @mouseenter="mouseenter(data)"
  59. @mouseleave="mouseleave(data)"
  60. >
  61. <span>{{ node.label }}</span>
  62. <!-- <el-tooltip
  63. class="item"
  64. effect="dark"
  65. :content="node.label"
  66. placement="top-start"
  67. >
  68. <span>{{ node.label }}</span>
  69. </el-tooltip> -->
  70. <span>
  71. <a
  72. class="deleteLink"
  73. v-show="data.show"
  74. @click="remove(node, data)"
  75. >
  76. <!-- <i size="mini" class="el-icon-delete"></i> -->
  77. </a>
  78. </span>
  79. </span>
  80. </template>
  81. </el-tree>
  82. <!-- </el-scrollbar> -->
  83. </div>
  84. <!-- 树形组件end -->
  85. <!-- 站点主题start -->
  86. <div
  87. class="grid-content nestingDom"
  88. style="width: calc(100% - 300px)"
  89. v-if="flag2 && treeLevel != 1"
  90. >
  91. <el-tabs
  92. v-if="treeLevel == 3 || groupingId == 0"
  93. v-model="activeName"
  94. type="card"
  95. >
  96. <el-tab-pane label="基本信息" name="first">
  97. <basic-info
  98. class="basicInfo"
  99. :siteId="siteId"
  100. :groupingId="groupingId"
  101. :siteName="siteName"
  102. @func="getMsgFormSon3"
  103. :activeName="activeName"
  104. ></basic-info>
  105. </el-tab-pane>
  106. <el-tab-pane label="监控设备" name="second">
  107. <watch-dog
  108. v-on:success="success(res)"
  109. :activeName="activeName"
  110. @func="getMsgFormSon"
  111. :siteId="siteId"
  112. ></watch-dog>
  113. </el-tab-pane>
  114. <el-tab-pane label="变量列表" name="third">
  115. <variable-list
  116. :activeName="activeName"
  117. :siteId="siteId"
  118. ></variable-list>
  119. </el-tab-pane>
  120. <el-tab-pane label="摄像头" name="five">
  121. <camera :siteId="siteId" :activeName="activeName"></camera>
  122. </el-tab-pane>
  123. <el-tab-pane label="电能质量评分配置" name="six">
  124. <power-Score :siteId="siteId" :activeName="activeName"></power-Score>
  125. </el-tab-pane>
  126. </el-tabs>
  127. <!-- 分组信息start -->
  128. <group-info-com
  129. :groupingId="groupingId"
  130. :label="label"
  131. @func="getMsgFormSon2"
  132. v-else
  133. ></group-info-com>
  134. <!-- 分组信息end -->
  135. <!-- 新建分组start -->
  136. <add-group-com
  137. :dialogTitle="dialogTitle"
  138. :itemInfo="tableItem"
  139. @closeDialog="closeDialog('默认关闭')"
  140. :flag="showDialog"
  141. ></add-group-com>
  142. <!-- 新建分组end -->
  143. <!-- 新建站点start -->
  144. <add-site-com
  145. :dialogTitle="dialogTitle"
  146. :itemInfo="tableItem"
  147. :groupingId="groupingId"
  148. @closeDialog="closeDialog"
  149. :flag="showDialog2"
  150. @changeFather="getFromSon"
  151. ></add-site-com>
  152. <!-- 新建站点end -->
  153. </div>
  154. <!-- 站点主题end -->
  155. </div>
  156. </template>
  157. <script>
  158. import { defineComponent, ref, reactive, watch, onMounted, nextTick } from 'vue'
  159. import basicInfo from './basicInfo'
  160. import WatchDog from './watchDog'
  161. import variableList from './variableList'
  162. import camera from './camera'
  163. import PowerScore from './powerScore'
  164. import groupInfoCom from './groupInfoCom'
  165. import addGroupCom from './addGroupCom'
  166. import addSiteCom from './addSiteCom'
  167. import * as api from '@/api/siteManage/index'
  168. import { ElMessage } from 'element-plus'
  169. import { useStore } from 'vuex'
  170. import { useRoute } from 'vue-router'
  171. export default defineComponent({
  172. components: {
  173. basicInfo,
  174. WatchDog,
  175. variableList,
  176. camera,
  177. PowerScore,
  178. groupInfoCom,
  179. addGroupCom,
  180. addSiteCom,
  181. },
  182. setup() {
  183. const store = useStore()
  184. const flag2 = ref(false)
  185. const tree = ref(null)
  186. const showTree = ref(true)
  187. const defaultExpand = ref(0)
  188. const showDialog = ref(false)
  189. const showDialog2 = ref(false)
  190. const dialogTitle = ref('')
  191. const treeLevel = ref(3)
  192. const groupingId = ref(1)
  193. const siteId = ref(0)
  194. const labelCom = ref('')
  195. const siteName = ref('')
  196. const label = ref('')
  197. const activeName = ref('first')
  198. const filterText = ref('')
  199. const selectNode = ref(0)
  200. const route = useRoute()
  201. let num = route.query.num
  202. const data = ref([
  203. {
  204. label: '所有站点',
  205. children: [],
  206. },
  207. ])
  208. // const data2 = ref([
  209. // {
  210. // grouping_id: 1,
  211. // id: 1,
  212. // label: '所有站点',
  213. // children: [
  214. // {
  215. // id: 1,
  216. // label: '分组测试1',
  217. // grouping_id: 1,
  218. // children: [
  219. // {
  220. // id: 368,
  221. // label: '测试站点89',
  222. // },
  223. // {
  224. // id: 367,
  225. // label: '测试站点88',
  226. // },
  227. // ],
  228. // },
  229. // {
  230. // grouping_id: 0,
  231. // id: 5,
  232. // label: '中国铁路上海...',
  233. // },
  234. // {
  235. // grouping_id: 0,
  236. // id: 5,
  237. // label: '上海拓石...',
  238. // },
  239. // ],
  240. // },
  241. // ])
  242. // const defaultProps2 = ref({
  243. // children: 'children',
  244. // label: 'label',
  245. // })
  246. const defaultProps = ref({
  247. children: 'children',
  248. label: 'label',
  249. })
  250. const getMsgFormSon = () => {
  251. activeName.value = 'third'
  252. }
  253. const getMsgFormSon2 = () => {
  254. siteTreeList()
  255. setTimeout(() => {
  256. treeLevel.value = 1
  257. }, 1000)
  258. }
  259. //站点基本信息保存后触发
  260. const getMsgFormSon3 = (data) => {
  261. siteTreeList()
  262. setTimeout(() => {
  263. tree.value.setCurrentKey(selectNode.value)
  264. }, 1000)
  265. if (data == 0) {
  266. setTimeout(() => {
  267. treeLevel.value = 1
  268. }, 1000)
  269. }
  270. }
  271. function mouseenter(data) {
  272. data.show = true
  273. }
  274. function mouseleave(data) {
  275. data.show = false
  276. }
  277. const handleNodeClick = (data, obj, node) => {
  278. activeName.value = 'first'
  279. data, node
  280. flag2.value = true
  281. treeLevel.value = obj.level
  282. groupingId.value = obj.data.grouping_id
  283. label.value = obj.data.label
  284. // console.log('obj.data')
  285. // console.log(obj.data.id)
  286. selectNode.value = obj.data.id
  287. labelCom.value = obj.data.label
  288. store.state.siteManageLabelCom = obj.data.label
  289. store.state.basicInfoSiteName = ''
  290. if (treeLevel.value == 3) {
  291. siteId.value = obj.data.id
  292. }
  293. if (treeLevel.value == 2 && groupingId.value == 0) {
  294. // console.log(obj.data)
  295. siteId.value = obj.data.id
  296. }
  297. }
  298. function filterNode(value, data) {
  299. if (!value) return true
  300. return data.label.indexOf(value) !== -1
  301. }
  302. // 异步任务 用于给tree传值
  303. const writeValue = (val) => {
  304. return tree.value.filter(val)
  305. }
  306. // 定义 watch 监听
  307. watch(
  308. filterText,
  309. (newCount, old, clear) => {
  310. // 执行异步任务,并得到关闭异步任务的 id
  311. let id = writeValue(newCount, old)
  312. // 如果 watch 监听被重复执行了,则会先清除上次未完成的异步任务
  313. clear(() => clearTimeout(id))
  314. },
  315. // watch 刚被创建的时候不执行
  316. { lazy: true }
  317. )
  318. watch(
  319. activeName,
  320. (newCount, old, clear) => {
  321. newCount, old, clear
  322. // 清除定时器
  323. clear(() => clearTimeout(store.state.siteCameraTimer))
  324. },
  325. // watch 刚被创建的时候不执行
  326. { lazy: true }
  327. )
  328. // 新建分组关闭操作
  329. const closeDialog = (res) => {
  330. if (store.state.basicInfoConst == 1 && res == '默认关闭') {
  331. showDialog.value = false
  332. showDialog2.value = false
  333. siteTreeList()
  334. flag2.value = false
  335. treeLevel.value = 3
  336. } else if (store.state.basicInfoConst == 1) {
  337. showDialog.value = false
  338. showDialog2.value = false
  339. }
  340. }
  341. const getFromSon = (param, param2, param3) => {
  342. // alert('保存后关闭')
  343. siteId.value = param2
  344. siteName.value = param
  345. groupingId.value = param3
  346. flag2.value = true
  347. treeLevel.value = 3
  348. }
  349. //新建分组
  350. const tableItem = reactive([])
  351. const addGroup = () => {
  352. tableItem.value = {
  353. groupingName: '',
  354. }
  355. dialogTitle.value = '新建分组'
  356. showDialog.value = true
  357. }
  358. //新建站点
  359. const addSite = () => {
  360. tableItem.value = {
  361. id: '',
  362. stationName: '',
  363. xh: '',
  364. userName: '',
  365. list: [],
  366. done: '',
  367. guaZai: '',
  368. checked: true,
  369. }
  370. dialogTitle.value = '新建站点'
  371. showDialog2.value = true
  372. }
  373. const remove = (node, data) => {
  374. const parent = node.parent
  375. const children = parent.data.children || parent.data
  376. const index = children.findIndex((d) => d.id === data.id)
  377. children.splice(index, 1)
  378. this.dataSource = [...this.dataSource]
  379. }
  380. //左侧树结构列表
  381. function siteTreeList() {
  382. api.siteTreeList({}).then((requset) => {
  383. if (requset.status === 'SUCCESS') {
  384. var jsona = JSON.stringify(requset.data)
  385. var jsonb = jsona.replace(/"grouping_name"/g, '"label"')
  386. jsonb = jsonb.replace(/"site_list"/g, '"children"')
  387. jsonb = jsonb.replace(/"site_name"/g, '"label"')
  388. jsonb = jsonb.replace(/"site_id"/g, '"id"')
  389. var jsonc = JSON.parse(jsonb)
  390. data.value[0].children = jsonc
  391. if (route.query.activeName && route.query.siteId) {
  392. setTimeout(() => {
  393. tree.value.setCurrentKey(route.query.siteId)
  394. }, 1000)
  395. flag2.value = true
  396. treeLevel.value = 3
  397. activeName.value = route.query.activeName
  398. siteId.value = route.query.siteId
  399. var bb = []
  400. jsonc.forEach(function (item) {
  401. if (item.id == siteId.value) {
  402. bb.push(item)
  403. }
  404. })
  405. store.state.siteManageLabelCom = bb[0].label
  406. }
  407. } else {
  408. ElMessage.error(requset.msg)
  409. }
  410. })
  411. }
  412. onMounted(() => {
  413. siteTreeList()
  414. })
  415. nextTick(() => {})
  416. return {
  417. showDialog,
  418. showDialog2,
  419. treeLevel,
  420. activeName,
  421. filterText,
  422. dialogTitle,
  423. data,
  424. defaultProps,
  425. tableItem,
  426. groupingId,
  427. siteId,
  428. labelCom,
  429. label,
  430. flag2,
  431. showTree,
  432. tree,
  433. getFromSon,
  434. siteName,
  435. defaultExpand,
  436. getMsgFormSon,
  437. getMsgFormSon2,
  438. getMsgFormSon3,
  439. mouseenter,
  440. mouseleave,
  441. filterNode,
  442. handleNodeClick,
  443. closeDialog,
  444. addGroup,
  445. addSite,
  446. remove,
  447. selectNode,
  448. num,
  449. }
  450. },
  451. })
  452. </script>
  453. <style scoped lang="scss">
  454. .custom-tree-node {
  455. overflow: hidden;
  456. white-space: nowrap;
  457. text-overflow: ellipsis;
  458. display: block;
  459. }
  460. .app-container.page-nesting {
  461. padding: 0;
  462. background: rgba(0, 0, 0, 0);
  463. }
  464. .grid-content {
  465. background: #fff;
  466. height: calc(100vh - 130px);
  467. overflow-y: auto;
  468. }
  469. .el-input__inner {
  470. border-radius: 20px !important;
  471. }
  472. .treeDom {
  473. width: 290px;
  474. position: absolute;
  475. left: 0;
  476. // margin-left: 20px;
  477. padding: 20px;
  478. min-height: calc(100vh - 130px);
  479. .el-icon-search {
  480. color: #409eff;
  481. }
  482. .el-button {
  483. width: 100px;
  484. }
  485. }
  486. .nestingDom {
  487. margin-left: 300px;
  488. }
  489. </style>
  490. <style lang="scss">
  491. // tab重置样式
  492. .el-tabs--card > .el-tabs__header .el-tabs__item {
  493. line-height: 50px;
  494. height: 50px;
  495. font-size: 16px;
  496. }
  497. .el-tabs--card > .el-tabs__header .el-tabs__item.is-active {
  498. border-bottom: 2px solid #409eff;
  499. color: #409eff;
  500. }
  501. .el-tabs--card .el-tabs__header:hover,
  502. .el-tabs__item:hover {
  503. color: #409eff !important;
  504. }
  505. .el-tabs__header {
  506. margin-bottom: 0;
  507. }
  508. .el-tabs--card > .el-tabs__header .el-tabs__item,
  509. .el-tabs--card > .el-tabs__header .el-tabs__nav {
  510. border: none;
  511. }
  512. </style>