TreeOptions.vue 4.1 KB

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