mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-24 22:29:19 +08:00
refact: 重构目录架构
This commit is contained in:
+171
@@ -0,0 +1,171 @@
|
||||
<script lang="ts" setup>
|
||||
import { computed, ref } from 'vue';
|
||||
import { Form, Input, Modal, Select, message, Switch } from 'ant-design-vue';
|
||||
|
||||
import {
|
||||
createPositionApi,
|
||||
updatePositionApi,
|
||||
type PositionVO
|
||||
} from '#/api/organization/position';
|
||||
|
||||
interface Props {
|
||||
departmentOptions: Array<{ label: string; value: number }>;
|
||||
}
|
||||
|
||||
interface Emits {
|
||||
(e: 'success'): void;
|
||||
}
|
||||
|
||||
defineProps<Props>();
|
||||
|
||||
const emit = defineEmits<Emits>();
|
||||
|
||||
// 响应式数据
|
||||
const formRef = ref();
|
||||
const loading = ref(false);
|
||||
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<FormData>({
|
||||
name: '',
|
||||
code: '',
|
||||
departmentId: undefined,
|
||||
remark: '',
|
||||
status: true,
|
||||
});
|
||||
|
||||
// 开关组件不需要选项数组
|
||||
|
||||
// 模态框标题
|
||||
const modalTitle = computed(() => isEdit.value ? '编辑岗位' : '添加岗位');
|
||||
|
||||
// 重置表单
|
||||
function resetForm() {
|
||||
formData.value = {
|
||||
name: '',
|
||||
code: '',
|
||||
departmentId: undefined,
|
||||
remark: '',
|
||||
status: true,
|
||||
};
|
||||
formRef.value?.resetFields();
|
||||
}
|
||||
|
||||
// 处理模态框关闭
|
||||
function handleCancel() {
|
||||
visible.value = false;
|
||||
}
|
||||
|
||||
// 处理表单提交
|
||||
async function handleSubmit() {
|
||||
try {
|
||||
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, submitData);
|
||||
message.success('更新成功');
|
||||
} else {
|
||||
await createPositionApi(submitData);
|
||||
message.success('创建成功');
|
||||
}
|
||||
|
||||
visible.value = false;
|
||||
emit('success');
|
||||
} catch (error) {
|
||||
console.error('保存岗位失败:', error);
|
||||
message.error('保存岗位失败');
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
// 暴露给父组件的方法
|
||||
function open(editMode: boolean = false, positionData?: PositionVO.PositionInfoVO | null) {
|
||||
isEdit.value = editMode;
|
||||
currentPositionData.value = positionData || null;
|
||||
|
||||
resetForm();
|
||||
|
||||
if (editMode && positionData) {
|
||||
formData.value = {
|
||||
name: positionData.name,
|
||||
code: positionData.code || '',
|
||||
departmentId: positionData.departmentId,
|
||||
remark: positionData.remark || '',
|
||||
status: positionData.status === 1, // 转换为boolean
|
||||
};
|
||||
}
|
||||
|
||||
visible.value = true;
|
||||
}
|
||||
|
||||
// 暴露方法给父组件
|
||||
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="name" :rules="[{ required: true, message: '请输入岗位名称' }]">
|
||||
<Input v-model:value="formData.name" placeholder="请输入岗位名称" />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="岗位编码" name="code">
|
||||
<Input v-model:value="formData.code" placeholder="请输入岗位编码" />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="所属部门" name="departmentId">
|
||||
<Select
|
||||
v-model:value="formData.departmentId"
|
||||
placeholder="请选择所属部门"
|
||||
:options="departmentOptions"
|
||||
allow-clear
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="描述" name="remark">
|
||||
<Input.TextArea v-model:value="formData.remark" placeholder="请输入岗位描述" :rows="3" />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="状态" name="status">
|
||||
<Switch
|
||||
v-model:checked="formData.status"
|
||||
checked-children="启用"
|
||||
un-checked-children="禁用"
|
||||
/>
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</Modal>
|
||||
</template>
|
||||
@@ -0,0 +1,272 @@
|
||||
<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 {
|
||||
deletePositionApi,
|
||||
getPositionPageApi,
|
||||
type PositionVO,
|
||||
type PositionDTO
|
||||
} from '#/api/organization/position';
|
||||
import type { PageQueryDTO } from '#/types/common';
|
||||
import PositionModal from './components/PositionModal.vue';
|
||||
|
||||
// 创建图标组件
|
||||
const PlusIcon = createIconifyIcon('lucide:plus');
|
||||
|
||||
defineOptions({ name: 'PositionManagement' });
|
||||
|
||||
// 响应式数据
|
||||
const loading = ref(false);
|
||||
const positionModalRef = ref();
|
||||
|
||||
// 搜索表单
|
||||
const searchForm = ref({
|
||||
name: '',
|
||||
status: undefined as number | undefined,
|
||||
});
|
||||
|
||||
// 状态选项
|
||||
const statusOptions = [
|
||||
{ label: '禁用', value: 0 },
|
||||
{ label: '启用', value: 1 },
|
||||
];
|
||||
|
||||
// 部门选项(这里需要根据实际情况获取部门列表)
|
||||
const departmentOptions = ref([
|
||||
{ label: '技术部', value: 1 },
|
||||
{ label: '产品部', value: 2 },
|
||||
{ label: '运营部', value: 3 },
|
||||
{ label: '市场部', value: 4 },
|
||||
]);
|
||||
|
||||
// VbenVxeGrid 表格配置
|
||||
const gridOptions: VxeGridProps<any> = {
|
||||
columns: [
|
||||
{
|
||||
type: 'seq' as const,
|
||||
minWidth: 'auto',
|
||||
title: '序号',
|
||||
},
|
||||
{
|
||||
field: 'name',
|
||||
title: '岗位名称',
|
||||
minWidth: 150,
|
||||
showOverflow: 'tooltip' as const,
|
||||
},
|
||||
{
|
||||
field: 'code',
|
||||
title: '岗位编码',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
title: '所属部门',
|
||||
minWidth: 150,
|
||||
slots: { default: 'department' },
|
||||
},
|
||||
{
|
||||
field: 'remark',
|
||||
title: '描述',
|
||||
minWidth: 200,
|
||||
showOverflow: 'tooltip' as const,
|
||||
},
|
||||
{
|
||||
title: '状态',
|
||||
minWidth: 100,
|
||||
slots: { default: 'status' },
|
||||
},
|
||||
{
|
||||
field: 'createTime',
|
||||
title: '创建时间',
|
||||
minWidth: 180,
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
minWidth: 200,
|
||||
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<PositionDTO.PositionFiltersDTO> = {
|
||||
page: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
filters: {
|
||||
name: searchForm.value.name || undefined,
|
||||
status: searchForm.value.status,
|
||||
},
|
||||
};
|
||||
const data = await getPositionPageApi(params);
|
||||
return {
|
||||
items: data.records,
|
||||
total: data.total,
|
||||
};
|
||||
} catch (error) {
|
||||
console.error('获取岗位列表失败:', error);
|
||||
message.error('获取岗位列表失败');
|
||||
return {
|
||||
items: [],
|
||||
total: 0,
|
||||
};
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
// 搜索表单配置
|
||||
const formOptions = computed(() => ({
|
||||
schema: [
|
||||
{
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入岗位名称',
|
||||
},
|
||||
fieldName: 'name',
|
||||
label: '岗位名称',
|
||||
},
|
||||
{
|
||||
component: 'Select',
|
||||
componentProps: {
|
||||
placeholder: '请选择状态',
|
||||
options: statusOptions,
|
||||
allowClear: true,
|
||||
},
|
||||
fieldName: 'status',
|
||||
label: '状态',
|
||||
},
|
||||
],
|
||||
showDefaultActions: true,
|
||||
collapsed: true,
|
||||
collapsedRows: 1,
|
||||
}));
|
||||
|
||||
// 刷新表格数据
|
||||
function refreshTable() {
|
||||
if (gridApi) {
|
||||
gridApi.reload();
|
||||
}
|
||||
}
|
||||
|
||||
// 处理添加岗位
|
||||
function handleAdd() {
|
||||
positionModalRef.value?.open(false);
|
||||
}
|
||||
|
||||
// 处理编辑岗位
|
||||
function handleEdit(record: PositionVO.PositionInfoVO) {
|
||||
positionModalRef.value?.open(true, record);
|
||||
}
|
||||
|
||||
// 处理删除岗位
|
||||
async function handleDelete(record: PositionVO.PositionInfoVO) {
|
||||
try {
|
||||
await deletePositionApi(record.id);
|
||||
message.success('删除成功');
|
||||
refreshTable();
|
||||
} catch (error) {
|
||||
console.error('删除岗位失败:', error);
|
||||
message.error('删除岗位失败');
|
||||
}
|
||||
}
|
||||
|
||||
// 处理模态框成功回调
|
||||
function handleModalSuccess() {
|
||||
refreshTable();
|
||||
}
|
||||
|
||||
// 创建 VbenVxeGrid 实例
|
||||
const [Grid, gridApi] = useVbenVxeGrid({
|
||||
gridOptions,
|
||||
formOptions: formOptions.value,
|
||||
showSearchForm: true,
|
||||
tableTitle: '岗位管理',
|
||||
});
|
||||
</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>
|
||||
</Space>
|
||||
</template>
|
||||
|
||||
<!-- 所属部门列 -->
|
||||
<template #department="{ row }: { row: any }">
|
||||
<span v-if="!row.departmentId">-</span>
|
||||
<span v-else>
|
||||
{{ departmentOptions.find(d => d.value === row.departmentId)?.label || '未知部门' }}
|
||||
</span>
|
||||
</template>
|
||||
|
||||
<!-- 状态列 -->
|
||||
<template #status="{ row }: { row: any }">
|
||||
<Tag :color="row.status === 1 ? 'green' : 'red'">
|
||||
{{ row.status === 1 ? '启用' : '禁用' }}
|
||||
</Tag>
|
||||
</template>
|
||||
|
||||
<!-- 操作列 -->
|
||||
<template #action="{ row }: { row: any }">
|
||||
<Space>
|
||||
<Button size="small" @click="handleEdit(row)">
|
||||
编辑
|
||||
</Button>
|
||||
<Button size="small" danger @click="handleDelete(row)">
|
||||
删除
|
||||
</Button>
|
||||
</Space>
|
||||
</template>
|
||||
</Grid>
|
||||
|
||||
<!-- 岗位模态框组件 -->
|
||||
<PositionModal
|
||||
ref="positionModalRef"
|
||||
:department-options="departmentOptions"
|
||||
@success="handleModalSuccess"
|
||||
/>
|
||||
</Page>
|
||||
</template>
|
||||
Reference in New Issue
Block a user