Skip to content
This repository has been archived by the owner on Feb 24, 2024. It is now read-only.

Commit

Permalink
feat: support array up down
Browse files Browse the repository at this point in the history
  • Loading branch information
neko-para committed Aug 19, 2023
1 parent ebcd3eb commit 4e9170a
Showing 1 changed file with 39 additions and 2 deletions.
41 changes: 39 additions & 2 deletions packages/client/src/components/array/ArrayEdit.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<script setup lang="ts" generic="T">
import {
AddOutlined,
ArrowDownwardOutlined,
ArrowUpwardOutlined,
DataArrayOutlined,
DeleteOutlined
} from '@vicons/material'
Expand Down Expand Up @@ -89,6 +91,22 @@ function add() {
}
}
function up(idx: number) {
if (isSingle.value) {
return
}
const v = value.value as T[]
v.splice(idx - 1, 0, ...v.splice(idx, 1))
}
function down(idx: number) {
if (isSingle.value) {
return
}
const v = value.value as T[]
v.splice(idx + 1, 0, ...v.splice(idx, 1))
}
function set(idx: number, val: T) {
if (isSingle.value) {
;(value.value as U) = val
Expand Down Expand Up @@ -139,9 +157,28 @@ function remove(idx: number) {
:value="v"
:update="(v: T) => set(i, v)"
></slot>
<div>
<div v-if="!readonly" class="flex gap-2">
<NButton
:disabled="single || valarr.length === 1 || i === 0"
@click="up(i)"
>
<template #icon>
<NIcon>
<ArrowUpwardOutlined></ArrowUpwardOutlined>
</NIcon>
</template>
</NButton>
<NButton
:disabled="single || valarr.length === 1 || i === valarr.length - 1"
@click="down(i)"
>
<template #icon>
<NIcon>
<ArrowDownwardOutlined></ArrowDownwardOutlined>
</NIcon>
</template>
</NButton>
<NButton
v-if="!readonly"
:disabled="!nullable && (single || valarr.length === 1)"
@click="remove(i)"
>
Expand Down

0 comments on commit 4e9170a

Please sign in to comment.