prettier: 代码格式化

This commit is contained in:
ah--desktop
2025-10-31 22:42:03 +08:00
parent 91ee49f45f
commit dfc6de49e0
62 changed files with 6814 additions and 5256 deletions
@@ -1,22 +1,23 @@
<script lang="ts" setup>
import { computed, ref, watch } from 'vue';
import { Form, Input, Modal, Select, message } from 'ant-design-vue';
import type { AccountDTO, AccountVO } from '#/api/organization/account';
import {
admin_createAccountApi,
import { computed, ref, watch } from 'vue';
import { Form, Input, message, Modal, Select } from 'ant-design-vue';
import {
admin_createAccountApi,
admin_updateAccountApi,
type AccountVO,
type AccountDTO
} from '#/api/organization/account';
interface Emits {
(e: 'success'): void;
}
const emit = defineEmits<Emits>();
defineOptions({ name: 'AccountFormModal' });
const emit = defineEmits<Emits>();
// 响应式数据
const formRef = ref();
const loading = ref(false);
@@ -38,7 +39,7 @@ const formData = ref<AccountDTO.CreateAccountDTO & { status?: number }>({
});
// 模态框标题
const modalTitle = computed(() => isEdit.value ? '编辑账户' : '添加账户');
const modalTitle = computed(() => (isEdit.value ? '编辑账户' : '添加账户'));
// 状态选项
const statusOptions = [
@@ -73,9 +74,9 @@ function handleCancel() {
function open(accountData?: AccountVO.AccountInfoVO | null) {
isEdit.value = !!accountData;
currentAccountData.value = accountData || null;
resetForm();
if (accountData) {
formData.value = {
loginCode: accountData.loginCode,
@@ -89,7 +90,7 @@ function open(accountData?: AccountVO.AccountInfoVO | null) {
status: accountData.status,
};
}
visible.value = true;
}
@@ -98,21 +99,22 @@ async function handleSubmit() {
try {
await formRef.value?.validate();
loading.value = true;
if (isEdit.value && currentAccountData.value) {
const { password, ...updateData } = formData.value;
const { password: _, ...updateData } = formData.value;
await admin_updateAccountApi(currentAccountData.value.id, updateData);
message.success('更新成功');
} else {
await admin_createAccountApi(formData.value);
message.success('创建成功');
}
visible.value = false;
emit('success');
} catch (error: any) {
console.error('保存账户失败:', error);
const errorMessage = error?.response?.data?.message || error?.message || '保存账户失败';
const errorMessage =
error?.response?.data?.message || error?.message || '保存账户失败';
message.error(errorMessage);
} finally {
loading.value = false;
@@ -147,48 +149,96 @@ defineExpose({
:label-col="{ span: 6 }"
:wrapper-col="{ span: 18 }"
>
<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
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: '请输入密码' },
{ 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
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>
<Form.Item label="真实姓名" name="realName" :rules="[{ required: true, message: '请输入真实姓名' }]">
<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: '请输入有效的手机号' }
]">
<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="departmentId" :rules="[{ required: true, message: '请输入部门ID' }]">
<Input v-model:value="formData.departmentId" type="number" placeholder="请输入部门ID" />
<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" :rules="[{ required: true, message: '请输入岗位ID' }]">
<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="avatarImageId">
<Input v-model:value="formData.avatarImageId" type="number" placeholder="请输入头像图片ID" />
<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"
@@ -196,7 +246,6 @@ defineExpose({
:options="statusOptions"
/>
</Form.Item>
</Form>
</Modal>
</template>
@@ -1,40 +1,42 @@
<script lang="ts" setup>
import { ref, computed } from 'vue';
import type { VxeGridProps } from '#/adapter/vxe-table';
import type { AccountDTO, AccountVO } from '#/api/organization/account';
import type { PageQueryDTO } from '#/types/common';
import { computed, ref } 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,
import { Button, message, Space, Tag } from 'ant-design-vue';
import { useVbenVxeGrid } from '#/adapter/vxe-table';
import {
admin_deleteAccountApi,
admin_getAccountPageApi,
type AccountVO,
type AccountDTO
} from '#/api/organization/account';
import type { PageQueryDTO } from '#/types/common';
import AccountFormModal from './components/AccountFormModal.vue';
defineOptions({ name: 'CompanyAccountManagement' });
// 创建图标组件
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,
loginCode: undefined as string | undefined,
realName: undefined as string | undefined,
phone: undefined as string | undefined,
companyId: undefined as number | undefined,
departmentId: undefined as number | undefined,
positionId: undefined as number | undefined,
role: undefined as string | undefined,
status: undefined as number | undefined,
});
// 状态选项
@@ -150,7 +152,25 @@ const gridOptions: VxeGridProps<any> = {
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')[],
layouts: [
'PrevJump',
'PrevPage',
'Number',
'NextPage',
'NextJump',
'Sizes',
'FullJump',
'Total',
] as (
| 'FullJump'
| 'NextJump'
| 'NextPage'
| 'Number'
| 'PrevJump'
| 'PrevPage'
| 'Sizes'
| 'Total'
)[],
},
// 配置远程加载
proxyConfig: {
@@ -170,7 +190,8 @@ const gridOptions: VxeGridProps<any> = {
};
} catch (error: any) {
console.error('查询数据失败:', error);
const errorMessage = error?.response?.data?.message || error?.message || '查询数据失败';
const errorMessage =
error?.response?.data?.message || error?.message || '查询数据失败';
message.error(errorMessage);
return {
items: [],
@@ -220,7 +241,8 @@ const handleDelete = async (row: AccountVO.AccountInfoVO) => {
refreshTable();
} catch (error: any) {
console.error('删除失败:', error);
const errorMessage = error?.response?.data?.message || error?.message || '删除失败';
const errorMessage =
error?.response?.data?.message || error?.message || '删除失败';
message.error(errorMessage);
}
};
@@ -234,15 +256,16 @@ const handleBatchDelete = async () => {
}
try {
const deletePromises = selectedRows.map((row: AccountVO.AccountInfoVO) =>
admin_deleteAccountApi(row.id)
const deletePromises = selectedRows.map((row: AccountVO.AccountInfoVO) =>
admin_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 || '批量删除失败';
const errorMessage =
error?.response?.data?.message || error?.message || '批量删除失败';
message.error(errorMessage);
}
};
@@ -273,7 +296,6 @@ const getStatusColor = (status: number) => {
function handleModalSuccess() {
refreshTable();
}
</script>
<template>
@@ -285,9 +307,7 @@ function handleModalSuccess() {
</template>
<!-- VbenVxeGrid 表格 -->
<Grid
:loading="loading"
>
<Grid :loading="loading">
<!-- 工具栏工具 -->
<template #toolbar-tools>
<Space>
@@ -295,11 +315,7 @@ function handleModalSuccess() {
<PlusIcon />
添加账户
</Button>
<Button
v-if="hasSelected"
danger
@click="handleBatchDelete"
>
<Button v-if="hasSelected" danger @click="handleBatchDelete">
批量删除
</Button>
</Space>
@@ -311,16 +327,12 @@ function handleModalSuccess() {
{{ getStatusText(row.status) }}
</Tag>
</template>
<!-- 操作列 -->
<template #action="{ row }">
<Space>
<Button size="small" @click="handleEdit(row)">
编辑
</Button>
<Button size="small" danger @click="handleDelete(row)">
删除
</Button>
<Button size="small" @click="handleEdit(row)"> 编辑 </Button>
<Button size="small" danger @click="handleDelete(row)"> 删除 </Button>
</Space>
</template>
</Grid>