Files
desktop/ui/src/components/CopyDialog.vue
T

49 lines
1.4 KiB
Vue

<template>
<n-modal :show="show" preset="card" title="复制到其他设备" style="width: 420px" :segmented="{ content: true, footer: 'soft' }" @update:show="emit('update:show', $event)">
<div class="modal-body">
<div v-if="others.length === 0" class="empty">没有其他设备</div>
<n-checkbox-group v-else v-model:value="picked">
<div v-for="item in others" :key="item.endpoint_id" style="margin: 6px 0">
<n-checkbox :value="item.endpoint_id">{{ item.name }}</n-checkbox>
</div>
</n-checkbox-group>
</div>
<template #footer>
<div class="modal-actions">
<n-button @click="emit('update:show', false)">取消</n-button>
<n-button type="primary" :disabled="picked.length === 0" @click="ok">确定</n-button>
</div>
</template>
</n-modal>
</template>
<script setup lang="ts">
import { computed, ref, watch } from 'vue'
import { NButton, NCheckbox, NCheckboxGroup, NModal } from 'naive-ui'
import type { Device } from '../types'
const props = defineProps<{
show: boolean
devices: Device[]
current: string
}>()
const emit = defineEmits<{
'update:show': [boolean]
confirm: [string[]]
}>()
const picked = ref<string[]>([])
const others = computed(() => props.devices.filter((item) => item.endpoint_id && item.endpoint_id !== props.current))
watch(
() => props.show,
(open) => {
if (open) picked.value = []
},
)
function ok() {
emit('confirm', picked.value)
}
</script>