app功能列表
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run

This commit is contained in:
2025-07-24 11:06:13 +08:00
parent 1b522f2bbf
commit 15ccb7f0b9
7 changed files with 546 additions and 1 deletions

View File

@@ -0,0 +1,61 @@
import type { FunListVO, FunListForm, FunListQuery } from './model';
import type { ID, IDS } from '#/api/common';
import type { PageResult } from '#/api/common';
import { commonExport } from '#/api/helper';
import { requestClient } from '#/api/request';
/**
* 查询APP功能列表列表
* @param params
* @returns APP功能列表列表
*/
export function funListList(params?: FunListQuery) {
return requestClient.get<PageResult<FunListVO>>('/system/funList/list', { params });
}
/**
* 导出APP功能列表列表
* @param params
* @returns APP功能列表列表
*/
export function funListExport(params?: FunListQuery) {
return commonExport('/system/funList/export', params ?? {});
}
/**
* 查询APP功能列表详情
* @param id id
* @returns APP功能列表详情
*/
export function funListInfo(id: ID) {
return requestClient.get<FunListVO>(`/system/funList/${id}`);
}
/**
* 新增APP功能列表
* @param data
* @returns void
*/
export function funListAdd(data: FunListForm) {
return requestClient.postWithMsg<void>('/system/funList', data);
}
/**
* 更新APP功能列表
* @param data
* @returns void
*/
export function funListUpdate(data: FunListForm) {
return requestClient.putWithMsg<void>('/system/funList', data);
}
/**
* 删除APP功能列表
* @param id id
* @returns void
*/
export function funListRemove(id: ID | IDS) {
return requestClient.deleteWithMsg<void>(`/system/funList/${id}`);
}

View File

@@ -0,0 +1,84 @@
import type { PageQuery, BaseEntity } from '#/api/common';
export interface FunListVO {
/**
* 主键
*/
id: string | number;
/**
* 角色id
*/
roleid: string | number;
/**
* 名称
*/
name: string;
/**
* icon
*/
icon: string;
/**
* url
*/
url: string;
}
export interface FunListForm extends BaseEntity {
/**
* 主键
*/
id?: string | number;
/**
* 角色id
*/
roleid?: string | number;
/**
* 名称
*/
name?: string;
/**
* icon
*/
icon?: string;
/**
* url
*/
url?: string;
}
export interface FunListQuery extends PageQuery {
/**
* 角色id
*/
roleid?: string | number;
/**
* 名称
*/
name?: string;
/**
* icon
*/
icon?: string;
/**
* url
*/
url?: string;
/**
* 日期范围参数
*/
params?: any;
}

View File

@@ -0,0 +1,100 @@
import type { FormSchemaGetter } from '#/adapter/form';
import type { VxeGridProps } from '#/adapter/vxe-table';
export const querySchema: FormSchemaGetter = () => [
{
component: 'Select',
fieldName: 'roleid',
label: '角色',
},
{
component: 'Input',
fieldName: 'name',
label: '名称',
},
{
component: 'Input',
fieldName: 'icon',
label: 'icon',
},
{
component: 'Input',
fieldName: 'url',
label: 'url',
},
];
// 需要使用i18n注意这里要改成getter形式 否则切换语言不会刷新
// export const columns: () => VxeGridProps['columns'] = () => [
export const columns: VxeGridProps['columns'] = [
{ type: 'checkbox', width: 60 },
{
title: '主键',
field: 'id',
},
{
title: '角色',
field: 'roleName',
},
{
title: '名称',
field: 'name',
},
{
field: 'icon',
title: '头像',
slots: { default: 'icon' },
minWidth: 80,
},
{
title: 'url',
field: 'url',
},
{
field: 'action',
fixed: 'right',
slots: { default: 'action' },
title: '操作',
width: 180,
},
];
export const modalSchema: FormSchemaGetter = () => [
{
label: '主键',
fieldName: 'id',
component: 'Input',
dependencies: {
show: () => false,
triggerFields: [''],
},
},
{
label: '角色',
fieldName: 'roleid',
component: 'Select',
},
{
label: '名称',
fieldName: 'name',
component: 'Input',
},
{
label: 'icon',
fieldName: 'icon',
component: 'FileUpload',
/**
* 注意这里获取为数组 需要自行定义回显/提交
* 文件上传还在demo阶段 可能有重大改动!
*/
componentProps: {
// accept: 'application/pdf', // 可选拓展名或者mime类型 ,拼接
// maxCount: 1, // 最大上传文件数 默认为1 为1会绑定为string而非string[]类型
},
},
{
label: 'url',
fieldName: 'url',
component: 'Input',
},
];

View File

@@ -0,0 +1,119 @@
<script setup lang="ts">
import { computed, ref } from 'vue';
import { useVbenModal } from '@vben/common-ui';
import { $t } from '@vben/locales';
import { cloneDeep } from '@vben/utils';
import { useVbenForm } from '#/adapter/form';
import { funListAdd, funListInfo, funListUpdate } from '#/api/system/funList';
import { defaultFormValueGetter, useBeforeCloseDiff } from '#/utils/popup';
import { modalSchema } from './data';
import { roleList } from '#/api/system/role';
const emit = defineEmits<{ reload: [] }>();
const isUpdate = ref(false);
const title = computed(() => {
return isUpdate.value ? $t('pages.common.edit') : $t('pages.common.add');
});
async function setupPackageSelect() {
const role = await roleList();
const options = role.rows.map((item) => ({
label: item.roleName,
value: item.roleId,
}));
formApi.updateSchema([
{
componentProps: {
optionFilterProp: 'label',
optionLabelProp: 'label',
options,
showSearch: true,
},
fieldName: 'roleid',
},
]);
}
const [BasicForm, formApi] = useVbenForm({
commonConfig: {
// 默认占满两列
formItemClass: 'col-span-2',
// 默认label宽度 px
labelWidth: 80,
// 通用配置项 会影响到所有表单项
componentProps: {
class: 'w-full',
}
},
schema: modalSchema(),
showDefaultActions: false,
wrapperClass: 'grid-cols-2',
});
const { onBeforeClose, markInitialized, resetInitialized } = useBeforeCloseDiff(
{
initializedGetter: defaultFormValueGetter(formApi),
currentGetter: defaultFormValueGetter(formApi),
},
);
const [BasicModal, modalApi] = useVbenModal({
// 在这里更改宽度
class: 'w-[550px]',
fullscreenButton: false,
onBeforeClose,
onClosed: handleClosed,
onConfirm: handleConfirm,
onOpenChange: async (isOpen) => {
if (!isOpen) {
return null;
}
modalApi.modalLoading(true);
const { id } = modalApi.getData() as { id?: number | string };
isUpdate.value = !!id;
if (isUpdate.value && id) {
const record = await funListInfo(id);
await formApi.setValues(record);
}
await markInitialized();
setupPackageSelect();
modalApi.modalLoading(false);
},
});
async function handleConfirm() {
try {
modalApi.lock(true);
const { valid } = await formApi.validate();
if (!valid) {
return;
}
// getValues获取为一个readonly的对象 需要修改必须先深拷贝一次
const data = cloneDeep(await formApi.getValues());
await (isUpdate.value ? funListUpdate(data) : funListAdd(data));
resetInitialized();
emit('reload');
modalApi.close();
} catch (error) {
console.error(error);
} finally {
modalApi.lock(false);
}
}
async function handleClosed() {
await formApi.resetForm();
resetInitialized();
}
</script>
<template>
<BasicModal :title="title">
<BasicForm />
</BasicModal>
</template>

View File

@@ -0,0 +1,181 @@
<script setup lang="ts">
import { Page, useVbenModal, type VbenFormProps } from '@vben/common-ui';
import { getVxePopupContainer } from '@vben/utils';
import { Avatar, Modal, Popconfirm, Space } from "ant-design-vue";
import {
useVbenVxeGrid,
vxeCheckboxChecked,
type VxeGridProps
} from '#/adapter/vxe-table';
import {
funListExport,
funListList,
funListRemove,
} from '#/api/system/funList';
import type { FunListForm } from '#/api/system/funList/model';
import { commonDownloadExcel } from '#/utils/file/download';
import funListModal from './funList-modal.vue';
import { columns, querySchema } from './data';
import { preferences } from "@vben/preferences";
const formOptions: VbenFormProps = {
commonConfig: {
labelWidth: 80,
componentProps: {
allowClear: true,
},
},
schema: querySchema(),
wrapperClass: 'grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4',
// 处理区间选择器RangePicker时间格式 将一个字段映射为两个字段 搜索/导出会用到
// 不需要直接删除
// fieldMappingTime: [
// [
// 'createTime',
// ['params[beginTime]', 'params[endTime]'],
// ['YYYY-MM-DD 00:00:00', 'YYYY-MM-DD 23:59:59'],
// ],
// ],
};
const gridOptions: VxeGridProps = {
checkboxConfig: {
// 高亮
highlight: true,
// 翻页时保留选中状态
reserve: true,
// 点击行选中
// trigger: 'row',
},
// 需要使用i18n注意这里要改成getter形式 否则切换语言不会刷新
// columns: columns(),
columns,
height: 'auto',
keepSource: true,
pagerConfig: {},
proxyConfig: {
ajax: {
query: async ({ page }, formValues = {}) => {
return await funListList({
pageNum: page.currentPage,
pageSize: page.pageSize,
...formValues,
});
},
},
},
rowConfig: {
keyField: 'id',
},
// 表格全局唯一表示 保存列配置需要用到
id: 'system-funList-index'
};
const [BasicTable, tableApi] = useVbenVxeGrid({
formOptions,
gridOptions,
});
const [FunListModal, modalApi] = useVbenModal({
connectedComponent: funListModal,
});
function handleAdd() {
modalApi.setData({});
modalApi.open();
}
async function handleEdit(row: Required<FunListForm>) {
modalApi.setData({ id: row.id });
modalApi.open();
}
async function handleDelete(row: Required<FunListForm>) {
await funListRemove(row.id);
await tableApi.query();
}
function handleMultiDelete() {
const rows = tableApi.grid.getCheckboxRecords();
const ids = rows.map((row: Required<FunListForm>) => row.id);
Modal.confirm({
title: '提示',
okType: 'danger',
content: `确认删除选中的${ids.length}条记录吗?`,
onOk: async () => {
await funListRemove(ids);
await tableApi.query();
},
});
}
function handleDownloadExcel() {
commonDownloadExcel(funListExport, 'APP功能列表数据', tableApi.formApi.form.values, {
fieldMappingTime: formOptions.fieldMappingTime,
});
}
</script>
<template>
<Page :auto-content-height="true">
<BasicTable table-title="APP功能列表列表">
<template #icon="{ row }">
<!-- 可能要判断空字符串情况 所以没有使用?? -->
<Avatar :src="row.icon || preferences.app.defaultAvatar" />
</template>
<template #toolbar-tools>
<Space>
<a-button
v-access:code="['system:funList:export']"
@click="handleDownloadExcel"
>
{{ $t('pages.common.export') }}
</a-button>
<a-button
:disabled="!vxeCheckboxChecked(tableApi)"
danger
type="primary"
v-access:code="['system:funList:remove']"
@click="handleMultiDelete">
{{ $t('pages.common.delete') }}
</a-button>
<a-button
type="primary"
v-access:code="['system:funList:add']"
@click="handleAdd"
>
{{ $t('pages.common.add') }}
</a-button>
</Space>
</template>
<template #action="{ row }">
<Space>
<ghost-button
v-access:code="['system:funList:edit']"
@click.stop="handleEdit(row)"
>
{{ $t('pages.common.edit') }}
</ghost-button>
<Popconfirm
:get-popup-container="getVxePopupContainer"
placement="left"
title="确认删除?"
@confirm="handleDelete(row)"
>
<ghost-button
danger
v-access:code="['system:funList:remove']"
@click.stop=""
>
{{ $t('pages.common.delete') }}
</ghost-button>
</Popconfirm>
</Space>
</template>
</BasicTable>
<FunListModal @reload="tableApi.query()" />
</Page>
</template>

View File

@@ -11,7 +11,6 @@ import { Page, useVbenDrawer, useVbenModal, } from '@vben/common-ui';
import { $t } from '@vben/locales';
import { preferences } from '@vben/preferences';
import { getVxePopupContainer } from '@vben/utils';
import {
Avatar,
Dropdown,

View File

@@ -1,3 +1,4 @@
{
"name": "vben-admin-monorepo",
"version": "5.5.6",