118 lines
4.5 KiB
Plaintext

<!--
Bricks 递归组件模板
通过 template is="brick" data="{{item}}" 递归渲染
-->
<template name="brick">
<!-- 文本组件 -->
<block wx:if="{{item.widgettype === 'Text'}}">
<text class="text-content">{{item.options.text}}</text>
</block>
<block wx:if="{{item.widgettype === 'Title1'}}">
<text class="title-1">{{item.options.text}}</text>
</block>
<block wx:if="{{item.widgettype === 'Title2'}}">
<text class="title-2">{{item.options.text}}</text>
</block>
<block wx:if="{{item.widgettype === 'Title3'}}">
<text class="title-3">{{item.options.text}}</text>
</block>
<block wx:if="{{item.widgettype === 'Title4'}}">
<text class="title-4">{{item.options.text}}</text>
</block>
<block wx:if="{{item.widgettype === 'Title5'}}">
<text class="title-5">{{item.options.text}}</text>
</block>
<block wx:if="{{item.widgettype === 'Title6'}}">
<text class="title-6">{{item.options.text}}</text>
</block>
<!-- 布局组件 - HBox/VBox -->
<block wx:if="{{item.widgettype === 'HBox' || item.widgettype === 'FHBox'}}">
<view class="flex-row {{item.widgettype === 'FHBox' ? 'flex-between' : ''}}">
<block wx:for="{{item.subwidgets}}" wx:key="widgettype" wx:for-item="child">
<template is="brick" data="{{item: child}}" />
</block>
</view>
</block>
<block wx:if="{{item.widgettype === 'VBox' || item.widgettype === 'FVBox'}}">
<view class="flex-col {{item.widgettype === 'FVBox' ? 'flex-between' : ''}}">
<block wx:for="{{item.subwidgets}}" wx:key="widgettype" wx:for-item="child">
<template is="brick" data="{{item: child}}" />
</block>
</view>
</block>
<!-- Filler -->
<block wx:if="{{item.widgettype === 'Filler' || item.widgettype === 'HFiller' || item.widgettype === 'VFiller'}}">
<view class="flex-fill"></view>
</block>
<!-- 输入组件 -->
<block wx:if="{{item.widgettype === 'KeyinText'}}">
<input class="input-field" placeholder="{{item.options.placeholder}}" value="{{item.options.value || item.options.text}}" bindinput="onInput" data-widget="{{item}}" />
</block>
<block wx:if="{{item.widgettype === 'Input'}}">
<block wx:if="{{item.options.type === 'password'}}">
<input class="input-field" type="idcard" placeholder="{{item.options.placeholder}}" password="{{true}}" />
</block>
<block wx:else>
<input class="input-field" placeholder="{{item.options.placeholder}}" value="{{item.options.value}}" />
</block>
</block>
<!-- 图片 -->
<block wx:if="{{item.widgettype === 'Image'}}">
<image class="image-content" src="{{item.options.src}}" mode="{{item.options.mode || 'aspectFit'}}" />
</block>
<!-- Icon -->
<block wx:if="{{item.widgettype === 'Icon' || item.widgettype === 'StatedIcon'}}">
<image class="icon-content" src="{{item.options.src}}" />
</block>
<!-- Running (Loading) -->
<block wx:if="{{item.widgettype === 'Running'}}">
<view class="loading">
<loading />
</view>
</block>
<!-- Scroll -->
<block wx:if="{{item.widgettype === 'VScrollPanel'}}">
<scroll-view class="scroll-panel" scroll-y="true">
<block wx:for="{{item.subwidgets}}" wx:key="widgettype" wx:for-item="child">
<template is="brick" data="{{item: child}}" />
</block>
</scroll-view>
</block>
<block wx:if="{{item.widgettype === 'HScrollPanel'}}">
<scroll-view class="scroll-panel" scroll-x="true">
<block wx:for="{{item.subwidgets}}" wx:key="widgettype" wx:for-item="child">
<template is="brick" data="{{item: child}}" />
</block>
</scroll-view>
</block>
<!-- Modal -->
<block wx:if="{{item.widgettype === 'Modal' || item.widgettype === 'Popup'}}">
<view class="modal-overlay" wx:if="{{item.options.visible}}" catchtap="onCloseModal">
<view class="modal-content" catchtap="stopPropagation">
<block wx:for="{{item.subwidgets}}" wx:key="widgettype" wx:for-item="child">
<template is="brick" data="{{item: child}}" />
</block>
</view>
</view>
</block>
<!-- 默认: 递归子组件 -->
<block wx:if="{{item.subwidgets && item.subwidgets.length > 0 && item.widgettype !== 'HBox' && item.widgettype !== 'FHBox' && item.widgettype !== 'VBox' && item.widgettype !== 'FVBox' && item.widgettype !== 'VScrollPanel' && item.widgettype !== 'HScrollPanel' && item.widgettype !== 'Modal' && item.widgettype !== 'Popup'}}">
<block wx:for="{{item.subwidgets}}" wx:key="widgettype" wx:for-item="child">
<template is="brick" data="{{item: child}}" />
</block>
</block>
</template>