mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
feat(Sku): sku image preview (#4236)
This commit is contained in:
parent
34c5fea967
commit
ae53f9b58f
@ -191,10 +191,9 @@ export default createComponent({
|
|||||||
const imageList = [this.goods.picture];
|
const imageList = [this.goods.picture];
|
||||||
|
|
||||||
if (this.skuTree.length > 0) {
|
if (this.skuTree.length > 0) {
|
||||||
const treeItem = this.skuTree.filter(item => item.k_s === 's1')[0] || {};
|
this.skuTree.forEach(treeItem => {
|
||||||
|
|
||||||
if (!treeItem.v) {
|
if (!treeItem.v) {
|
||||||
return imageList;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
treeItem.v.forEach(vItem => {
|
treeItem.v.forEach(vItem => {
|
||||||
@ -203,6 +202,7 @@ export default createComponent({
|
|||||||
imageList.push(img);
|
imageList.push(img);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return imageList;
|
return imageList;
|
||||||
|
@ -17,19 +17,22 @@ export type SkuHeaderProps = {
|
|||||||
|
|
||||||
const [createComponent, bem] = createNamespace('sku-header');
|
const [createComponent, bem] = createNamespace('sku-header');
|
||||||
|
|
||||||
function getSkuImg(sku: SkuData, selectedSku: SelectedSkuData) {
|
function getSkuImg(sku: SkuData, selectedSku: SelectedSkuData): string | undefined {
|
||||||
const id = selectedSku.s1;
|
let img;
|
||||||
|
|
||||||
if (id) {
|
sku.tree.some(item => {
|
||||||
// skuImg 挂载在 skuTree 中 s1 上
|
const id = selectedSku[item.k_s];
|
||||||
const treeItem = sku.tree.filter(item => item.k_s === 's1')[0] || {};
|
|
||||||
if (treeItem.v) {
|
if (id && item.v) {
|
||||||
const matchedSku = treeItem.v.filter(skuValue => skuValue.id === id)[0];
|
const matchedSku = item.v.filter(skuValue => skuValue.id === id)[0] || {};
|
||||||
if (matchedSku) {
|
img = matchedSku.imgUrl || matchedSku.img_url;
|
||||||
return matchedSku.imgUrl || matchedSku.img_url;
|
return img;
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
return img;
|
||||||
}
|
}
|
||||||
|
|
||||||
function SkuHeader(
|
function SkuHeader(
|
||||||
|
@ -47,7 +47,4 @@ export type SkuGoodsData = {
|
|||||||
picture: string;
|
picture: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type SelectedSkuData = {
|
export type SelectedSkuData = Record<string, string>;
|
||||||
s1: string;
|
|
||||||
s2: string;
|
|
||||||
};
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user