Package Exports
- @xuguo/sku
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@xuguo/sku) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
sku算法库
主要实现前端 sku规格切换的逻辑层
使用情况
该库让使用者不再关心逻辑,暂时对外仅提供一个接口createSkuSelector
:
希望您的数据结构符合如下:
spu: {
// ...spuAttrs
skuList: [
{
// ...skuAttrs,
skuIdKey: val,
specsLsit: [
{
specId: val,
specName: name,
specValue: val,
specValueId: id,
// ...otherAttrs
}
// ...
]
}
// ...
]
}
本库仅对数据结构有如上要求,可通过spuOps
来定义如何获取相应数据
- 初始化
import { createSkuSelector } from '@xuguo/sku'
let judger = createSkuSelector(spulist, spuOps)
- 如何得到数据
judger.specLines[index].specs[index]
- 如何处理规格点击事件
judger.specTap(spec)
- 规格对象的状态 规格状态来自下面的枚举类,状态在内部完成修改
enum SpecStatus {
PENDING = 'pending',
DISABLED = 'disabled',
SELECTED = 'selected',
}
// judger.specLines[row].specs[col].status
- 如何得到skuId和specsId
onSkuCombined
的回调时机在,点击勾选规格完成后构成一个sku的时候
judger.onSkuCombined((skuId, specsIdJoin) => {
// Do something
})