feat: 命名空间新增复制功能
This commit is contained in:
parent
1e7856f2da
commit
ce91c83de7
@ -1,6 +1,7 @@
|
||||
<script setup lang="tsx">
|
||||
import { NButton, NPopconfirm } from 'naive-ui';
|
||||
import { NButton, NPopconfirm, NPopover } from 'naive-ui';
|
||||
import { ref } from 'vue';
|
||||
import { useClipboard } from '@vueuse/core';
|
||||
import { fetchDeleteNamespace, fetchGetNamespaceList } from '@/service/api';
|
||||
import { $t } from '@/locales';
|
||||
import { useAppStore } from '@/store/modules/app';
|
||||
@ -14,12 +15,27 @@ import NamespaceSearch from './modules/namespace-search.vue';
|
||||
const appStore = useAppStore();
|
||||
const authStore = useAuthStore();
|
||||
const namespaceId = ref<string>(localStg.get('namespaceId')!);
|
||||
const { copy, isSupported } = useClipboard();
|
||||
|
||||
const handleChange = (uniqueId: string) => {
|
||||
namespaceId.value = uniqueId;
|
||||
authStore.setNamespaceId(uniqueId);
|
||||
};
|
||||
|
||||
async function handleCopy(source: string) {
|
||||
if (!isSupported) {
|
||||
window.$message?.error('您的浏览器不支持 Clipboard API');
|
||||
return;
|
||||
}
|
||||
|
||||
if (!source) {
|
||||
return;
|
||||
}
|
||||
|
||||
await copy(source);
|
||||
window.$message?.success('复制成功');
|
||||
}
|
||||
|
||||
const { columns, columnChecks, data, getData, loading, mobilePagination, searchParams, resetSearchParams } = useTable({
|
||||
apiFn: fetchGetNamespaceList,
|
||||
apiParams: {
|
||||
@ -59,7 +75,19 @@ const { columns, columnChecks, data, getData, loading, mobilePagination, searchP
|
||||
key: 'uniqueId',
|
||||
title: $t('page.namespace.uniqueId'),
|
||||
align: 'left',
|
||||
width: 180
|
||||
width: 180,
|
||||
render: row => (
|
||||
<NPopover>
|
||||
{{
|
||||
trigger: () => (
|
||||
<NButton text type="primary" onClick={() => handleCopy(row.uniqueId)}>
|
||||
{row.uniqueId}
|
||||
</NButton>
|
||||
),
|
||||
default: () => <span>点击复制</span>
|
||||
}}
|
||||
</NPopover>
|
||||
)
|
||||
},
|
||||
{
|
||||
key: 'createDt',
|
||||
|
@ -1,6 +1,7 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, reactive, watch } from 'vue';
|
||||
import { nanoid } from '@sa/utils';
|
||||
import { useClipboard } from '@vueuse/core';
|
||||
import { useFormRules, useNaiveForm } from '@/hooks/common/form';
|
||||
import OperateDrawer from '@/components/common/operate-drawer.vue';
|
||||
import { $t } from '@/locales';
|
||||
@ -26,6 +27,7 @@ interface Emits {
|
||||
|
||||
const emit = defineEmits<Emits>();
|
||||
|
||||
const { copy, isSupported } = useClipboard();
|
||||
const authStore = useAuthStore();
|
||||
const visible = defineModel<boolean>('visible', {
|
||||
default: false
|
||||
@ -111,6 +113,20 @@ watch(visible, () => {
|
||||
restoreValidation();
|
||||
}
|
||||
});
|
||||
|
||||
async function handleCopy(source: string) {
|
||||
if (!isSupported) {
|
||||
window.$message?.error('您的浏览器不支持 Clipboard API');
|
||||
return;
|
||||
}
|
||||
|
||||
if (!source) {
|
||||
return;
|
||||
}
|
||||
|
||||
await copy(source);
|
||||
window.$message?.success('复制成功');
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@ -123,9 +139,17 @@ watch(visible, () => {
|
||||
:disabled="props.operateType === 'edit'"
|
||||
:placeholder="$t('page.namespace.form.uniqueId')"
|
||||
/>
|
||||
<NTooltip trigger="hover">
|
||||
<NTooltip v-if="props.operateType === 'edit'" trigger="hover">
|
||||
<template #trigger>
|
||||
<NButton type="default" ghost :disabled="props.operateType === 'edit'" @click="setUniqueId">
|
||||
<NButton type="default" ghost @click="handleCopy(model.uniqueId)">
|
||||
<icon-ic:round-content-copy class="text-icon" />
|
||||
</NButton>
|
||||
</template>
|
||||
复制
|
||||
</NTooltip>
|
||||
<NTooltip v-else trigger="hover">
|
||||
<template #trigger>
|
||||
<NButton type="default" ghost @click="setUniqueId">
|
||||
<icon-ic-round-refresh class="text-icon" />
|
||||
</NButton>
|
||||
</template>
|
||||
|
Loading…
Reference in New Issue
Block a user