mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-24 23:09:19 +08:00
feat: 忘记干嘛了
This commit is contained in:
@@ -2,6 +2,11 @@
|
||||
* 订单相关VO类型定义
|
||||
*/
|
||||
|
||||
import type { OrderStatusVO } from '#/api/ecommerce/order-status/types';
|
||||
import type { ProductSpecVO } from '#/api/ecommerce/product-spec/types';
|
||||
import type { ProductVO } from '#/api/ecommerce/product/types';
|
||||
import type { ShopVO } from '#/api/ecommerce/shop/types';
|
||||
|
||||
export namespace OrderVO {
|
||||
/** 订单信息 */
|
||||
export interface Info {
|
||||
@@ -51,6 +56,14 @@ export namespace OrderVO {
|
||||
otherCost?: number;
|
||||
/** 备注 */
|
||||
remark?: string;
|
||||
/** 关联商品信息 */
|
||||
product?: ProductVO.Info;
|
||||
/** 关联商品规格信息 */
|
||||
productSpec?: ProductSpecVO.Info;
|
||||
/** 关联订单状态信息 */
|
||||
orderStatus?: OrderStatusVO.Info;
|
||||
/** 关联店铺信息 */
|
||||
shop?: ShopVO.Info;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { requestClient } from '#/api/request';
|
||||
import type { DepartmentDTO, DepartmentVO } from './types';
|
||||
|
||||
import type { PageQueryDTO, PageResultVO } from '#/types/common';
|
||||
import type { DepartmentDTO, DepartmentVO } from './types';
|
||||
|
||||
import { requestClient } from '#/api/request';
|
||||
|
||||
/**
|
||||
* 部门管理API
|
||||
@@ -10,27 +11,57 @@ import type { DepartmentDTO, DepartmentVO } from './types';
|
||||
/**
|
||||
* 分页获取部门列表
|
||||
*/
|
||||
export async function getDepartmentPageApi(params: PageQueryDTO<DepartmentDTO.DepartmentFiltersDTO>) {
|
||||
return requestClient.post<PageResultVO<DepartmentVO.DepartmentInfoVO>>('/department/page', params);
|
||||
export async function getDepartmentPageApi(
|
||||
params: PageQueryDTO<DepartmentDTO.DepartmentFiltersDTO>,
|
||||
) {
|
||||
return requestClient.post<PageResultVO<DepartmentVO.DepartmentInfoVO>>(
|
||||
'/department/page',
|
||||
params,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建部门
|
||||
*/
|
||||
export async function createDepartmentApi(data: DepartmentDTO.CreateDepartmentDTO) {
|
||||
return requestClient.post<DepartmentVO.DepartmentInfoVO>('/department/create', data);
|
||||
export async function createDepartmentApi(
|
||||
data: DepartmentDTO.CreateDepartmentDTO,
|
||||
) {
|
||||
return requestClient.post<DepartmentVO.DepartmentInfoVO>(
|
||||
'/department/create',
|
||||
data,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新部门
|
||||
*/
|
||||
export async function updateDepartmentApi(id: number, data: DepartmentDTO.UpdateDepartmentDTO) {
|
||||
return requestClient.put<DepartmentVO.DepartmentInfoVO>(`/department/update/${id}`, data);
|
||||
export async function updateDepartmentApi(
|
||||
id: number,
|
||||
data: DepartmentDTO.UpdateDepartmentDTO,
|
||||
) {
|
||||
return requestClient.put<DepartmentVO.DepartmentInfoVO>(
|
||||
`/department/update/${id}`,
|
||||
data,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除部门
|
||||
*/
|
||||
export async function deleteDepartmentApi(id: number) {
|
||||
return requestClient.delete<void>(`/department/delete/${id}`);
|
||||
return requestClient.delete(`/department/delete/${id}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取全部部门
|
||||
*/
|
||||
export async function getAllDepartmentsApi() {
|
||||
return requestClient.get<DepartmentVO.DepartmentInfoVO[]>('/department/all');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取部门树
|
||||
*/
|
||||
export async function getDepartmentTreeApi() {
|
||||
return requestClient.get<DepartmentVO.DepartmentInfoVO[]>('/department/tree');
|
||||
}
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { requestClient } from '#/api/request';
|
||||
import type { PositionDTO, PositionVO } from './types';
|
||||
|
||||
import type { PageQueryDTO, PageResultVO } from '#/types/common';
|
||||
import type { PositionDTO, PositionVO } from './types';
|
||||
|
||||
import { requestClient } from '#/api/request';
|
||||
|
||||
/**
|
||||
* 岗位管理API
|
||||
@@ -10,27 +11,41 @@ import type { PositionDTO, PositionVO } from './types';
|
||||
/**
|
||||
* 分页获取岗位列表
|
||||
*/
|
||||
export async function getPositionPageApi(params: PageQueryDTO<PositionDTO.PositionFiltersDTO>) {
|
||||
return requestClient.post<PageResultVO<PositionVO.PositionInfoVO>>('/position/page', params);
|
||||
export async function getPositionPageApi(
|
||||
params: PageQueryDTO<PositionDTO.PositionFiltersDTO>,
|
||||
) {
|
||||
return requestClient.post<PageResultVO<PositionVO.PositionInfoVO>>(
|
||||
'/position/page',
|
||||
params,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建岗位
|
||||
*/
|
||||
export async function createPositionApi(data: PositionDTO.CreatePositionDTO) {
|
||||
return requestClient.post<PositionVO.PositionInfoVO>('/position/create', data);
|
||||
return requestClient.post<PositionVO.PositionInfoVO>(
|
||||
'/position/create',
|
||||
data,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新岗位
|
||||
*/
|
||||
export async function updatePositionApi(id: number, data: PositionDTO.UpdatePositionDTO) {
|
||||
return requestClient.put<PositionVO.PositionInfoVO>(`/position/update/${id}`, data);
|
||||
export async function updatePositionApi(
|
||||
id: number,
|
||||
data: PositionDTO.UpdatePositionDTO,
|
||||
) {
|
||||
return requestClient.put<PositionVO.PositionInfoVO>(
|
||||
`/position/update/${id}`,
|
||||
data,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除岗位
|
||||
*/
|
||||
export async function deletePositionApi(id: number) {
|
||||
return requestClient.delete<void>(`/position/delete/${id}`);
|
||||
return requestClient.delete(`/position/delete/${id}`);
|
||||
}
|
||||
|
||||
+170
-13
@@ -1,16 +1,21 @@
|
||||
<script lang="ts" setup>
|
||||
import type { AccountDTO, AccountVO } from '#/api/organization/account';
|
||||
import type { DepartmentVO } from '#/api/organization/department';
|
||||
import type { PositionVO } from '#/api/organization/position';
|
||||
import type { PageQueryDTO } from '#/types/common';
|
||||
|
||||
import { computed, ref, watch } from 'vue';
|
||||
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
|
||||
import { Form, Input, message, Select } from 'ant-design-vue';
|
||||
import { Cascader, Form, Input, message, Select } from 'ant-design-vue';
|
||||
|
||||
import {
|
||||
admin_createAccountApi,
|
||||
admin_updateAccountApi,
|
||||
} from '#/api/organization/account';
|
||||
import { getDepartmentTreeApi } from '#/api/organization/department';
|
||||
import { getPositionPageApi } from '#/api/organization/position';
|
||||
|
||||
interface Emits {
|
||||
(e: 'success'): void;
|
||||
@@ -37,6 +42,21 @@ const formRef = ref();
|
||||
const loading = ref(false);
|
||||
const isEdit = ref(false);
|
||||
const currentAccountData = ref<AccountVO.AccountInfoVO | null>(null);
|
||||
const departmentOptionsLoading = ref(false);
|
||||
const positionOptionsLoading = ref(false);
|
||||
const selectorsLoaded = ref(false);
|
||||
|
||||
interface DepartmentCascaderOption {
|
||||
children?: DepartmentCascaderOption[];
|
||||
label: string;
|
||||
value: number;
|
||||
}
|
||||
|
||||
interface PositionSelectOption {
|
||||
departmentId?: number;
|
||||
label: string;
|
||||
value: number;
|
||||
}
|
||||
|
||||
// 表单数据
|
||||
const formData = ref<AccountDTO.CreateAccountDTO & { status?: number }>({
|
||||
@@ -50,6 +70,17 @@ const formData = ref<AccountDTO.CreateAccountDTO & { status?: number }>({
|
||||
remark: '',
|
||||
status: 0,
|
||||
});
|
||||
const departmentPath = ref<number[]>([]);
|
||||
const departmentTreeOptions = ref<DepartmentCascaderOption[]>([]);
|
||||
const allPositionOptions = ref<PositionSelectOption[]>([]);
|
||||
|
||||
const positionOptions = computed(() => {
|
||||
const selectedDepartmentId = formData.value.departmentId;
|
||||
if (!selectedDepartmentId) return allPositionOptions.value;
|
||||
return allPositionOptions.value.filter(
|
||||
(item) => !item.departmentId || item.departmentId === selectedDepartmentId,
|
||||
);
|
||||
});
|
||||
|
||||
// 模态框标题
|
||||
const modalTitle = computed(() => (isEdit.value ? '编辑账户' : '添加账户'));
|
||||
@@ -75,6 +106,7 @@ function resetForm() {
|
||||
remark: '',
|
||||
status: 0,
|
||||
};
|
||||
departmentPath.value = [];
|
||||
formRef.value?.resetFields();
|
||||
}
|
||||
|
||||
@@ -84,7 +116,111 @@ function handleCancel() {
|
||||
}
|
||||
|
||||
// 暴露给父组件的方法
|
||||
function open(accountData?: AccountVO.AccountInfoVO | null) {
|
||||
function buildDepartmentTreeOptions(
|
||||
departments: DepartmentVO.DepartmentInfoVO[],
|
||||
): DepartmentCascaderOption[] {
|
||||
return departments.map((item) => ({
|
||||
children:
|
||||
item.children && item.children.length > 0
|
||||
? buildDepartmentTreeOptions(item.children)
|
||||
: undefined,
|
||||
label: item.name,
|
||||
value: item.id,
|
||||
}));
|
||||
}
|
||||
|
||||
function findDepartmentPathById(
|
||||
options: DepartmentCascaderOption[],
|
||||
departmentId: number,
|
||||
currentPath: number[] = [],
|
||||
): number[] | null {
|
||||
for (const option of options) {
|
||||
const nextPath = [...currentPath, option.value];
|
||||
if (option.value === departmentId) return nextPath;
|
||||
if (option.children?.length) {
|
||||
const result = findDepartmentPathById(
|
||||
option.children,
|
||||
departmentId,
|
||||
nextPath,
|
||||
);
|
||||
if (result) return result;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
async function loadDepartmentOptions() {
|
||||
try {
|
||||
departmentOptionsLoading.value = true;
|
||||
const data = await getDepartmentTreeApi();
|
||||
departmentTreeOptions.value = buildDepartmentTreeOptions(data || []);
|
||||
} catch (error) {
|
||||
console.error('获取部门树失败:', error);
|
||||
message.error('获取部门树失败');
|
||||
departmentTreeOptions.value = [];
|
||||
} finally {
|
||||
departmentOptionsLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function loadPositionOptions() {
|
||||
try {
|
||||
positionOptionsLoading.value = true;
|
||||
const params: PageQueryDTO = {
|
||||
page: 1,
|
||||
pageSize: 1000,
|
||||
};
|
||||
const data = await getPositionPageApi(params);
|
||||
const list = data.records || [];
|
||||
allPositionOptions.value = list.map((item: PositionVO.PositionInfoVO) => ({
|
||||
departmentId: item.departmentId,
|
||||
label: item.name,
|
||||
value: item.id,
|
||||
}));
|
||||
} catch (error) {
|
||||
console.error('获取岗位列表失败:', error);
|
||||
message.error('获取岗位列表失败');
|
||||
allPositionOptions.value = [];
|
||||
} finally {
|
||||
positionOptionsLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function ensureSelectorOptionsLoaded() {
|
||||
if (selectorsLoaded.value) return;
|
||||
await Promise.all([loadDepartmentOptions(), loadPositionOptions()]);
|
||||
selectorsLoaded.value = true;
|
||||
}
|
||||
|
||||
function syncDepartmentPathByDepartmentId() {
|
||||
if (!formData.value.departmentId) {
|
||||
departmentPath.value = [];
|
||||
return;
|
||||
}
|
||||
const path = findDepartmentPathById(
|
||||
departmentTreeOptions.value,
|
||||
formData.value.departmentId,
|
||||
);
|
||||
departmentPath.value = path || [];
|
||||
}
|
||||
|
||||
function handleDepartmentChange(value: number[]) {
|
||||
departmentPath.value = value || [];
|
||||
const selectedDepartmentId = departmentPath.value.at(-1) || 0;
|
||||
const previousDepartmentId = formData.value.departmentId;
|
||||
formData.value.departmentId = selectedDepartmentId;
|
||||
|
||||
if (
|
||||
previousDepartmentId !== selectedDepartmentId &&
|
||||
formData.value.positionId &&
|
||||
!positionOptions.value.some((item) => item.value === formData.value.positionId)
|
||||
) {
|
||||
formData.value.positionId = 0;
|
||||
}
|
||||
}
|
||||
|
||||
async function open(accountData?: AccountVO.AccountInfoVO | null) {
|
||||
await ensureSelectorOptionsLoaded();
|
||||
isEdit.value = !!accountData;
|
||||
currentAccountData.value = accountData || null;
|
||||
|
||||
@@ -104,6 +240,8 @@ function open(accountData?: AccountVO.AccountInfoVO | null) {
|
||||
};
|
||||
}
|
||||
|
||||
syncDepartmentPathByDepartmentId();
|
||||
|
||||
modalApi.open();
|
||||
}
|
||||
|
||||
@@ -144,6 +282,18 @@ watch(
|
||||
},
|
||||
);
|
||||
|
||||
watch(
|
||||
() => formData.value.departmentId,
|
||||
() => {
|
||||
if (
|
||||
formData.value.positionId &&
|
||||
!positionOptions.value.some((item) => item.value === formData.value.positionId)
|
||||
) {
|
||||
formData.value.positionId = 0;
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
// 暴露方法给父组件
|
||||
defineExpose({
|
||||
open,
|
||||
@@ -217,26 +367,33 @@ defineExpose({
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item
|
||||
label="部门ID"
|
||||
label="所属部门"
|
||||
name="departmentId"
|
||||
:rules="[{ required: true, message: '请输入部门ID' }]"
|
||||
:rules="[{ required: true, message: '请选择所属部门' }]"
|
||||
>
|
||||
<Input
|
||||
v-model:value="formData.departmentId"
|
||||
type="number"
|
||||
placeholder="请输入部门ID"
|
||||
<Cascader
|
||||
:value="departmentPath"
|
||||
:options="departmentTreeOptions"
|
||||
:loading="departmentOptionsLoading"
|
||||
placeholder="请选择所属部门"
|
||||
:field-names="{ label: 'label', value: 'value', children: 'children' }"
|
||||
change-on-select
|
||||
class="w-full"
|
||||
@change="(value) => handleDepartmentChange((value || []) as number[])"
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item
|
||||
label="岗位ID"
|
||||
label="职位"
|
||||
name="positionId"
|
||||
:rules="[{ required: true, message: '请输入岗位ID' }]"
|
||||
:rules="[{ required: true, message: '请选择职位' }]"
|
||||
>
|
||||
<Input
|
||||
<Select
|
||||
v-model:value="formData.positionId"
|
||||
type="number"
|
||||
placeholder="请输入岗位ID"
|
||||
:loading="positionOptionsLoading"
|
||||
:options="positionOptions"
|
||||
placeholder="请选择职位"
|
||||
:disabled="positionOptionsLoading"
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user