refact: 重构目录架构

This commit is contained in:
ah--desktop
2025-10-26 10:03:58 +08:00
parent 9447d05ea1
commit 39ade97a16
91 changed files with 259 additions and 731 deletions
@@ -0,0 +1,223 @@
<script lang="ts" setup>
import { computed, ref, watch } from 'vue';
import { Form, Input, Modal, Select, message } from 'ant-design-vue';
import {
super_createAccountApi,
super_updateAccountApi,
type SuperAccountVO,
type SuperAccountDTO
} from '#/api/organization/account-super';
interface Emits {
(e: 'success'): void;
}
const emit = defineEmits<Emits>();
defineOptions({ name: 'SuperAccountFormModal' });
// 响应式数据
const formRef = ref();
const loading = ref(false);
const visible = ref(false);
const isEdit = ref(false);
const currentAccountData = ref<SuperAccountVO.AccountInfoVO | null>(null);
// 表单数据
const formData = ref<SuperAccountDTO.SuperCreateAccountDTO & { status?: number }>({
loginCode: '',
password: '',
realName: '',
phone: '',
companyId: 0,
departmentId: undefined,
positionId: undefined,
role: '',
avatarImageId: undefined,
remark: '',
status: 0,
});
// 模态框标题
const modalTitle = computed(() => isEdit.value ? '编辑账户' : '添加账户');
// 状态选项
const statusOptions = [
{ label: '正常', value: 0 },
{ label: '删除', value: 1 },
{ label: '停用', value: 2 },
{ label: '冻结', value: 3 },
];
// 重置表单
function resetForm() {
formData.value = {
loginCode: '',
password: '',
realName: '',
phone: '',
companyId: 0,
departmentId: undefined,
positionId: undefined,
role: '',
avatarImageId: undefined,
remark: '',
status: 0,
};
formRef.value?.resetFields();
}
// 处理模态框关闭
function handleCancel() {
visible.value = false;
}
// 暴露给父组件的方法
function open(accountData?: SuperAccountVO.AccountInfoVO | null) {
isEdit.value = !!accountData;
currentAccountData.value = accountData || null;
resetForm();
if (accountData) {
formData.value = {
loginCode: accountData.loginCode,
password: '', // 编辑时密码为空
realName: accountData.realName,
phone: accountData.phone || '',
companyId: accountData.companyId || 0,
departmentId: accountData.departmentId,
positionId: accountData.positionId,
role: accountData.role || '',
avatarImageId: accountData.avatarImageId,
remark: accountData.remark || '',
status: accountData.status,
};
}
visible.value = true;
}
// 处理表单提交
async function handleSubmit() {
try {
await formRef.value?.validate();
loading.value = true;
if (isEdit.value && currentAccountData.value) {
const { password, ...updateData } = formData.value;
await super_updateAccountApi(currentAccountData.value.id, updateData);
message.success('更新成功');
} else {
await super_createAccountApi(formData.value);
message.success('创建成功');
}
visible.value = false;
emit('success');
} catch (error: any) {
console.error('保存账户失败:', error);
const errorMessage = error?.response?.data?.message || error?.message || '保存账户失败';
message.error(errorMessage);
} finally {
loading.value = false;
}
}
// 监听弹窗关闭
watch(visible, (val) => {
if (!val) {
resetForm();
}
});
// 暴露方法给父组件
defineExpose({
open,
});
</script>
<template>
<Modal
:open="visible"
:title="modalTitle"
width="500px"
:confirm-loading="loading"
@ok="handleSubmit"
@cancel="handleCancel"
>
<Form
ref="formRef"
:model="formData"
:label-col="{ span: 6 }"
:wrapper-col="{ span: 18 }"
>
<Form.Item label="登录账号" name="loginCode" :rules="[
{ required: true, message: '请输入登录账号' },
{ min: 3, max: 20, message: '登录账号长度为3-20个字符' },
{ pattern: /^[a-zA-Z0-9_]+$/, message: '登录账号只能包含字母、数字和下划线' }
]">
<Input v-model:value="formData.loginCode" placeholder="请输入登录账号" />
</Form.Item>
<Form.Item v-if="!isEdit" label="密码" name="password" :rules="[
{ required: true, message: '请输入密码' },
{ min: 6, max: 20, message: '密码长度为6-20个字符' }
]">
<Input v-model:value="formData.password" type="password" placeholder="请输入密码" />
</Form.Item>
<Form.Item label="真实姓名" name="realName" :rules="[{ required: true, message: '请输入真实姓名' }]">
<Input v-model:value="formData.realName" placeholder="请输入真实姓名" />
</Form.Item>
<Form.Item label="备注" name="remark">
<Input v-model:value="formData.remark" placeholder="请输入备注" />
</Form.Item>
<Form.Item label="手机号" name="phone" :rules="[
{ pattern: /^1[3-9]\d{9}$/, message: '请输入有效的手机号' }
]">
<Input v-model:value="formData.phone" placeholder="请输入手机号" />
</Form.Item>
<Form.Item label="公司ID" name="companyId" :rules="[{ required: true, message: '请输入公司ID' }]">
<Input v-model:value="formData.companyId" type="number" placeholder="请输入公司ID" />
</Form.Item>
<Form.Item label="部门ID" name="departmentId">
<Input v-model:value="formData.departmentId" type="number" placeholder="请输入部门ID" />
</Form.Item>
<Form.Item label="岗位ID" name="positionId">
<Input v-model:value="formData.positionId" type="number" placeholder="请输入岗位ID" />
</Form.Item>
<Form.Item label="角色" name="role" :rules="[{ required: true, message: '请输入角色' }]">
<Select
v-model:value="formData.role"
placeholder="请选择角色"
:options="[
{ label: '超级管理员', value: 'super' },
{ label: '管理员', value: 'admin' },
{ label: '普通用户', value: 'user' }
]"
/>
</Form.Item>
<Form.Item label="头像图片ID" name="avatarImageId">
<Input v-model:value="formData.avatarImageId" type="number" placeholder="请输入头像图片ID" />
</Form.Item>
<Form.Item v-if="isEdit" label="状态" name="status">
<Select
v-model:value="formData.status"
placeholder="请选择状态"
:options="statusOptions"
/>
</Form.Item>
</Form>
</Modal>
</template>
@@ -0,0 +1,330 @@
<script lang="ts" setup>
import { ref, computed } from 'vue';
import { Page } from '@vben/common-ui';
import { Button, message, Space, Tag } from 'ant-design-vue';
import { createIconifyIcon } from '@vben/icons';
import { useVbenVxeGrid } from '#/adapter/vxe-table';
import type { VxeGridProps } from '#/adapter/vxe-table';
import {
super_deleteAccountApi,
super_getAccountPageApi,
type SuperAccountVO,
type SuperAccountDTO
} from '#/api/organization/account-super';
import type { PageQueryDTO } from '#/types/common';
import SuperAccountFormModal from './components/SuperAccountFormModal.vue';
// 创建图标组件
const PlusIcon = createIconifyIcon('lucide:plus');
defineOptions({ name: 'SuperAccountManagement' });
// 响应式数据
const loading = ref(false);
const accountFormModalRef = ref();
// 搜索表单
const searchForm = ref({
loginCode: undefined as undefined | string,
realName: undefined as undefined | string,
phone: undefined as undefined | string,
companyId: undefined as undefined | number,
departmentId: undefined as undefined | number,
positionId: undefined as undefined | number,
role: undefined as undefined | string,
status: undefined as undefined | number,
});
// 状态选项
const statusOptions = [
{ label: '正常', value: 0 },
{ label: '删除', value: 1 },
{ label: '停用', value: 2 },
{ label: '冻结', value: 3 },
];
// 搜索表单配置
const formOptions = computed(() => ({
schemas: [
{
fieldName: 'loginCode',
label: '登录账号',
},
{
fieldName: 'realName',
label: '真实姓名',
},
{
fieldName: 'phone',
label: '手机号',
},
{
fieldName: 'status',
label: '状态',
component: 'Select',
componentProps: {
options: statusOptions,
placeholder: '请选择状态',
},
},
],
showDefaultActions: true,
collapsed: true,
collapsedRows: 1,
}));
// VbenVxeGrid 表格配置
const gridOptions: VxeGridProps<any> = {
columns: [
{
type: 'seq' as const,
minWidth: 'auto',
title: '序号',
},
{
field: 'loginCode',
title: '登录账号',
minWidth: 120,
},
{
field: 'realName',
title: '真实姓名',
minWidth: 120,
},
{
field: 'phone',
title: '手机号',
minWidth: 120,
},
{
field: 'companyName',
title: '公司',
minWidth: 150,
},
{
field: 'departmentName',
title: '部门',
minWidth: 120,
},
{
field: 'positionName',
title: '职位',
minWidth: 120,
},
{
field: 'role',
title: '角色',
minWidth: 100,
},
{
field: 'status',
title: '状态',
minWidth: 80,
slots: { default: 'status' },
},
{
field: 'createTime',
title: '创建时间',
minWidth: 160,
},
{
title: '操作',
width: 120,
fixed: 'right' as const,
slots: { default: 'action' },
},
],
height: 'auto',
border: true,
stripe: true,
showOverflow: true,
size: 'small',
toolbarConfig: {
custom: true,
refresh: true,
zoom: true,
},
data: [],
pagerConfig: {
enabled: true,
pageSizes: [10, 20, 50, 100],
layouts: ['PrevJump', 'PrevPage', 'Number', 'NextPage', 'NextJump', 'Sizes', 'FullJump', 'Total'] as ('PrevJump' | 'PrevPage' | 'Number' | 'NextPage' | 'NextJump' | 'Sizes' | 'FullJump' | 'Total')[],
},
// 配置远程加载
proxyConfig: {
ajax: {
query: async ({ page }) => {
try {
loading.value = true;
const params: PageQueryDTO<SuperAccountDTO.AccountFilterDTO> = {
page: page.currentPage,
pageSize: page.pageSize,
...searchForm.value,
};
const response = await super_getAccountPageApi(params);
return {
items: response.records,
total: response.total,
};
} catch (error: any) {
console.error('查询数据失败:', error);
const errorMessage = error?.response?.data?.message || error?.message || '查询数据失败';
message.error(errorMessage);
return {
items: [],
total: 0,
};
} finally {
loading.value = false;
}
},
},
},
};
// 表格实例
const [Grid, gridApi] = useVbenVxeGrid({
gridOptions,
formOptions: formOptions.value,
showSearchForm: true,
tableTitle: '超级账户管理',
});
// 计算属性
const hasSelected = computed(() => {
const vxeTable = (gridApi as any).grid;
return vxeTable?.getCheckboxRecords?.()?.length > 0;
});
// 刷新表格数据
function refreshTable() {
if (gridApi) {
gridApi.reload();
}
}
const handleAdd = () => {
accountFormModalRef.value?.open();
};
const handleEdit = (row: SuperAccountVO.AccountInfoVO) => {
accountFormModalRef.value?.open(row);
};
const handleDelete = async (row: SuperAccountVO.AccountInfoVO) => {
try {
await super_deleteAccountApi(row.id);
message.success('删除成功');
refreshTable();
} catch (error: any) {
console.error('删除失败:', error);
const errorMessage = error?.response?.data?.message || error?.message || '删除失败';
message.error(errorMessage);
}
};
const handleBatchDelete = async () => {
const vxeTable = (gridApi as any).grid;
const selectedRows = vxeTable?.getCheckboxRecords?.();
if (!selectedRows?.length) {
message.warning('请选择要删除的数据');
return;
}
try {
const deletePromises = selectedRows.map((row: SuperAccountVO.AccountInfoVO) =>
super_deleteAccountApi(row.id)
);
await Promise.all(deletePromises);
message.success(`成功删除 ${selectedRows.length} 条记录`);
refreshTable();
} catch (error: any) {
console.error('批量删除失败:', error);
const errorMessage = error?.response?.data?.message || error?.message || '批量删除失败';
message.error(errorMessage);
}
};
// 处理模态框成功回调
function handleModalSuccess() {
refreshTable();
}
// 获取状态文本
const getStatusText = (status: number) => {
const statusMap = {
0: '正常',
1: '删除',
2: '停用',
3: '冻结',
};
return statusMap[status as keyof typeof statusMap] || '未知';
};
// 获取状态颜色
const getStatusColor = (status: number) => {
const colorMap = {
0: 'green',
1: 'red',
2: 'orange',
3: 'purple',
};
return colorMap[status as keyof typeof colorMap] || 'default';
};
</script>
<template>
<Page title="超级账户管理" auto-content-height>
<template #description>
<div class="text-foreground/80 mt-2">
管理超级管理员账户信息,支持账户的增删改查操作
</div>
</template>
<!-- VbenVxeGrid 表格 -->
<Grid
:loading="loading"
>
<!-- 工具栏工具 -->
<template #toolbar-tools>
<Space>
<Button type="primary" @click="handleAdd">
<PlusIcon />
添加账户
</Button>
<Button
v-if="hasSelected"
danger
@click="handleBatchDelete"
>
批量删除
</Button>
</Space>
</template>
<!-- 状态列 -->
<template #status="{ row }">
<Tag :color="getStatusColor(row.status)">
{{ getStatusText(row.status) }}
</Tag>
</template>
<!-- 操作列 -->
<template #action="{ row }">
<Space>
<Button size="small" @click="handleEdit(row)">
编辑
</Button>
<Button size="small" danger @click="handleDelete(row)">
删除
</Button>
</Space>
</template>
</Grid>
<!-- 账户表单弹窗 -->
<SuperAccountFormModal ref="accountFormModalRef" @success="handleModalSuccess" />
</Page>
</template>