index.vue 11 KB

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