Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
这是一个规格选择
创建有多种规格的商品、服务的编辑页面
:::demo 基础用法
import SKU from 'zan-sku';
const skuTree = [
{
id: 10740,
text: '颜色'
},
{
id: 40732,
text: '尺寸'
}
];
const sku = [{
id: 3,
text: '蓝色'
}, {
id: 10,
text: '红色'
}, {
id: 30,
text: '土豪金'
}, {
id: 137,
text: '黑色'
}, {
id: 138,
text: '灰色'
}];
class Simple extends Component {
fetchSKUTree() {
return new Promise(resolve => {
resolve(skuTree);
});
}
fetchSKU() {
return new Promise(resolve => {
resolve(sku);
});
}
render() {
return (
<SKU
onFetchGroup={this.fetchSKUTree}
onFetchSKU={this.fetchSKU}
uploadConfig={{
tokenUrl: '//materials.youzan.com/dock/token.json',
fetchUrl: '//materials.youzan.com/dock/fetch.json'
}}
/>
);
}
}
ReactDOM.render(
<Simple />
, mountNode
);
:::
参数 | 说明 | 类型 | 默认值 | 备选值 |
---|---|---|---|---|
className | 自定义额外类名 | string | '' | |
value | 当前选中的sku列表 | array | [] | |
maxSize | 最大规格名称数 | number | 3 | |
maxSKUTextLength | 规格名称文字最大长度 | number | 4 | |
maxLeafTextLength | 规格值文字最大长度 | number | 20 | |
skuTree | 可选的规格列表 | array | [] | |
uploadConfig | 自定义上传图片参数 | object | {} | |
optionValue | 自定义sku的id的key值 | string | 'id' | |
optionText | 自定义sku的文案的key值 | string | 'text' | |
onFetchGroup | 异步获取可选的规格列表,如“颜色”、“尺寸” | function | Promise | |
onFetchSKU | 异步获取单个规格可选的值,如“红色”、“蓝色” | function | Promise | |
onCreateGroup | 创建新的规格名,如“星座” | function | Promise | |
onCreateSKU | 创建新的规格值,如“处女座” | function | Promise | |
onChange | 当sku发生改变时的回调,返回值为sku当前value | function | noop | |
prefix | 自定义前缀 | string | 'rc-sku' | null |
为了更方便操作规格数据,SKU组件提供了一些工具方法
通过计算笛卡尔积,将树形的value变成扁平的数组
参数 | 说明 | 类型 | 默认值 | 备选值 |
---|---|---|---|---|
sku | 当前选中规格的value | array | [] | |
items | 当前已存在的数据 | array | [] | |
options | 可配置参数 | object | {} | optionValue: 'id', optionText: 'text' |
:::demo flatten
import { flatten } from 'zan-sku';
let skus = [
{ id: 1, text: '颜色', leaf: [{id: 11, text: '红色'}, {id: 12, text: '蓝色'}] },
{ id: 2, text: '尺寸', leaf: [{id: 21, text: '大'}, {id: 22, text: '小'}] }
];
console.log(flatten(skus));
/**
* output:
* [
* {"skus":[{"k_id":1,"k":"颜色","v_id":11,"v":"红色"},{"k_id":2,"k":"尺寸","v_id":21,"v":"大"}]},
* {"skus":[{"k_id":1,"k":"颜色","v_id":11,"v":"红色"},{"k_id":2,"k":"尺寸","v_id":22,"v":"小"}]}
* {"skus":[{"k_id":1,"k":"颜色","v_id":12,"v":"蓝色"},{"k_id":2,"k":"尺寸","v_id":21,"v":"大"}]}
* {"skus":[{"k_id":1,"k":"颜色","v_id":12,"v":"蓝色"},{"k_id":2,"k":"尺寸","v_id":22,"v":"小"}]}
* ]
*/
let items = [
{
"price": "10.00",
"code": "AE86",
"skus":[{"k_id":1,"k":"颜色","v_id":11,"v":"红色"},{"k_id":2,"k":"尺寸","v_id":22,"v":"小"}]
}
];
console.log(flatten(skus, items));
/**
* output:
* [
* {"skus":[{"k_id":1,"k":"颜色","v_id":11,"v":"红色"},{"k_id":2,"k":"尺寸","v_id":21,"v":"大"}]},
* {
* "price":"10.00",
* "code":"AE86",
* "skus":[{"k_id":1,"k":"颜色","v_id":11,"v":"红色"},{"k_id":2,"k":"尺寸","v_id":22,"v":"小"}]
* },
* {"skus":[{"k_id":1,"k":"颜色","v_id":12,"v":"蓝色"},{"k_id":2,"k":"尺寸","v_id":21,"v":"大"}]}
* {"skus":[{"k_id":1,"k":"颜色","v_id":12,"v":"蓝色"},{"k_id":2,"k":"尺寸","v_id":22,"v":"小"}]}
* ]
*/
ReactDOM.render(
<span />
, mountNode
);
:::
判断两个sku的结构是否完全相同,包括子节点的顺序
:::demo isSame
import { isSame } from 'zan-sku';
let skuA = [
{ id: 1, text: '颜色', leaf: [{id: 11, text: '红色'}, {id: 12, text: '蓝色'}] },
{ id: 2, text: '尺寸', leaf: [{id: 21, text: '大'}, {id: 22, text: '小'}] }
];
let skuB = [
{ id: 1, text: '颜色', leaf: [{id: 11, text: '红色'}, {id: 12, text: '蓝色'}] },
{ id: 2, text: '尺寸', leaf: [{id: 21, text: '大'}, {id: 22, text: '小'}] }
];
let skuC = [
{ id: 1, text: '颜色', leaf: [{id: 11, text: '红色'}, {id: 12, text: '蓝色'}] },
{ id: 2, text: '尺寸', leaf: [{id: 22, text: '小'}, {id: 21, text: '大'}] }
];
let skuD = [
{ id: 1, text: '颜色', leaf: [{id: 11, text: '红色'}, {id: 12, text: '蓝色'}] },
{ id: 3, text: '尺寸', leaf: [{id: 21, text: '大'}, {id: 22, text: '小'}] }
];
console.log(isSame(skuA, skuB));
console.log(isSame(skuA, skuC));
console.log(isSame(skuA, skuD));
/**
* output:
*
* true
* false
* false
*/
ReactDOM.render(
<span />
, mountNode
);
:::
FAQs
这是一个React组件
The npm package zan-sku receives a total of 2 weekly downloads. As such, zan-sku popularity was classified as not popular.
We found that zan-sku demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 6 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.