mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-26 19:36:36 +08:00
[improvement] Sku: tsx (#2801)
This commit is contained in:
parent
bff9c9d6d9
commit
5c7c14d8df
@ -2,10 +2,25 @@ import { use } from '../../utils';
|
|||||||
import { inherit } from '../../utils/functional';
|
import { inherit } from '../../utils/functional';
|
||||||
import Button from '../../button';
|
import Button from '../../button';
|
||||||
|
|
||||||
|
// Types
|
||||||
|
import Vue, { CreateElement, RenderContext } from 'vue/types';
|
||||||
|
import { DefaultSlots } from '../../utils/use/sfc';
|
||||||
|
|
||||||
|
export type SkuActionsProps = {
|
||||||
|
buyText?: string;
|
||||||
|
skuEventBus: Vue;
|
||||||
|
showAddCartBtn?: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
const [sfc, bem] = use('sku-actions');
|
const [sfc, bem] = use('sku-actions');
|
||||||
|
|
||||||
function SkuActions(h, props, slots, ctx) {
|
function SkuActions(
|
||||||
const emit = name => () => {
|
h: CreateElement,
|
||||||
|
props: SkuActionsProps,
|
||||||
|
slots: DefaultSlots,
|
||||||
|
ctx: RenderContext<SkuActionsProps>
|
||||||
|
) {
|
||||||
|
const emit = (name: string) => () => {
|
||||||
props.skuEventBus.$emit(name);
|
props.skuEventBus.$emit(name);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -30,4 +45,4 @@ SkuActions.props = {
|
|||||||
showAddCartBtn: Boolean
|
showAddCartBtn: Boolean
|
||||||
};
|
};
|
||||||
|
|
||||||
export default sfc(SkuActions);
|
export default sfc<SkuActionsProps>(SkuActions);
|
@ -2,9 +2,21 @@ import { use } from '../../utils';
|
|||||||
import { inherit } from '../../utils/functional';
|
import { inherit } from '../../utils/functional';
|
||||||
import Icon from '../../icon';
|
import Icon from '../../icon';
|
||||||
|
|
||||||
|
// Types
|
||||||
|
import Vue, { CreateElement, RenderContext } from 'vue/types';
|
||||||
|
import { DefaultSlots } from '../../utils/use/sfc';
|
||||||
|
import { SkuData, SkuGoodsData, SelectedSkuData } from '../type';
|
||||||
|
|
||||||
|
export type SkuHeaderProps = {
|
||||||
|
sku: SkuData;
|
||||||
|
goods: SkuGoodsData;
|
||||||
|
skuEventBus: Vue;
|
||||||
|
selectedSku: SelectedSkuData;
|
||||||
|
};
|
||||||
|
|
||||||
const [sfc, bem] = use('sku-header');
|
const [sfc, bem] = use('sku-header');
|
||||||
|
|
||||||
function getSkuImg(sku, selectedSku) {
|
function getSkuImg(sku: SkuData, selectedSku: SelectedSkuData) {
|
||||||
const id = selectedSku.s1;
|
const id = selectedSku.s1;
|
||||||
|
|
||||||
if (id) {
|
if (id) {
|
||||||
@ -19,7 +31,12 @@ function getSkuImg(sku, selectedSku) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function SkuHeader(h, props, slots, ctx) {
|
function SkuHeader(
|
||||||
|
h: CreateElement,
|
||||||
|
props: SkuHeaderProps,
|
||||||
|
slots: DefaultSlots,
|
||||||
|
ctx: RenderContext<SkuHeaderProps>
|
||||||
|
) {
|
||||||
const { sku, goods, skuEventBus, selectedSku } = props;
|
const { sku, goods, skuEventBus, selectedSku } = props;
|
||||||
const goodsImg = getSkuImg(sku, selectedSku) || goods.picture;
|
const goodsImg = getSkuImg(sku, selectedSku) || goods.picture;
|
||||||
|
|
||||||
@ -54,4 +71,4 @@ SkuHeader.props = {
|
|||||||
selectedSku: Object
|
selectedSku: Object
|
||||||
};
|
};
|
||||||
|
|
||||||
export default sfc(SkuHeader);
|
export default sfc<SkuHeaderProps>(SkuHeader);
|
@ -1,19 +0,0 @@
|
|||||||
import { use } from '../../utils';
|
|
||||||
import { inherit } from '../../utils/functional';
|
|
||||||
|
|
||||||
const [sfc, bem] = use('sku-row');
|
|
||||||
|
|
||||||
function SkuRow(h, props, slots, ctx) {
|
|
||||||
return (
|
|
||||||
<div class={bem()} {...inherit(ctx)}>
|
|
||||||
<div class={bem('title')}>{props.skuRow.k}:</div>
|
|
||||||
{slots.default && slots.default()}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
SkuRow.props = {
|
|
||||||
skuRow: Object
|
|
||||||
};
|
|
||||||
|
|
||||||
export default sfc(SkuRow);
|
|
33
packages/sku/components/SkuRow.tsx
Normal file
33
packages/sku/components/SkuRow.tsx
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
import { use } from '../../utils';
|
||||||
|
import { inherit } from '../../utils/functional';
|
||||||
|
|
||||||
|
// Types
|
||||||
|
import { CreateElement, RenderContext } from 'vue/types';
|
||||||
|
import { DefaultSlots } from '../../utils/use/sfc';
|
||||||
|
import { SkuTreeItemData } from '../type';
|
||||||
|
|
||||||
|
export type SkuRowProps = {
|
||||||
|
skuRow: SkuTreeItemData;
|
||||||
|
};
|
||||||
|
|
||||||
|
const [sfc, bem] = use('sku-row');
|
||||||
|
|
||||||
|
function SkuRow(
|
||||||
|
h: CreateElement,
|
||||||
|
props: SkuRowProps,
|
||||||
|
slots: DefaultSlots,
|
||||||
|
ctx: RenderContext<SkuRowProps>
|
||||||
|
) {
|
||||||
|
return (
|
||||||
|
<div class={bem()} {...inherit(ctx)}>
|
||||||
|
<div class={bem('title')}>{props.skuRow.k}:</div>
|
||||||
|
{slots.default && slots.default()}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
SkuRow.props = {
|
||||||
|
skuRow: Object
|
||||||
|
};
|
||||||
|
|
||||||
|
export default sfc<SkuRowProps>(SkuRow);
|
50
packages/sku/type.ts
Normal file
50
packages/sku/type.ts
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
export type SkuData = {
|
||||||
|
price: string;
|
||||||
|
none_sku: boolean;
|
||||||
|
stock_num: number;
|
||||||
|
hide_stock: boolean;
|
||||||
|
collection_id: number;
|
||||||
|
tree: SkuTreeItemData[];
|
||||||
|
list: SkuListItemData[];
|
||||||
|
messages: SkuMessageData[];
|
||||||
|
};
|
||||||
|
|
||||||
|
export type SkuTreeItemData = {
|
||||||
|
k: string;
|
||||||
|
v: SkuTreeItemValueData[];
|
||||||
|
k_s: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type SkuTreeItemValueData = {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
imgUrl?: string;
|
||||||
|
img_url?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type SkuListItemData = {
|
||||||
|
id: number;
|
||||||
|
s1: string;
|
||||||
|
s2: string;
|
||||||
|
s3: string;
|
||||||
|
price: number;
|
||||||
|
stock_num: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type SkuMessageData = {
|
||||||
|
name: string;
|
||||||
|
type: string;
|
||||||
|
required?: string;
|
||||||
|
datetime?: string;
|
||||||
|
multiple?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type SkuGoodsData = {
|
||||||
|
title: string;
|
||||||
|
picture: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type SelectedSkuData = {
|
||||||
|
s1: string;
|
||||||
|
s2: string;
|
||||||
|
};
|
@ -165,6 +165,7 @@ In swipeable mode, you can switch tabs with swipe gestrue in the content
|
|||||||
| swipeable | Whether to switch tabs with swipe gestrue in the content | `Boolean` | `false` |
|
| swipeable | Whether to switch tabs with swipe gestrue in the content | `Boolean` | `false` |
|
||||||
| animated | Whether to change tabs with animation | `Boolean` | `false` |
|
| animated | Whether to change tabs with animation | `Boolean` | `false` |
|
||||||
| ellipsis | Whether to ellipsis too long title | `Boolean` | `true` |
|
| ellipsis | Whether to ellipsis too long title | `Boolean` | `true` |
|
||||||
|
| lazy-render | Whether to enable tab content lazy render | `Boolean` | `true` |
|
||||||
|
|
||||||
### Tab API
|
### Tab API
|
||||||
|
|
||||||
|
@ -169,6 +169,7 @@ export default {
|
|||||||
| swipe-threshold | 滚动阈值,标签数量超过多少个可滚动 | `Number` | `4` | - |
|
| swipe-threshold | 滚动阈值,标签数量超过多少个可滚动 | `Number` | `4` | - |
|
||||||
| animated | 是否开启切换标签内容时的转场动画 | `Boolean` | `false` | 1.4.5 |
|
| animated | 是否开启切换标签内容时的转场动画 | `Boolean` | `false` | 1.4.5 |
|
||||||
| ellipsis | 是否省略过长的标题文字 | `Boolean` | `true` | 1.5.0 |
|
| ellipsis | 是否省略过长的标题文字 | `Boolean` | `true` | 1.5.0 |
|
||||||
|
| lazy-render | 是否开启标签页内容延迟渲染 | `Boolean` | `true` | 1.6.6 |
|
||||||
|
|
||||||
### Tab API
|
### Tab API
|
||||||
|
|
||||||
|
@ -106,4 +106,4 @@ toast2.clear();
|
|||||||
| loadingType | Loading icon type, can be set to `spinner` | `String` | `circular` |
|
| loadingType | Loading icon type, can be set to `spinner` | `String` | `circular` |
|
||||||
| duration | Toast duration(ms), won't disappear if value is 0 | `Number` | `3000` |
|
| duration | Toast duration(ms), won't disappear if value is 0 | `Number` | `3000` |
|
||||||
| className | Custom className | `String | Array | Object` | - |
|
| className | Custom className | `String | Array | Object` | - |
|
||||||
| get-container | Return the mount node for Popup | `String | () => HTMLElement` | `body` |
|
| get-container | Return the mount node for Toast | `String | () => HTMLElement` | `body` |
|
||||||
|
Loading…
x
Reference in New Issue
Block a user