index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444
  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. :props="defaultProps"
  38. :data="data"
  39. @node-click="handleNodeClick"
  40. node-key="id"
  41. :expand-on-click-node="false"
  42. :highlight-current="showTree"
  43. default-expand-all
  44. :filter-node-method="filterNode"
  45. ref="tree"
  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 class="grid-content nestingDom" style="width: calc(100% - 300px)" v-if="flag2">
  81. <el-tabs
  82. v-if="treeLevel == 3 || groupingId == 0"
  83. v-model="activeName"
  84. type="card"
  85. >
  86. <el-tab-pane label="基本信息" name="first">
  87. <basic-info class="basicInfo" :siteId="siteId" ></basic-info>
  88. </el-tab-pane>
  89. <el-tab-pane label="监控设备" name="second" >
  90. <watch-dog
  91. v-on:success="success(res)"
  92. :avtiveName="activeName"
  93. @func="getMsgFormSon"
  94. :siteId="siteId"
  95. ></watch-dog>
  96. </el-tab-pane>
  97. <el-tab-pane label="变量列表" name="third">
  98. <variable-list :activeName="activeName" ></variable-list>
  99. </el-tab-pane>
  100. <el-tab-pane label="摄像头" name="five" >
  101. <camera :siteId="siteId"></camera>
  102. </el-tab-pane>
  103. <el-tab-pane label="电能质量评分配置" name="six">
  104. <power-Score :siteId="siteId"></power-Score>
  105. </el-tab-pane>
  106. </el-tabs>
  107. <!-- 分组信息start -->
  108. <group-info-com
  109. :groupingId="groupingId"
  110. :label="label"
  111. @func="getMsgFormSon2"
  112. v-else
  113. ></group-info-com>
  114. <!-- 分组信息end -->
  115. <!-- 新建分组start -->
  116. <add-group-com
  117. :dialogTitle="dialogTitle"
  118. :itemInfo="tableItem"
  119. @closeDialog="closeDialog"
  120. :flag="showDialog"
  121. ></add-group-com>
  122. <!-- 新建分组end -->
  123. <!-- 新建站点start -->
  124. <add-site-com
  125. :dialogTitle="dialogTitle"
  126. :itemInfo="tableItem"
  127. @closeDialog="closeDialog"
  128. :flag="showDialog2"
  129. ></add-site-com>
  130. <!-- 新建站点end -->
  131. </div>
  132. <!-- 站点主题end -->
  133. </div>
  134. </template>
  135. <script>
  136. import { defineComponent, ref, reactive, watch, onMounted,nextTick } from 'vue'
  137. import basicInfo from './basicInfo'
  138. import WatchDog from './watchDog'
  139. import variableList from './variableList'
  140. import camera from './camera'
  141. import PowerScore from './powerScore'
  142. import groupInfoCom from './groupInfoCom'
  143. import addGroupCom from './addGroupCom'
  144. import addSiteCom from './addSiteCom'
  145. import * as api from '@/api/siteManage/index'
  146. import { ElMessage } from 'element-plus'
  147. export default defineComponent({
  148. components: {
  149. basicInfo,
  150. WatchDog,
  151. variableList,
  152. camera,
  153. PowerScore,
  154. groupInfoCom,
  155. addGroupCom,
  156. addSiteCom,
  157. },
  158. setup() {
  159. const flag2=ref(false)
  160. const showTree = ref(true)
  161. const defaultExpand=ref(0)
  162. const showDialog = ref(false)
  163. const showDialog2 = ref(false)
  164. const dialogTitle = ref('')
  165. const treeLevel = ref(3)
  166. const groupingId = ref(1)
  167. const siteId = ref(368)
  168. const label = ref('')
  169. const activeName = ref('first')
  170. const filterText = ref('')
  171. const data = ref([
  172. {
  173. label: '所有站点',
  174. children: [],
  175. },
  176. ])
  177. // const data2 = ref([
  178. // {
  179. // grouping_id: 1,
  180. // id: 1,
  181. // label: '所有站点',
  182. // children: [
  183. // {
  184. // id: 1,
  185. // label: '分组测试1',
  186. // grouping_id: 1,
  187. // children: [
  188. // {
  189. // id: 368,
  190. // label: '测试站点89',
  191. // },
  192. // {
  193. // id: 367,
  194. // label: '测试站点88',
  195. // },
  196. // ],
  197. // },
  198. // {
  199. // grouping_id: 0,
  200. // id: 5,
  201. // label: '中国铁路上海...',
  202. // },
  203. // {
  204. // grouping_id: 0,
  205. // id: 5,
  206. // label: '上海拓石...',
  207. // },
  208. // ],
  209. // },
  210. // ])
  211. // const defaultProps2 = ref({
  212. // children: 'children',
  213. // label: 'label',
  214. // })
  215. const defaultProps = ref({
  216. children: 'children',
  217. label: 'label',
  218. })
  219. const getMsgFormSon = () => {
  220. activeName.value = 'third'
  221. }
  222. const getMsgFormSon2 = () => {
  223. siteTreeList()
  224. }
  225. function mouseenter(data) {
  226. data.show = true
  227. }
  228. function mouseleave(data) {
  229. data.show = false
  230. }
  231. function filterNode(value, data) {
  232. if (!value) return true
  233. return data.label.indexOf(value) !== -1
  234. }
  235. const handleNodeClick = (data, obj, node) => {
  236. data, node
  237. flag2.value=true
  238. console.log(obj.data)
  239. treeLevel.value = obj.level
  240. groupingId.value = obj.data.grouping_id
  241. label.value = obj.data.label
  242. console.log('obj.data')
  243. console.log(obj.data)
  244. if (treeLevel.value == 3) {
  245. siteId.value = obj.data.id
  246. }
  247. if (treeLevel.value == 2 && groupingId.value == 0) {
  248. // console.log(obj.data)
  249. siteId.value = obj.data.id
  250. }
  251. console.log('父组件的siteId')
  252. console.log(siteId.value)
  253. }
  254. const tree = ref(null)
  255. watch(filterText, (val) => {
  256. //直接监听
  257. val
  258. console.log(tree)
  259. // tree.value.filter(val)
  260. })
  261. // 关闭操作
  262. const closeDialog = () => {
  263. showDialog.value = false
  264. showDialog2.value = false
  265. siteTreeList()
  266. flag2.value=false
  267. treeLevel.value = 3
  268. }
  269. //新建分组
  270. const tableItem = reactive([])
  271. const addGroup = () => {
  272. tableItem.value = {
  273. groupingName: '',
  274. }
  275. dialogTitle.value = '新建分组'
  276. showDialog.value = true
  277. }
  278. //新建站点
  279. const addSite = () => {
  280. tableItem.value = {
  281. id: '',
  282. stationName: '',
  283. xh: '',
  284. userName: '',
  285. list: [],
  286. done: '',
  287. guaZai: '',
  288. checked: true,
  289. }
  290. dialogTitle.value = '新建站点'
  291. showDialog2.value = true
  292. }
  293. const remove = (node, data) => {
  294. const parent = node.parent
  295. const children = parent.data.children || parent.data
  296. const index = children.findIndex((d) => d.id === data.id)
  297. children.splice(index, 1)
  298. this.dataSource = [...this.dataSource]
  299. }
  300. //左侧树结构列表
  301. function siteTreeList() {
  302. api.siteTreeList({}).then((requset) => {
  303. if (requset.status === 'SUCCESS') {
  304. var jsona = JSON.stringify(requset.data)
  305. var jsonb = jsona.replace(/"grouping_name"/g, '"label"')
  306. jsonb = jsonb.replace(/"site_list"/g, '"children"')
  307. jsonb = jsonb.replace(/"site_name"/g, '"label"')
  308. jsonb = jsonb.replace(/"site_id"/g, '"id"')
  309. var jsonc = JSON.parse(jsonb)
  310. data.value[0].children = jsonc
  311. // data2.value[0].children = jsonc
  312. console.log(data)
  313. // console.log(data2)
  314. } else {
  315. ElMessage.error(requset.msg)
  316. }
  317. })
  318. }
  319. onMounted(() => {
  320. // console.log(groupingId.value)
  321. siteTreeList();
  322. })
  323. nextTick(() => {
  324. // defaultExpand.value = data.value[0].children.id
  325. // tree.value.setCurrentKey(tree[0].node.id)
  326. })
  327. return {
  328. showDialog,
  329. showDialog2,
  330. treeLevel,
  331. activeName,
  332. filterText,
  333. dialogTitle,
  334. data,
  335. defaultProps,
  336. tableItem,
  337. groupingId,
  338. siteId,
  339. label,
  340. flag2,
  341. showTree,
  342. // data2,
  343. // defaultProps2,
  344. defaultExpand,
  345. getMsgFormSon,
  346. getMsgFormSon2,
  347. mouseenter,
  348. mouseleave,
  349. filterNode,
  350. handleNodeClick,
  351. closeDialog,
  352. addGroup,
  353. addSite,
  354. remove,
  355. }
  356. },
  357. })
  358. </script>
  359. <style scoped lang="scss">
  360. .app-container.page-nesting {
  361. padding: 0;
  362. background: rgba(0, 0, 0, 0);
  363. }
  364. .grid-content {
  365. background: #fff;
  366. height: calc(100vh - 130px);
  367. overflow-y: auto;
  368. }
  369. .el-input__inner {
  370. border-radius: 20px !important;
  371. }
  372. .treeDom {
  373. width: 290px;
  374. position: absolute;
  375. left: 0;
  376. // margin-left: 20px;
  377. padding: 20px;
  378. min-height: calc(100vh - 130px);
  379. .el-icon-search {
  380. color: #409eff;
  381. }
  382. .el-button {
  383. width: 100px;
  384. }
  385. }
  386. .nestingDom {
  387. margin-left: 300px;
  388. }
  389. </style>
  390. <style lang="scss">
  391. // tab重置样式
  392. .el-tabs--card > .el-tabs__header .el-tabs__item {
  393. line-height: 50px;
  394. height: 50px;
  395. font-size: 16px;
  396. }
  397. .el-tabs--card > .el-tabs__header .el-tabs__item.is-active {
  398. border-bottom: 2px solid #409eff;
  399. color: #409eff;
  400. }
  401. .el-tabs--card .el-tabs__header:hover,
  402. .el-tabs__item:hover {
  403. color: #409eff !important;
  404. }
  405. .el-tabs__header {
  406. margin-bottom: 0;
  407. }
  408. .el-tabs--card > .el-tabs__header .el-tabs__item,
  409. .el-tabs--card > .el-tabs__header .el-tabs__nav {
  410. border: none;
  411. }
  412. </style>