mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
types(AddressList): use tsx (#8143)
This commit is contained in:
parent
e943b081f8
commit
eaf01090cc
@ -1,3 +1,5 @@
|
|||||||
|
import { PropType } from 'vue';
|
||||||
|
|
||||||
// Utils
|
// Utils
|
||||||
import { createNamespace } from '../utils';
|
import { createNamespace } from '../utils';
|
||||||
|
|
||||||
@ -9,12 +11,23 @@ import Radio from '../radio';
|
|||||||
|
|
||||||
const [createComponent, bem] = createNamespace('address-item');
|
const [createComponent, bem] = createNamespace('address-item');
|
||||||
|
|
||||||
|
export type AddressListItem = {
|
||||||
|
id: number | string;
|
||||||
|
tel: number | string;
|
||||||
|
name: string;
|
||||||
|
address: string;
|
||||||
|
isDefault?: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
export default createComponent({
|
export default createComponent({
|
||||||
props: {
|
props: {
|
||||||
data: Object,
|
|
||||||
disabled: Boolean,
|
disabled: Boolean,
|
||||||
switchable: Boolean,
|
switchable: Boolean,
|
||||||
defaultTagText: String,
|
defaultTagText: String,
|
||||||
|
address: {
|
||||||
|
type: Object as PropType<AddressListItem>,
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
emits: ['edit', 'click', 'select'],
|
emits: ['edit', 'click', 'select'],
|
||||||
@ -40,7 +53,7 @@ export default createComponent({
|
|||||||
);
|
);
|
||||||
|
|
||||||
const renderTag = () => {
|
const renderTag = () => {
|
||||||
if (props.data.isDefault && props.defaultTagText) {
|
if (props.address.isDefault && props.defaultTagText) {
|
||||||
return (
|
return (
|
||||||
<Tag type="danger" round class={bem('tag')}>
|
<Tag type="danger" round class={bem('tag')}>
|
||||||
{props.defaultTagText}
|
{props.defaultTagText}
|
||||||
@ -50,19 +63,19 @@ export default createComponent({
|
|||||||
};
|
};
|
||||||
|
|
||||||
const renderContent = () => {
|
const renderContent = () => {
|
||||||
const { data, disabled, switchable } = props;
|
const { address, disabled, switchable } = props;
|
||||||
|
|
||||||
const Info = [
|
const Info = [
|
||||||
<div class={bem('name')}>
|
<div class={bem('name')}>
|
||||||
{`${data.name} ${data.tel}`}
|
{`${address.name} ${address.tel}`}
|
||||||
{renderTag()}
|
{renderTag()}
|
||||||
</div>,
|
</div>,
|
||||||
<div class={bem('address')}>{data.address}</div>,
|
<div class={bem('address')}>{address.address}</div>,
|
||||||
];
|
];
|
||||||
|
|
||||||
if (switchable && !disabled) {
|
if (switchable && !disabled) {
|
||||||
return (
|
return (
|
||||||
<Radio name={data.id} iconSize={18}>
|
<Radio name={address.id} iconSize={18}>
|
||||||
{Info}
|
{Info}
|
||||||
</Radio>
|
</Radio>
|
||||||
);
|
);
|
||||||
@ -84,7 +97,7 @@ export default createComponent({
|
|||||||
border={false}
|
border={false}
|
||||||
valueClass={bem('value')}
|
valueClass={bem('value')}
|
||||||
/>
|
/>
|
||||||
{slots.bottom?.({ ...props.data, disabled })}
|
{slots.bottom?.({ ...props.address, disabled })}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
@ -90,11 +90,11 @@ export default {
|
|||||||
| Event | Description | Arguments |
|
| Event | Description | Arguments |
|
||||||
| --- | --- | --- |
|
| --- | --- | --- |
|
||||||
| add | Emitted when the add button is clicked | - |
|
| add | Emitted when the add button is clicked | - |
|
||||||
| edit | Emitted when the edit icon of address is clicked | item: address object,index |
|
| edit | Emitted when the edit icon of address is clicked | _item: Address, index: number_ |
|
||||||
| select | Emitted when an address is selected | item: address object,index |
|
| select | Emitted when an address is selected | _item: Address, index: number_ |
|
||||||
| edit-disabled | Emitted when the edit icon of disabled address is clicked | item: address object,index |
|
| edit-disabled | Emitted when the edit icon of disabled address is clicked | _item: Address, index: number_ |
|
||||||
| select-disabled | Emitted when a disabled address is selected | item: address object,index |
|
| select-disabled | Emitted when a disabled address is selected | _item: Address, index: number_ |
|
||||||
| click-item | Emitted when an address item is clicked | item: address object,index |
|
| click-item | Emitted when an address item is clicked | _item: Address, index: number_ |
|
||||||
|
|
||||||
### Data Structure of Address
|
### Data Structure of Address
|
||||||
|
|
||||||
@ -108,11 +108,11 @@ export default {
|
|||||||
|
|
||||||
### Slots
|
### Slots
|
||||||
|
|
||||||
| Name | Description | SlotProps |
|
| Name | Description | SlotProps |
|
||||||
| ----------- | ------------------------------ | --------- |
|
| ----------- | ------------------------------ | --------------- |
|
||||||
| default | Custom content after list | - |
|
| default | Custom content after list | - |
|
||||||
| top | Custom content before list | - |
|
| top | Custom content before list | - |
|
||||||
| item-bottom | Custom content after list item | item |
|
| item-bottom | Custom content after list item | _item: Address_ |
|
||||||
|
|
||||||
### Less Variables
|
### Less Variables
|
||||||
|
|
||||||
|
@ -91,14 +91,14 @@ export default {
|
|||||||
|
|
||||||
### Events
|
### Events
|
||||||
|
|
||||||
| 事件名 | 说明 | 回调参数 |
|
| 事件名 | 说明 | 回调参数 |
|
||||||
| --------------- | ------------------------ | --------------------------- |
|
| --------------- | ------------------------ | ------------------------------ |
|
||||||
| add | 点击新增按钮时触发 | - |
|
| add | 点击新增按钮时触发 | - |
|
||||||
| edit | 点击编辑按钮时触发 | item: 地址对象,index: 索引 |
|
| edit | 点击编辑按钮时触发 | _item: Address, index: number_ |
|
||||||
| select | 切换选中的地址时触发 | item: 地址对象,index: 索引 |
|
| select | 切换选中的地址时触发 | _item: Address, index: number_ |
|
||||||
| edit-disabled | 编辑不可配送的地址时触发 | item: 地址对象,index: 索引 |
|
| edit-disabled | 编辑不可配送的地址时触发 | _item: Address, index: number_ |
|
||||||
| select-disabled | 选中不可配送的地址时触发 | item: 地址对象,index: 索引 |
|
| select-disabled | 选中不可配送的地址时触发 | _item: Address, index: number_ |
|
||||||
| click-item | 点击任意地址时触发 | item: 地址对象,index: 索引 |
|
| click-item | 点击任意地址时触发 | _item: Address, index: number_ |
|
||||||
|
|
||||||
### Address 数据结构
|
### Address 数据结构
|
||||||
|
|
||||||
@ -112,11 +112,11 @@ export default {
|
|||||||
|
|
||||||
### Slots
|
### Slots
|
||||||
|
|
||||||
| 名称 | 说明 | 参数 |
|
| 名称 | 说明 | 参数 |
|
||||||
| ----------- | -------------------- | ---------- |
|
| ----------- | -------------------- | --------------- |
|
||||||
| default | 在列表下方插入内容 | - |
|
| default | 在列表下方插入内容 | - |
|
||||||
| top | 在顶部插入内容 | - |
|
| top | 在顶部插入内容 | - |
|
||||||
| item-bottom | 在列表项底部插入内容 | 列表项的值 |
|
| item-bottom | 在列表项底部插入内容 | _item: Address_ |
|
||||||
|
|
||||||
### 样式变量
|
### 样式变量
|
||||||
|
|
||||||
|
@ -1,21 +1,29 @@
|
|||||||
|
import { PropType } from 'vue';
|
||||||
|
|
||||||
// Utils
|
// Utils
|
||||||
import { createNamespace } from '../utils';
|
import { createNamespace } from '../utils';
|
||||||
|
|
||||||
// Components
|
// Components
|
||||||
import Button from '../button';
|
import Button from '../button';
|
||||||
import RadioGroup from '../radio-group';
|
import RadioGroup from '../radio-group';
|
||||||
import AddressItem from './Item';
|
import AddressItem, { AddressListItem } from './Item';
|
||||||
|
|
||||||
const [createComponent, bem, t] = createNamespace('address-list');
|
const [createComponent, bem, t] = createNamespace('address-list');
|
||||||
|
|
||||||
export default createComponent({
|
export default createComponent({
|
||||||
props: {
|
props: {
|
||||||
list: Array,
|
|
||||||
modelValue: [Number, String],
|
modelValue: [Number, String],
|
||||||
disabledList: Array,
|
|
||||||
disabledText: String,
|
disabledText: String,
|
||||||
addButtonText: String,
|
addButtonText: String,
|
||||||
defaultTagText: String,
|
defaultTagText: String,
|
||||||
|
list: {
|
||||||
|
type: Array as PropType<AddressListItem[]>,
|
||||||
|
default: () => [],
|
||||||
|
},
|
||||||
|
disabledList: {
|
||||||
|
type: Array as PropType<AddressListItem[]>,
|
||||||
|
default: () => [],
|
||||||
|
},
|
||||||
switchable: {
|
switchable: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: true,
|
default: true,
|
||||||
@ -33,7 +41,11 @@ export default createComponent({
|
|||||||
],
|
],
|
||||||
|
|
||||||
setup(props, { slots, emit }) {
|
setup(props, { slots, emit }) {
|
||||||
const renderItem = (item, index, disabled) => {
|
const renderItem = (
|
||||||
|
item: AddressListItem,
|
||||||
|
index: number,
|
||||||
|
disabled?: boolean
|
||||||
|
) => {
|
||||||
const onEdit = () => {
|
const onEdit = () => {
|
||||||
const name = disabled ? 'edit-disabled' : 'edit';
|
const name = disabled ? 'edit-disabled' : 'edit';
|
||||||
emit(name, item, index);
|
emit(name, item, index);
|
||||||
@ -58,7 +70,7 @@ export default createComponent({
|
|||||||
bottom: slots['item-bottom'],
|
bottom: slots['item-bottom'],
|
||||||
}}
|
}}
|
||||||
key={item.id}
|
key={item.id}
|
||||||
data={item}
|
address={item}
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
switchable={props.switchable}
|
switchable={props.switchable}
|
||||||
defaultTagText={props.defaultTagText}
|
defaultTagText={props.defaultTagText}
|
||||||
@ -69,7 +81,7 @@ export default createComponent({
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const renderList = (list, disabled) => {
|
const renderList = (list: AddressListItem[], disabled?: boolean) => {
|
||||||
if (list) {
|
if (list) {
|
||||||
return list.map((item, index) => renderItem(item, index, disabled));
|
return list.map((item, index) => renderItem(item, index, disabled));
|
||||||
}
|
}
|
2
src/vue-tsx-shim.d.ts
vendored
2
src/vue-tsx-shim.d.ts
vendored
@ -10,12 +10,14 @@ declare module 'vue' {
|
|||||||
// see: https://github.com/vuejs/vue-next/issues/1553
|
// see: https://github.com/vuejs/vue-next/issues/1553
|
||||||
// https://github.com/vuejs/vue-next/issues/3029
|
// https://github.com/vuejs/vue-next/issues/3029
|
||||||
onBlur?: EventHandler;
|
onBlur?: EventHandler;
|
||||||
|
onEdit?: EventHandler;
|
||||||
onFocus?: EventHandler;
|
onFocus?: EventHandler;
|
||||||
onInput?: EventHandler;
|
onInput?: EventHandler;
|
||||||
onClick?: EventHandler;
|
onClick?: EventHandler;
|
||||||
onCancel?: EventHandler;
|
onCancel?: EventHandler;
|
||||||
onClosed?: EventHandler;
|
onClosed?: EventHandler;
|
||||||
onChange?: EventHandler;
|
onChange?: EventHandler;
|
||||||
|
onSelect?: EventHandler;
|
||||||
onToggle?: EventHandler;
|
onToggle?: EventHandler;
|
||||||
onConfirm?: EventHandler;
|
onConfirm?: EventHandler;
|
||||||
onClickStep?: EventHandler;
|
onClickStep?: EventHandler;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user