GroupTree.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  1. <template>
  2. <div id="DeviceTree">
  3. <div v-if="showHeader" class="page-header" style="margin-bottom: 1rem;">
  4. <div class="page-title">业务分组</div>
  5. <div class="page-header-btn">
  6. <div style="display: inline;">
  7. <el-input @input="search" style="visibility:hidden; margin-right: 1rem; width: 12rem;" size="mini" placeholder="关键字"
  8. prefix-icon="el-icon-search" v-model="searchSrt" clearable></el-input>
  9. <el-checkbox v-model="showCode">显示编号</el-checkbox>
  10. </div>
  11. </div>
  12. </div>
  13. <div v-if="showHeader" style="height: 2rem; background-color: #FFFFFF" ></div>
  14. <div>
  15. <vue-easy-tree
  16. class="flow-tree"
  17. ref="veTree"
  18. node-key="deviceId"
  19. height="78vh"
  20. lazy
  21. style="padding: 0 0 2rem 0.5rem"
  22. :load="loadNode"
  23. :data="treeData"
  24. :props="props"
  25. :default-expanded-keys="['']"
  26. @node-contextmenu="contextmenuEventHandler"
  27. @node-click="nodeClickHandler"
  28. >
  29. <span class="custom-tree-node" slot-scope="{ node, data }">
  30. <span @click.stop v-if="edit">
  31. <el-radio v-if="node.data.type === 0 && node.level > 2" style="margin-right: 0" v-model="chooseId" @input="chooseIdChange(node.data.deviceId, node.data.businessGroup)" :label="node.data.deviceId">{{''}}</el-radio>
  32. </span>
  33. <span v-if="node.data.type === 0" style="color: #409EFF" class="iconfont icon-bianzubeifen3"></span>
  34. <span v-if="node.data.type === 1" style="color: #409EFF" class="iconfont icon-shexiangtou2"></span>
  35. <span style=" padding-left: 1px" v-if="node.data.deviceId !=='' && showCode" :title="node.data.deviceId">{{ node.label }}(编号:{{ node.data.deviceId }})</span>
  36. <span style=" padding-left: 1px" v-if="node.data.deviceId ==='' || !showCode" :title="node.data.deviceId">{{ node.label }}</span>
  37. </span>
  38. </vue-easy-tree>
  39. </div>
  40. <groupEdit ref="groupEdit"></groupEdit>
  41. <gbDeviceSelect ref="gbDeviceSelect"></gbDeviceSelect>
  42. </div>
  43. </template>
  44. <script>
  45. import VueEasyTree from "@wchbrad/vue-easy-tree";
  46. import groupEdit from './../dialog/groupEdit'
  47. import gbDeviceSelect from './../dialog/GbDeviceSelect'
  48. export default {
  49. name: 'DeviceTree',
  50. components: {
  51. VueEasyTree, groupEdit, gbDeviceSelect
  52. },
  53. data() {
  54. return {
  55. props: {
  56. label: "name",
  57. },
  58. showCode: false,
  59. searchSrt: "",
  60. chooseId: "",
  61. treeData: [],
  62. }
  63. },
  64. props: ['edit', 'clickEvent', 'chooseIdChange', 'onChannelChange', 'showHeader'],
  65. created() {
  66. },
  67. methods: {
  68. search() {
  69. },
  70. loadNode: function (node, resolve) {
  71. if (node.level === 0) {
  72. resolve([{
  73. deviceId: "",
  74. name: "根资源组",
  75. isLeaf: false,
  76. type: 0
  77. }]);
  78. } else {
  79. this.$axios({
  80. method: 'get',
  81. url: `/api/group/tree/list`,
  82. params: {
  83. query: this.searchSrt,
  84. parent: node.data.id
  85. }
  86. }).then((res) => {
  87. if (res.data.code === 0) {
  88. resolve(res.data.data);
  89. }
  90. }).catch(function (error) {
  91. console.log(error);
  92. });
  93. }
  94. },
  95. reset: function () {
  96. this.$forceUpdate();
  97. },
  98. contextmenuEventHandler: function (event, data, node, element) {
  99. if (!this.edit) {
  100. return;
  101. }
  102. console.log(node.level)
  103. if (node.data.type === 1) {
  104. data.parentId = node.parent.data.id;
  105. this.$contextmenu({
  106. items: [
  107. {
  108. label: "移除通道",
  109. icon: "el-icon-delete",
  110. disabled: false,
  111. onClick: () => {
  112. console.log(data)
  113. this.$axios({
  114. method: "post",
  115. url: `/api/common/channel/group/delete`,
  116. data: {
  117. channelIds: [data.id]
  118. }
  119. }).then((res) => {
  120. console.log("移除成功")
  121. if (this.onChannelChange) {
  122. this.onChannelChange()
  123. }
  124. node.parent.loaded = false
  125. node.parent.expand();
  126. }).catch(function (error) {
  127. console.log(error);
  128. });
  129. }
  130. }
  131. ],
  132. event, // 鼠标事件信息
  133. customClass: "custom-class", // 自定义菜单 class
  134. zIndex: 3000, // 菜单样式 z-index
  135. });
  136. } else if (node.data.type === 0) {
  137. this.$contextmenu({
  138. items: [
  139. {
  140. label: "刷新节点",
  141. icon: "el-icon-refresh",
  142. disabled: false,
  143. onClick: () => {
  144. this.refreshNode(node);
  145. }
  146. },
  147. {
  148. label: "新建节点",
  149. icon: "el-icon-plus",
  150. disabled: false,
  151. onClick: () => {
  152. this.addGroup(data.id, node);
  153. }
  154. },
  155. {
  156. label: "编辑节点",
  157. icon: "el-icon-edit",
  158. disabled: node.level === 1,
  159. onClick: () => {
  160. this.editGroup(data, node);
  161. }
  162. },
  163. {
  164. label: "删除节点",
  165. icon: "el-icon-delete",
  166. disabled: node.level === 1,
  167. divided: true,
  168. onClick: () => {
  169. this.$confirm('确定删除?', '提示', {
  170. confirmButtonText: '确定',
  171. cancelButtonText: '取消',
  172. type: 'warning'
  173. }).then(() => {
  174. this.removeGroup(data.id, node)
  175. }).catch(() => {
  176. });
  177. }
  178. },
  179. {
  180. label: "添加设备",
  181. icon: "el-icon-plus",
  182. disabled: node.level <= 2,
  183. onClick: () => {
  184. this.addChannelFormDevice(data.id, node)
  185. }
  186. },
  187. {
  188. label: "移除设备",
  189. icon: "el-icon-delete",
  190. disabled: node.level <= 2,
  191. onClick: () => {
  192. this.removeChannelFormDevice(data.id, node)
  193. }
  194. },
  195. // {
  196. // label: "导出",
  197. // icon: "el-icon-download",
  198. // disabled: false,
  199. // children: [
  200. // {
  201. // label: "导出到文件",
  202. // onClick: () => {
  203. //
  204. // },
  205. // },
  206. // {
  207. // label: "导出到其他平台",
  208. // onClick: () => {
  209. //
  210. // },
  211. // }
  212. // ]
  213. // },
  214. ],
  215. event, // 鼠标事件信息
  216. customClass: "custom-class", // 自定义菜单 class
  217. zIndex: 3000, // 菜单样式 z-index
  218. });
  219. }
  220. return false;
  221. },
  222. removeGroup: function (id, node) {
  223. this.$axios({
  224. method: "delete",
  225. url: `/api/group/delete`,
  226. params: {
  227. id: node.data.id,
  228. }
  229. }).then((res) => {
  230. if (res.data.code === 0) {
  231. console.log("移除成功")
  232. node.parent.loaded = false
  233. node.parent.expand();
  234. if (this.onChannelChange) {
  235. this.onChannelChange()
  236. }
  237. }
  238. }).catch(function (error) {
  239. console.log(error);
  240. });
  241. },
  242. addChannelFormDevice: function (id, node) {
  243. this.$refs.gbDeviceSelect.openDialog((rows)=>{
  244. let deviceIds = []
  245. for (let i = 0; i < rows.length; i++) {
  246. deviceIds.push(rows[i].id)
  247. }
  248. this.$axios({
  249. method: 'post',
  250. url: `/api/common/channel/group/device/add`,
  251. data: {
  252. parentId: node.data.deviceId,
  253. businessGroup: node.data.businessGroup,
  254. deviceIds: deviceIds,
  255. }
  256. }).then((res)=> {
  257. if (res.data.code === 0) {
  258. this.$message.success({
  259. showClose: true,
  260. message: "保存成功"
  261. })
  262. if (this.onChannelChange) {
  263. this.onChannelChange()
  264. }
  265. node.loaded = false
  266. node.expand();
  267. }else {
  268. this.$message.error({
  269. showClose: true,
  270. message: res.data.msg
  271. })
  272. }
  273. this.loading = false
  274. }).catch((error)=> {
  275. this.$message.error({
  276. showClose: true,
  277. message: error
  278. })
  279. this.loading = false
  280. });
  281. })
  282. },
  283. removeChannelFormDevice: function (id, node) {
  284. this.$refs.gbDeviceSelect.openDialog((rows)=>{
  285. let deviceIds = []
  286. for (let i = 0; i < rows.length; i++) {
  287. deviceIds.push(rows[i].id)
  288. }
  289. this.$axios({
  290. method: 'post',
  291. url: `/api/common/channel/group/device/delete`,
  292. data: {
  293. deviceIds: deviceIds,
  294. }
  295. }).then((res)=> {
  296. if (res.data.code === 0) {
  297. this.$message.success({
  298. showClose: true,
  299. message: "保存成功"
  300. })
  301. if (this.onChannelChange) {
  302. this.onChannelChange()
  303. }
  304. node.loaded = false
  305. node.expand();
  306. }else {
  307. this.$message.error({
  308. showClose: true,
  309. message: res.data.msg
  310. })
  311. }
  312. this.loading = false
  313. }).catch((error)=> {
  314. this.$message.error({
  315. showClose: true,
  316. message: error
  317. })
  318. this.loading = false
  319. });
  320. })
  321. },
  322. refreshNode: function (node) {
  323. node.loaded = false
  324. node.expand();
  325. },
  326. refresh: function (id) {
  327. // 查询node
  328. let node = this.$refs.veTree.getNode(id)
  329. node.loaded = false
  330. node.expand();
  331. },
  332. addGroup: function (id, node) {
  333. this.$refs.groupEdit.openDialog({
  334. id: 0,
  335. name: "",
  336. deviceId: "",
  337. civilCode: "",
  338. parentDeviceId: node.level > 2 ? node.data.deviceId:"",
  339. parentId: node.data.id,
  340. businessGroup: node.level > 2 ? node.data.businessGroup: node.data.deviceId,
  341. },form => {
  342. node.loaded = false
  343. node.expand();
  344. }, id);
  345. },
  346. editGroup: function (id, node) {
  347. console.log(node)
  348. this.$refs.groupEdit.openDialog(node.data,form => {
  349. node.parent.loaded = false
  350. node.parent.expand();
  351. }, id);
  352. },
  353. nodeClickHandler: function (data, node, tree) {
  354. if (this.clickEvent) {
  355. this.clickEvent(data)
  356. }
  357. }
  358. },
  359. destroyed() {
  360. // if (this.jessibuca) {
  361. // this.jessibuca.destroy();
  362. // }
  363. // this.playing = false;
  364. // this.loaded = false;
  365. // this.performance = "";
  366. },
  367. }
  368. </script>
  369. <style>
  370. .device-tree-main-box {
  371. text-align: left;
  372. }
  373. .device-online {
  374. color: #252525;
  375. }
  376. .device-offline {
  377. color: #727272;
  378. }
  379. .custom-tree-node .el-radio__label {
  380. padding-left: 4px !important;
  381. }
  382. </style>