|
3 | 3 | v-for="(element, index) in items"
|
4 | 4 | :key="'array-' + index"
|
5 | 5 | :gutter="10"
|
6 |
| - class="w-100 mb-2" |
| 6 | + class="w-100" |
7 | 7 | >
|
8 |
| - <el-col :span="22"> |
| 8 | + <el-col :span="2" class="d-flex flex-column mt-1 mb-2 reorder"> |
| 9 | + <ChevronUp @click.prevent.stop="moveItem(index, 'up')" /> |
| 10 | + <ChevronDown @click.prevent.stop="moveItem(index, 'down')" /> |
| 11 | + </el-col> |
| 12 | + <el-col :span="20"> |
9 | 13 | <InputText
|
10 | 14 | :model-value="element"
|
11 | 15 | @update:model-value="(v) => handleInput(v, index)"
|
|
23 | 27 | <script setup lang="ts">
|
24 | 28 | import {ref} from "vue";
|
25 | 29 |
|
26 |
| - import {DeleteOutline} from "../../code/utils/icons"; |
| 30 | + import {DeleteOutline, ChevronUp, ChevronDown} from "../../code/utils/icons"; |
27 | 31 |
|
28 | 32 | import InputText from "../../code/components/inputs/InputText.vue";
|
29 | 33 | import Add from "../../code/components/Add.vue";
|
|
50 | 54 | items.value.splice(index, 1);
|
51 | 55 | emits("update:modelValue", items.value);
|
52 | 56 | };
|
| 57 | + const moveItem = (index: number, direction: "up" | "down") => { |
| 58 | + if (direction === "up" && index > 0) { |
| 59 | + [items.value[index - 1], items.value[index]] = [ |
| 60 | + items.value[index], |
| 61 | + items.value[index - 1], |
| 62 | + ]; |
| 63 | + } else if (direction === "down" && index < items.value.length - 1) { |
| 64 | + [items.value[index + 1], items.value[index]] = [ |
| 65 | + items.value[index], |
| 66 | + items.value[index + 1], |
| 67 | + ]; |
| 68 | + } |
| 69 | + emits("update:modelValue", items.value); |
| 70 | + }; |
53 | 71 | </script>
|
| 72 | + |
| 73 | +<style scoped lang="scss"> |
| 74 | +@import "../../code/styles/code.scss"; |
| 75 | +</style> |
0 commit comments