Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修复image组件图片懒加载失效 #3036

Merged
merged 5 commits into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/image/image.less
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@
height: 100%;
}

&--lazy{
position: absolute;
opacity: 0;
anlyyao marked this conversation as resolved.
Show resolved Hide resolved
top: 0;
}

&--shape {
&-circle {
border-radius: 50%;
Expand Down
93 changes: 47 additions & 46 deletions src/image/image.wxml
Original file line number Diff line number Diff line change
@@ -1,52 +1,53 @@
<wxs src="../common/utils.wxs" module="_" />

<view style="position: relative;">
anlyyao marked this conversation as resolved.
Show resolved Hide resolved
<!-- 加载中占位 -->
<view
wx:if="{{isLoading}}"
style="{{_._style([innerStyle, style, customStyle])}}"
class="class {{prefix}}-class {{classPrefix}} {{classPrefix}}__mask {{classPrefix}}--loading {{classPrefix}}--shape-{{shape}}"
aria-hidden="{{ariaHidden}}"
>
<t-loading
wx:if="{{loading === 'default'}}"
theme="dots"
size="44rpx"
loading
inherit-color
t-class="t-class-load"
t-class-text="{{classPrefix}}--loading-text"
></t-loading>
<view wx:elif="{{loading !== '' && loading !== 'slot'}}" class="{{classPrefix}}__common {{prefix}}-class-load">
{{loading}}
<view
wx:if="{{isLoading}}"
style="{{_._style([innerStyle, style, customStyle])}}"
class="class {{prefix}}-class {{classPrefix}} {{classPrefix}}__mask {{classPrefix}}--loading {{classPrefix}}--shape-{{shape}}"
aria-hidden="{{ariaHidden}}"
>
<t-loading
wx:if="{{loading === 'default'}}"
theme="dots"
size="44rpx"
loading
inherit-color
t-class="t-class-load"
t-class-text="{{classPrefix}}--loading-text"
></t-loading>
<view wx:elif="{{loading !== '' && loading !== 'slot'}}" class="{{classPrefix}}__common {{prefix}}-class-load">
{{loading}}
</view>
<slot wx:else name="loading" />
</view>
<slot wx:else name="loading" />
</view>
<!-- 加载失败占位 -->
<view
wx:elif="{{isFailed}}"
style="{{_._style([innerStyle, style, customStyle])}}"
class="class {{prefix}}-class {{classPrefix}} {{classPrefix}}__mask {{classPrefix}}--failed {{classPrefix}}--shape-{{shape}}"
aria-hidden="{{ariaHidden}}"
>
<view wx:if="{{error === 'default'}}" style="font-size: 44rpx" class="{{prefix}}-class-load">
<t-icon name="close" aria-role="img" aria-label="加载失败" />
<!-- 加载失败占位 -->
<view
wx:elif="{{isFailed}}"
style="{{_._style([innerStyle, style, customStyle])}}"
class="class {{prefix}}-class {{classPrefix}} {{classPrefix}}__mask {{classPrefix}}--failed {{classPrefix}}--shape-{{shape}}"
aria-hidden="{{ariaHidden}}"
>
<view wx:if="{{error === 'default'}}" style="font-size: 44rpx" class="{{prefix}}-class-load">
<t-icon name="close" aria-role="img" aria-label="加载失败" />
</view>
<view wx:elif="{{error && error !== 'slot'}}" class="{{classPrefix}}__common {{prefix}}-class-load"> {{error}} </view>
<slot wx:else name="error" />
</view>
<view wx:elif="{{error && error !== 'slot'}}" class="{{classPrefix}}__common {{prefix}}-class-load"> {{error}} </view>
<slot wx:else name="error" />
<!-- 图片 -->
<image
id="{{tId||'image'}}"
class="class {{prefix}}-class {{classPrefix}} {{classPrefix}}--shape-{{shape}} {{isLoading || isFailed ? classPrefix + '--lazy' : ''}}"
anlyyao marked this conversation as resolved.
Show resolved Hide resolved
src="{{src}}"
style="{{_._style([innerStyle, style, customStyle])}}"
mode="{{mode}}"
webp="{{webp}}"
lazy-load="{{lazy}}"
bind:load="onLoaded"
bind:error="onLoadError"
show-menu-by-longpress="{{showMenuByLongpress}}"
aria-hidden="{{ariaHidden || isLoading || isFailed}}"
aria-label="{{ariaLabel}}"
/>
</view>
<!-- 图片 -->
<image
id="{{tId||'image'}}"
hidden="{{isLoading || isFailed}}"
class="class {{prefix}}-class {{classPrefix}} {{classPrefix}}--shape-{{shape}}"
src="{{src}}"
style="{{_._style([innerStyle, style, customStyle])}}"
mode="{{mode}}"
webp="{{webp}}"
lazy-load="{{lazy}}"
bind:load="onLoaded"
bind:error="onLoadError"
show-menu-by-longpress="{{showMenuByLongpress}}"
aria-hidden="{{ariaHidden || isLoading || isFailed}}"
aria-label="{{ariaLabel}}"
/>
Loading