diff --git a/src/share-sheet/index.js b/src/share-sheet/index.js index 59f63e105..843a95928 100644 --- a/src/share-sheet/index.js +++ b/src/share-sheet/index.js @@ -1,11 +1,18 @@ // Utils -import { createNamespace, isDef } from '../utils'; +import { createNamespace, isDef, pick } from '../utils'; // Components import Popup, { popupSharedProps } from '../popup'; const PRESET_ICONS = ['qq', 'weibo', 'wechat', 'link', 'qrcode', 'poster']; +function getIconURL(icon) { + if (PRESET_ICONS.indexOf(icon) !== -1) { + return `https://img.yzcdn.cn/vant/share-icon-${icon}.png`; + } + return icon; +} + const [createComponent, bem, t] = createNamespace('share-sheet'); export default createComponent({ @@ -28,121 +35,106 @@ export default createComponent({ }, }, - emits: ['cancel', 'select', 'update:show', 'click-overlay'], + emits: ['cancel', 'select', 'update:show'], - methods: { - onCancel() { - this.toggle(false); - this.$emit('cancel'); - }, + setup(props, { emit, slots }) { + const toggle = (value) => { + emit('update:show', value); + }; - onSelect(option, index) { - this.$emit('select', option, index); - }, + const onCancel = () => { + toggle(false); + emit('cancel'); + }; - toggle(val) { - this.$emit('update:show', val); - }, + const onSelect = (option, index) => { + emit('select', option, index); + }; - getIconURL(icon) { - if (PRESET_ICONS.indexOf(icon) !== -1) { - return `https://img.yzcdn.cn/vant/share-icon-${icon}.png`; - } + const renderHeader = () => { + const title = slots.title ? slots.title() : props.title; + const description = slots.description + ? slots.description() + : props.description; - return icon; - }, - - genHeader() { - const title = this.$slots.title ? this.$slots.title() : this.title; - const description = this.$slots.description - ? this.$slots.description() - : this.description; - - if (!title && !description) { - return; - } - - return ( -
- {title &&

{title}

} - {description && {description}} -
- ); - }, - - genOptions(options, showBorder) { - return ( -
- {options.map((option, index) => ( -
{ - this.onSelect(option, index); - }} - > - - {option.name && {option.name}} - {option.description && ( - - {option.description} - - )} -
- ))} -
- ); - }, - - genRows() { - const { options } = this; - if (Array.isArray(options[0])) { - return options.map((item, index) => this.genOptions(item, index !== 0)); - } - return this.genOptions(options); - }, - - genCancelText() { - const cancelText = isDef(this.cancelText) ? this.cancelText : t('cancel'); - - if (cancelText) { + if (title || description) { return ( - ); } - }, + }; - onClickOverlay() { - this.$emit('click-overlay'); - }, - }, - - render() { - return ( + return () => ( - {this.genHeader()} - {this.genRows()} - {this.genCancelText()} + {renderHeader()} + {renderRows()} + {renderCancelText()} ); },