Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(components): support displaying and hiding permission buttons in… #590

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 28 additions & 3 deletions src/components/advanced/table-header-operation.vue
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<script setup lang="ts">
import { ref, watchEffect } from 'vue';
import { useAuth } from '@/hooks/business/auth';
import { $t } from '@/locales';

defineOptions({
Expand All @@ -9,16 +11,39 @@ interface Props {
itemAlign?: NaiveUI.Align;
disabledDelete?: boolean;
loading?: boolean;
showAdd?: boolean;
addCode?: string; // Button Add Permission Code
showDelete?: boolean;
deleteCode?: string; // Button Delete Permission Code
}

defineProps<Props>();
const props = withDefaults(defineProps<Props>(), {
itemAlign: 'center',
disabledDelete: false,
loading: false,
showAdd: true,
addCode: '',
showDelete: true,
deleteCode: ''
});

interface Emits {
(e: 'add'): void;
(e: 'delete'): void;
(e: 'refresh'): void;
}

const { hasAuth } = useAuth();

const showAddButton = ref(false);
const showDeleteButton = ref(false);

// Monitor changes in permission codes and update the display status of buttons
watchEffect(() => {
showAddButton.value = props.showAdd && (!props.addCode || hasAuth(props.addCode));
showDeleteButton.value = props.showDelete && (!props.deleteCode || hasAuth(props.deleteCode));
});

const emit = defineEmits<Emits>();

const columns = defineModel<NaiveUI.TableColumnCheck[]>('columns', {
Expand All @@ -42,13 +67,13 @@ function refresh() {
<NSpace :align="itemAlign" wrap justify="end" class="lt-sm:w-200px">
<slot name="prefix"></slot>
<slot name="default">
<NButton size="small" ghost type="primary" @click="add">
<NButton v-if="showAddButton" size="small" ghost type="primary" @click="add">
<template #icon>
<icon-ic-round-plus class="text-icon" />
</template>
{{ $t('common.add') }}
</NButton>
<NPopconfirm @positive-click="batchDelete">
<NPopconfirm v-if="showDeleteButton" @positive-click="batchDelete">
<template #trigger>
<NButton size="small" ghost type="error" :disabled="disabledDelete">
<template #icon>
Expand Down
Loading