Skip to content

Commit e6a3b73

Browse files
jasper-opsMoonofweisheng
authored andcommitted
feat: ✨ img组件增加enable-preview属性来支持点击预览功能
Closes: #193
1 parent d057607 commit e6a3b73

File tree

4 files changed

+29
-2
lines changed

4 files changed

+29
-2
lines changed

docs/component/img.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,19 @@ mode为小程序原生属性,参考[微信小程序image官方文档](https://
5858
/>
5959
```
6060

61+
## 可预览
62+
63+
通过设置`enable-preview`属性可以支持点击预览,底层调用uni.previewImage来实现预览效果
64+
65+
```html
66+
<wd-img
67+
:width="100"
68+
:height="100"
69+
:src="joy"
70+
:enable-preview="true"
71+
/>
72+
```
73+
6174
## Attributes
6275

6376
| 参数 | 说明 | 类型 | 可选值 | 默认值 | 最低版本 |
@@ -68,6 +81,7 @@ mode为小程序原生属性,参考[微信小程序image官方文档](https://
6881
| mode | 填充模式 | string | 'top left' / 'top right' / 'bottom left' / 'bottom right' / 'right' / 'left' / 'center' / 'bottom' / 'top' / 'heightFix' / 'widthFix' / 'aspectFill' / 'aspectFit' / 'scaleToFill' | 'scaleToFill' | - |
6982
| round | 是否显示为圆形 | boolean | - | false | - |
7083
| radius | 圆角大小,默认单位为px | number / string | - | - | - |
84+
| enable-preview | 是否支持点击预览 | boolean | - | false | - |
7185

7286
## Events
7387

src/pages/img/Index.vue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* @Date: 2023-11-02 18:57:41
44
* @LastEditTime: 2023-11-02 19:02:24
55
* @LastEditors: weisheng
6-
* @Description:
6+
* @Description:
77
* @FilePath: \wot-design-uni\src\pages\img\Index.vue
88
* 记得注释
99
-->
@@ -32,6 +32,10 @@
3232
<view class="center">{{ mode }}</view>
3333
</view>
3434
</demo-block>
35+
36+
<demo-block title="可预览">
37+
<wd-img :width="100" :height="100" :src="joy" :enable-preview="true" />
38+
</demo-block>
3539
</page-wraper>
3640
</template>
3741
<script lang="ts" setup>

src/uni_modules/wot-design-uni/components/wd-img/types.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,9 @@ export const imgProps = {
3030
/**
3131
* 圆角大小,默认单位为px
3232
*/
33-
radius: numericProp
33+
radius: numericProp,
34+
/**
35+
* 是否允许预览
36+
*/
37+
enablePreview: makeBooleanProp(false)
3438
}

src/uni_modules/wot-design-uni/components/wd-img/wd-img.vue

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ function handleError(event: Event) {
4646
emit('error', event)
4747
}
4848
function handleClick() {
49+
if (props.enablePreview && props.src) {
50+
uni.previewImage({
51+
urls: [props.src]
52+
})
53+
}
4954
emit('click')
5055
}
5156
function handleLoad(event: Event) {

0 commit comments

Comments
 (0)