channelTree.vue 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <template>
  2. <div>
  3. <el-tree :data="channelList" :props="props" @node-click="sendDevicePush">
  4. <span slot-scope="{ node }">
  5. <span v-if="node.isLeaf">
  6. <i class="el-icon-video-camera" :style="{color:node.disabled==1?'#67C23A':'#F56C6C'}"></i>
  7. </span>
  8. <span v-else>
  9. <i class="el-icon-folder"></i>
  10. </span>
  11. <span>
  12. {{ node.label }}
  13. </span>
  14. </span>
  15. </el-tree>
  16. </div>
  17. </template>
  18. <script>
  19. import ChannelTreeItem from "@/components/channelTreeItem"
  20. import {tree} from '@/api/deviceApi'
  21. export default {
  22. components: {
  23. ChannelTreeItem,
  24. },
  25. props:{
  26. device: {
  27. type: Object,
  28. required: true
  29. }
  30. },
  31. data() {
  32. return {
  33. loading: false,
  34. channelList: [],
  35. props: {
  36. label: 'title',
  37. children: 'children',
  38. isLeaf: 'hasChildren',
  39. disabled: 'status'
  40. },
  41. }
  42. },
  43. computed: {
  44. },
  45. mounted() {
  46. this.leafs = []
  47. this.getTree()
  48. },
  49. methods: {
  50. getTree() {
  51. this.loading = true
  52. var that = this
  53. tree(this.device.deviceId).then(function (res) {
  54. console.log(res.data.data);
  55. that.channelList = res.data.data;
  56. that.loading = false;
  57. }).catch(function (error) {
  58. console.log(error);
  59. that.loading = false;
  60. });
  61. },
  62. sendDevicePush(c) {
  63. if(c.hasChildren) return
  64. this.$emit('sendDevicePush',c)
  65. }
  66. }
  67. }
  68. </script>