zksu
/
WEB
forked from yoone/WEB
1
0
Fork 0

Compare commits

..

No commits in common. "c8064f20e3af3a01d668f8c2381eeafb92c89789" and "85ad42278b113401b2c8542668822bdfbce1d0fb" have entirely different histories.

15 changed files with 26253 additions and 33513 deletions

View File

@ -1,18 +1,15 @@
## 实现计划 ## 实现计划
### 1. 地图数据准备 ### 1. 地图数据准备
- 获取加拿大和澳大利亚的省级地图数据JSON格式
- 获取加拿大和澳大利亚的省级地图数据JSON 格式)
- 将地图数据文件添加到项目的`public`目录下,命名为`canada.json`和`australia.json` - 将地图数据文件添加到项目的`public`目录下,命名为`canada.json`和`australia.json`
### 2. 组件实现 ### 2. 组件实现
- 为加拿大创建地图组件:`/Users/zksu/Developer/work/workcode/WEB/src/pages/Area/Canada/index.tsx` - 为加拿大创建地图组件:`/Users/zksu/Developer/work/workcode/WEB/src/pages/Area/Canada/index.tsx`
- 为澳大利亚创建地图组件:`/Users/zksu/Developer/work/workcode/WEB/src/pages/Area/Australia/index.tsx` - 为澳大利亚创建地图组件:`/Users/zksu/Developer/work/workcode/WEB/src/pages/Area/Australia/index.tsx`
- 组件将基于现有的`Map/index.tsx`实现,修改地图数据加载和配置 - 组件将基于现有的`Map/index.tsx`实现,修改地图数据加载和配置
### 3. 数据结构设计 ### 3. 数据结构设计
- 定义省级数据接口,包含: - 定义省级数据接口,包含:
- 英文名称(用于匹配地图数据) - 英文名称(用于匹配地图数据)
- 中文名称 - 中文名称
@ -20,24 +17,20 @@
- 人口数据 - 人口数据
### 4. 地图渲染配置 ### 4. 地图渲染配置
- 使用ECharts的Map组件渲染省级地图
- 使用 ECharts 的 Map 组件渲染省级地图 - 配置tooltip显示中文名称、简称和人口数据
- 配置 tooltip 显示中文名称、简称和人口数据
- 添加视觉映射组件,根据人口数据显示不同颜色 - 添加视觉映射组件,根据人口数据显示不同颜色
### 5. 数据获取与处理 ### 5. 数据获取与处理
- 定义本地数据结构,包含各个省的中文名称、简称和人口 - 定义本地数据结构,包含各个省的中文名称、简称和人口
- 将数据转换为 ECharts 需要的格式 - 将数据转换为ECharts需要的格式
### 6. 组件优化 ### 6. 组件优化
- 添加加载状态 - 添加加载状态
- 处理地图数据加载失败的情况 - 处理地图数据加载失败的情况
- 优化地图交互体验,如缩放、拖拽等 - 优化地图交互体验,如缩放、拖拽等
### 7. 实现步骤 ### 7. 实现步骤
1. 准备地图数据文件 1. 准备地图数据文件
2. 创建加拿大地图组件 2. 创建加拿大地图组件
3. 创建澳大利亚地图组件 3. 创建澳大利亚地图组件
@ -46,9 +39,8 @@
6. 测试地图渲染和交互 6. 测试地图渲染和交互
### 技术要点 ### 技术要点
- 使用ECharts的MapChart组件
- 使用 ECharts 的 MapChart 组件 - 动态加载地图JSON数据
- 动态加载地图 JSON 数据
- 数据映射和转换 - 数据映射和转换
- Tooltip 自定义格式化 - Tooltip自定义格式化
- 视觉映射配置 - 视觉映射配置

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

View File

@ -22,54 +22,14 @@ const AustraliaMap: React.FC = () => {
// 澳大利亚省级数据 // 澳大利亚省级数据
const provinceData: ProvinceData[] = [ const provinceData: ProvinceData[] = [
{ { name: 'New South Wales', chineseName: '新南威尔士州', shortName: 'NSW', population: 8166369 },
name: 'New South Wales', { name: 'Victoria', chineseName: '维多利亚州', shortName: 'VIC', population: 6704352 },
chineseName: '新南威尔士州', { name: 'Queensland', chineseName: '昆士兰州', shortName: 'QLD', population: 5265049 },
shortName: 'NSW', { name: 'Western Australia', chineseName: '西澳大利亚州', shortName: 'WA', population: 2885548 },
population: 8166369, { name: 'South Australia', chineseName: '南澳大利亚州', shortName: 'SA', population: 1806604 },
}, { name: 'Tasmania', chineseName: '塔斯马尼亚州', shortName: 'TAS', population: 569825 },
{ { name: 'Australian Capital Territory', chineseName: '澳大利亚首都领地', shortName: 'ACT', population: 453349 },
name: 'Victoria', { name: 'Northern Territory', chineseName: '北领地', shortName: 'NT', population: 249072 },
chineseName: '维多利亚州',
shortName: 'VIC',
population: 6704352,
},
{
name: 'Queensland',
chineseName: '昆士兰州',
shortName: 'QLD',
population: 5265049,
},
{
name: 'Western Australia',
chineseName: '西澳大利亚州',
shortName: 'WA',
population: 2885548,
},
{
name: 'South Australia',
chineseName: '南澳大利亚州',
shortName: 'SA',
population: 1806604,
},
{
name: 'Tasmania',
chineseName: '塔斯马尼亚州',
shortName: 'TAS',
population: 569825,
},
{
name: 'Australian Capital Territory',
chineseName: '澳大利亚首都领地',
shortName: 'ACT',
population: 453349,
},
{
name: 'Northern Territory',
chineseName: '北领地',
shortName: 'NT',
population: 249072,
},
]; ];
useEffect(() => { useEffect(() => {
@ -97,9 +57,7 @@ const AustraliaMap: React.FC = () => {
if (params.data) { if (params.data) {
return ` return `
<div> <div>
<div><strong>${params.data.chineseName}</strong> (${ <div><strong>${params.data.chineseName}</strong> (${params.data.shortName})</div>
params.data.shortName
})</div>
<div>人口: ${params.data.population.toLocaleString()}</div> <div>人口: ${params.data.population.toLocaleString()}</div>
</div> </div>
`; `;
@ -109,8 +67,8 @@ const AustraliaMap: React.FC = () => {
}, },
visualMap: { visualMap: {
left: 'left', left: 'left',
min: Math.min(...provinceData.map((p) => p.population)), min: Math.min(...provinceData.map(p => p.population)),
max: Math.max(...provinceData.map((p) => p.population)), max: Math.max(...provinceData.map(p => p.population)),
inRange: { inRange: {
color: ['#f0f0f0', '#52c41a', '#389e0d'], color: ['#f0f0f0', '#52c41a', '#389e0d'],
}, },
@ -131,9 +89,7 @@ const AustraliaMap: React.FC = () => {
show: true, show: true,
formatter: (params: any) => { formatter: (params: any) => {
if (params.data) { if (params.data) {
return `${params.data.shortName}\n${ return `${params.data.shortName}\n${params.data.chineseName}\n${params.data.population.toLocaleString()}`;
params.data.chineseName
}\n${params.data.population.toLocaleString()}`;
} }
return params.name; return params.name;
}, },

View File

@ -22,84 +22,19 @@ const CanadaMap: React.FC = () => {
// 加拿大省级数据 // 加拿大省级数据
const provinceData: ProvinceData[] = [ const provinceData: ProvinceData[] = [
{ { name: 'British Columbia', chineseName: '不列颠哥伦比亚省', shortName: 'BC', population: 5147712 },
name: 'British Columbia', { name: 'Alberta', chineseName: '阿尔伯塔省', shortName: 'AB', population: 4413146 },
chineseName: '不列颠哥伦比亚省', { name: 'Saskatchewan', chineseName: '萨斯喀彻温省', shortName: 'SK', population: 1181666 },
shortName: 'BC', { name: 'Manitoba', chineseName: '曼尼托巴省', shortName: 'MB', population: 1383765 },
population: 5147712, { name: 'Ontario', chineseName: '安大略省', shortName: 'ON', population: 14711827 },
}, { name: 'Quebec', chineseName: '魁北克省', shortName: 'QC', population: 8501833 },
{ { name: 'New Brunswick', chineseName: '新不伦瑞克省', shortName: 'NB', population: 789225 },
name: 'Alberta', { name: 'Nova Scotia', chineseName: '新斯科舍省', shortName: 'NS', population: 971395 },
chineseName: '阿尔伯塔省', { name: 'Prince Edward Island', chineseName: '爱德华王子岛省', shortName: 'PE', population: 160302 },
shortName: 'AB', { name: 'Newfoundland and Labrador', chineseName: '纽芬兰与拉布拉多省', shortName: 'NL', population: 521365 },
population: 4413146, { name: 'Yukon', chineseName: '育空地区', shortName: 'YT', population: 43985 },
}, { name: 'Northwest Territories', chineseName: '西北地区', shortName: 'NT', population: 45515 },
{ { name: 'Nunavut', chineseName: '努纳武特地区', shortName: 'NU', population: 39430 },
name: 'Saskatchewan',
chineseName: '萨斯喀彻温省',
shortName: 'SK',
population: 1181666,
},
{
name: 'Manitoba',
chineseName: '曼尼托巴省',
shortName: 'MB',
population: 1383765,
},
{
name: 'Ontario',
chineseName: '安大略省',
shortName: 'ON',
population: 14711827,
},
{
name: 'Quebec',
chineseName: '魁北克省',
shortName: 'QC',
population: 8501833,
},
{
name: 'New Brunswick',
chineseName: '新不伦瑞克省',
shortName: 'NB',
population: 789225,
},
{
name: 'Nova Scotia',
chineseName: '新斯科舍省',
shortName: 'NS',
population: 971395,
},
{
name: 'Prince Edward Island',
chineseName: '爱德华王子岛省',
shortName: 'PE',
population: 160302,
},
{
name: 'Newfoundland and Labrador',
chineseName: '纽芬兰与拉布拉多省',
shortName: 'NL',
population: 521365,
},
{
name: 'Yukon',
chineseName: '育空地区',
shortName: 'YT',
population: 43985,
},
{
name: 'Northwest Territories',
chineseName: '西北地区',
shortName: 'NT',
population: 45515,
},
{
name: 'Nunavut',
chineseName: '努纳武特地区',
shortName: 'NU',
population: 39430,
},
]; ];
useEffect(() => { useEffect(() => {
@ -127,9 +62,7 @@ const CanadaMap: React.FC = () => {
if (params.data) { if (params.data) {
return ` return `
<div> <div>
<div><strong>${params.data.chineseName}</strong> (${ <div><strong>${params.data.chineseName}</strong> (${params.data.shortName})</div>
params.data.shortName
})</div>
<div>人口: ${params.data.population.toLocaleString()}</div> <div>人口: ${params.data.population.toLocaleString()}</div>
</div> </div>
`; `;
@ -139,8 +72,8 @@ const CanadaMap: React.FC = () => {
}, },
visualMap: { visualMap: {
left: 'left', left: 'left',
min: Math.min(...provinceData.map((p) => p.population)), min: Math.min(...provinceData.map(p => p.population)),
max: Math.max(...provinceData.map((p) => p.population)), max: Math.max(...provinceData.map(p => p.population)),
inRange: { inRange: {
color: ['#f0f0f0', '#1890ff', '#096dd9'], color: ['#f0f0f0', '#1890ff', '#096dd9'],
}, },
@ -160,9 +93,7 @@ const CanadaMap: React.FC = () => {
show: true, show: true,
formatter: (params: any) => { formatter: (params: any) => {
if (params.data) { if (params.data) {
return `${params.data.shortName}\n${ return `${params.data.shortName}\n${params.data.chineseName}\n${params.data.population.toLocaleString()}`;
params.data.chineseName
}\n${params.data.population.toLocaleString()}`;
} }
return params.name; return params.name;
}, },

View File

@ -66,7 +66,6 @@ const DictItemModal: React.FC<DictItemModalProps> = ({
label="名称" label="名称"
name="name" name="name"
rules={[{ required: true, message: '请输入名称' }]} rules={[{ required: true, message: '请输入名称' }]}
normalize={(value) => (value || '').trim()}
> >
<Input placeholder="名称 (e.g., zyn)" /> <Input placeholder="名称 (e.g., zyn)" />
</Form.Item> </Form.Item>
@ -74,36 +73,19 @@ const DictItemModal: React.FC<DictItemModalProps> = ({
label="标题" label="标题"
name="title" name="title"
rules={[{ required: true, message: '请输入标题' }]} rules={[{ required: true, message: '请输入标题' }]}
normalize={(value) => (value || '').trim()}
> >
<Input placeholder="标题 (e.g., ZYN)" /> <Input placeholder="标题 (e.g., ZYN)" />
</Form.Item> </Form.Item>
<Form.Item <Form.Item label="中文标题" name="titleCN">
label="中文标题"
name="titleCN"
normalize={(value) => (value || '').trim()}
>
<Input placeholder="中文标题 (e.g., 品牌)" /> <Input placeholder="中文标题 (e.g., 品牌)" />
</Form.Item> </Form.Item>
<Form.Item <Form.Item label="简称 (可选)" name="shortName">
label="简称 (可选)"
name="shortName"
normalize={(value) => (value || '').trim()}
>
<Input placeholder="简称 (可选)" /> <Input placeholder="简称 (可选)" />
</Form.Item> </Form.Item>
<Form.Item <Form.Item label="图片 (可选)" name="image">
label="图片 (可选)"
name="image"
normalize={(value) => (value || '').trim()}
>
<Input placeholder="图片链接 (可选)" /> <Input placeholder="图片链接 (可选)" />
</Form.Item> </Form.Item>
<Form.Item <Form.Item label="值 (可选)" name="value">
label="值 (可选)"
name="value"
normalize={(value) => (value || '').trim()}
>
<Input placeholder="值 (可选)" /> <Input placeholder="值 (可选)" />
</Form.Item> </Form.Item>
</Form> </Form>

View File

@ -67,8 +67,6 @@ const CsvTool: React.FC = () => {
const [selectedSites, setSelectedSites] = useState<Site[]>([]); // 现在使用多选 const [selectedSites, setSelectedSites] = useState<Site[]>([]); // 现在使用多选
const [generateBundleSkuForSingle, setGenerateBundleSkuForSingle] = const [generateBundleSkuForSingle, setGenerateBundleSkuForSingle] =
useState(true); // 是否为type为single的记录生成包含quantity的bundle SKU useState(true); // 是否为type为single的记录生成包含quantity的bundle SKU
const [generateSkuForProducts, setGenerateSkuForProducts] = useState(true); // 是否为产品生成SKU
const [generateNameForProducts, setGenerateNameForProducts] = useState(true); // 是否为产品生成名称
const [config, setConfig] = useState<SkuConfig>({ const [config, setConfig] = useState<SkuConfig>({
brands: [], brands: [],
categories: [], categories: [],
@ -530,10 +528,8 @@ const CsvTool: React.FC = () => {
// 获取产品类型 // 获取产品类型
const type = row.type || ''; const type = row.type || '';
// 根据选项决定是否生成SKU // 生成基础SKU不包含站点前缀
let baseSku = row.sku; // 默认为原有SKU const baseSku = generateSku(
if (generateSkuForProducts) {
baseSku = generateSku(
brand, brand,
version, version,
category, category,
@ -544,12 +540,7 @@ const CsvTool: React.FC = () => {
quantity, quantity,
type, type,
); );
} const name = generateName(
// 根据选项决定是否生成名称
let generatedName = row.name; // 默认为原有名称
if (generateNameForProducts) {
generatedName = generateName(
brand, brand,
version, version,
category, category,
@ -560,13 +551,16 @@ const CsvTool: React.FC = () => {
quantity, quantity,
type, type,
); );
} // 为所有站点生成带前缀的siteSkus
const siteSkus = generateSiteSkus(baseSku);
// 返回包含新SKU的行数据将SKU直接保存到sku栏 // 返回包含新SKU和siteSkus的行数据将SKU直接保存到sku栏
return { return {
...row, ...row,
sku: baseSku, // 根据选项决定是否更新SKU sku: baseSku, // 直接生成在sku栏
name: generateNameForProducts ? generatedName : row.name, // 根据选项决定是否更新名称 generatedName: name,
// name: name, // 生成的产品名称
siteSkus,
attribute_quantity: quantity, // 确保quantity保存到attribute_quantity attribute_quantity: quantity, // 确保quantity保存到attribute_quantity
}; };
}); });
@ -582,25 +576,12 @@ const CsvTool: React.FC = () => {
); );
// Get quantity values from the config (same source as other attributes like brand) // Get quantity values from the config (same source as other attributes like brand)
const quantityValues = config.quantities const quantityValues = config.quantities.map(
.sort((a, b) => Number(a.name) - Number(b.name)) (quantity) => quantity.name,
.map((quantity) => quantity.name);
// 获取源文件中已有的所有 SKU 列表(包括 single 和 bundle用于检查重复
const existingSkus = new Set(
csvData.map((row) => row.sku).filter((sku) => sku),
);
// 获取源文件中已有的 bundle 类型记录的 SKU用于进一步检查
const existingBundleSkus = new Set(
csvData
.filter((row) => row.type === 'bundle')
.map((row) => row.sku)
.filter((sku) => sku),
); );
// Generate bundle products for each single record and quantity // Generate bundle products for each single record and quantity
const generatedBundleRecords = singleRecords const generatedBundleRecords = singleRecords.flatMap((singleRecord) => {
.flatMap((singleRecord) => {
return quantityValues.map((quantity) => { return quantityValues.map((quantity) => {
// Extract all necessary attributes from the single record // Extract all necessary attributes from the single record
const brand = singleRecord.attribute_brand || ''; const brand = singleRecord.attribute_brand || '';
@ -609,12 +590,9 @@ const CsvTool: React.FC = () => {
const flavor = singleRecord.attribute_flavor || ''; const flavor = singleRecord.attribute_flavor || '';
const strength = singleRecord.attribute_strength || ''; const strength = singleRecord.attribute_strength || '';
const humidity = singleRecord.attribute_humidity || ''; const humidity = singleRecord.attribute_humidity || '';
const size = const size = singleRecord.attribute_size || singleRecord.size || '';
singleRecord.attribute_size || singleRecord.size || ''; // Generate bundle SKU with the quantity
// 根据选项决定是否生成bundle SKU const bundleSku = generateSku(
let bundleSku;
if (generateSkuForProducts) {
bundleSku = generateSku(
brand, brand,
version, version,
category, category,
@ -625,23 +603,9 @@ const CsvTool: React.FC = () => {
quantity, quantity,
'bundle', 'bundle',
); );
} else {
// 如果不生成SKU则使用基于原有SKU和数量的组合
bundleSku = `${singleRecord.sku}-bundle-${quantity}`;
}
// 检查 bundle SKU 是否已存在于源文件中(包括所有类型的记录) // Generate bundle name with the quantity
if ( const bundleName = generateName(
existingSkus.has(bundleSku) ||
existingBundleSkus.has(bundleSku)
) {
return null; // 跳过已存在的 SKU
}
// 根据选项决定是否生成bundle名称
let bundleName;
if (generateNameForProducts) {
bundleName = generateName(
brand, brand,
version, version,
category, category,
@ -652,24 +616,23 @@ const CsvTool: React.FC = () => {
quantity, quantity,
'bundle', 'bundle',
); );
} else {
// 如果不生成名称,则使用基于原有名称和数量的组合 // Generate siteSkus for the bundle
bundleName = `${singleRecord.name} Bundle x ${quantity}`; const bundleSiteSkus = generateSiteSkus(bundleSku);
}
// Create the bundle record // Create the bundle record
return { return {
...singleRecord, ...singleRecord,
type: 'bundle', // Change type to bundle type: 'bundle', // Change type to bundle
sku: bundleSku, // Use the new bundle SKU sku: bundleSku, // Use the new bundle SKU
name: bundleName, // Use the new bundle name name: bundleName, // Use the new bundle name
// siteSkus: bundleSiteSkus, siteSkus: bundleSiteSkus,
attribute_quantity: quantity, // Set the attribute_quantity attribute_quantity: quantity, // Set the attribute_quantity
component_1_sku: singleRecord.sku, // Set component_1_sku to the single product's sku component_1_sku: singleRecord.sku, // Set component_1_sku to the single product's sku
component_1_quantity: Number(quantity), // Set component_1_quantity to the same as attribute_quantity component_1_quantity: Number(quantity), // Set component_1_quantity to the same as attribute_quantity
}; };
}); });
}) });
.filter(Boolean); // 过滤掉 null 值
// Combine original dataWithSku with generated bundle records // Combine original dataWithSku with generated bundle records
finalData = [...dataWithSku, ...generatedBundleRecords]; finalData = [...dataWithSku, ...generatedBundleRecords];
@ -801,6 +764,22 @@ const CsvTool: React.FC = () => {
}))} }))}
fieldProps={{ allowClear: true }} fieldProps={{ allowClear: true }}
/> />
<ProForm.Item
name="generateBundleSkuForSingle"
label="为type=single生成bundle产品数据行"
tooltip="为类型为single的记录生成包含quantity的bundle SKU"
valuePropName="checked"
initialValue={true}
>
<Checkbox
onChange={(e) =>
setGenerateBundleSkuForSingle(e.target.checked)
}
>
single类型生成bundle SKU
</Checkbox>
</ProForm.Item>
</ProForm> </ProForm>
</Card> </Card>
@ -890,50 +869,6 @@ const CsvTool: React.FC = () => {
</label> </label>
<Input value={file ? file.name : '暂未选择文件'} readOnly /> <Input value={file ? file.name : '暂未选择文件'} readOnly />
</div> </div>
<ProForm.Item
name="generateSkuForProducts"
label="为产品生成SKU"
tooltip="为所有产品记录生成SKU"
valuePropName="checked"
initialValue={true}
>
<Checkbox
onChange={(e) => setGenerateSkuForProducts(e.target.checked)}
>
SKU
</Checkbox>
</ProForm.Item>
<ProForm.Item
name="generateNameForProducts"
label="为产品生成名称"
tooltip="为所有产品记录生成名称"
valuePropName="checked"
initialValue={true}
>
<Checkbox
onChange={(e) => setGenerateNameForProducts(e.target.checked)}
>
</Checkbox>
</ProForm.Item>
<ProForm.Item
name="generateBundleSkuForSingle"
label="为type=single生成bundle产品数据行"
tooltip="为类型为single的记录生成包含quantity的bundle SKU"
valuePropName="checked"
initialValue={true}
>
<Checkbox
onChange={(e) =>
setGenerateBundleSkuForSingle(e.target.checked)
}
>
single类型生成bundle SKU
</Checkbox>
</ProForm.Item>
<Button <Button
type="primary" type="primary"
onClick={handleProcessData} onClick={handleProcessData}

View File

@ -1,18 +1,9 @@
import { categorycontrollerGetall } from '@/servers/api/category'; import React, { useEffect, useState, useMemo } from 'react';
import { dictcontrollerGetdictitems } from '@/servers/api/dict';
import { productcontrollerGetproductlistgrouped } from '@/servers/api/product';
import { PageContainer, ProFormSelect } from '@ant-design/pro-components'; import { PageContainer, ProFormSelect } from '@ant-design/pro-components';
import { import { Card, Collapse, Divider, Image, Select, Space, Typography, message } from 'antd';
Card, import { categorycontrollerGetall } from '@/servers/api/category';
Collapse, import { productcontrollerGetproductlistgrouped } from '@/servers/api/product';
Divider, import { dictcontrollerGetdictitems } from '@/servers/api/dict';
Image,
Select,
Space,
Typography,
message,
} from 'antd';
import React, { useEffect, useMemo, useState } from 'react';
// Define interfaces // Define interfaces
interface Category { interface Category {
@ -64,22 +55,13 @@ const ProductCard: React.FC<{ product: Product }> = ({ product }) => {
/> />
</div> */} </div> */}
<div> <div>
<Typography.Text <Typography.Text type="secondary" style={{ fontSize: 12, display: 'block', marginBottom: '4px' }}>
type="secondary"
style={{ fontSize: 12, display: 'block', marginBottom: '4px' }}
>
{product.sku} {product.sku}
</Typography.Text> </Typography.Text>
<Typography.Text <Typography.Text ellipsis style={{ width: '100%', display: 'block', marginBottom: '8px' }}>
ellipsis
style={{ width: '100%', display: 'block', marginBottom: '8px' }}
>
{product.name} {product.name}
</Typography.Text> </Typography.Text>
<Typography.Text <Typography.Text strong style={{ fontSize: 16, color: '#ff4d4f', display: 'block' }}>
strong
style={{ fontSize: 16, color: '#ff4d4f', display: 'block' }}
>
¥{product.price || '--'} ¥{product.price || '--'}
</Typography.Text> </Typography.Text>
</div> </div>
@ -108,11 +90,7 @@ const ProductGroup: React.FC<{
)} )}
<Typography.Title level={5} style={{ margin: 0 }}> <Typography.Title level={5} style={{ margin: 0 }}>
<span> <span>
{attributeValue?.titleCN || {attributeValue?.titleCN || attributeValue?.title || attributeValue?.name || attributeValueId||'未知'}
attributeValue?.title ||
attributeValue?.name ||
attributeValueId ||
'未知'}
( {groupProducts.length} ) ( {groupProducts.length} )
</span> </span>
</Typography.Title> </Typography.Title>
@ -130,14 +108,7 @@ const ProductGroup: React.FC<{
key: attributeValueId, key: attributeValueId,
label: panelHeader, label: panelHeader,
children: ( children: (
<div <div style={{ display: 'flex', flexWrap: 'wrap', gap: '16px', paddingTop: '8px' }}>
style={{
display: 'flex',
flexWrap: 'wrap',
gap: '16px',
paddingTop: '8px',
}}
>
{groupProducts.map((product) => ( {groupProducts.map((product) => (
<ProductCard key={product.id} product={product} /> <ProductCard key={product.id} product={product} />
))} ))}
@ -155,9 +126,7 @@ const ProductGroupBy: React.FC = () => {
const [categories, setCategories] = useState<Category[]>([]); const [categories, setCategories] = useState<Category[]>([]);
const [selectedCategory, setSelectedCategory] = useState<string | null>(null); const [selectedCategory, setSelectedCategory] = useState<string | null>(null);
// Store selected values for each attribute // Store selected values for each attribute
const [attributeFilters, setAttributeFilters] = useState<{ const [attributeFilters, setAttributeFilters] = useState<{ [key: string]: number | null }>({});
[key: string]: number | null;
}>({});
// Group by attribute // Group by attribute
const [groupByAttribute, setGroupByAttribute] = useState<string | null>(null); const [groupByAttribute, setGroupByAttribute] = useState<string | null>(null);
@ -170,16 +139,12 @@ const ProductGroupBy: React.FC = () => {
// Extract all unique attributes from categories // Extract all unique attributes from categories
const categoryAttributes = useMemo(() => { const categoryAttributes = useMemo(() => {
if (!selectedCategory) return []; if (!selectedCategory) return [];
const categoryItem = categories.find( const categoryItem = categories.find((category: any) => category.name === selectedCategory);
(category: any) => category.name === selectedCategory,
);
if (!categoryItem) return []; if (!categoryItem) return [];
const attributesList: Attribute[] = categoryItem.attributes.map( const attributesList: Attribute[] = categoryItem.attributes.map((attribute: any, index) => ({
(attribute: any, index) => ({
...attribute.attributeDict, ...attribute.attributeDict,
id: index + 1, id: index + 1,
}), }));
);
return attributesList; return attributesList;
}, [selectedCategory]); }, [selectedCategory]);
@ -187,16 +152,12 @@ const ProductGroupBy: React.FC = () => {
const fetchCategories = async () => { const fetchCategories = async () => {
try { try {
const response = await categorycontrollerGetall(); const response = await categorycontrollerGetall();
const rawCategories = Array.isArray(response) const rawCategories = Array.isArray(response) ? response : response?.data || [];
? response
: response?.data || [];
setCategories(rawCategories); setCategories(rawCategories);
// Set default category // Set default category
if (rawCategories.length > 0) { if (rawCategories.length > 0) {
const defaultCategory = rawCategories.find( const defaultCategory = rawCategories.find((category: any) => category.name === 'nicotine-pouches');
(category: any) => category.name === 'nicotine-pouches',
);
setSelectedCategory(defaultCategory?.name || rawCategories[0].name); setSelectedCategory(defaultCategory?.name || rawCategories[0].name);
} }
} catch (error) { } catch (error) {
@ -209,17 +170,16 @@ const ProductGroupBy: React.FC = () => {
useEffect(() => { useEffect(() => {
if (!selectedCategory) return; if (!selectedCategory) return;
const category = categories.find((cat) => cat.name === selectedCategory); const category = categories.find(cat => cat.name === selectedCategory);
if (!category) return; if (!category) return;
// Get attributes for this category // Get attributes for this category
const attributesForCategory = categoryAttributes.filter( const attributesForCategory = categoryAttributes.filter(attr =>
(attr) => attr.name === 'brand' || category.attributes.includes(attr.name)
attr.name === 'brand' || category.attributes.includes(attr.name),
); );
// Reset attribute filters when category changes // Reset attribute filters when category changes
const newFilters: { [key: string]: number | null } = {}; const newFilters: { [key: string]: number | null } = {};
attributesForCategory.forEach((attr) => { attributesForCategory.forEach(attr => {
newFilters[attr.name] = null; newFilters[attr.name] = null;
}); });
setAttributeFilters(newFilters); setAttributeFilters(newFilters);
@ -231,11 +191,8 @@ const ProductGroupBy: React.FC = () => {
}, [selectedCategory, categories, categoryAttributes]); }, [selectedCategory, categories, categoryAttributes]);
// Handle attribute filter change // Handle attribute filter change
const handleAttributeFilterChange = ( const handleAttributeFilterChange = (attributeName: string, value: number | null) => {
attributeName: string, setAttributeFilters(prev => ({ ...prev, [attributeName]: value }));
value: number | null,
) => {
setAttributeFilters((prev) => ({ ...prev, [attributeName]: value }));
}; };
// Fetch products based on filters // Fetch products based on filters
@ -246,9 +203,10 @@ const ProductGroupBy: React.FC = () => {
try { try {
const params: any = { const params: any = {
category: selectedCategory, category: selectedCategory,
groupBy: groupByAttribute, groupBy: groupByAttribute
}; };
const response = await productcontrollerGetproductlistgrouped(params); const response = await productcontrollerGetproductlistgrouped(params);
const grouped = response?.data || {}; const grouped = response?.data || {};
setGroupedProducts(grouped); setGroupedProducts(grouped);
@ -284,9 +242,7 @@ const ProductGroupBy: React.FC = () => {
<div style={{ padding: '16px', background: '#fff' }}> <div style={{ padding: '16px', background: '#fff' }}>
{/* Filter Section */} {/* Filter Section */}
<div style={{ marginBottom: '24px' }}> <div style={{ marginBottom: '24px' }}>
<Title level={4} style={{ marginBottom: '16px' }}> <Title level={4} style={{ marginBottom: '16px' }}></Title>
</Title>
<Space direction="vertical" size="large"> <Space direction="vertical" size="large">
{/* Category Filter */} {/* Category Filter */}
<div> <div>
@ -300,7 +256,7 @@ const ProductGroupBy: React.FC = () => {
showSearch showSearch
optionFilterProp="children" optionFilterProp="children"
> >
{categories.map((category) => ( {categories.map(category => (
<Option key={category.id} value={category.name}> <Option key={category.id} value={category.name}>
{category.title} {category.title}
</Option> </Option>
@ -312,54 +268,34 @@ const ProductGroupBy: React.FC = () => {
{categoryAttributes.length > 0 && ( {categoryAttributes.length > 0 && (
<div> <div>
<Text strong></Text> <Text strong></Text>
<Space <Space direction="vertical" style={{ marginTop: '8px', width: '100%' }}>
direction="vertical" {categoryAttributes.map(attr => (
style={{ marginTop: '8px', width: '100%' }} <div key={attr.id} style={{ display: 'flex', alignItems: 'center' }}>
>
{categoryAttributes.map((attr) => (
<div
key={attr.id}
style={{ display: 'flex', alignItems: 'center' }}
>
<Text style={{ width: '100px' }}>{attr.title}</Text> <Text style={{ width: '100px' }}>{attr.title}</Text>
<ProFormSelect <ProFormSelect
placeholder={`请选择${attr.title}`} placeholder={`请选择${attr.title}`}
style={{ width: 300 }} style={{ width: 300 }}
value={attributeFilters[attr.name] || null} value={attributeFilters[attr.name] || null}
onChange={(value) => onChange={value => handleAttributeFilterChange(attr.name, value)}
handleAttributeFilterChange(attr.name, value)
}
allowClear allowClear
showSearch showSearch
optionFilterProp="children" optionFilterProp="children"
request={async (params) => { request={async (params) => {
try { try {
console.log('params', params, attr); console.log('params', params,attr);
const response = await dictcontrollerGetdictitems({ const response = await dictcontrollerGetdictitems({ dictId: attr.name });
dictId: attr.name, const rawValues = Array.isArray(response) ? response : response?.data?.items || [];
}); const filteredValues = rawValues.filter((value: any) =>
const rawValues = Array.isArray(response) value.dictId === attr.name || value.dict?.id === attr.name || value.dict?.name === attr.name
? response
: response?.data?.items || [];
const filteredValues = rawValues.filter(
(value: any) =>
value.dictId === attr.name ||
value.dict?.id === attr.name ||
value.dict?.name === attr.name,
); );
return { return {
options: filteredValues.map((value: any) => ({ options: filteredValues.map((value: any) => ({
label: `${value.name}${ label: `${value.name}${value.titleCN || value.title}`,
value.titleCN || value.title value: value.id
}`, }))
value: value.id,
})),
}; };
} catch (error) { } catch (error) {
console.error( console.error(`Failed to fetch ${attr.title} values:`, error);
`Failed to fetch ${attr.title} values:`,
error,
);
message.error(`获取${attr.title}属性值失败`); message.error(`获取${attr.title}属性值失败`);
return { options: [] }; return { options: [] };
} }
@ -383,7 +319,7 @@ const ProductGroupBy: React.FC = () => {
showSearch showSearch
optionFilterProp="children" optionFilterProp="children"
> >
{categoryAttributes.map((attr) => ( {categoryAttributes.map(attr => (
<Option key={attr.id} value={attr.name}> <Option key={attr.id} value={attr.name}>
{attr.title} {attr.title}
</Option> </Option>
@ -398,20 +334,15 @@ const ProductGroupBy: React.FC = () => {
{/* Products Section */} {/* Products Section */}
<div> <div>
<Title level={4} style={{ marginBottom: '16px' }}> <Title level={4} style={{ marginBottom: '16px' }}> ({products.length} )</Title>
({products.length} )
</Title>
{loading ? ( {loading ? (
<div style={{ textAlign: 'center', padding: '64px' }}> <div style={{ textAlign: 'center', padding: '64px' }}>
<Text>...</Text> <Text>...</Text>
</div> </div>
) : groupByAttribute && Object.keys(groupedProducts).length > 0 ? ( ) : groupByAttribute && Object.keys(groupedProducts).length > 0 ? (
<div <div style={{ display: 'flex', flexDirection: 'column', gap: '24px' }}>
style={{ display: 'flex', flexDirection: 'column', gap: '24px' }} {Object.entries(groupedProducts).map(([attrValueId, groupProducts]) => {
>
{Object.entries(groupedProducts).map(
([attrValueId, groupProducts]) => {
return ( return (
<ProductGroup <ProductGroup
key={attrValueId} key={attrValueId}
@ -421,18 +352,10 @@ const ProductGroupBy: React.FC = () => {
attributeName={groupByAttribute!} attributeName={groupByAttribute!}
/> />
); );
}, })}
)}
</div> </div>
) : ( ) : (
<div <div style={{ textAlign: 'center', padding: '64px', background: '#fafafa', borderRadius: 8 }}>
style={{
textAlign: 'center',
padding: '64px',
background: '#fafafa',
borderRadius: 8,
}}
>
<Text type="secondary"></Text> <Text type="secondary"></Text>
</div> </div>
)} )}

View File

@ -1,8 +1,8 @@
import { productcontrollerCreateproduct, productcontrollerGetproductlist } from '@/servers/api/product';
import { import {
productcontrollerCreateproduct, ModalForm,
productcontrollerGetproductlist, ProFormSelect,
} from '@/servers/api/product'; } from '@ant-design/pro-components';
import { ModalForm, ProFormSelect } from '@ant-design/pro-components';
import { App } from 'antd'; import { App } from 'antd';
import React from 'react'; import React from 'react';
@ -48,8 +48,8 @@ const BatchCreateBundleModal: React.FC<{
components: [ components: [
{ {
sku: product.sku, sku: product.sku,
quantity: q, quantity: q
}, }
], ],
attributes: [], attributes: [],
}); });
@ -88,7 +88,9 @@ const BatchCreateBundleModal: React.FC<{
const params = keyWords const params = keyWords
? { sku: keyWords, name: keyWords, type: 'single' } ? { sku: keyWords, name: keyWords, type: 'single' }
: { pageSize: 9999, type: 'single' }; : { pageSize: 9999, type: 'single' };
const { data } = await productcontrollerGetproductlist(params as any); const { data } = await productcontrollerGetproductlist(
params as any,
);
if (!data || !data.items) { if (!data || !data.items) {
return []; return [];
} }

View File

@ -6,6 +6,7 @@ import {
productcontrollerGetproductlist, productcontrollerGetproductlist,
productcontrollerUpdateproduct, productcontrollerUpdateproduct,
} from '@/servers/api/product'; } from '@/servers/api/product';
import { sitecontrollerAll } from '@/servers/api/site';
import { stockcontrollerGetstocks as getStocks } from '@/servers/api/stock'; import { stockcontrollerGetstocks as getStocks } from '@/servers/api/stock';
import { import {
ActionType, ActionType,

View File

@ -18,10 +18,10 @@ import {
import { request } from '@umijs/max'; import { request } from '@umijs/max';
import { App, Button, Modal, Popconfirm, Tag, Upload } from 'antd'; import { App, Button, Modal, Popconfirm, Tag, Upload } from 'antd';
import React, { useEffect, useRef, useState } from 'react'; import React, { useEffect, useRef, useState } from 'react';
import BatchCreateBundleModal from './BatchCreateBundleModal';
import CreateForm from './CreateForm'; import CreateForm from './CreateForm';
import EditForm from './EditForm'; import EditForm from './EditForm';
import SyncToSiteModal from './SyncToSiteModal'; import SyncToSiteModal from './SyncToSiteModal';
import BatchCreateBundleModal from './BatchCreateBundleModal';
const NameCn: React.FC<{ const NameCn: React.FC<{
id: number; id: number;
@ -189,8 +189,7 @@ const List: React.FC = () => {
const [batchEditModalVisible, setBatchEditModalVisible] = useState(false); const [batchEditModalVisible, setBatchEditModalVisible] = useState(false);
const [syncProducts, setSyncProducts] = useState<API.Product[]>([]); const [syncProducts, setSyncProducts] = useState<API.Product[]>([]);
const [syncModalVisible, setSyncModalVisible] = useState(false); const [syncModalVisible, setSyncModalVisible] = useState(false);
const [batchCreateBundleModalVisible, setBatchCreateBundleModalVisible] = const [batchCreateBundleModalVisible, setBatchCreateBundleModalVisible] = useState(false);
useState(false);
const { message } = App.useApp(); const { message } = App.useApp();
// 导出产品 CSV(带认证请求) // 导出产品 CSV(带认证请求)
@ -467,7 +466,9 @@ const List: React.FC = () => {
</Button>, </Button>,
// 批量创建 bundle 产品按钮 // 批量创建 bundle 产品按钮
<Button onClick={() => setBatchCreateBundleModalVisible(true)}> <Button
onClick={() => setBatchCreateBundleModalVisible(true)}
>
</Button>, </Button>,
// 批量同步按钮 // 批量同步按钮

View File

@ -58,9 +58,7 @@ export interface SiteItem {
const SiteList: React.FC = () => { const SiteList: React.FC = () => {
const actionRef = useRef<ActionType>(); const actionRef = useRef<ActionType>();
const [open, setOpen] = useState(false); const [open, setOpen] = useState(false);
const [editing, setEditing] = useState< const [editing, setEditing] = useState<SiteItem & { areas: string[] } | null>(null);
(SiteItem & { areas: string[] }) | null
>(null);
const [selectedRowKeys, setSelectedRowKeys] = useState<React.Key[]>([]); const [selectedRowKeys, setSelectedRowKeys] = useState<React.Key[]>([]);
const [batchEditOpen, setBatchEditOpen] = useState(false); const [batchEditOpen, setBatchEditOpen] = useState(false);
const [batchEditForm] = Form.useForm(); const [batchEditForm] = Form.useForm();
@ -294,11 +292,11 @@ const SiteList: React.FC = () => {
<Button <Button
size="small" size="small"
onClick={() => { onClick={() => {
function normalEditing(row: SiteItem) { function normalEditing(row:SiteItem){
return { return {
...row, ...row,
areas: row.areas?.map((area) => area.code) || [], areas: row.areas?.map(area=>area.code) || [],
}; }
} }
setEditing(normalEditing(row)); setEditing(normalEditing(row));
setOpen(true); setOpen(true);

View File

@ -15,9 +15,7 @@ const ShopLayout: React.FC = () => {
const location = useLocation(); const location = useLocation();
const [editModalOpen, setEditModalOpen] = useState(false); const [editModalOpen, setEditModalOpen] = useState(false);
const [editingSite, setEditingSite] = useState< const [editingSite, setEditingSite] = useState<SiteItem & { areas: string[] } | null>(null);
(SiteItem & { areas: string[] }) | null
>(null);
const fetchSites = async () => { const fetchSites = async () => {
try { try {
@ -97,12 +95,7 @@ const ShopLayout: React.FC = () => {
<Row gutter={16} style={{ height: 'calc(100vh - 100px)' }}> <Row gutter={16} style={{ height: 'calc(100vh - 100px)' }}>
<Col span={4} style={{ height: '100%' }}> <Col span={4} style={{ height: '100%' }}>
<Sider <Sider
style={{ style={{ background: 'white', height: '100%', overflow: 'hidden', zIndex: 1 }}
background: 'white',
height: '100%',
overflow: 'hidden',
zIndex: 1,
}}
> >
<div style={{ padding: '0 10px 16px' }}> <div style={{ padding: '0 10px 16px' }}>
<div <div
@ -110,7 +103,7 @@ const ShopLayout: React.FC = () => {
display: 'flex', display: 'flex',
alignItems: 'center', alignItems: 'center',
flexWrap: 'wrap', flexWrap: 'wrap',
gap: '4px', gap: '4px'
}} }}
> >
<Select <Select
@ -135,8 +128,8 @@ const ShopLayout: React.FC = () => {
function normalizeEditing(site: SiteItem) { function normalizeEditing(site: SiteItem) {
return { return {
...site, ...site,
areas: site.areas?.map((area) => area.code) || [], areas: site.areas?.map(area => area.code) || [],
}; }
} }
setEditingSite(normalizeEditing(currentSite)); setEditingSite(normalizeEditing(currentSite));
setEditModalOpen(true); setEditModalOpen(true);

View File

@ -238,9 +238,11 @@ const OrdersPage: React.FC = () => {
? `快递方式: ${item.shipping_provider}` ? `快递方式: ${item.shipping_provider}`
: ''} : ''}
</span> </span>
{item.shipping_method {
item.shipping_method
? `发货方式: ${item.shipping_method}` ? `发货方式: ${item.shipping_method}`
: ''} : ''
}
<span> <span>
{item.tracking_number {item.tracking_number
? `物流单号: ${item.tracking_number}` ? `物流单号: ${item.tracking_number}`