fix: 为代码生成模板添加按钮权限,导出功能;修复已知bug

This commit is contained in:
ANHE 2025-03-18 22:54:52 +08:00
parent bed79ce123
commit 43ea8ed755
4 changed files with 97 additions and 25 deletions

View File

@ -1,8 +1,10 @@
<script setup lang="tsx"> <script setup lang="tsx">
import { NButton, NPopconfirm } from 'naive-ui'; import { NButton, NPopconfirm } from 'naive-ui';
import { fetchGet${BusinessName}List, fetchBatchDelete${BusinessName} } from '@/service/api/${moduleName}/${businessName}'; import { fetchBatchDelete${BusinessName}, fetchGet${BusinessName}List } from '@/service/api/${moduleName}/${businessName}';
import { $t } from '@/locales'; import { $t } from '@/locales';
import { useAuth } from '@/hooks/business/auth';
import { useAppStore } from '@/store/modules/app'; import { useAppStore } from '@/store/modules/app';
import { useDownload } from '@/hooks/business/download';
import { useTable, useTableOperate } from '@/hooks/common/table'; import { useTable, useTableOperate } from '@/hooks/common/table';
import ${BusinessName}OperateDrawer from './modules/${business_name}-operate-drawer.vue'; import ${BusinessName}OperateDrawer from './modules/${business_name}-operate-drawer.vue';
import ${BusinessName}Search from './modules/${business_name}-search.vue'; import ${BusinessName}Search from './modules/${business_name}-search.vue';
@ -12,6 +14,8 @@ defineOptions({
}); });
const appStore = useAppStore(); const appStore = useAppStore();
const { download } = useDownload();
const { hasAuth } = useAuth();
const { const {
columns, columns,
@ -63,23 +67,43 @@ const {
title: $t('common.operate'), title: $t('common.operate'),
align: 'center', align: 'center',
width: 130, width: 130,
render: row => ( render: row => {
<div class="flex-center gap-8px"> const editBtn = () => {
<NButton type="primary" ghost size="small" onClick={() => edit(row.#foreach($column in $columns)#if($column.isPk == '1')$column.javaField#end#end!)}> if (!hasAuth('${moduleName}:${businessName}:edit')) {
{$t('common.edit')} return null;
</NButton> }
<NPopconfirm onPositiveClick={() => handleDelete(row.#foreach($column in $columns)#if($column.isPk == '1')$column.javaField#end#end!)}> return (
{{ <NButton type="primary" ghost size="small" onClick={() => edit(row.#foreach($column in $columns)#if($column.isPk == '1')$column.javaField#end#end!)}>
default: () => $t('common.confirmDelete'), {$t('common.edit')}
trigger: () => (
<NButton type="error" ghost size="small">
{$t('common.delete')}
</NButton> </NButton>
) );
}} };
</NPopconfirm>
</div> const deleteBtn = () => {
) if (!hasAuth('${moduleName}:${businessName}:remove')) {
return null;
}
return (
<NPopconfirm onPositiveClick={() => handleDelete(row.#foreach($column in $columns)#if($column.isPk == '1')$column.javaField#end#end!)}>
{{
default: () => $t('common.confirmDelete'),
trigger: () => (
<NButton type="error" ghost size="small">
{$t('common.delete')}
</NButton>
)
}}
</NPopconfirm>
);
};
return (
<div class="flex-center gap-8px">
{editBtn()}
{deleteBtn()}
</div>
);
}
} }
] ]
}); });
@ -112,6 +136,10 @@ async function handleDelete(#foreach($column in $columns)#if($column.isPk == '1'
async function edit(#foreach($column in $columns)#if($column.isPk == '1')$column.javaField#end#end: CommonType.IdType) { async function edit(#foreach($column in $columns)#if($column.isPk == '1')$column.javaField#end#end: CommonType.IdType) {
handleEdit('#foreach($column in $columns)#if($column.isPk == '1')$column.javaField#end#end', #foreach($column in $columns)#if($column.isPk == '1')$column.javaField#end#end); handleEdit('#foreach($column in $columns)#if($column.isPk == '1')$column.javaField#end#end', #foreach($column in $columns)#if($column.isPk == '1')$column.javaField#end#end);
} }
async function handleExport() {
download('/${moduleName}/${businessName}/export', searchParams, `${businessName}_#[[${new Date().getTime()}]]#.xlsx`);
}
</script> </script>
<template> <template>
@ -123,8 +151,12 @@ async function edit(#foreach($column in $columns)#if($column.isPk == '1')$column
v-model:columns="columnChecks" v-model:columns="columnChecks"
:disabled-delete="checkedRowKeys.length === 0" :disabled-delete="checkedRowKeys.length === 0"
:loading="loading" :loading="loading"
:show-add="hasAuth('${moduleName}:${businessName}:add')"
:show-delete="hasAuth('${moduleName}:${businessName}:remove')"
:show-export="hasAuth('${moduleName}:${businessName}:export')"
@add="handleAdd" @add="handleAdd"
@delete="handleBatchDelete" @delete="handleBatchDelete"
@export="handleExport"
@refresh="getData" @refresh="getData"
/> />
</template> </template>

View File

@ -18,7 +18,7 @@ withDefaults(defineProps<Props>(), {
itemAlign: undefined, itemAlign: undefined,
showAdd: true, showAdd: true,
showDelete: true, showDelete: true,
showExport: false showExport: true
}); });
interface Emits { interface Emits {

View File

@ -6,7 +6,7 @@ import { SetupStoreId } from '@/enum';
import { useRouterPush } from '@/hooks/common/router'; import { useRouterPush } from '@/hooks/common/router';
import { fetchGetUserInfo, fetchLogin, fetchLogout } from '@/service/api'; import { fetchGetUserInfo, fetchLogin, fetchLogout } from '@/service/api';
import { localStg } from '@/utils/storage'; import { localStg } from '@/utils/storage';
// import { $t } from '@/locales'; import { $t } from '@/locales';
import { useRouteStore } from '../route'; import { useRouteStore } from '../route';
import { useTabStore } from '../tab'; import { useTabStore } from '../tab';
import { clearAuthStorage, getToken } from './shared'; import { clearAuthStorage, getToken } from './shared';
@ -80,10 +80,9 @@ export const useAuthStore = defineStore(SetupStoreId.Auth, () => {
if (pass) { if (pass) {
await redirectFromLogin(redirect); await redirectFromLogin(redirect);
window.$notification?.success({ window.$notification?.success({
title: $t('page.login.common.loginSuccess'), title: $t('page.login.common.loginSuccess'),
content: $t('page.login.common.welcomeBack', { userName: userInfo.userName }), content: $t('page.login.common.welcomeBack', { userName: userInfo.user?.nickName }),
duration: 4500 duration: 4500
}); });
} }

View File

@ -2,9 +2,12 @@
import { NButton, NPopconfirm } from 'naive-ui'; import { NButton, NPopconfirm } from 'naive-ui';
import { fetchBatchDeleteTenant, fetchGetTenantList } from '@/service/api/system/tenant'; import { fetchBatchDeleteTenant, fetchGetTenantList } from '@/service/api/system/tenant';
import { $t } from '@/locales'; import { $t } from '@/locales';
import { useAuth } from '@/hooks/business/auth';
import { useAppStore } from '@/store/modules/app'; import { useAppStore } from '@/store/modules/app';
import { useTable, useTableOperate } from '@/hooks/common/table'; import { useTable, useTableOperate } from '@/hooks/common/table';
import DictTag from '@/components/custom/dict-tag.vue'; import DictTag from '@/components/custom/dict-tag.vue';
import { useDownload } from '@/hooks/business/download';
import { useDict } from '@/hooks/business/dict';
import TenantOperateDrawer from './modules/tenant-operate-drawer.vue'; import TenantOperateDrawer from './modules/tenant-operate-drawer.vue';
import TenantSearch from './modules/tenant-search.vue'; import TenantSearch from './modules/tenant-search.vue';
@ -12,7 +15,11 @@ defineOptions({
name: 'TenantList' name: 'TenantList'
}); });
useDict('sys_normal_disable');
const appStore = useAppStore(); const appStore = useAppStore();
const { download } = useDownload();
const { hasAuth } = useAuth();
const { const {
columns, columns,
@ -92,12 +99,23 @@ const {
title: $t('common.operate'), title: $t('common.operate'),
align: 'center', align: 'center',
width: 180, width: 180,
render: row => render: row => {
row.tenantId !== '000000' ? ( if (row.tenantId === '000000') return null;
<div class="flex-center gap-8px"> const editBtn = () => {
if (!hasAuth('system:tenant:edit')) {
return null;
}
return (
<NButton type="primary" ghost size="small" onClick={() => edit(row.id!)}> <NButton type="primary" ghost size="small" onClick={() => edit(row.id!)}>
{$t('common.edit')} {$t('common.edit')}
</NButton> </NButton>
);
};
const syncBtn = () => {
if (!hasAuth('system:tenant:edit')) {
return null;
}
return (
<NPopconfirm onPositiveClick={() => handleDelete(row.id!)}> <NPopconfirm onPositiveClick={() => handleDelete(row.id!)}>
{{ {{
default: () => `确认同步[${row.companyName}]的套餐吗?`, default: () => `确认同步[${row.companyName}]的套餐吗?`,
@ -108,6 +126,13 @@ const {
) )
}} }}
</NPopconfirm> </NPopconfirm>
);
};
const deleteBtn = () => {
if (!hasAuth('system:tenant:delete')) {
return null;
}
return (
<NPopconfirm onPositiveClick={() => handleDelete(row.id!)}> <NPopconfirm onPositiveClick={() => handleDelete(row.id!)}>
{{ {{
default: () => $t('common.confirmDelete'), default: () => $t('common.confirmDelete'),
@ -118,8 +143,16 @@ const {
) )
}} }}
</NPopconfirm> </NPopconfirm>
);
};
return (
<div class="flex-center gap-8px">
{editBtn()}
{syncBtn()}
{deleteBtn()}
</div> </div>
) : null );
}
} }
] ]
}); });
@ -144,6 +177,10 @@ async function handleDelete(id: CommonType.IdType) {
async function edit(id: CommonType.IdType) { async function edit(id: CommonType.IdType) {
handleEdit('id', id); handleEdit('id', id);
} }
async function handleExport() {
download('/system/tenant/export', searchParams, '租户列表.xlsx');
}
</script> </script>
<template> <template>
@ -155,8 +192,12 @@ async function edit(id: CommonType.IdType) {
v-model:columns="columnChecks" v-model:columns="columnChecks"
:disabled-delete="checkedRowKeys.length === 0" :disabled-delete="checkedRowKeys.length === 0"
:loading="loading" :loading="loading"
:show-add="hasAuth('system:tenant:add')"
:show-delete="hasAuth('system:tenant:delete')"
:show-export="hasAuth('system:tenant:export')"
@add="handleAdd" @add="handleAdd"
@delete="handleBatchDelete" @delete="handleBatchDelete"
@export="handleExport"
@refresh="getData" @refresh="getData"
/> />
</template> </template>