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">
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 { useAuth } from '@/hooks/business/auth';
import { useAppStore } from '@/store/modules/app';
import { useDownload } from '@/hooks/business/download';
import { useTable, useTableOperate } from '@/hooks/common/table';
import ${BusinessName}OperateDrawer from './modules/${business_name}-operate-drawer.vue';
import ${BusinessName}Search from './modules/${business_name}-search.vue';
@ -12,6 +14,8 @@ defineOptions({
});
const appStore = useAppStore();
const { download } = useDownload();
const { hasAuth } = useAuth();
const {
columns,
@ -63,23 +67,43 @@ const {
title: $t('common.operate'),
align: 'center',
width: 130,
render: row => (
<div class="flex-center gap-8px">
<NButton type="primary" ghost size="small" onClick={() => edit(row.#foreach($column in $columns)#if($column.isPk == '1')$column.javaField#end#end!)}>
{$t('common.edit')}
</NButton>
<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')}
render: row => {
const editBtn = () => {
if (!hasAuth('${moduleName}:${businessName}:edit')) {
return null;
}
return (
<NButton type="primary" ghost size="small" onClick={() => edit(row.#foreach($column in $columns)#if($column.isPk == '1')$column.javaField#end#end!)}>
{$t('common.edit')}
</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) {
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>
<template>
@ -123,8 +151,12 @@ async function edit(#foreach($column in $columns)#if($column.isPk == '1')$column
v-model:columns="columnChecks"
:disabled-delete="checkedRowKeys.length === 0"
:loading="loading"
:show-add="hasAuth('${moduleName}:${businessName}:add')"
:show-delete="hasAuth('${moduleName}:${businessName}:remove')"
:show-export="hasAuth('${moduleName}:${businessName}:export')"
@add="handleAdd"
@delete="handleBatchDelete"
@export="handleExport"
@refresh="getData"
/>
</template>

View File

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

View File

@ -6,7 +6,7 @@ import { SetupStoreId } from '@/enum';
import { useRouterPush } from '@/hooks/common/router';
import { fetchGetUserInfo, fetchLogin, fetchLogout } from '@/service/api';
import { localStg } from '@/utils/storage';
// import { $t } from '@/locales';
import { $t } from '@/locales';
import { useRouteStore } from '../route';
import { useTabStore } from '../tab';
import { clearAuthStorage, getToken } from './shared';
@ -80,10 +80,9 @@ export const useAuthStore = defineStore(SetupStoreId.Auth, () => {
if (pass) {
await redirectFromLogin(redirect);
window.$notification?.success({
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
});
}

View File

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