feat: 产品列表页排序
- 为ProductType添加sort字段用于排序 - 产品列表页项目按照sort升序排序
This commit is contained in:
@ -14,6 +14,7 @@ describe('toProductListView', () => {
|
||||
product_type: {
|
||||
id: 1,
|
||||
translations: [{ id: 20, name: 'Type Name' }],
|
||||
sort: 1,
|
||||
},
|
||||
};
|
||||
|
||||
@ -22,7 +23,11 @@ describe('toProductListView', () => {
|
||||
name: 'Product Name',
|
||||
summary: 'Product Summary',
|
||||
cover: 'cover-file-uuid-1234',
|
||||
product_type: 'Type Name',
|
||||
product_type: {
|
||||
id: 1,
|
||||
name: 'Type Name',
|
||||
sort: 1,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
@ -34,6 +39,7 @@ describe('toProductListView', () => {
|
||||
product_type: {
|
||||
id: 20,
|
||||
translations: [],
|
||||
sort: 1,
|
||||
},
|
||||
};
|
||||
|
||||
@ -42,7 +48,11 @@ describe('toProductListView', () => {
|
||||
name: '',
|
||||
summary: '',
|
||||
cover: 'cover-file-uuid-1234',
|
||||
product_type: '',
|
||||
product_type: {
|
||||
id: 20,
|
||||
name: '',
|
||||
sort: 1,
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -1,3 +1,22 @@
|
||||
/**
|
||||
* 将Directus返回的ProductType数据转换为ProductTypeView视图模型
|
||||
*
|
||||
* @param raw: 原始的ProductType数据
|
||||
* @returns 转换后的ProductTypeView对象
|
||||
*
|
||||
* @example
|
||||
* const view = toProductTypeView(rawProductType);
|
||||
*/
|
||||
export function toProductTypeView(raw: ProductType): ProductTypeView {
|
||||
const trans = raw.translations?.[0] ?? { name: '' };
|
||||
|
||||
return {
|
||||
id: raw.id,
|
||||
name: trans.name,
|
||||
sort: raw?.sort ?? 999,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 将 Directus返回的 Product 数据转换为 ProductListView 视图模型
|
||||
*
|
||||
@ -11,10 +30,8 @@ export function toProductListView(raw: Product): ProductListView {
|
||||
const trans = raw.translations?.[0] ?? { name: '', summary: '' };
|
||||
|
||||
const type = isObject<ProductType>(raw.product_type)
|
||||
? raw.product_type.translations.length === 0
|
||||
? ''
|
||||
: raw.product_type.translations[0].name
|
||||
: '';
|
||||
? toProductTypeView(raw.product_type)
|
||||
: undefined;
|
||||
|
||||
return {
|
||||
id: raw.id,
|
||||
|
||||
Reference in New Issue
Block a user