mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-24 21:49:19 +08:00
feat: 新增权限码管理和多处优化
This commit is contained in:
+52
-45
@@ -25,17 +25,16 @@ const isEdit = ref(false);
|
||||
const currentAccountData = ref<AccountVO.AccountInfoVO | null>(null);
|
||||
|
||||
// 表单数据
|
||||
const formData = ref<AccountDTO.CreateAccountDTO>({
|
||||
username: '',
|
||||
const formData = ref<AccountDTO.CreateAccountDTO & { status?: number }>({
|
||||
loginCode: '',
|
||||
password: '',
|
||||
realName: '',
|
||||
email: '',
|
||||
phone: '',
|
||||
companyId: undefined,
|
||||
departmentId: undefined,
|
||||
positionId: undefined,
|
||||
roleId: undefined,
|
||||
status: 1,
|
||||
avatarImageId: undefined,
|
||||
departmentId: 0,
|
||||
positionId: 0,
|
||||
remark: '',
|
||||
status: 0,
|
||||
});
|
||||
|
||||
// 模态框标题
|
||||
@@ -43,23 +42,24 @@ const modalTitle = computed(() => isEdit.value ? '编辑账户' : '添加账户'
|
||||
|
||||
// 状态选项
|
||||
const statusOptions = [
|
||||
{ label: '禁用', value: 0 },
|
||||
{ label: '正常', value: 1 },
|
||||
{ label: '正常', value: 0 },
|
||||
{ label: '删除', value: 1 },
|
||||
{ label: '停用', value: 2 },
|
||||
{ label: '冻结', value: 3 },
|
||||
];
|
||||
|
||||
// 重置表单
|
||||
function resetForm() {
|
||||
formData.value = {
|
||||
username: '',
|
||||
loginCode: '',
|
||||
password: '',
|
||||
realName: '',
|
||||
email: '',
|
||||
phone: '',
|
||||
companyId: undefined,
|
||||
departmentId: undefined,
|
||||
positionId: undefined,
|
||||
roleId: undefined,
|
||||
status: 1,
|
||||
avatarImageId: undefined,
|
||||
departmentId: 0,
|
||||
positionId: 0,
|
||||
remark: '',
|
||||
status: 0,
|
||||
};
|
||||
formRef.value?.resetFields();
|
||||
}
|
||||
@@ -70,23 +70,22 @@ function handleCancel() {
|
||||
}
|
||||
|
||||
// 暴露给父组件的方法
|
||||
function open(editMode: boolean = false, accountData?: AccountVO.AccountInfoVO | null) {
|
||||
isEdit.value = editMode;
|
||||
function open(accountData?: AccountVO.AccountInfoVO | null) {
|
||||
isEdit.value = !!accountData;
|
||||
currentAccountData.value = accountData || null;
|
||||
|
||||
resetForm();
|
||||
|
||||
if (editMode && accountData) {
|
||||
if (accountData) {
|
||||
formData.value = {
|
||||
username: accountData.username,
|
||||
loginCode: accountData.loginCode,
|
||||
password: '', // 编辑时密码为空
|
||||
realName: accountData.realName,
|
||||
email: accountData.email || '',
|
||||
phone: accountData.phone || '',
|
||||
companyId: accountData.companyId,
|
||||
departmentId: accountData.departmentId,
|
||||
positionId: accountData.positionId,
|
||||
roleId: accountData.roleId,
|
||||
avatarImageId: accountData.avatarImageId,
|
||||
departmentId: accountData.departmentId || 0,
|
||||
positionId: accountData.positionId || 0,
|
||||
remark: accountData.remark || '',
|
||||
status: accountData.status,
|
||||
};
|
||||
}
|
||||
@@ -102,7 +101,7 @@ async function handleSubmit() {
|
||||
|
||||
if (isEdit.value && currentAccountData.value) {
|
||||
const { password, ...updateData } = formData.value;
|
||||
await admin_updateAccountApi({ ...updateData, id: currentAccountData.value.id });
|
||||
await admin_updateAccountApi(currentAccountData.value.id, updateData);
|
||||
message.success('更新成功');
|
||||
} else {
|
||||
await admin_createAccountApi(formData.value);
|
||||
@@ -111,9 +110,10 @@ async function handleSubmit() {
|
||||
|
||||
visible.value = false;
|
||||
emit('success');
|
||||
} catch (error) {
|
||||
} catch (error: any) {
|
||||
console.error('保存账户失败:', error);
|
||||
message.error('保存账户失败');
|
||||
const errorMessage = error?.response?.data?.message || error?.message || '保存账户失败';
|
||||
message.error(errorMessage);
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
@@ -147,11 +147,19 @@ defineExpose({
|
||||
: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 label="登录账号" name="loginCode" :rules="[
|
||||
{ required: true, message: '请输入登录账号' },
|
||||
{ min: 4, max: 20, message: '登录账号长度为4-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: '请输入密码' }]">
|
||||
<Form.Item v-if="!isEdit" label="密码" name="password" :rules="[
|
||||
{ required: true, message: '请输入密码' },
|
||||
{ min: 8, max: 20, message: '密码长度为8-20个字符' },
|
||||
{ pattern: /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[a-zA-Z\d@$!%*?&]{8,}$/, message: '密码必须包含大小写字母、数字,长度至少8位' }
|
||||
]">
|
||||
<Input v-model:value="formData.password" type="password" placeholder="请输入密码" />
|
||||
</Form.Item>
|
||||
|
||||
@@ -159,37 +167,36 @@ defineExpose({
|
||||
<Input v-model:value="formData.realName" placeholder="请输入真实姓名" />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="邮箱" name="email">
|
||||
<Input v-model:value="formData.email" placeholder="请输入邮箱" />
|
||||
<Form.Item label="备注" name="remark">
|
||||
<Input v-model:value="formData.remark" placeholder="请输入备注" />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="手机号" name="phone">
|
||||
<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">
|
||||
<Input v-model:value="formData.companyId" type="number" placeholder="请输入公司ID" />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="部门ID" name="departmentId">
|
||||
<Form.Item label="部门ID" name="departmentId" :rules="[{ required: true, message: '请输入部门ID' }]">
|
||||
<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 label="岗位ID" name="positionId" :rules="[{ required: true, message: '请输入岗位ID' }]">
|
||||
<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 label="头像图片ID" name="avatarImageId">
|
||||
<Input v-model:value="formData.avatarImageId" type="number" placeholder="请输入头像图片ID" />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="状态" name="status">
|
||||
<Form.Item v-if="isEdit" label="状态" name="status">
|
||||
<Select
|
||||
v-model:value="formData.status"
|
||||
placeholder="请选择状态"
|
||||
:options="statusOptions"
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
</Form>
|
||||
</Modal>
|
||||
</template>
|
||||
|
||||
+10
-7
@@ -168,9 +168,10 @@ const gridOptions: VxeGridProps<any> = {
|
||||
items: response.records,
|
||||
total: response.total,
|
||||
};
|
||||
} catch (error) {
|
||||
} catch (error: any) {
|
||||
console.error('查询数据失败:', error);
|
||||
message.error('查询数据失败');
|
||||
const errorMessage = error?.response?.data?.message || error?.message || '查询数据失败';
|
||||
message.error(errorMessage);
|
||||
return {
|
||||
items: [],
|
||||
total: 0,
|
||||
@@ -217,9 +218,10 @@ const handleDelete = async (row: AccountVO.AccountInfoVO) => {
|
||||
await admin_deleteAccountApi(row.id);
|
||||
message.success('删除成功');
|
||||
refreshTable();
|
||||
} catch (error) {
|
||||
} catch (error: any) {
|
||||
console.error('删除失败:', error);
|
||||
message.error('删除失败');
|
||||
const errorMessage = error?.response?.data?.message || error?.message || '删除失败';
|
||||
message.error(errorMessage);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -236,11 +238,12 @@ const handleBatchDelete = async () => {
|
||||
admin_deleteAccountApi(row.id)
|
||||
);
|
||||
await Promise.all(deletePromises);
|
||||
message.success('批量删除成功');
|
||||
message.success(`成功删除 ${selectedRows.length} 条记录`);
|
||||
refreshTable();
|
||||
} catch (error) {
|
||||
} catch (error: any) {
|
||||
console.error('批量删除失败:', error);
|
||||
message.error('批量删除失败');
|
||||
const errorMessage = error?.response?.data?.message || error?.message || '批量删除失败';
|
||||
message.error(errorMessage);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
+29
-18
@@ -76,11 +76,11 @@
|
||||
<Input v-model:value="formData.email" placeholder="请输入邮箱" />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="状态" name="status" :rules="[{ required: true, message: '请选择状态' }]">
|
||||
<Select
|
||||
v-model:value="formData.status"
|
||||
placeholder="请选择状态"
|
||||
:options="statusOptions"
|
||||
<Form.Item label="状态" name="status">
|
||||
<Switch
|
||||
v-model:checked="formData.status"
|
||||
checked-children="正常"
|
||||
un-checked-children="禁用"
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
@@ -99,7 +99,7 @@
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { computed, ref, onUnmounted } from 'vue';
|
||||
import { Form, Input, Modal, Select, DatePicker, Button, message } from 'ant-design-vue';
|
||||
import { Form, Input, Modal, DatePicker, Button, message, Switch } from 'ant-design-vue';
|
||||
import { createIconifyIcon } from '@vben/icons';
|
||||
import dayjs from 'dayjs';
|
||||
import {
|
||||
@@ -131,23 +131,31 @@ const newLogoFile = ref<File | null>(null); // 新选择的logo文件
|
||||
const originalLogoUrl = ref(''); // 原始logo URL
|
||||
const imageLoadError = ref(false); // 图片加载错误状态
|
||||
|
||||
// 内部表单数据类型
|
||||
interface FormData {
|
||||
name: string;
|
||||
address: string;
|
||||
contactPerson: string;
|
||||
contactPhone: string;
|
||||
email: string;
|
||||
logoImageId?: number;
|
||||
status: boolean;
|
||||
expireTime: any;
|
||||
}
|
||||
|
||||
// 表单数据
|
||||
const formData = ref({
|
||||
const formData = ref<FormData>({
|
||||
name: '',
|
||||
address: '',
|
||||
contactPerson: '',
|
||||
contactPhone: '',
|
||||
email: '',
|
||||
logoImageId: undefined as number | undefined,
|
||||
status: 1,
|
||||
expireTime: undefined as any,
|
||||
logoImageId: undefined,
|
||||
status: true,
|
||||
expireTime: undefined,
|
||||
});
|
||||
|
||||
// 状态选项
|
||||
const statusOptions = [
|
||||
{ label: '正常', value: 1 },
|
||||
{ label: '禁用', value: 0 },
|
||||
];
|
||||
// 开关组件不需要选项数组
|
||||
|
||||
// 模态框标题
|
||||
const modalTitle = computed(() => isEdit.value ? '编辑公司' : '添加公司');
|
||||
@@ -171,7 +179,7 @@ function initFormData() {
|
||||
contactPhone: currentCompanyData.value.contactPhone || '',
|
||||
email: currentCompanyData.value.email || '',
|
||||
logoImageId: undefined,
|
||||
status: currentCompanyData.value.status,
|
||||
status: currentCompanyData.value.status === 1, // 转换为boolean
|
||||
expireTime: currentCompanyData.value.expireTime ? dayjs(currentCompanyData.value.expireTime) : undefined,
|
||||
};
|
||||
|
||||
@@ -186,7 +194,7 @@ function initFormData() {
|
||||
contactPhone: '',
|
||||
email: '',
|
||||
logoImageId: undefined,
|
||||
status: 1,
|
||||
status: true,
|
||||
expireTime: undefined,
|
||||
};
|
||||
originalLogoUrl.value = '';
|
||||
@@ -212,7 +220,10 @@ async function handleSubmit() {
|
||||
loading.value = true;
|
||||
|
||||
// 准备提交数据
|
||||
const submitData = { ...formData.value };
|
||||
const submitData = {
|
||||
...formData.value,
|
||||
status: formData.value.status ? 1 : 0 // 转换boolean为number
|
||||
};
|
||||
|
||||
// 处理日期格式
|
||||
if (submitData.expireTime) {
|
||||
|
||||
+27
-18
@@ -1,12 +1,11 @@
|
||||
<script lang="ts" setup>
|
||||
import { computed, ref } from 'vue';
|
||||
import { Form, Input, Modal, Select, message } from 'ant-design-vue';
|
||||
import { Form, Input, Modal, Select, message, Switch } from 'ant-design-vue';
|
||||
|
||||
import {
|
||||
createDepartmentApi,
|
||||
updateDepartmentApi,
|
||||
type DepartmentVO,
|
||||
type DepartmentDTO
|
||||
type DepartmentVO
|
||||
} from '#/api/org/department';
|
||||
|
||||
interface Props {
|
||||
@@ -28,19 +27,23 @@ const visible = ref(false);
|
||||
const isEdit = ref(false);
|
||||
const currentDepartmentData = ref<DepartmentVO.DepartmentInfoVO | null>(null);
|
||||
|
||||
// 内部表单数据类型
|
||||
interface FormData {
|
||||
name: string;
|
||||
parentId?: number;
|
||||
remark: string;
|
||||
status: boolean;
|
||||
}
|
||||
|
||||
// 表单数据
|
||||
const formData = ref<DepartmentDTO.CreateDepartmentDTO>({
|
||||
const formData = ref<FormData>({
|
||||
name: '',
|
||||
parentId: undefined,
|
||||
remark: '',
|
||||
status: 1,
|
||||
status: true,
|
||||
});
|
||||
|
||||
// 状态选项
|
||||
const statusOptions = [
|
||||
{ label: '禁用', value: 0 },
|
||||
{ label: '启用', value: 1 },
|
||||
];
|
||||
// 开关组件不需要选项数组
|
||||
|
||||
// 父部门选项
|
||||
const parentDepartmentOptions = computed(() => {
|
||||
@@ -90,7 +93,7 @@ function resetForm() {
|
||||
name: '',
|
||||
parentId: undefined,
|
||||
remark: '',
|
||||
status: 1,
|
||||
status: true,
|
||||
};
|
||||
formRef.value?.resetFields();
|
||||
}
|
||||
@@ -106,11 +109,17 @@ async function handleSubmit() {
|
||||
await formRef.value?.validate();
|
||||
loading.value = true;
|
||||
|
||||
// 转换boolean值为number值
|
||||
const submitData = {
|
||||
...formData.value,
|
||||
status: formData.value.status ? 1 : 0
|
||||
};
|
||||
|
||||
if (isEdit.value && currentDepartmentData.value) {
|
||||
await updateDepartmentApi(currentDepartmentData.value.id, formData.value);
|
||||
await updateDepartmentApi(currentDepartmentData.value.id, submitData);
|
||||
message.success('更新成功');
|
||||
} else {
|
||||
await createDepartmentApi(formData.value);
|
||||
await createDepartmentApi(submitData);
|
||||
message.success('创建成功');
|
||||
}
|
||||
|
||||
@@ -136,7 +145,7 @@ function open(editMode: boolean = false, departmentData?: DepartmentVO.Departmen
|
||||
name: departmentData.name,
|
||||
parentId: departmentData.parentId,
|
||||
remark: departmentData.remark || '',
|
||||
status: departmentData.status,
|
||||
status: departmentData.status === 1, // 转换为boolean
|
||||
};
|
||||
}
|
||||
|
||||
@@ -182,10 +191,10 @@ defineExpose({
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="状态" name="status">
|
||||
<Select
|
||||
v-model:value="formData.status"
|
||||
placeholder="请选择状态"
|
||||
:options="statusOptions"
|
||||
<Switch
|
||||
v-model:checked="formData.status"
|
||||
checked-children="启用"
|
||||
un-checked-children="禁用"
|
||||
/>
|
||||
</Form.Item>
|
||||
</Form>
|
||||
|
||||
+28
-18
@@ -1,12 +1,11 @@
|
||||
<script lang="ts" setup>
|
||||
import { computed, ref } from 'vue';
|
||||
import { Form, Input, Modal, Select, message } from 'ant-design-vue';
|
||||
import { Form, Input, Modal, Select, message, Switch } from 'ant-design-vue';
|
||||
|
||||
import {
|
||||
createPositionApi,
|
||||
updatePositionApi,
|
||||
type PositionVO,
|
||||
type PositionDTO
|
||||
type PositionVO
|
||||
} from '#/api/org/position';
|
||||
|
||||
interface Props {
|
||||
@@ -28,20 +27,25 @@ const visible = ref(false);
|
||||
const isEdit = ref(false);
|
||||
const currentPositionData = ref<PositionVO.PositionInfoVO | null>(null);
|
||||
|
||||
// 内部表单数据类型
|
||||
interface FormData {
|
||||
name: string;
|
||||
code: string;
|
||||
departmentId?: number;
|
||||
remark: string;
|
||||
status: boolean;
|
||||
}
|
||||
|
||||
// 表单数据
|
||||
const formData = ref<PositionDTO.CreatePositionDTO>({
|
||||
const formData = ref<FormData>({
|
||||
name: '',
|
||||
code: '',
|
||||
departmentId: undefined,
|
||||
remark: '',
|
||||
status: 1,
|
||||
status: true,
|
||||
});
|
||||
|
||||
// 状态选项
|
||||
const statusOptions = [
|
||||
{ label: '禁用', value: 0 },
|
||||
{ label: '启用', value: 1 },
|
||||
];
|
||||
// 开关组件不需要选项数组
|
||||
|
||||
// 模态框标题
|
||||
const modalTitle = computed(() => isEdit.value ? '编辑岗位' : '添加岗位');
|
||||
@@ -53,7 +57,7 @@ function resetForm() {
|
||||
code: '',
|
||||
departmentId: undefined,
|
||||
remark: '',
|
||||
status: 1,
|
||||
status: true,
|
||||
};
|
||||
formRef.value?.resetFields();
|
||||
}
|
||||
@@ -69,11 +73,17 @@ async function handleSubmit() {
|
||||
await formRef.value?.validate();
|
||||
loading.value = true;
|
||||
|
||||
// 转换boolean值为number值
|
||||
const submitData = {
|
||||
...formData.value,
|
||||
status: formData.value.status ? 1 : 0
|
||||
};
|
||||
|
||||
if (isEdit.value && currentPositionData.value) {
|
||||
await updatePositionApi(currentPositionData.value.id, formData.value);
|
||||
await updatePositionApi(currentPositionData.value.id, submitData);
|
||||
message.success('更新成功');
|
||||
} else {
|
||||
await createPositionApi(formData.value);
|
||||
await createPositionApi(submitData);
|
||||
message.success('创建成功');
|
||||
}
|
||||
|
||||
@@ -100,7 +110,7 @@ function open(editMode: boolean = false, positionData?: PositionVO.PositionInfoV
|
||||
code: positionData.code || '',
|
||||
departmentId: positionData.departmentId,
|
||||
remark: positionData.remark || '',
|
||||
status: positionData.status,
|
||||
status: positionData.status === 1, // 转换为boolean
|
||||
};
|
||||
}
|
||||
|
||||
@@ -150,10 +160,10 @@ defineExpose({
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="状态" name="status">
|
||||
<Select
|
||||
v-model:value="formData.status"
|
||||
placeholder="请选择状态"
|
||||
:options="statusOptions"
|
||||
<Switch
|
||||
v-model:checked="formData.status"
|
||||
checked-children="启用"
|
||||
un-checked-children="禁用"
|
||||
/>
|
||||
</Form.Item>
|
||||
</Form>
|
||||
|
||||
+156
-204
@@ -1,153 +1,150 @@
|
||||
<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 { 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';
|
||||
super_createAccountApi,
|
||||
super_updateAccountApi,
|
||||
type SuperAccountVO,
|
||||
type SuperAccountDTO
|
||||
} from '#/api/org/superAccount';
|
||||
|
||||
// 创建图标组件
|
||||
const SaveIcon = createIconifyIcon('lucide:save');
|
||||
const CancelIcon = createIconifyIcon('lucide:x');
|
||||
|
||||
// Props
|
||||
interface Props {
|
||||
visible?: boolean;
|
||||
accountData?: AccountVO.AccountInfoVO;
|
||||
interface Emits {
|
||||
(e: 'success'): void;
|
||||
}
|
||||
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
visible: false,
|
||||
accountData: undefined,
|
||||
});
|
||||
const emit = defineEmits<Emits>();
|
||||
|
||||
// Emits
|
||||
const emit = defineEmits<{
|
||||
success: [];
|
||||
cancel: [];
|
||||
}>();
|
||||
defineOptions({ name: 'SuperAccountFormModal' });
|
||||
|
||||
// 响应式数据
|
||||
const formRef = ref();
|
||||
const loading = ref(false);
|
||||
const formData = ref<any>({
|
||||
username: '',
|
||||
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: undefined,
|
||||
companyId: 0,
|
||||
departmentId: undefined,
|
||||
positionId: undefined,
|
||||
roleId: undefined,
|
||||
status: 1,
|
||||
role: '',
|
||||
avatarImageId: undefined,
|
||||
remark: '',
|
||||
status: 0,
|
||||
});
|
||||
|
||||
// 计算属性
|
||||
const isEdit = computed(() => !!props.accountData);
|
||||
const modalTitle = computed(() => isEdit.value ? '编辑账户' : '新增账户');
|
||||
// 模态框标题
|
||||
const modalTitle = computed(() => isEdit.value ? '编辑账户' : '添加账户');
|
||||
|
||||
// 角色选项
|
||||
const roleOptions = [
|
||||
{ label: '超级管理员', value: 'super' },
|
||||
{ label: '管理员', value: 'admin' },
|
||||
{ label: '普通用户', value: 'user' },
|
||||
// 状态选项
|
||||
const statusOptions = [
|
||||
{ label: '正常', value: 0 },
|
||||
{ label: '删除', value: 1 },
|
||||
{ label: '停用', value: 2 },
|
||||
{ label: '冻结', value: 3 },
|
||||
];
|
||||
|
||||
// 监听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 = () => {
|
||||
// 重置表单
|
||||
function resetForm() {
|
||||
formData.value = {
|
||||
username: '',
|
||||
loginCode: '',
|
||||
password: '',
|
||||
realName: '',
|
||||
phone: '',
|
||||
companyId: undefined,
|
||||
companyId: 0,
|
||||
departmentId: undefined,
|
||||
positionId: undefined,
|
||||
roleId: undefined,
|
||||
status: 1,
|
||||
role: '',
|
||||
avatarImageId: undefined,
|
||||
remark: '',
|
||||
status: 0,
|
||||
};
|
||||
};
|
||||
formRef.value?.resetFields();
|
||||
}
|
||||
|
||||
const handleSave = async () => {
|
||||
// 处理模态框关闭
|
||||
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) {
|
||||
await admin_updateAccountApi(formData.value as AccountDTO.UpdateAccountDTO);
|
||||
|
||||
if (isEdit.value && currentAccountData.value) {
|
||||
const { password, ...updateData } = formData.value;
|
||||
await super_updateAccountApi(currentAccountData.value.id, updateData);
|
||||
message.success('更新成功');
|
||||
} else {
|
||||
await admin_createAccountApi(formData.value as AccountDTO.CreateAccountDTO);
|
||||
await super_createAccountApi(formData.value);
|
||||
message.success('创建成功');
|
||||
}
|
||||
|
||||
|
||||
visible.value = false;
|
||||
emit('success');
|
||||
handleCancel();
|
||||
} catch (error) {
|
||||
console.error('保存失败:', error);
|
||||
message.error('保存失败');
|
||||
} catch (error: any) {
|
||||
console.error('保存账户失败:', error);
|
||||
const errorMessage = error?.response?.data?.message || error?.message || '保存账户失败';
|
||||
message.error(errorMessage);
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
const handleCancel = () => {
|
||||
resetForm();
|
||||
emit('cancel');
|
||||
};
|
||||
// 监听弹窗关闭
|
||||
watch(visible, (val) => {
|
||||
if (!val) {
|
||||
resetForm();
|
||||
}
|
||||
});
|
||||
|
||||
// 暴露方法给父组件
|
||||
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();
|
||||
}
|
||||
},
|
||||
open,
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal
|
||||
v-model:open="props.visible"
|
||||
:open="visible"
|
||||
:title="modalTitle"
|
||||
width="600px"
|
||||
width="500px"
|
||||
:confirm-loading="loading"
|
||||
@ok="handleSave"
|
||||
@ok="handleSubmit"
|
||||
@cancel="handleCancel"
|
||||
>
|
||||
<Form
|
||||
@@ -156,116 +153,71 @@ defineExpose({
|
||||
: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个字符之间' }
|
||||
]"
|
||||
>
|
||||
<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="请输入密码" />
|
||||
</FormItem>
|
||||
|
||||
<FormItem
|
||||
label="真实姓名"
|
||||
name="realName"
|
||||
:rules="[
|
||||
{ required: true, message: '请输入真实姓名' },
|
||||
{ max: 50, message: '真实姓名长度不能超过50个字符' }
|
||||
]"
|
||||
>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="真实姓名" name="realName" :rules="[{ required: true, message: '请输入真实姓名' }]">
|
||||
<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: '请选择公司' }
|
||||
]"
|
||||
>
|
||||
</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" />
|
||||
</FormItem>
|
||||
|
||||
<FormItem
|
||||
label="部门ID"
|
||||
name="departmentId"
|
||||
>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="部门ID" name="departmentId">
|
||||
<Input v-model:value="formData.departmentId" type="number" placeholder="请输入部门ID" />
|
||||
</FormItem>
|
||||
|
||||
<FormItem
|
||||
label="岗位ID"
|
||||
name="positionId"
|
||||
>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item 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.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>
|
||||
|
||||
<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>
|
||||
|
||||
+33
-30
@@ -8,11 +8,11 @@ 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';
|
||||
super_deleteAccountApi,
|
||||
super_getAccountPageApi,
|
||||
type SuperAccountVO,
|
||||
type SuperAccountDTO
|
||||
} from '#/api/org/superAccount';
|
||||
import type { PageQueryDTO } from '#/types/common';
|
||||
import SuperAccountFormModal from './components/SuperAccountFormModal.vue';
|
||||
|
||||
@@ -27,14 +27,14 @@ 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,
|
||||
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,
|
||||
});
|
||||
|
||||
// 状态选项
|
||||
@@ -49,7 +49,7 @@ const statusOptions = [
|
||||
const formOptions = computed(() => ({
|
||||
schemas: [
|
||||
{
|
||||
fieldName: 'username',
|
||||
fieldName: 'loginCode',
|
||||
label: '登录账号',
|
||||
},
|
||||
{
|
||||
@@ -84,7 +84,7 @@ const gridOptions: VxeGridProps<any> = {
|
||||
title: '序号',
|
||||
},
|
||||
{
|
||||
field: 'username',
|
||||
field: 'loginCode',
|
||||
title: '登录账号',
|
||||
minWidth: 120,
|
||||
},
|
||||
@@ -158,19 +158,20 @@ const gridOptions: VxeGridProps<any> = {
|
||||
query: async ({ page }) => {
|
||||
try {
|
||||
loading.value = true;
|
||||
const params: PageQueryDTO<AccountDTO.AccountFilterDTO> = {
|
||||
const params: PageQueryDTO<SuperAccountDTO.AccountFilterDTO> = {
|
||||
page: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
...searchForm.value,
|
||||
};
|
||||
const response = await admin_getAccountPageApi(params);
|
||||
const response = await super_getAccountPageApi(params);
|
||||
return {
|
||||
items: response.records,
|
||||
total: response.total,
|
||||
};
|
||||
} catch (error) {
|
||||
} catch (error: any) {
|
||||
console.error('查询数据失败:', error);
|
||||
message.error('查询数据失败');
|
||||
const errorMessage = error?.response?.data?.message || error?.message || '查询数据失败';
|
||||
message.error(errorMessage);
|
||||
return {
|
||||
items: [],
|
||||
total: 0,
|
||||
@@ -208,18 +209,19 @@ const handleAdd = () => {
|
||||
accountFormModalRef.value?.open();
|
||||
};
|
||||
|
||||
const handleEdit = (row: AccountVO.AccountInfoVO) => {
|
||||
accountFormModalRef.value?.open(true, row);
|
||||
const handleEdit = (row: SuperAccountVO.AccountInfoVO) => {
|
||||
accountFormModalRef.value?.open(row);
|
||||
};
|
||||
|
||||
const handleDelete = async (row: AccountVO.AccountInfoVO) => {
|
||||
const handleDelete = async (row: SuperAccountVO.AccountInfoVO) => {
|
||||
try {
|
||||
await admin_deleteAccountApi(row.id);
|
||||
await super_deleteAccountApi(row.id);
|
||||
message.success('删除成功');
|
||||
refreshTable();
|
||||
} catch (error) {
|
||||
} catch (error: any) {
|
||||
console.error('删除失败:', error);
|
||||
message.error('删除失败');
|
||||
const errorMessage = error?.response?.data?.message || error?.message || '删除失败';
|
||||
message.error(errorMessage);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -232,15 +234,16 @@ const handleBatchDelete = async () => {
|
||||
}
|
||||
|
||||
try {
|
||||
const deletePromises = selectedRows.map((row: AccountVO.AccountInfoVO) =>
|
||||
admin_deleteAccountApi(row.id)
|
||||
const deletePromises = selectedRows.map((row: SuperAccountVO.AccountInfoVO) =>
|
||||
super_deleteAccountApi(row.id)
|
||||
);
|
||||
await Promise.all(deletePromises);
|
||||
message.success('批量删除成功');
|
||||
message.success(`成功删除 ${selectedRows.length} 条记录`);
|
||||
refreshTable();
|
||||
} catch (error) {
|
||||
} catch (error: any) {
|
||||
console.error('批量删除失败:', error);
|
||||
message.error('批量删除失败');
|
||||
const errorMessage = error?.response?.data?.message || error?.message || '批量删除失败';
|
||||
message.error(errorMessage);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user