fix: 修复前端 TypeScript 类型错误

- file-upload.ts: 重写上传逻辑,正确使用 files 数组和类型
- CompanyMenuDrawer/CompanyPermissionDrawer: 修复 Tree @check 事件类型
- 移除各页面未使用的导入和函数
- promotion-fee: 修复类型导出问题
- 修复 VxeGrid 配置重复和无效属性问题
This commit is contained in:
小蟑螂
2026-05-07 20:41:03 +08:00
parent ff790a7a97
commit d8da5a1b33
17 changed files with 314 additions and 100 deletions
@@ -1 +1,2 @@
export * from './apis';
export * from './types';
@@ -282,15 +282,17 @@ function handleSelectNone() {
}
// 处理树形控件的选中变化
function handleTreeCheckChange(checkedKeysValue: any) {
function handleTreeCheckChange(
checked: (number | string)[] | { checked: (number | string)[]; halfChecked: (number | string)[] },
) {
const checkedKeysValue = Array.isArray(checked) ? checked : checked.checked;
// 对比新旧值,找出被取消勾选的节点
const oldKeys = new Set(checkedKeys.value);
const newKeys = new Set(checkedKeysValue);
// 找出新增的(勾选)和移除的(取消勾选)的节点
const addedKeys = newKeys.difference(oldKeys);
const oldKeys = new Set<number>(checkedKeys.value);
const newKeys = new Set<number>(checkedKeysValue as number[]);
// 找出移除的(取消勾选)的节点
const removedKeys = oldKeys.difference(newKeys);
// 如果是取消勾选,需要把取消节点的子节点也一并移除
if (removedKeys.size > 0) {
// 构建 parentId -> childIds 的映射
@@ -302,7 +304,7 @@ function handleTreeCheckChange(checkedKeysValue: any) {
parentToChildren.set(menu.parentId, children);
}
}
// 递归移除子节点
function removeDescendants(nodeId: number) {
const children = parentToChildren.get(nodeId) || [];
@@ -311,12 +313,12 @@ function handleTreeCheckChange(checkedKeysValue: any) {
removeDescendants(childId);
}
}
for (const removedId of removedKeys) {
removeDescendants(removedId);
}
}
checkedKeys.value = [...newKeys];
}
@@ -6,7 +6,6 @@ import { useVbenDrawer } from '@vben/common-ui';
import {
Button,
Checkbox,
Flex,
message,
Spin,
Tag,
@@ -109,7 +108,7 @@ async function loadData() {
]);
// 处理权限列表(只取启用状态的)
const permArray = Array.isArray(permData) ? permData : (permData?.data || []);
const permArray = Array.isArray(permData) ? permData : [];
allPermissions.value = permArray.filter((p: any) => p.status === 1);
// 公司已有权限
@@ -21,39 +21,52 @@ export async function uploadFileToOssFromSystem(
dir: string = 'general',
): Promise<UploadResult> {
const signRes = await batchSignUrlApi({
filenames: [file.name],
dir,
files: [{ filename: file.name, fileHash: '' }],
});
const fileInfo = signRes.files[0];
if (!fileInfo) {
throw new Error('签名响应为空');
}
// 已存在则直接返回
if (signRes.existingFiles && signRes.existingFiles.length > 0) {
const existing = signRes.existingFiles[0];
if (fileInfo.exists && fileInfo.accessUrl && fileInfo.storagePath) {
return {
accessUrl: existing.accessUrl,
storagePath: existing.storagePath,
accessUrl: fileInfo.accessUrl,
storagePath: fileInfo.storagePath,
};
}
// 前端直传 OSS
const { uploadUrl, ossHeaders } = signRes.signUrls[0];
await fetch(uploadUrl, {
method: 'PUT',
headers: ossHeaders,
body: file,
});
if (fileInfo.uploadUrl && fileInfo.uploadHeaders) {
await fetch(fileInfo.uploadUrl, {
method: 'PUT',
headers: fileInfo.uploadHeaders,
body: file,
});
}
// 通知后端创建文件记录
const createRes = await batchCreateOssFilesApi({
filenames: [file.name],
dir,
ossKeys: [signRes.ossKeys[0]],
accessUrls: [signRes.accessUrls[0]],
fileSizes: [file.size],
fileFormats: [file.name.split('.').pop() || ''],
files: [
{
filename: file.name,
fileHash: '',
storagePath: fileInfo.storagePath || '',
fileSize: file.size,
mimeType: file.type,
category: dir,
},
],
});
const firstFile = createRes[0];
if (!firstFile) {
throw new Error('文件记录创建失败');
}
return {
accessUrl: createRes[0].accessUrl,
storagePath: createRes[0].storagePath,
accessUrl: firstFile.accessUrl || '',
storagePath: firstFile.storagePath || '',
};
}
@@ -27,11 +27,6 @@ const formatAmount = (amount: number) => {
return `¥${amount.toLocaleString('zh-CN')}`;
};
const safeNumber = (value: number | string | undefined) => {
const num = Number(value);
return Number.isFinite(num) ? num : 0;
};
// 渲染店铺销售占比排行图表
const renderShopBarChart = () => {
if (!barChartRef.value || !props.shopSalesRatios) return;
@@ -7,7 +7,7 @@ import { computed, ref } from 'vue';
import { Page } from '@vben/common-ui';
import { createIconifyIcon } from '@vben/icons';
import { Button, message, Popconfirm, Space, Tag } from 'ant-design-vue';
import { Button, message, Popconfirm, Space } from 'ant-design-vue';
import { useVbenVxeGrid } from '#/adapter/vxe-table';
import {
@@ -533,11 +533,6 @@ function handleSortChange({
gridReloadRef.value?.();
}
// 获取店铺选项(首次加载)
async function fetchShopOptions() {
await fetchShops(1, false);
}
// 获取订单状态选项
async function fetchOrderStatusOptions() {
try {
@@ -5,7 +5,7 @@ import { computed, ref } from 'vue';
import { useVbenModal } from '@vben/common-ui';
import { Form, Input, message, Select, Switch } from 'ant-design-vue';
import { Form, Input, message, Switch } from 'ant-design-vue';
import { createPlatformApi, updatePlatformApi } from '#/api/ecommerce/platform';
@@ -7,14 +7,12 @@ import { computed, ref } from 'vue';
import { Page } from '@vben/common-ui';
import { createIconifyIcon } from '@vben/icons';
import { Avatar, Button, message, Popconfirm, Space, Tag } from 'ant-design-vue';
import { Button, message, Popconfirm, Space, Tag } from 'ant-design-vue';
import { useVbenVxeGrid } from '#/adapter/vxe-table';
import {
createPlatformApi,
deletePlatformApi,
getPlatformPageApi,
updatePlatformApi,
} from '#/api/ecommerce/platform';
import PlatformFormModal from './components/PlatformFormModal.vue';
@@ -226,23 +226,12 @@ function refreshTable() {
}
}
// 重置搜索表单
function handleReset() {
searchForm.value = {
shopId: undefined,
startTargetMonth: undefined,
endTargetMonth: undefined,
};
gridReloadRef.value?.();
}
// 创建 VbenVxeGrid 实例
const [Grid, gridApi] = useVbenVxeGrid({
gridOptions,
formOptions: formOptions.value,
showSearchForm: true,
tableTitle: '店铺月销量目标管理',
handleReset,
});
gridReloadRef.value = () => gridApi.reload();
@@ -8,7 +8,6 @@ import { Page } from '@vben/common-ui';
import {
Button,
Card,
Checkbox,
Flex,
Input,
message,
@@ -135,10 +134,13 @@ async function loadCompanyMenus() {
}
// Tree勾选变化
function handleTreeCheckChange(checkedKeys: any) {
function handleTreeCheckChange(
checked: (number | string)[] | { checked: (number | string)[]; halfChecked: (number | string)[] },
) {
const checkedKeys = Array.isArray(checked) ? checked : checked.checked;
// 对比新旧值,找出被取消勾选的节点
const oldKeys = new Set(selectedMenuIds.value);
const newKeys = new Set(Array.isArray(checkedKeys) ? checkedKeys : checkedKeys);
const oldKeys = new Set<number>(selectedMenuIds.value);
const newKeys = new Set<number>(checkedKeys as number[]);
const removedKeys = [...oldKeys].filter((k) => !newKeys.has(k));
const addedKeys = [...newKeys].filter((k) => !oldKeys.has(k));
@@ -4,6 +4,7 @@ import type { PermissionVO } from '#/api/system/permission/types';
import { createIconifyIcon } from '@vben/icons';
import { Checkbox, Tag } from 'ant-design-vue';
import type { CheckboxChangeEvent } from 'ant-design-vue/es/checkbox/interface';
const ChevronDownIcon = createIconifyIcon('lucide:chevron-down');
const ChevronRightIcon = createIconifyIcon('lucide:chevron-right');
@@ -56,10 +57,18 @@ function getDescendantIds(node: PermissionVO.PermissionInfoVO): number[] {
return result;
}
function onCheckboxChange(e: Event) {
const checked = (e.target as HTMLInputElement).checked;
function onCheckboxChange(e: CheckboxChangeEvent) {
const checked = e.target.checked;
emit('check', props.node.id, checked);
}
function handleToggle(id: number) {
emit('toggle', id);
}
function handleCheck(id: number, checked: boolean) {
emit('check', id, checked);
}
</script>
<template>
@@ -111,8 +120,8 @@ function onCheckboxChange(e: Event) {
:level="level + 1"
:expanded-ids="expandedIds"
:selected-ids="selectedIds"
@toggle="(id) => emit('toggle', id)"
@check="(id, checked) => emit('check', id, checked)"
@toggle="handleToggle"
@check="handleCheck"
/>
</template>
</div>
@@ -6,7 +6,7 @@ import { computed, onMounted, ref } from 'vue';
import { Page } from '@vben/common-ui';
import { Button, Card, Checkbox, Flex, Input, message, Pagination, Select, Spin, Tag } from 'ant-design-vue';
import { Button, Card, Flex, Input, message, Pagination, Select, Spin, Tag } from 'ant-design-vue';
import { batchUpdateCompanyPermissionsApi, getCompanyPermissionIdsApi } from '#/api/organization/company-permission/apis';
import { getCompanyPageApi } from '#/api/organization/company';
@@ -223,23 +223,6 @@ function findNode(nodes: PermissionVO.PermissionInfoVO[], id: number): Permissio
return null;
}
// 节点是否全选
function isNodeChecked(node: PermissionVO.PermissionInfoVO): boolean {
if (!node.children || node.children.length === 0) {
return selectedPermissionIds.value.includes(node.id);
}
const allIds = getDescendantIds(node.id);
return allIds.length > 0 && allIds.every((id) => selectedPermissionIds.value.includes(id));
}
// 节点是否半选
function isNodeIndeterminate(node: PermissionVO.PermissionInfoVO): boolean {
if (!node.children || node.children.length === 0) return false;
const allIds = getDescendantIds(node.id);
const selectedCount = allIds.filter((id) => selectedPermissionIds.value.includes(id)).length;
return selectedCount > 0 && selectedCount < allIds.length;
}
// 展开/收起
function toggleExpand(nodeId: number) {
const newSet = new Set(expandedIds.value);
@@ -2,12 +2,12 @@
import type { VxeGridProps } from '#/adapter/vxe-table';
import type { PermissionVO } from '#/api/system/permission';
import { computed, ref } from 'vue';
import { ref } from 'vue';
import { Page } from '@vben/common-ui';
import { createIconifyIcon } from '@vben/icons';
import { Button, message, Popconfirm, Space, Tag, Spin } from 'ant-design-vue';
import { Button, message, Popconfirm, Space, Tag } from 'ant-design-vue';
import { useVbenVxeGrid } from '#/adapter/vxe-table';
import {
@@ -100,11 +100,10 @@ const gridOptions: VxeGridProps<any> = {
height: 'auto',
border: true,
stripe: true,
rowConfig: { isHover: true },
showOverflow: true,
size: 'small',
expandAll: false,
rowConfig: {
isHover: true,
drag: true,
},
rowDragConfig: {
@@ -71,7 +71,6 @@ const gridOptions: VxeGridProps<FlatNode> = {
stripe: true,
showOverflow: true,
size: 'small',
expandAll: true,
columnConfig: {
resizable: true,
},
@@ -131,16 +130,6 @@ function getTypeText(type: string) {
return map[type] || type;
}
function getTypeColor(type: string) {
const map: Record<string, string> = {
api: 'blue',
button: 'green',
data: 'orange',
module: 'purple',
};
return map[type] || 'default';
}
function getTypeTagColor(type: string) {
const map: Record<string, string> = {
api: 'processing',