TreeNode.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <template>
  2. <div class="tree-node-container" ref="node">
  3. <div class="tree-node" @click="nodeClick(id)">
  4. <div class="node-state">{{state}}</div>
  5. <div class="node-title">{{title}}</div>
  6. </div>
  7. <div class="node-postfix">
  8. <div class="icon" target="delete" @click="deleteNode(id)"></div>
  9. <div class="icon" target="add" @click="addChild(id)"></div>
  10. </div>
  11. </div>
  12. </template>
  13. <script>
  14. export default {
  15. name: 'TreeNode',
  16. props: {
  17. id: Number,
  18. state: String,
  19. title: String,
  20. },
  21. methods: {
  22. setTreeNodeOffsetX(x) {
  23. this.$refs.node.style.left = `${x}px`;
  24. },
  25. setTreeNodeOffsetY(y) {
  26. this.$refs.node.style.top = `${y}px`;
  27. },
  28. setTreeNodeOffset(x, y) {
  29. this.$refs.node.style.left = `${x}px`;
  30. this.$refs.node.style.top = `${y}px`;
  31. },
  32. getTreeNodeSize() {
  33. return {
  34. height: this.$refs.node.offsetHeight,
  35. width: this.$refs.node.offsetWidth,
  36. };
  37. },
  38. addChild(id) {
  39. this.$emit('add-child', id);
  40. },
  41. deleteNode(id) {
  42. this.$emit('delete-node', id);
  43. },
  44. nodeClick(id) {
  45. this.$emit('node-click', id);
  46. },
  47. },
  48. };
  49. </script>
  50. <style lang="scss" scoped>
  51. .tree-node-container {
  52. position: absolute;
  53. height: 140px;
  54. width: 20%;
  55. user-select: none;
  56. & .node-postfix {
  57. position: absolute;
  58. top: 120px;
  59. width: 100%;
  60. height: 20px;
  61. display: none;
  62. }
  63. &:hover .node-postfix {
  64. display: block;
  65. }
  66. }
  67. .tree-node {
  68. box-sizing: border-box;
  69. border-radius: 2px;
  70. border: 1px solid #3f3f3f;
  71. height: 120px;
  72. width: 100%;
  73. }
  74. .icon {
  75. width: 14px;
  76. height: 14px;
  77. float: right;
  78. background-position: center;
  79. background-repeat: no-repeat;
  80. background-size: 100% 100%;
  81. margin-top: 4px;
  82. margin-right: 10px;
  83. transition: all .2s linear;
  84. }
  85. .icon:hover{
  86. cursor: pointer;
  87. transition-duration: 0.2s;
  88. transform: scale(1.1);
  89. transition-timing-function:ease-in-out;
  90. }
  91. .icon[target=add]{
  92. background-image: url("../assets/icon/add.svg");
  93. }
  94. .icon[target=delete]{
  95. background-image: url("../assets/icon/delete.svg");
  96. }
  97. </style>