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',
@@ -14,7 +14,6 @@ import { useVbenForm } from '@vben-core/form-ui';
import { VbenButton, VbenCheckbox } from '@vben-core/shadcn-ui';
import Title from './auth-title.vue';
import ThirdPartyLogin from './third-party-login.vue';
interface Props extends AuthenticationProps {
formSchema?: VbenFormSchema[];
+241
View File
@@ -0,0 +1,241 @@
# ecom-dmb 项目优化报告
> 报告时间:2026-05-07
> 报告人:Claude
---
## 一、项目概述
| 项目 | 路径 |
|------|------|
| 后端 | `ecom-dmb-backend/` |
| 前端 | `ecom-dmb-frontend/` |
### 技术栈
- **后端**:Spring Boot + MyBatis-Plus + MySQL + Redis + Knife4j
- **前端**:Vue3 + Vben Admin 5.5.9 + Ant Design Vue + Tailwind CSS + ECharts
---
## 二、已完成任务(本轮)
| 任务 | 状态 | 说明 |
|------|------|------|
| 商品概览 P&L → 各规格销量 Top10 | ✅ | 前后端同步修改 |
### 2.1 本轮修改清单
#### 前端
| 文件 | 操作 |
|------|------|
| `product/overview/components/FinancialPanel.vue` | 删除 |
| `product/overview/components/SpecSalesTop10Panel.vue` | 新增 |
| `product/overview/index.vue` | 替换组件引用 |
| `product/overview/components/StatCards.vue` | 清理无用 props |
| `api/ecommerce/product-overview/types/types.vo.ts` | 新增 `SpecSalesRankItem` 类型 + `specSalesTop10` 字段 |
#### 后端
| 文件 | 操作 |
|------|------|
| `ProductOverviewVO.java` | 新增 `specSalesTop10` + `SpecSalesRankItem`;移除 P&L 字段 |
| `ProductOverviewServiceImpl.java` | 新增 `buildSpecSalesTop10()`;移除相关 P&L 计算 |
---
## 三、待处理问题(按优先级)
### 🔴 P0 - 必须修复
#### 1. OSS AccessKey/Secret 硬编码(严重)
**位置:** `ecom-dmb-backend/src/main/resources/application.yml` 第 117-118 行
```
oss.access-key-id: LTAI5t8oyyor6wLrQasDUQA3
oss.access-key-secret: U0d3BeKADTJUteSsT5gBtxzlbHoJFi
```
**风险:** 阿里云密钥已泄露,可能被滥用
**建议:**
1. 立即在阿里云控制台轮换密钥
2. 移除 `application.yml` 中的默认值,改为纯环境变量引用
3. 生产环境确保设置 `OSS_ACCESS_KEY_ID` 和 `OSS_ACCESS_KEY_SECRET` 环境变量
---
#### 2. `sub_plan_pricing.stauts` 字段 typo
**位置:** `ecom-dmb-backend/sql/sub_design.sql` 第 38 行
```sql
`stauts` tinyint NOT NULL DEFAULT 1 COMMENT '是否启用当前价格(1-启用,0-禁用)',
```
**问题:** SQL 列名是 `stauts`,但 PO 属性是 `status`,会导致 MyBatis-Plus 映射问题
**建议:**
1. 新增正确字段 `status`
2. 迁移 `stauts` 数据到 `status`
3. 删除 `stauts` 列
4. 更新 `SubPlanPricingPO` 映射
---
#### 3. Knife4j 残留配置
**位置:** `application.yml` 第 95-99 行
```yaml
- group: "媒体模块"
paths-to-match:
- "/media/image/**"
- "/media/file/**"
packages-to-scan: "top.xyquan.ecomdmbbackend.modules.media.controller"
```
**问题:** `modules/media/` 已删除,但 knife4j 分组配置仍存在,会在 Swagger 文档中产生无效分组
**建议:** 删除该 knife4j 分组配置
---
### ⚠️ P1 - 建议修复
#### 4. JWT Secret 默认值过弱
**位置:** `application.yml` 第 47 行
```
jwt.secret: your-secret-key-here-must-be-at-least-64-bytes-long-for-hs512-algorithm-security
```
**建议:** 确保生产环境设置 `JWT_SECRET` 环境变量
---
#### 5. sys_oper_log 表 DDL 状态确认
**说明:** `INSPECTION.md` 记录此表缺失,但探索发现 `src/main/resources/db/migration/V1__sys_oper_log.sql` 可能已创建
**建议:** 确认该 SQL 文件存在且已执行到数据库
---
#### 6. `sub_subscription` 注释引用错误表名
**位置:** `sql/sub_design.sql` 第 86 行
```sql
`company_id` ... COMMENT '公司ID(关联sys_company)',
```
**问题:** 实际 FK 指向 `org_company`,注释写成 `sys_company`
**建议:** 更新注释为 `org_company`
---
#### 7. PositionPermission Service 缺少公司归属校验
**说明:** `/position-permission/*` 接口理论上只有超管可访问,但 Service 层未校验职位所属公司
**建议:** 在 `PositionPermissionServiceImpl` 增加公司归属校验作为防御性编程
---
## 四、代码质量
### 4.1 前端 Typecheck
**执行命令:** `pnpm typecheck`
**结果:** ❌ 存在 30+ 个 type 错误(大部分为已有问题,与本轮改动无关)
**本轮相关:** 无新增 type 错误
---
### 4.2 后端编译
**执行命令:** `./mvnw compile`
**结果:** ✅ BUILD SUCCESS
---
### 4.3 前端 Lint
**问题:**
- ~84 文件有 Prettier 格式化警告
- 1 文件有 CSS 属性排序错误:`CompanyMenuDrawer.vue`
---
## 五、优化建议
### 5.1 短期(1-2 周)
1. **立即轮换 OSS 密钥** - 最高优先级
2. **修复 stauts typo** - 涉及表结构变更,需谨慎
3. **删除 knife4j 残留配置** - 简单删除即可
4. **确认 sys_oper_log DDL 已执行** - 避免 @OperLog 运行时异常
### 5.2 中期(1 个月)
1. **统一环境变量管理** - 将所有敏感配置(JWT、OSS、DB、Redis)改为纯环境变量引用
2. **完善单元测试** - TODO.md 提到"暂跳过",建议补充核心业务逻辑测试(盈亏计算、ROI、税费)
3. **前端 lint 清理** - 84 个文件的格式化问题影响代码审查体验
### 5.3 长期
1. **CI/CD 流程** - 添加自动编译、测试、lint 检查
2. **前端组件库建设** - 抽出公共组件,减少重复代码
3. **后端 API 文档** - 确保 Knife4j 配置完整且准确
---
## 六、项目进度追踪
| 阶段 | 任务 | 状态 | 备注 |
|------|------|------|------|
| 一:前端架构 | 理解技术栈、目录结构 | ✅ | |
| 二:前端安全 | 导出功能、companyId 校验 | ✅ | |
| 三:后端安全 | 全局拦截器、JWT/DB/Redis 加密 | ✅ | |
| 四:功能补充 | Dashboard 导出、操作日志 | ✅ | |
| 五:基础设施 | Redis、README、备份脚本 | ✅ | |
| 五:单元测试 | 盈亏/ROI/税费计算逻辑 | ❌ | TODO.md 未完成 |
---
## 七、关键文件路径
### 敏感配置
```
ecom-dmb-backend/src/main/resources/application.yml
```
### SQL 文件
```
ecom-dmb-backend/sql/
├── sub_design.sql # stauts typo
└── sys_design.sql # sys_oper_log 需确认
```
### 前端类型定义
```
ecom-dmb-frontend/apps/web-antd/src/api/ecommerce/product-overview/types/types.vo.ts
```
### 后端 VO
```
ecom-dmb-backend/src/main/java/.../product/overview/model/vo/ProductOverviewVO.java
```
---
> 本报告由 Claude 根据项目代码和已有文档分析生成