feat: clone button on locations #586

This commit is contained in:
Jacky 2024-10-03 17:55:04 +08:00
parent ea46c806cf
commit 6e17ddf194
No known key found for this signature in database
GPG key ID: 215C21B10DF38B4D

View file

@ -1,6 +1,7 @@
<script setup lang="ts"> <script setup lang="ts">
import { DeleteOutlined, HolderOutlined } from '@ant-design/icons-vue' import { CopyOutlined, DeleteOutlined, HolderOutlined } from '@ant-design/icons-vue'
import Draggable from 'vuedraggable' import Draggable from 'vuedraggable'
import _ from 'lodash'
import CodeEditor from '@/components/CodeEditor' import CodeEditor from '@/components/CodeEditor'
import type { NgxConfig, NgxLocation } from '@/api/ngx' import type { NgxConfig, NgxLocation } from '@/api/ngx'
@ -37,6 +38,12 @@ function save() {
function remove(index: number) { function remove(index: number) {
ngx_config.servers[props.currentServerIndex!].locations?.splice(index, 1) ngx_config.servers[props.currentServerIndex!].locations?.splice(index, 1)
} }
function duplicate(index: number) {
const loc = ngx_config.servers[props.currentServerIndex!].locations![index]
ngx_config.servers[props.currentServerIndex!].locations?.splice(index, 0, _.cloneDeep(loc))
}
</script> </script>
<template> <template>
@ -51,7 +58,10 @@ function remove(index: number) {
handle=".ant-collapse-header" handle=".ant-collapse-header"
> >
<template #item="{ element: v, index }"> <template #item="{ element: v, index }">
<ACollapse :bordered="false"> <ACollapse
:bordered="false"
collapsible="header"
>
<ACollapsePanel> <ACollapsePanel>
<template #header> <template #header>
<div> <div>
@ -64,6 +74,16 @@ function remove(index: number) {
v-if="!readonly" v-if="!readonly"
#extra #extra
> >
<ASpace>
<AButton
type="text"
size="small"
@click="() => duplicate(index)"
>
<template #icon>
<CopyOutlined style="font-size: 14px;" />
</template>
</AButton>
<APopconfirm <APopconfirm
:title="$gettext('Are you sure you want to remove this location?')" :title="$gettext('Are you sure you want to remove this location?')"
:ok-text="$gettext('Yes')" :ok-text="$gettext('Yes')"
@ -79,6 +99,7 @@ function remove(index: number) {
</template> </template>
</AButton> </AButton>
</APopconfirm> </APopconfirm>
</ASpace>
</template> </template>
<AForm layout="vertical"> <AForm layout="vertical">
<AFormItem :label="$gettext('Comments')"> <AFormItem :label="$gettext('Comments')">