Merge remote-tracking branch 'yudao/dev' into dev

This commit is contained in:
jason
2025-05-19 12:39:10 +08:00
30 changed files with 394 additions and 291 deletions

View File

@@ -1,2 +1,4 @@
export { default as TableAction } from './table-action.vue';
export const ACTION_KEY = 'action_key_msg';
export * from './typing';

View File

@@ -69,7 +69,6 @@ const getActions = computed(() => {
.map((action) => {
const { popConfirm } = action;
return {
// getPopupContainer: document.body,
type: 'link' as ButtonType,
...action,
...popConfirm,
@@ -135,7 +134,7 @@ function handleMenuClick(e: any) {
</script>
<template>
<div class="m-table-action">
<div class="table-actions">
<Space
:size="
getActions?.some((item: ActionItem) => item.type === 'link') ? 0 : 8
@@ -230,7 +229,7 @@ function handleMenuClick(e: any) {
</div>
</template>
<style lang="scss">
.m-table-action {
.table-actions {
.ant-btn {
padding: 4px;
margin-left: 0;

View File

@@ -1,16 +1,10 @@
import type { VbenFormSchema } from '#/adapter/form';
import type { OnActionClickFn, VxeTableGridOptions } from '#/adapter/vxe-table';
import type { SystemDictDataApi } from '#/api/system/dict/data';
import type { SystemDictTypeApi } from '#/api/system/dict/type';
import { useAccess } from '@vben/access';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import { z } from '#/adapter/form';
import { getSimpleDictTypeList } from '#/api/system/dict/type';
import { CommonStatusEnum, DICT_TYPE, getDictOptions } from '#/utils';
const { hasAccessByCodes } = useAccess();
// ============================== 字典类型 ==============================
/** 类型新增/修改的表单 */
@@ -96,9 +90,7 @@ export function useTypeGridFormSchema(): VbenFormSchema[] {
}
/** 类型列表的字段 */
export function useTypeGridColumns<T = SystemDictTypeApi.DictType>(
onActionClick: OnActionClickFn<T>,
): VxeTableGridOptions['columns'] {
export function useTypeGridColumns(): VxeTableGridOptions['columns'] {
return [
{
field: 'id',
@@ -136,29 +128,10 @@ export function useTypeGridColumns<T = SystemDictTypeApi.DictType>(
formatter: 'formatDateTime',
},
{
minWidth: 120,
title: '操作',
field: 'operation',
width: 160,
fixed: 'right',
align: 'center',
cellRender: {
attrs: {
nameField: 'type',
nameTitle: '字典类型',
onClick: onActionClick,
},
name: 'CellOperation',
options: [
{
code: 'edit',
show: hasAccessByCodes(['system:dict:update']),
},
{
code: 'delete',
show: hasAccessByCodes(['system:dict:delete']),
},
],
},
slots: { default: 'actions' },
},
];
}
@@ -310,9 +283,7 @@ export function useDataGridFormSchema(): VbenFormSchema[] {
/**
* 字典数据表格列
*/
export function useDataGridColumns<T = SystemDictDataApi.DictData>(
onActionClick: OnActionClickFn<T>,
): VxeTableGridOptions['columns'] {
export function useDataGridColumns(): VxeTableGridOptions['columns'] {
return [
{
field: 'id',
@@ -360,29 +331,10 @@ export function useDataGridColumns<T = SystemDictDataApi.DictData>(
formatter: 'formatDateTime',
},
{
minWidth: 120,
title: '操作',
field: 'operation',
width: 160,
fixed: 'right',
align: 'center',
cellRender: {
attrs: {
nameField: 'label',
nameTitle: '字典数据',
onClick: onActionClick,
},
name: 'CellOperation',
options: [
{
code: 'edit',
show: hasAccessByCodes(['system:dict:update']),
},
{
code: 'delete',
show: hasAccessByCodes(['system:dict:delete']),
},
],
},
slots: { default: 'actions' },
},
];
}

View File

@@ -1,8 +1,5 @@
<script lang="ts" setup>
import type {
OnActionClickParams,
VxeTableGridOptions,
} from '#/adapter/vxe-table';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { SystemDictDataApi } from '#/api/system/dict/data';
import { watch } from 'vue';
@@ -19,6 +16,7 @@ import {
exportDictData,
getDictDataPage,
} from '#/api/system/dict/data';
import { ACTION_KEY, TableAction } from '#/components/table-action';
import { $t } from '#/locales';
import { useDataGridColumns, useDataGridFormSchema } from '../data';
@@ -53,41 +51,22 @@ function onCreate() {
}
/** 编辑字典数据 */
function onEdit(row: any) {
function onEdit(row: SystemDictDataApi.DictData) {
dataFormModalApi.setData(row).open();
}
/** 删除字典数据 */
async function onDelete(row: any) {
const hideLoading = message.loading({
content: $t('common.processing'),
duration: 0,
key: 'process_message',
async function onDelete(row: SystemDictDataApi.DictData) {
message.loading({
content: $t('ui.actionMessage.deleting', [row.label]),
key: ACTION_KEY,
});
try {
await deleteDictData(row.id);
message.success({
content: $t('common.operationSuccess'),
key: 'process_message',
});
onRefresh();
} finally {
hideLoading();
}
}
/** 表格操作按钮回调 */
function onActionClick({ code, row }: OnActionClickParams) {
switch (code) {
case 'delete': {
onDelete(row);
break;
}
case 'edit': {
onEdit(row);
break;
}
}
await deleteDictData(row.id as number);
message.success({
content: $t('ui.actionMessage.deleteSuccess', [row.label]),
key: ACTION_KEY,
});
onRefresh();
}
const [Grid, gridApi] = useVbenVxeGrid({
@@ -95,7 +74,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
schema: useDataGridFormSchema(),
},
gridOptions: {
columns: useDataGridColumns(onActionClick),
columns: useDataGridColumns(),
height: 'auto',
keepSource: true,
proxyConfig: {
@@ -155,6 +134,30 @@ watch(
{{ $t('ui.actionTitle.export') }}
</Button>
</template>
<template #actions="{ row }">
<TableAction
:actions="[
{
label: $t('common.edit'),
type: 'link',
icon: 'ant-design:edit-outlined',
auth: ['system:dict:update'],
onClick: onEdit.bind(null, row),
},
{
label: $t('common.delete'),
type: 'link',
danger: true,
icon: 'ant-design:delete-outlined',
auth: ['system:dict:delete'],
popConfirm: {
title: $t('ui.actionMessage.deleteConfirm', [row.label]),
confirm: onDelete.bind(null, row),
},
},
]"
/>
</template>
</Grid>
</div>
</template>

View File

@@ -1,6 +1,5 @@
<script lang="ts" setup>
import type {
OnActionClickParams,
VxeGridListeners,
VxeTableGridOptions,
} from '#/adapter/vxe-table';
@@ -18,6 +17,7 @@ import {
exportDictType,
getDictTypePage,
} from '#/api/system/dict/type';
import { ACTION_KEY, TableAction } from '#/components/table-action';
import { $t } from '#/locales';
import { useTypeGridColumns, useTypeGridFormSchema } from '../data';
@@ -53,38 +53,16 @@ function onEdit(row: any) {
/** 删除字典类型 */
async function onDelete(row: SystemDictTypeApi.DictType) {
const hideLoading = message.loading({
content: $t('common.processing'),
duration: 0,
key: 'process_message',
message.loading({
content: $t('ui.actionMessage.deleting', [row.name]),
key: ACTION_KEY,
});
try {
await deleteDictType(row.id as number);
message.success({
content: $t('common.operationSuccess'),
key: 'process_message',
});
onRefresh();
} finally {
hideLoading();
}
}
/** 表格操作按钮回调 */
function onActionClick({
code,
row,
}: OnActionClickParams<SystemDictTypeApi.DictType>) {
switch (code) {
case 'delete': {
onDelete(row);
break;
}
case 'edit': {
onEdit(row);
break;
}
}
await deleteDictType(row.id as number);
message.success({
content: $t('ui.actionMessage.deleteSuccess', [row.name]),
key: ACTION_KEY,
});
onRefresh();
}
/** 表格事件 */
@@ -99,7 +77,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
schema: useTypeGridFormSchema(),
},
gridOptions: {
columns: useTypeGridColumns(onActionClick),
columns: useTypeGridColumns(),
height: 'auto',
keepSource: true,
proxyConfig: {
@@ -150,6 +128,30 @@ const [Grid, gridApi] = useVbenVxeGrid({
{{ $t('ui.actionTitle.export') }}
</Button>
</template>
<template #actions="{ row }">
<TableAction
:actions="[
{
label: $t('common.edit'),
type: 'link',
icon: 'ant-design:edit-outlined',
auth: ['system:dict:update'],
onClick: onEdit.bind(null, row),
},
{
label: $t('common.delete'),
type: 'link',
danger: true,
icon: 'ant-design:delete-outlined',
auth: ['system:dict:delete'],
popConfirm: {
title: $t('ui.actionMessage.deleteConfirm', [row.name]),
confirm: onDelete.bind(null, row),
},
},
]"
/>
</template>
</Grid>
</div>
</template>

View File

@@ -11,7 +11,7 @@ import { Button, message } from 'ant-design-vue';
import { useVbenVxeGrid } from '#/adapter/vxe-table';
import { deleteRole, exportRole, getRolePage } from '#/api/system/role';
import { DocAlert } from '#/components/doc-alert';
import { TableAction } from '#/components/table-action';
import { ACTION_KEY, TableAction } from '#/components/table-action';
import { $t } from '#/locales';
import { useGridColumns, useGridFormSchema } from './data';
@@ -58,19 +58,16 @@ function onCreate() {
/** 删除角色 */
async function onDelete(row: SystemRoleApi.Role) {
const hideLoading = message.loading({
message.loading({
content: $t('ui.actionMessage.deleting', [row.name]),
duration: 0,
key: 'action_process_msg',
key: ACTION_KEY,
});
try {
await deleteRole(row.id as number);
hideLoading();
message.success($t('ui.actionMessage.deleteSuccess', [row.name]));
onRefresh();
} catch {
hideLoading();
}
await deleteRole(row.id as number);
message.success({
content: $t('ui.actionMessage.deleteSuccess', [row.name]),
key: ACTION_KEY,
});
onRefresh();
}
/** 分配角色的数据权限 */

View File

@@ -15,6 +15,7 @@ import { useVbenVxeGrid } from '#/adapter/vxe-table';
import { deleteTenant, exportTenant, getTenantPage } from '#/api/system/tenant';
import { getTenantPackageList } from '#/api/system/tenant-package';
import { DocAlert } from '#/components/doc-alert';
import { ACTION_KEY, TableAction } from '#/components/table-action';
import { $t } from '#/locales';
import { useGridColumns, useGridFormSchema } from './data';
@@ -58,18 +59,16 @@ function onEdit(row: SystemTenantApi.Tenant) {
/** 删除租户 */
async function onDelete(row: SystemTenantApi.Tenant) {
const hideLoading = message.loading({
message.loading({
content: $t('ui.actionMessage.deleting', [row.name]),
duration: 0,
key: 'action_process_msg',
key: ACTION_KEY,
});
try {
await deleteTenant(row.id as number);
message.success($t('ui.actionMessage.deleteSuccess', [row.name]));
onRefresh();
} catch {
hideLoading();
}
await deleteTenant(row.id as number);
message.success({
content: $t('ui.actionMessage.deleteSuccess', [row.name]),
key: ACTION_KEY,
});
onRefresh();
}
const [Grid, gridApi] = useVbenVxeGrid({
@@ -78,8 +77,6 @@ const [Grid, gridApi] = useVbenVxeGrid({
},
gridOptions: {
columns: useGridColumns(getPackageName),
height: 'auto',
keepSource: true,
proxyConfig: {
ajax: {
query: async ({ page }, formValues) => {

View File

@@ -13,6 +13,7 @@ import {
getTenantPackagePage,
} from '#/api/system/tenant-package';
import { DocAlert } from '#/components/doc-alert';
import { ACTION_KEY, TableAction } from '#/components/table-action';
import { $t } from '#/locales';
import { useGridColumns, useGridFormSchema } from './data';
@@ -40,18 +41,16 @@ function onEdit(row: SystemTenantPackageApi.TenantPackage) {
/** 删除租户套餐 */
async function onDelete(row: SystemTenantPackageApi.TenantPackage) {
const hideLoading = message.loading({
message.loading({
content: $t('ui.actionMessage.deleting', [row.name]),
duration: 0,
key: 'action_process_msg',
key: ACTION_KEY,
});
try {
await deleteTenantPackage(row.id as number);
message.success($t('ui.actionMessage.deleteSuccess', [row.name]));
onRefresh();
} catch {
hideLoading();
}
await deleteTenantPackage(row.id as number);
message.success({
content: $t('ui.actionMessage.deleteSuccess', [row.name]),
key: ACTION_KEY,
});
onRefresh();
}
const [Grid, gridApi] = useVbenVxeGrid({

View File

@@ -19,7 +19,7 @@ import {
updateUserStatus,
} from '#/api/system/user';
import { DocAlert } from '#/components/doc-alert';
import { TableAction } from '#/components/table-action';
import { ACTION_KEY, TableAction } from '#/components/table-action';
import { $t } from '#/locales';
import { DICT_TYPE, getDictLabel } from '#/utils';
@@ -85,18 +85,16 @@ function onEdit(row: SystemUserApi.User) {
/** 删除用户 */
async function onDelete(row: SystemUserApi.User) {
const hideLoading = message.loading({
message.loading({
content: $t('ui.actionMessage.deleting', [row.username]),
duration: 0,
key: 'action_process_msg',
key: ACTION_KEY,
});
try {
await deleteUser(row.id as number);
message.success($t('ui.actionMessage.deleteSuccess', [row.username]));
onRefresh();
} catch {
hideLoading();
}
await deleteUser(row.id as number);
message.success({
content: $t('ui.actionMessage.deleteSuccess', [row.username]),
key: ACTION_KEY,
});
onRefresh();
}
/** 重置密码 */