mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-24 21:49:19 +08:00
wip(account): 开发账户管理相关
This commit is contained in:
+195
@@ -0,0 +1,195 @@
|
||||
<script lang="ts" setup>
|
||||
import { computed, ref, watch } from 'vue';
|
||||
import { Form, Input, Modal, Select, message } from 'ant-design-vue';
|
||||
|
||||
import {
|
||||
admin_createAccountApi,
|
||||
admin_updateAccountApi,
|
||||
type AccountVO,
|
||||
type AccountDTO
|
||||
} from '#/api/org/account';
|
||||
|
||||
interface Emits {
|
||||
(e: 'success'): void;
|
||||
}
|
||||
|
||||
const emit = defineEmits<Emits>();
|
||||
|
||||
defineOptions({ name: 'AccountFormModal' });
|
||||
|
||||
// 响应式数据
|
||||
const formRef = ref();
|
||||
const loading = ref(false);
|
||||
const visible = ref(false);
|
||||
const isEdit = ref(false);
|
||||
const currentAccountData = ref<AccountVO.AccountInfoVO | null>(null);
|
||||
|
||||
// 表单数据
|
||||
const formData = ref<AccountDTO.CreateAccountDTO>({
|
||||
username: '',
|
||||
password: '',
|
||||
realName: '',
|
||||
email: '',
|
||||
phone: '',
|
||||
companyId: undefined,
|
||||
departmentId: undefined,
|
||||
positionId: undefined,
|
||||
roleId: undefined,
|
||||
status: 1,
|
||||
});
|
||||
|
||||
// 模态框标题
|
||||
const modalTitle = computed(() => isEdit.value ? '编辑账户' : '添加账户');
|
||||
|
||||
// 状态选项
|
||||
const statusOptions = [
|
||||
{ label: '禁用', value: 0 },
|
||||
{ label: '正常', value: 1 },
|
||||
];
|
||||
|
||||
// 重置表单
|
||||
function resetForm() {
|
||||
formData.value = {
|
||||
username: '',
|
||||
password: '',
|
||||
realName: '',
|
||||
email: '',
|
||||
phone: '',
|
||||
companyId: undefined,
|
||||
departmentId: undefined,
|
||||
positionId: undefined,
|
||||
roleId: undefined,
|
||||
status: 1,
|
||||
};
|
||||
formRef.value?.resetFields();
|
||||
}
|
||||
|
||||
// 处理模态框关闭
|
||||
function handleCancel() {
|
||||
visible.value = false;
|
||||
}
|
||||
|
||||
// 暴露给父组件的方法
|
||||
function open(editMode: boolean = false, accountData?: AccountVO.AccountInfoVO | null) {
|
||||
isEdit.value = editMode;
|
||||
currentAccountData.value = accountData || null;
|
||||
|
||||
resetForm();
|
||||
|
||||
if (editMode && accountData) {
|
||||
formData.value = {
|
||||
username: accountData.username,
|
||||
password: '', // 编辑时密码为空
|
||||
realName: accountData.realName,
|
||||
email: accountData.email || '',
|
||||
phone: accountData.phone || '',
|
||||
companyId: accountData.companyId,
|
||||
departmentId: accountData.departmentId,
|
||||
positionId: accountData.positionId,
|
||||
roleId: accountData.roleId,
|
||||
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 admin_updateAccountApi({ ...updateData, id: currentAccountData.value.id });
|
||||
message.success('更新成功');
|
||||
} else {
|
||||
await admin_createAccountApi(formData.value);
|
||||
message.success('创建成功');
|
||||
}
|
||||
|
||||
visible.value = false;
|
||||
emit('success');
|
||||
} catch (error) {
|
||||
console.error('保存账户失败:', error);
|
||||
message.error('保存账户失败');
|
||||
} 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="username" :rules="[{ required: true, message: '请输入用户名' }]">
|
||||
<Input v-model:value="formData.username" placeholder="请输入用户名" />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item v-if="!isEdit" label="密码" name="password" :rules="[{ required: true, message: '请输入密码' }]">
|
||||
<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="email">
|
||||
<Input v-model:value="formData.email" placeholder="请输入邮箱" />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="手机号" name="phone">
|
||||
<Input v-model:value="formData.phone" placeholder="请输入手机号" />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="公司ID" name="companyId">
|
||||
<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="角色ID" name="roleId">
|
||||
<Input v-model:value="formData.roleId" type="number" placeholder="请输入角色ID" />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="状态" name="status">
|
||||
<Select
|
||||
v-model:value="formData.status"
|
||||
placeholder="请选择状态"
|
||||
:options="statusOptions"
|
||||
/>
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</Modal>
|
||||
</template>
|
||||
@@ -0,0 +1,328 @@
|
||||
<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 {
|
||||
admin_deleteAccountApi,
|
||||
admin_getAccountPageApi,
|
||||
type AccountVO,
|
||||
type AccountDTO
|
||||
} from '#/api/org/account';
|
||||
import type { PageQueryDTO } from '#/types/common';
|
||||
import AccountFormModal from './components/AccountFormModal.vue';
|
||||
|
||||
// 创建图标组件
|
||||
const PlusIcon = createIconifyIcon('lucide:plus');
|
||||
|
||||
defineOptions({ name: 'CompanyAccountManagement' });
|
||||
|
||||
// 响应式数据
|
||||
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<AccountDTO.AccountFilterDTO> = {
|
||||
page: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
...searchForm.value,
|
||||
};
|
||||
const response = await admin_getAccountPageApi(params);
|
||||
return {
|
||||
items: response.records,
|
||||
total: response.total,
|
||||
};
|
||||
} catch (error) {
|
||||
console.error('查询数据失败:', error);
|
||||
message.error('查询数据失败');
|
||||
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: AccountVO.AccountInfoVO) => {
|
||||
accountFormModalRef.value?.open(row);
|
||||
};
|
||||
|
||||
const handleDelete = async (row: AccountVO.AccountInfoVO) => {
|
||||
try {
|
||||
await admin_deleteAccountApi(row.id);
|
||||
message.success('删除成功');
|
||||
refreshTable();
|
||||
} catch (error) {
|
||||
console.error('删除失败:', error);
|
||||
message.error('删除失败');
|
||||
}
|
||||
};
|
||||
|
||||
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: AccountVO.AccountInfoVO) =>
|
||||
admin_deleteAccountApi(row.id)
|
||||
);
|
||||
await Promise.all(deletePromises);
|
||||
message.success('批量删除成功');
|
||||
refreshTable();
|
||||
} catch (error) {
|
||||
console.error('批量删除失败:', error);
|
||||
message.error('批量删除失败');
|
||||
}
|
||||
};
|
||||
|
||||
// 获取状态文本
|
||||
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';
|
||||
};
|
||||
|
||||
// 处理模态框成功回调
|
||||
function handleModalSuccess() {
|
||||
refreshTable();
|
||||
}
|
||||
|
||||
</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>
|
||||
|
||||
<!-- 账户表单弹窗 -->
|
||||
<AccountFormModal ref="accountFormModalRef" @success="handleModalSuccess" />
|
||||
</Page>
|
||||
</template>
|
||||
-264
@@ -1,264 +0,0 @@
|
||||
<script lang="ts" setup>
|
||||
import { ref, reactive, watch } from 'vue';
|
||||
import { Modal, Form, FormItem, Input, Select, SelectOption, Button, message } from 'ant-design-vue';
|
||||
import { createIconifyIcon } from '@vben/icons';
|
||||
|
||||
import {
|
||||
createAccountApi,
|
||||
updateAccountApi,
|
||||
type AccountVO,
|
||||
type AccountDTO
|
||||
} from '#/api/org/account';
|
||||
|
||||
// 创建图标组件
|
||||
const SaveIcon = createIconifyIcon('lucide:save');
|
||||
const CloseIcon = createIconifyIcon('lucide:x');
|
||||
|
||||
defineOptions({ name: 'AccountFormModal' });
|
||||
|
||||
// 响应式数据
|
||||
const visible = ref(false);
|
||||
const loading = ref(false);
|
||||
const isEdit = ref(false);
|
||||
const formRef = ref();
|
||||
|
||||
// 表单数据
|
||||
const formData = reactive<AccountDTO.CreateAccountDTO>({
|
||||
username: '',
|
||||
password: '',
|
||||
realName: '',
|
||||
email: '',
|
||||
phone: '',
|
||||
companyId: undefined,
|
||||
departmentId: undefined,
|
||||
positionId: undefined,
|
||||
roleId: undefined,
|
||||
status: 1,
|
||||
});
|
||||
|
||||
// 表单规则
|
||||
const formRules = {
|
||||
username: [
|
||||
{ required: true, message: '请输入用户名', trigger: 'blur' },
|
||||
{ min: 3, max: 20, message: '用户名长度为3-20个字符', trigger: 'blur' },
|
||||
],
|
||||
password: [
|
||||
{ required: true, message: '请输入密码', trigger: 'blur' },
|
||||
{ min: 6, max: 20, message: '密码长度为6-20个字符', trigger: 'blur' },
|
||||
],
|
||||
realName: [
|
||||
{ required: true, message: '请输入真实姓名', trigger: 'blur' },
|
||||
],
|
||||
email: [
|
||||
{ type: 'email', message: '请输入正确的邮箱格式', trigger: 'blur' },
|
||||
],
|
||||
phone: [
|
||||
{ pattern: /^1[3-9]\d{9}$/, message: '请输入正确的手机号', trigger: 'blur' },
|
||||
],
|
||||
};
|
||||
|
||||
// 状态选项
|
||||
const statusOptions = [
|
||||
{ label: '禁用', value: 0 },
|
||||
{ label: '正常', value: 1 },
|
||||
];
|
||||
|
||||
// 方法
|
||||
const open = (record?: AccountVO.AccountInfoVO) => {
|
||||
visible.value = true;
|
||||
isEdit.value = !!record;
|
||||
|
||||
if (record) {
|
||||
Object.assign(formData, {
|
||||
username: record.username,
|
||||
realName: record.realName,
|
||||
email: record.email,
|
||||
phone: record.phone,
|
||||
companyId: record.companyId,
|
||||
departmentId: record.departmentId,
|
||||
positionId: record.positionId,
|
||||
roleId: record.roleId,
|
||||
status: record.status,
|
||||
});
|
||||
} else {
|
||||
resetForm();
|
||||
}
|
||||
};
|
||||
|
||||
const close = () => {
|
||||
visible.value = false;
|
||||
resetForm();
|
||||
};
|
||||
|
||||
const resetForm = () => {
|
||||
Object.assign(formData, {
|
||||
username: '',
|
||||
password: '',
|
||||
realName: '',
|
||||
email: '',
|
||||
phone: '',
|
||||
companyId: undefined,
|
||||
departmentId: undefined,
|
||||
positionId: undefined,
|
||||
roleId: undefined,
|
||||
status: 1,
|
||||
});
|
||||
formRef.value?.resetFields();
|
||||
};
|
||||
|
||||
const handleSubmit = async () => {
|
||||
try {
|
||||
await formRef.value?.validate();
|
||||
loading.value = true;
|
||||
|
||||
if (isEdit.value) {
|
||||
const { password, ...updateData } = formData;
|
||||
await updateAccountApi(formData.id!, updateData);
|
||||
message.success('更新成功');
|
||||
} else {
|
||||
await createAccountApi(formData);
|
||||
message.success('创建成功');
|
||||
}
|
||||
|
||||
close();
|
||||
emit('success');
|
||||
} catch (error) {
|
||||
console.error('提交失败:', error);
|
||||
message.error(isEdit.value ? '更新失败' : '创建失败');
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
// 事件
|
||||
const emit = defineEmits<{
|
||||
success: [];
|
||||
}>();
|
||||
|
||||
// 监听弹窗关闭
|
||||
watch(visible, (val) => {
|
||||
if (!val) {
|
||||
resetForm();
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal
|
||||
v-model:open="visible"
|
||||
:title="isEdit ? '编辑账户' : '新增账户'"
|
||||
width="600px"
|
||||
:confirm-loading="loading"
|
||||
@cancel="close"
|
||||
>
|
||||
<Form
|
||||
ref="formRef"
|
||||
:model="formData"
|
||||
:rules="formRules"
|
||||
layout="vertical"
|
||||
class="mt-4"
|
||||
>
|
||||
<div class="grid grid-cols-2 gap-4">
|
||||
<FormItem label="用户名" name="username">
|
||||
<Input
|
||||
v-model:value="formData.username"
|
||||
placeholder="请输入用户名"
|
||||
:disabled="isEdit"
|
||||
/>
|
||||
</FormItem>
|
||||
|
||||
<FormItem label="密码" name="password" v-if="!isEdit">
|
||||
<Input
|
||||
v-model:value="formData.password"
|
||||
type="password"
|
||||
placeholder="请输入密码"
|
||||
/>
|
||||
</FormItem>
|
||||
|
||||
<FormItem label="真实姓名" name="realName">
|
||||
<Input
|
||||
v-model:value="formData.realName"
|
||||
placeholder="请输入真实姓名"
|
||||
/>
|
||||
</FormItem>
|
||||
|
||||
<FormItem label="邮箱" name="email">
|
||||
<Input
|
||||
v-model:value="formData.email"
|
||||
placeholder="请输入邮箱"
|
||||
/>
|
||||
</FormItem>
|
||||
|
||||
<FormItem label="手机号" name="phone">
|
||||
<Input
|
||||
v-model:value="formData.phone"
|
||||
placeholder="请输入手机号"
|
||||
/>
|
||||
</FormItem>
|
||||
|
||||
<FormItem label="公司ID" name="companyId">
|
||||
<Input
|
||||
v-model:value="formData.companyId"
|
||||
type="number"
|
||||
placeholder="请输入公司ID"
|
||||
/>
|
||||
</FormItem>
|
||||
|
||||
<FormItem label="部门ID" name="departmentId">
|
||||
<Input
|
||||
v-model:value="formData.departmentId"
|
||||
type="number"
|
||||
placeholder="请输入部门ID"
|
||||
/>
|
||||
</FormItem>
|
||||
|
||||
<FormItem label="职位ID" name="positionId">
|
||||
<Input
|
||||
v-model:value="formData.positionId"
|
||||
type="number"
|
||||
placeholder="请输入职位ID"
|
||||
/>
|
||||
</FormItem>
|
||||
|
||||
<FormItem label="角色ID" name="roleId">
|
||||
<Input
|
||||
v-model:value="formData.roleId"
|
||||
type="number"
|
||||
placeholder="请输入角色ID"
|
||||
/>
|
||||
</FormItem>
|
||||
|
||||
<FormItem label="状态" name="status">
|
||||
<Select
|
||||
v-model:value="formData.status"
|
||||
placeholder="请选择状态"
|
||||
>
|
||||
<SelectOption
|
||||
v-for="option in statusOptions"
|
||||
:key="option.value"
|
||||
:value="option.value"
|
||||
>
|
||||
{{ option.label }}
|
||||
</SelectOption>
|
||||
</Select>
|
||||
</FormItem>
|
||||
</div>
|
||||
</Form>
|
||||
|
||||
<template #footer>
|
||||
<div class="flex justify-end space-x-2">
|
||||
<Button @click="close" :icon="CloseIcon">
|
||||
取消
|
||||
</Button>
|
||||
<Button
|
||||
type="primary"
|
||||
:loading="loading"
|
||||
:icon="SaveIcon"
|
||||
@click="handleSubmit"
|
||||
>
|
||||
{{ isEdit ? '更新' : '创建' }}
|
||||
</Button>
|
||||
</div>
|
||||
</template>
|
||||
</Modal>
|
||||
</template>
|
||||
-346
@@ -1,346 +0,0 @@
|
||||
<script lang="ts" setup>
|
||||
import { ref, computed, h, onMounted } 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 {
|
||||
deleteAccountApi,
|
||||
getAccountPageApi,
|
||||
type AccountVO,
|
||||
type AccountDTO
|
||||
} from '#/api/org/account';
|
||||
import type { PageQueryDTO } from '#/types/common';
|
||||
import AccountFormModal from './components/AccountFormModal.vue';
|
||||
|
||||
// 创建图标组件
|
||||
const PlusIcon = createIconifyIcon('lucide:plus');
|
||||
const EditIcon = createIconifyIcon('lucide:edit');
|
||||
const TrashIcon = createIconifyIcon('lucide:trash-2');
|
||||
|
||||
defineOptions({ name: 'AdminAccountManagement' });
|
||||
|
||||
// 响应式数据
|
||||
const loading = ref(false);
|
||||
const accountFormModalRef = ref();
|
||||
|
||||
// 搜索表单
|
||||
const searchForm = ref({
|
||||
loginCode: '',
|
||||
realName: '',
|
||||
phone: '',
|
||||
companyId: undefined as number | undefined,
|
||||
departmentId: undefined as number | undefined,
|
||||
positionId: undefined as number | undefined,
|
||||
role: '',
|
||||
status: undefined as number | undefined,
|
||||
});
|
||||
|
||||
// 状态选项
|
||||
const statusOptions = [
|
||||
{ label: '正常', value: 0 },
|
||||
{ label: '删除', value: 1 },
|
||||
{ label: '停用', value: 2 },
|
||||
{ label: '冻结', value: 3 },
|
||||
];
|
||||
|
||||
// VbenVxeGrid 表格配置
|
||||
const gridOptions: VxeGridProps<any> = {
|
||||
columns: [
|
||||
{
|
||||
type: 'seq' as const,
|
||||
minWidth: 'auto',
|
||||
title: '序号',
|
||||
},
|
||||
{
|
||||
field: 'username',
|
||||
title: '用户名',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
field: 'realName',
|
||||
title: '真实姓名',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
field: 'email',
|
||||
title: '邮箱',
|
||||
minWidth: 150,
|
||||
},
|
||||
{
|
||||
field: 'phone',
|
||||
title: '手机号',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
field: 'companyName',
|
||||
title: '公司',
|
||||
minWidth: 150,
|
||||
},
|
||||
{
|
||||
field: 'departmentName',
|
||||
title: '部门',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
field: 'positionName',
|
||||
title: '职位',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
field: 'roleName',
|
||||
title: '角色',
|
||||
minWidth: 100,
|
||||
},
|
||||
{
|
||||
field: 'status',
|
||||
title: '状态',
|
||||
minWidth: 80,
|
||||
cellRender: ({ row }) => {
|
||||
const statusMap = {
|
||||
0: { text: '正常', color: 'green' },
|
||||
1: { text: '删除', color: 'red' },
|
||||
2: { text: '停用', color: 'orange' },
|
||||
3: { text: '冻结', color: 'purple' },
|
||||
};
|
||||
const status = statusMap[row.status as keyof typeof statusMap];
|
||||
return h(Tag, { color: status.color }, () => status.text);
|
||||
},
|
||||
},
|
||||
{
|
||||
field: 'createTime',
|
||||
title: '创建时间',
|
||||
minWidth: 160,
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
width: 120,
|
||||
fixed: 'right' as const,
|
||||
cellRender: ({ row }) => {
|
||||
return h(Space, {}, () => [
|
||||
h(Button, {
|
||||
type: 'link',
|
||||
size: 'small',
|
||||
icon: h(EditIcon),
|
||||
onClick: () => handleEdit(row),
|
||||
}, () => '编辑'),
|
||||
h(Button, {
|
||||
type: 'link',
|
||||
size: 'small',
|
||||
danger: true,
|
||||
icon: h(TrashIcon),
|
||||
onClick: () => handleDelete(row),
|
||||
}, () => '删除'),
|
||||
]);
|
||||
},
|
||||
},
|
||||
],
|
||||
data: [],
|
||||
loading: false,
|
||||
height: 'auto',
|
||||
border: true,
|
||||
stripe: true,
|
||||
showOverflow: 'tooltip',
|
||||
showHeaderOverflow: 'tooltip',
|
||||
resizable: true,
|
||||
keepSource: true,
|
||||
id: 'admin-account-grid',
|
||||
};
|
||||
|
||||
// 表格实例
|
||||
const { gridRef, getVxeGridInstance } = useVbenVxeGrid({
|
||||
gridOptions,
|
||||
});
|
||||
|
||||
// 计算属性
|
||||
const hasSelected = computed(() => {
|
||||
const instance = getVxeGridInstance();
|
||||
return instance?.getCheckboxRecords().length > 0;
|
||||
});
|
||||
|
||||
// 方法
|
||||
const handleSearch = async () => {
|
||||
await loadData();
|
||||
};
|
||||
|
||||
const handleReset = () => {
|
||||
searchForm.value = {
|
||||
loginCode: '',
|
||||
realName: '',
|
||||
phone: '',
|
||||
companyId: undefined,
|
||||
departmentId: undefined,
|
||||
positionId: undefined,
|
||||
role: '',
|
||||
status: undefined,
|
||||
};
|
||||
loadData();
|
||||
};
|
||||
|
||||
const loadData = async () => {
|
||||
try {
|
||||
loading.value = true;
|
||||
const instance = getVxeGridInstance();
|
||||
instance?.commitProxy('query');
|
||||
} catch (error) {
|
||||
console.error('加载数据失败:', error);
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
const handleAdd = () => {
|
||||
accountFormModalRef.value?.open();
|
||||
};
|
||||
|
||||
const handleEdit = (row: AccountVO.AccountInfoVO) => {
|
||||
accountFormModalRef.value?.open(row);
|
||||
};
|
||||
|
||||
const handleDelete = async (row: AccountVO.AccountInfoVO) => {
|
||||
try {
|
||||
await deleteAccountApi(row.id);
|
||||
message.success('删除成功');
|
||||
await loadData();
|
||||
} catch (error) {
|
||||
console.error('删除失败:', error);
|
||||
message.error('删除失败');
|
||||
}
|
||||
};
|
||||
|
||||
const handleBatchDelete = async () => {
|
||||
const instance = getVxeGridInstance();
|
||||
const selectedRows = instance?.getCheckboxRecords();
|
||||
if (!selectedRows?.length) {
|
||||
message.warning('请选择要删除的数据');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const deletePromises = selectedRows.map((row: AccountVO.AccountInfoVO) =>
|
||||
deleteAccountApi(row.id)
|
||||
);
|
||||
await Promise.all(deletePromises);
|
||||
message.success('批量删除成功');
|
||||
await loadData();
|
||||
} catch (error) {
|
||||
console.error('批量删除失败:', error);
|
||||
message.error('批量删除失败');
|
||||
}
|
||||
};
|
||||
|
||||
// 表格代理配置
|
||||
const gridProxyConfig = {
|
||||
ajax: {
|
||||
query: async ({ page, sorts, filters }: any) => {
|
||||
const params: PageQueryDTO<AccountDTO.AccountFilterDTO> = {
|
||||
pageNum: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
...searchForm.value,
|
||||
};
|
||||
|
||||
try {
|
||||
const response = await getAccountPageApi(params);
|
||||
return {
|
||||
result: response.data.records,
|
||||
page: {
|
||||
total: response.data.total,
|
||||
},
|
||||
};
|
||||
} catch (error) {
|
||||
console.error('查询数据失败:', error);
|
||||
return {
|
||||
result: [],
|
||||
page: {
|
||||
total: 0,
|
||||
},
|
||||
};
|
||||
}
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
// 初始化
|
||||
onMounted(() => {
|
||||
const instance = getVxeGridInstance();
|
||||
instance?.setProxyConfig(gridProxyConfig);
|
||||
loadData();
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Page>
|
||||
<template #title>
|
||||
<div class="flex items-center justify-between">
|
||||
<h1 class="text-xl font-semibold">超管账户管理</h1>
|
||||
<Space>
|
||||
<Button @click="handleAdd" type="primary" :icon="PlusIcon">
|
||||
新增账户
|
||||
</Button>
|
||||
<Button
|
||||
v-if="hasSelected"
|
||||
danger
|
||||
@click="handleBatchDelete"
|
||||
>
|
||||
批量删除
|
||||
</Button>
|
||||
</Space>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<!-- 搜索表单 -->
|
||||
<div class="mb-4 p-4 bg-gray-50 rounded-lg">
|
||||
<div class="grid grid-cols-4 gap-4">
|
||||
<div>
|
||||
<label class="block text-sm font-medium mb-1">用户名</label>
|
||||
<input
|
||||
v-model="searchForm.loginCode"
|
||||
placeholder="请输入用户名"
|
||||
class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-sm font-medium mb-1">真实姓名</label>
|
||||
<input
|
||||
v-model="searchForm.realName"
|
||||
placeholder="请输入真实姓名"
|
||||
class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-sm font-medium mb-1">手机号</label>
|
||||
<input
|
||||
v-model="searchForm.phone"
|
||||
placeholder="请输入手机号"
|
||||
class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-sm font-medium mb-1">状态</label>
|
||||
<select
|
||||
v-model="searchForm.status"
|
||||
class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"
|
||||
>
|
||||
<option value="">全部</option>
|
||||
<option v-for="option in statusOptions" :key="option.value" :value="option.value">
|
||||
{{ option.label }}
|
||||
</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mt-4 flex justify-end space-x-2">
|
||||
<Button @click="handleReset">重置</Button>
|
||||
<Button type="primary" @click="handleSearch">搜索</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 表格 -->
|
||||
<VbenVxeGrid ref="gridRef" v-bind="gridOptions" />
|
||||
|
||||
<!-- 账户表单弹窗 -->
|
||||
<AccountFormModal ref="accountFormModalRef" @success="loadData" />
|
||||
</Page>
|
||||
</template>
|
||||
+271
@@ -0,0 +1,271 @@
|
||||
<script lang="ts" setup>
|
||||
import { ref, computed, watch } from 'vue';
|
||||
import { Modal, Form, FormItem, Input, Select, Button, message } from 'ant-design-vue';
|
||||
import { createIconifyIcon } from '@vben/icons';
|
||||
|
||||
import {
|
||||
admin_createAccountApi,
|
||||
admin_updateAccountApi,
|
||||
type AccountVO,
|
||||
type AccountDTO
|
||||
} from '#/api/org/account';
|
||||
|
||||
// 创建图标组件
|
||||
const SaveIcon = createIconifyIcon('lucide:save');
|
||||
const CancelIcon = createIconifyIcon('lucide:x');
|
||||
|
||||
// Props
|
||||
interface Props {
|
||||
visible?: boolean;
|
||||
accountData?: AccountVO.AccountInfoVO;
|
||||
}
|
||||
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
visible: false,
|
||||
accountData: undefined,
|
||||
});
|
||||
|
||||
// Emits
|
||||
const emit = defineEmits<{
|
||||
success: [];
|
||||
cancel: [];
|
||||
}>();
|
||||
|
||||
// 响应式数据
|
||||
const formRef = ref();
|
||||
const loading = ref(false);
|
||||
const formData = ref<any>({
|
||||
username: '',
|
||||
password: '',
|
||||
realName: '',
|
||||
phone: '',
|
||||
companyId: undefined,
|
||||
departmentId: undefined,
|
||||
positionId: undefined,
|
||||
roleId: undefined,
|
||||
status: 1,
|
||||
});
|
||||
|
||||
// 计算属性
|
||||
const isEdit = computed(() => !!props.accountData);
|
||||
const modalTitle = computed(() => isEdit.value ? '编辑账户' : '新增账户');
|
||||
|
||||
// 角色选项
|
||||
const roleOptions = [
|
||||
{ label: '超级管理员', value: 'super' },
|
||||
{ label: '管理员', value: 'admin' },
|
||||
{ label: '普通用户', value: 'user' },
|
||||
];
|
||||
|
||||
// 监听props变化
|
||||
watch(() => props.accountData, (newData) => {
|
||||
if (newData) {
|
||||
formData.value = {
|
||||
id: newData.id,
|
||||
username: newData.username,
|
||||
realName: newData.realName,
|
||||
phone: newData.phone,
|
||||
companyId: newData.companyId,
|
||||
departmentId: newData.departmentId,
|
||||
positionId: newData.positionId,
|
||||
roleId: newData.roleId,
|
||||
status: newData.status,
|
||||
};
|
||||
} else {
|
||||
resetForm();
|
||||
}
|
||||
}, { immediate: true });
|
||||
|
||||
// 方法
|
||||
const resetForm = () => {
|
||||
formData.value = {
|
||||
username: '',
|
||||
password: '',
|
||||
realName: '',
|
||||
phone: '',
|
||||
companyId: undefined,
|
||||
departmentId: undefined,
|
||||
positionId: undefined,
|
||||
roleId: undefined,
|
||||
status: 1,
|
||||
};
|
||||
};
|
||||
|
||||
const handleSave = async () => {
|
||||
try {
|
||||
await formRef.value?.validate();
|
||||
loading.value = true;
|
||||
|
||||
if (isEdit.value) {
|
||||
await admin_updateAccountApi(formData.value as AccountDTO.UpdateAccountDTO);
|
||||
message.success('更新成功');
|
||||
} else {
|
||||
await admin_createAccountApi(formData.value as AccountDTO.CreateAccountDTO);
|
||||
message.success('创建成功');
|
||||
}
|
||||
|
||||
emit('success');
|
||||
handleCancel();
|
||||
} catch (error) {
|
||||
console.error('保存失败:', error);
|
||||
message.error('保存失败');
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
const handleCancel = () => {
|
||||
resetForm();
|
||||
emit('cancel');
|
||||
};
|
||||
|
||||
// 暴露方法给父组件
|
||||
defineExpose({
|
||||
open: (data?: AccountVO.AccountInfoVO) => {
|
||||
if (data) {
|
||||
formData.value = {
|
||||
id: data.id,
|
||||
username: data.username,
|
||||
realName: data.realName,
|
||||
phone: data.phone,
|
||||
companyId: data.companyId,
|
||||
departmentId: data.departmentId,
|
||||
positionId: data.positionId,
|
||||
roleId: data.roleId,
|
||||
status: data.status,
|
||||
};
|
||||
} else {
|
||||
resetForm();
|
||||
}
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal
|
||||
v-model:open="props.visible"
|
||||
:title="modalTitle"
|
||||
width="600px"
|
||||
:confirm-loading="loading"
|
||||
@ok="handleSave"
|
||||
@cancel="handleCancel"
|
||||
>
|
||||
<Form
|
||||
ref="formRef"
|
||||
:model="formData"
|
||||
:label-col="{ span: 6 }"
|
||||
:wrapper-col="{ span: 18 }"
|
||||
>
|
||||
<FormItem
|
||||
label="登录账号"
|
||||
name="username"
|
||||
:rules="[
|
||||
{ required: true, message: '请输入登录账号' },
|
||||
{ min: 3, max: 20, message: '登录账号长度必须在3-20个字符之间' },
|
||||
{ pattern: /^[a-zA-Z0-9_]+$/, message: '登录账号只能包含字母、数字和下划线' }
|
||||
]"
|
||||
>
|
||||
<Input v-model:value="formData.username" placeholder="请输入登录账号" />
|
||||
</FormItem>
|
||||
|
||||
<FormItem
|
||||
v-if="!isEdit"
|
||||
label="密码"
|
||||
name="password"
|
||||
:rules="[
|
||||
{ required: true, message: '请输入密码' },
|
||||
{ min: 8, max: 20, message: '密码长度必须在8-20个字符之间' }
|
||||
]"
|
||||
>
|
||||
<Input v-model:value="formData.password" type="password" placeholder="请输入密码" />
|
||||
</FormItem>
|
||||
|
||||
<FormItem
|
||||
label="真实姓名"
|
||||
name="realName"
|
||||
:rules="[
|
||||
{ required: true, message: '请输入真实姓名' },
|
||||
{ max: 50, message: '真实姓名长度不能超过50个字符' }
|
||||
]"
|
||||
>
|
||||
<Input v-model:value="formData.realName" placeholder="请输入真实姓名" />
|
||||
</FormItem>
|
||||
|
||||
<FormItem
|
||||
label="手机号码"
|
||||
name="phone"
|
||||
:rules="[
|
||||
{ pattern: /^1[3-9]\d{9}$/, message: '手机号码格式不正确' }
|
||||
]"
|
||||
>
|
||||
<Input v-model:value="formData.phone" placeholder="请输入手机号码" />
|
||||
</FormItem>
|
||||
|
||||
<FormItem
|
||||
label="公司ID"
|
||||
name="companyId"
|
||||
:rules="[
|
||||
{ required: true, message: '请选择公司' }
|
||||
]"
|
||||
>
|
||||
<Input v-model:value="formData.companyId" type="number" placeholder="请输入公司ID" />
|
||||
</FormItem>
|
||||
|
||||
<FormItem
|
||||
label="部门ID"
|
||||
name="departmentId"
|
||||
>
|
||||
<Input v-model:value="formData.departmentId" type="number" placeholder="请输入部门ID" />
|
||||
</FormItem>
|
||||
|
||||
<FormItem
|
||||
label="岗位ID"
|
||||
name="positionId"
|
||||
>
|
||||
<Input v-model:value="formData.positionId" type="number" placeholder="请输入岗位ID" />
|
||||
</FormItem>
|
||||
|
||||
<FormItem
|
||||
label="角色"
|
||||
name="roleId"
|
||||
:rules="[
|
||||
{ required: true, message: '请选择角色' }
|
||||
]"
|
||||
>
|
||||
<Select v-model:value="formData.roleId" placeholder="请选择角色">
|
||||
<Select.Option
|
||||
v-for="option in roleOptions"
|
||||
:key="option.value"
|
||||
:value="option.value"
|
||||
>
|
||||
{{ option.label }}
|
||||
</Select.Option>
|
||||
</Select>
|
||||
</FormItem>
|
||||
|
||||
<FormItem
|
||||
label="状态"
|
||||
name="status"
|
||||
:rules="[
|
||||
{ required: true, message: '请选择状态' }
|
||||
]"
|
||||
>
|
||||
<Select v-model:value="formData.status" placeholder="请选择状态">
|
||||
<Select.Option :value="0">禁用</Select.Option>
|
||||
<Select.Option :value="1">正常</Select.Option>
|
||||
</Select>
|
||||
</FormItem>
|
||||
</Form>
|
||||
|
||||
<template #footer>
|
||||
<div class="flex justify-end space-x-2">
|
||||
<Button @click="handleCancel" :icon="CancelIcon">
|
||||
取消
|
||||
</Button>
|
||||
<Button type="primary" @click="handleSave" :loading="loading" :icon="SaveIcon">
|
||||
保存
|
||||
</Button>
|
||||
</div>
|
||||
</template>
|
||||
</Modal>
|
||||
</template>
|
||||
+327
@@ -0,0 +1,327 @@
|
||||
<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 {
|
||||
admin_deleteAccountApi,
|
||||
admin_getAccountPageApi,
|
||||
type AccountVO,
|
||||
type AccountDTO
|
||||
} from '#/api/org/account';
|
||||
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({
|
||||
username: '',
|
||||
realName: '',
|
||||
phone: '',
|
||||
companyId: undefined as number | undefined,
|
||||
departmentId: undefined as number | undefined,
|
||||
positionId: undefined as number | undefined,
|
||||
roleId: undefined as number | undefined,
|
||||
status: undefined as number | undefined,
|
||||
});
|
||||
|
||||
// 状态选项
|
||||
const statusOptions = [
|
||||
{ label: '正常', value: 0 },
|
||||
{ label: '删除', value: 1 },
|
||||
{ label: '停用', value: 2 },
|
||||
{ label: '冻结', value: 3 },
|
||||
];
|
||||
|
||||
// 搜索表单配置
|
||||
const formOptions = computed(() => ({
|
||||
schemas: [
|
||||
{
|
||||
fieldName: 'username',
|
||||
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: 'username',
|
||||
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<AccountDTO.AccountFilterDTO> = {
|
||||
page: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
...searchForm.value,
|
||||
};
|
||||
const response = await admin_getAccountPageApi(params);
|
||||
return {
|
||||
items: response.records,
|
||||
total: response.total,
|
||||
};
|
||||
} catch (error) {
|
||||
console.error('查询数据失败:', error);
|
||||
message.error('查询数据失败');
|
||||
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: AccountVO.AccountInfoVO) => {
|
||||
accountFormModalRef.value?.open(true, row);
|
||||
};
|
||||
|
||||
const handleDelete = async (row: AccountVO.AccountInfoVO) => {
|
||||
try {
|
||||
await admin_deleteAccountApi(row.id);
|
||||
message.success('删除成功');
|
||||
refreshTable();
|
||||
} catch (error) {
|
||||
console.error('删除失败:', error);
|
||||
message.error('删除失败');
|
||||
}
|
||||
};
|
||||
|
||||
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: AccountVO.AccountInfoVO) =>
|
||||
admin_deleteAccountApi(row.id)
|
||||
);
|
||||
await Promise.all(deletePromises);
|
||||
message.success('批量删除成功');
|
||||
refreshTable();
|
||||
} catch (error) {
|
||||
console.error('批量删除失败:', error);
|
||||
message.error('批量删除失败');
|
||||
}
|
||||
};
|
||||
|
||||
// 处理模态框成功回调
|
||||
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>
|
||||
Reference in New Issue
Block a user