mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-25 08:29:20 +08:00
prettier: 代码格式化
This commit is contained in:
+107
-52
@@ -1,31 +1,37 @@
|
||||
<script lang="ts" setup>
|
||||
import { computed, ref, watch } from 'vue';
|
||||
import { Form, Input, Modal, Select, message } from 'ant-design-vue';
|
||||
import type {
|
||||
SuperAccountDTO,
|
||||
SuperAccountVO,
|
||||
} from '#/api/organization/account-super';
|
||||
|
||||
import {
|
||||
super_createAccountApi,
|
||||
import { computed, ref, watch } from 'vue';
|
||||
|
||||
import { Form, Input, message, Modal, Select } from 'ant-design-vue';
|
||||
|
||||
import {
|
||||
super_createAccountApi,
|
||||
super_updateAccountApi,
|
||||
type SuperAccountVO,
|
||||
type SuperAccountDTO
|
||||
} from '#/api/organization/account-super';
|
||||
|
||||
interface Emits {
|
||||
(e: 'success'): void;
|
||||
}
|
||||
|
||||
const emit = defineEmits<Emits>();
|
||||
|
||||
defineOptions({ name: 'SuperAccountFormModal' });
|
||||
|
||||
const emit = defineEmits<Emits>();
|
||||
|
||||
// 响应式数据
|
||||
const formRef = ref();
|
||||
const loading = ref(false);
|
||||
const visible = ref(false);
|
||||
const isEdit = ref(false);
|
||||
const currentAccountData = ref<SuperAccountVO.AccountInfoVO | null>(null);
|
||||
const currentAccountData = ref<null | SuperAccountVO.AccountInfoVO>(null);
|
||||
|
||||
// 表单数据
|
||||
const formData = ref<SuperAccountDTO.SuperCreateAccountDTO & { status?: number }>({
|
||||
const formData = ref<
|
||||
SuperAccountDTO.SuperCreateAccountDTO & { status?: number }
|
||||
>({
|
||||
loginCode: '',
|
||||
password: '',
|
||||
realName: '',
|
||||
@@ -40,7 +46,7 @@ const formData = ref<SuperAccountDTO.SuperCreateAccountDTO & { status?: number }
|
||||
});
|
||||
|
||||
// 模态框标题
|
||||
const modalTitle = computed(() => isEdit.value ? '编辑账户' : '添加账户');
|
||||
const modalTitle = computed(() => (isEdit.value ? '编辑账户' : '添加账户'));
|
||||
|
||||
// 状态选项
|
||||
const statusOptions = [
|
||||
@@ -74,12 +80,12 @@ function handleCancel() {
|
||||
}
|
||||
|
||||
// 暴露给父组件的方法
|
||||
function open(accountData?: SuperAccountVO.AccountInfoVO | null) {
|
||||
function open(accountData?: null | SuperAccountVO.AccountInfoVO) {
|
||||
isEdit.value = !!accountData;
|
||||
currentAccountData.value = accountData || null;
|
||||
|
||||
|
||||
resetForm();
|
||||
|
||||
|
||||
if (accountData) {
|
||||
formData.value = {
|
||||
loginCode: accountData.loginCode,
|
||||
@@ -95,7 +101,7 @@ function open(accountData?: SuperAccountVO.AccountInfoVO | null) {
|
||||
status: accountData.status,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
visible.value = true;
|
||||
}
|
||||
|
||||
@@ -104,21 +110,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 super_updateAccountApi(currentAccountData.value.id, updateData);
|
||||
message.success('更新成功');
|
||||
} else {
|
||||
await super_createAccountApi(formData.value);
|
||||
message.success('创建成功');
|
||||
}
|
||||
|
||||
|
||||
visible.value = false;
|
||||
emit('success');
|
||||
} catch (error: any) {
|
||||
console.error('保存账户失败:', error);
|
||||
const errorMessage = error?.response?.data?.message || error?.message || '保存账户失败';
|
||||
const errorMessage =
|
||||
error?.response?.data?.message || error?.message || '保存账户失败';
|
||||
message.error(errorMessage);
|
||||
} finally {
|
||||
loading.value = false;
|
||||
@@ -153,63 +160,112 @@ defineExpose({
|
||||
:label-col="{ span: 6 }"
|
||||
:wrapper-col="{ span: 18 }"
|
||||
>
|
||||
<Form.Item label="登录账号" name="loginCode" :rules="[
|
||||
{ required: true, message: '请输入登录账号' },
|
||||
{ min: 3, max: 20, message: '登录账号长度为3-20个字符' },
|
||||
{ pattern: /^[a-zA-Z0-9_]+$/, message: '登录账号只能包含字母、数字和下划线' }
|
||||
]">
|
||||
<Input v-model:value="formData.loginCode" placeholder="请输入登录账号" />
|
||||
<Form.Item
|
||||
label="登录账号"
|
||||
name="loginCode"
|
||||
:rules="[
|
||||
{ required: true, message: '请输入登录账号' },
|
||||
{ min: 3, max: 20, message: '登录账号长度为3-20个字符' },
|
||||
{
|
||||
pattern: /^[a-zA-Z0-9_]+$/,
|
||||
message: '登录账号只能包含字母、数字和下划线',
|
||||
},
|
||||
]"
|
||||
>
|
||||
<Input
|
||||
v-model:value="formData.loginCode"
|
||||
placeholder="请输入登录账号"
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item v-if="!isEdit" label="密码" name="password" :rules="[
|
||||
{ required: true, message: '请输入密码' },
|
||||
{ min: 6, max: 20, message: '密码长度为6-20个字符' }
|
||||
]">
|
||||
<Input v-model:value="formData.password" type="password" placeholder="请输入密码" />
|
||||
|
||||
<Form.Item
|
||||
v-if="!isEdit"
|
||||
label="密码"
|
||||
name="password"
|
||||
:rules="[
|
||||
{ required: true, message: '请输入密码' },
|
||||
{ min: 6, max: 20, message: '密码长度为6-20个字符' },
|
||||
]"
|
||||
>
|
||||
<Input
|
||||
v-model:value="formData.password"
|
||||
type="password"
|
||||
placeholder="请输入密码"
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="真实姓名" name="realName" :rules="[{ required: true, message: '请输入真实姓名' }]">
|
||||
|
||||
<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="companyId" :rules="[{ required: true, message: '请输入公司ID' }]">
|
||||
<Input v-model:value="formData.companyId" type="number" placeholder="请输入公司ID" />
|
||||
|
||||
<Form.Item
|
||||
label="公司ID"
|
||||
name="companyId"
|
||||
:rules="[{ required: true, message: '请输入公司ID' }]"
|
||||
>
|
||||
<Input
|
||||
v-model:value="formData.companyId"
|
||||
type="number"
|
||||
placeholder="请输入公司ID"
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
|
||||
<Form.Item label="部门ID" name="departmentId">
|
||||
<Input v-model:value="formData.departmentId" type="number" placeholder="请输入部门ID" />
|
||||
<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" />
|
||||
<Input
|
||||
v-model:value="formData.positionId"
|
||||
type="number"
|
||||
placeholder="请输入岗位ID"
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="角色" name="role" :rules="[{ required: true, message: '请输入角色' }]">
|
||||
|
||||
<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' }
|
||||
{ label: '普通用户', value: 'user' },
|
||||
]"
|
||||
/>
|
||||
</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"
|
||||
@@ -217,7 +273,6 @@ defineExpose({
|
||||
:options="statusOptions"
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
</Form>
|
||||
</Modal>
|
||||
</template>
|
||||
|
||||
@@ -1,40 +1,45 @@
|
||||
<script lang="ts" setup>
|
||||
import { ref, computed } from 'vue';
|
||||
|
||||
import { Page } from '@vben/common-ui';
|
||||
import { Button, message, Space, Tag } from 'ant-design-vue';
|
||||
import { createIconifyIcon } from '@vben/icons';
|
||||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import type { VxeGridProps } from '#/adapter/vxe-table';
|
||||
|
||||
import {
|
||||
super_deleteAccountApi,
|
||||
super_getAccountPageApi,
|
||||
type SuperAccountVO,
|
||||
type SuperAccountDTO
|
||||
import type {
|
||||
SuperAccountDTO,
|
||||
SuperAccountVO,
|
||||
} from '#/api/organization/account-super';
|
||||
import type { PageQueryDTO } from '#/types/common';
|
||||
|
||||
import { computed, ref } from 'vue';
|
||||
|
||||
import { Page } from '@vben/common-ui';
|
||||
import { createIconifyIcon } from '@vben/icons';
|
||||
|
||||
import { Button, message, Space, Tag } from 'ant-design-vue';
|
||||
|
||||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import {
|
||||
super_deleteAccountApi,
|
||||
super_getAccountPageApi,
|
||||
} from '#/api/organization/account-super';
|
||||
|
||||
import SuperAccountFormModal from './components/SuperAccountFormModal.vue';
|
||||
|
||||
defineOptions({ name: 'SuperAccountManagement' });
|
||||
|
||||
// 创建图标组件
|
||||
const PlusIcon = createIconifyIcon('lucide:plus');
|
||||
|
||||
defineOptions({ name: 'SuperAccountManagement' });
|
||||
|
||||
// 响应式数据
|
||||
const loading = ref(false);
|
||||
const accountFormModalRef = ref();
|
||||
|
||||
// 搜索表单
|
||||
const searchForm = ref({
|
||||
loginCode: undefined as undefined | string,
|
||||
realName: undefined as undefined | string,
|
||||
phone: undefined as undefined | string,
|
||||
companyId: undefined as undefined | number,
|
||||
departmentId: undefined as undefined | number,
|
||||
positionId: undefined as undefined | number,
|
||||
role: undefined as undefined | string,
|
||||
status: undefined as undefined | number,
|
||||
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 +155,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 +193,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 +244,8 @@ const handleDelete = async (row: SuperAccountVO.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 +259,16 @@ const handleBatchDelete = async () => {
|
||||
}
|
||||
|
||||
try {
|
||||
const deletePromises = selectedRows.map((row: SuperAccountVO.AccountInfoVO) =>
|
||||
super_deleteAccountApi(row.id)
|
||||
const deletePromises = selectedRows.map(
|
||||
(row: SuperAccountVO.AccountInfoVO) => super_deleteAccountApi(row.id),
|
||||
);
|
||||
await Promise.all(deletePromises);
|
||||
message.success(`成功删除 ${selectedRows.length} 条记录`);
|
||||
refreshTable();
|
||||
} catch (error: any) {
|
||||
console.error('批量删除失败:', error);
|
||||
const errorMessage = error?.response?.data?.message || error?.message || '批量删除失败';
|
||||
const errorMessage =
|
||||
error?.response?.data?.message || error?.message || '批量删除失败';
|
||||
message.error(errorMessage);
|
||||
}
|
||||
};
|
||||
@@ -284,9 +310,7 @@ const getStatusColor = (status: number) => {
|
||||
</template>
|
||||
|
||||
<!-- VbenVxeGrid 表格 -->
|
||||
<Grid
|
||||
:loading="loading"
|
||||
>
|
||||
<Grid :loading="loading">
|
||||
<!-- 工具栏工具 -->
|
||||
<template #toolbar-tools>
|
||||
<Space>
|
||||
@@ -294,11 +318,7 @@ const getStatusColor = (status: number) => {
|
||||
<PlusIcon />
|
||||
添加账户
|
||||
</Button>
|
||||
<Button
|
||||
v-if="hasSelected"
|
||||
danger
|
||||
@click="handleBatchDelete"
|
||||
>
|
||||
<Button v-if="hasSelected" danger @click="handleBatchDelete">
|
||||
批量删除
|
||||
</Button>
|
||||
</Space>
|
||||
@@ -310,21 +330,20 @@ const getStatusColor = (status: number) => {
|
||||
{{ 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>
|
||||
|
||||
<!-- 账户表单弹窗 -->
|
||||
<SuperAccountFormModal ref="accountFormModalRef" @success="handleModalSuccess" />
|
||||
<SuperAccountFormModal
|
||||
ref="accountFormModalRef"
|
||||
@success="handleModalSuccess"
|
||||
/>
|
||||
</Page>
|
||||
</template>
|
||||
|
||||
Reference in New Issue
Block a user