mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-25 04:29:20 +08:00
prettier: 代码格式化
This commit is contained in:
+95
-46
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user