TreeOptions.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <template>
  2. <div class="_fd-tree-opt">
  3. <el-tree
  4. :data="formValue"
  5. node-key="index"
  6. :expand-on-click-node="false">
  7. <template #default="{ node, data }">
  8. <div class="_fd-tree-opt-node">
  9. <el-input size="mini" class="_fd-tree-opt-first" v-model="data[overColumns.label]"
  10. @blur="change"/>
  11. <ValueInput class="_fd-tree-opt-last" size="mini" v-model="data[overColumns.value]" @blur="change"
  12. @change-type="change">
  13. <template #append>
  14. <div class="_fd-tree-opt-btn" @click="add(node, data)">
  15. <i class="fc-icon icon-add"></i>
  16. </div>
  17. <div class="_fd-tree-opt-btn" @click="append(data)">
  18. <i class="fc-icon icon-add-child"></i>
  19. </div>
  20. <div class="_fd-tree-opt-btn _fd-tree-opt-danger" @click="remove(node, data)">
  21. <i class="fc-icon icon-delete"></i>
  22. </div>
  23. </template>
  24. </ValueInput>
  25. </div>
  26. </template>
  27. </el-tree>
  28. </div>
  29. </template>
  30. <script>
  31. import {defineComponent} from 'vue';
  32. import {deepCopy} from '@form-create/utils/lib/deepextend';
  33. import ValueInput from './ValueInput.vue';
  34. export default defineComponent({
  35. name: 'TreeOptions',
  36. emits: ['input'],
  37. components: {
  38. ValueInput
  39. },
  40. props: {
  41. value: Array,
  42. columns: Object,
  43. },
  44. inject: ['designer'],
  45. data() {
  46. return {
  47. formValue: [...deepCopy(this.value || [])],
  48. };
  49. },
  50. computed: {
  51. t() {
  52. return this.designer.t;
  53. },
  54. overColumns() {
  55. if (!this.columns) {
  56. return {
  57. label: 'label',
  58. value: 'value',
  59. };
  60. }
  61. return {
  62. label: this.columns.label || 'label',
  63. value: this.columns.value || 'value',
  64. };
  65. }
  66. },
  67. created() {
  68. if (!this.formValue.length) {
  69. this.formValue = [{}];
  70. }
  71. },
  72. methods: {
  73. tidyValue() {
  74. return deepCopy(this.formValue);
  75. },
  76. change() {
  77. this.$emit('input', this.tidyValue());
  78. },
  79. add(node) {
  80. const parent = node.parent;
  81. const children = parent.data.children || parent.data;
  82. children.push({});
  83. },
  84. append(data) {
  85. if (!data.children) {
  86. this.$set(data, 'children', []);
  87. }
  88. data.children.push({});
  89. },
  90. remove(node, data) {
  91. const parent = node.parent;
  92. if (parent.data.children) {
  93. parent.data.children.splice(parent.data.children.indexOf(data), 1);
  94. if (!parent.data.children.length) {
  95. delete parent.data.children;
  96. }
  97. } else {
  98. parent.data.splice(parent.data.indexOf(data), 1);
  99. }
  100. this.change();
  101. },
  102. }
  103. });
  104. </script>
  105. <style>
  106. ._fd-tree-opt ._fd-tree-opt-btn {
  107. height: 19px;
  108. width: 18px;
  109. color: #fff;
  110. text-align: center;
  111. line-height: 20px;
  112. padding-bottom: 1px;
  113. float: left;
  114. cursor: pointer;
  115. justify-content: center;
  116. background-color: #2f73ff;
  117. }
  118. ._fd-tree-opt-node {
  119. display: flex;
  120. align-items: center;
  121. }
  122. ._fd-tree-opt-first {
  123. width: 60px;
  124. margin-right: 8px;
  125. }
  126. ._fd-tree-opt-first .el-input__inner {
  127. padding: 0 5px;
  128. }
  129. ._fd-tree-opt-last {
  130. width: 165px;
  131. }
  132. ._fd-tree-opt ._fd-tree-opt-danger {
  133. background-color: #ff2d2e;
  134. border-radius: 0 2px 2px 0;
  135. }
  136. ._fd-tree-opt .el-tree-node__content {
  137. margin-bottom: 3px;
  138. height: 28px;
  139. }
  140. ._fd-tree-opt .el-input-group__append {
  141. width: 55px;
  142. padding-right: 2px;
  143. padding-left: 1px;
  144. background: #fff;
  145. }
  146. </style>