perf(calendar): shorten template code (#3972)

This commit is contained in:
rex 2021-01-19 11:08:56 +08:00 committed by GitHub
parent 7d5cb853e9
commit 600e189aa0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 64 additions and 62 deletions

View File

@ -1,7 +1,4 @@
<wxs src="./index.wxs" module="computed"></wxs> <view class="van-calendar">
<template name="calendar">
<view class="van-calendar">
<header <header
title="{{ title }}" title="{{ title }}"
showTitle="{{ showTitle }}" showTitle="{{ showTitle }}"
@ -11,7 +8,11 @@
<slot name="title" slot="title"></slot> <slot name="title" slot="title"></slot>
</header> </header>
<scroll-view class="van-calendar__body" scroll-y scroll-into-view="{{ scrollIntoView }}"> <scroll-view
class="van-calendar__body"
scroll-y
scroll-into-view="{{ scrollIntoView }}"
>
<month <month
wx:for="{{ computed.getMonths(minDate, maxDate) }}" wx:for="{{ computed.getMonths(minDate, maxDate) }}"
wx:key="index" wx:key="index"
@ -34,11 +35,15 @@
/> />
</scroll-view> </scroll-view>
<view class="van-calendar__footer {{ safeAreaInsetBottom ? 'van-calendar__footer--safe-area-inset-bottom' : '' }}"> <view
class="{{ utils.bem('calendar__footer', { safeAreaInsetBottom }) }}"
>
<slot name="footer"></slot> <slot name="footer"></slot>
</view> </view>
<view class="van-calendar__footer {{ safeAreaInsetBottom ? 'van-calendar__footer--safe-area-inset-bottom' : '' }}"> <view
class="{{ utils.bem('calendar__footer', { safeAreaInsetBottom }) }}"
>
<van-button <van-button
wx:if="{{ showConfirm }}" wx:if="{{ showConfirm }}"
round round
@ -50,8 +55,11 @@
nativeType="text" nativeType="text"
bind:click="onConfirm" bind:click="onConfirm"
> >
{{ computed.getButtonDisabled(type, currentDate) ? confirmDisabledText : confirmText }} {{
computed.getButtonDisabled(type, currentDate)
? confirmDisabledText
: confirmText
}}
</van-button> </van-button>
</view> </view>
</view> </view>
</template>

View File

@ -1,4 +1,5 @@
<wxs src="./index.wxs" module="computed" /> <wxs src="./index.wxs" module="computed" />
<wxs src="../wxs/utils.wxs" module="utils" />
<import src="./calendar.wxml" /> <import src="./calendar.wxml" />
@ -16,16 +17,9 @@
bind:after-enter="onOpened" bind:after-enter="onOpened"
bind:after-leave="onClosed" bind:after-leave="onClosed"
> >
<template <include src="calendar.wxml" />
is="calendar"
data="{{ title, subtitle, showTitle, showSubtitle, minDate, maxDate, type, color, showMark, formatter, rowHeight, currentDate, safeAreaInsetBottom, showConfirm, confirmDisabledText, confirmText, scrollIntoView, allowSameDay }}"
/>
</van-popup> </van-popup>
<template <include wx:else src="calendar.wxml" />
wx:else
is="calendar"
data="{{ title, subtitle, showTitle, showSubtitle, minDate, maxDate, type, color, showMark, formatter, rowHeight, currentDate, safeAreaInsetBottom, showConfirm, confirmDisabledText, confirmText, scrollIntoView, allowSameDay }}"
/>
<van-toast id="van-toast" /> <van-toast id="van-toast" />