1.5.1 • Published 1 year ago

@wines/gallery v1.5.1

Weekly downloads
-
License
-
Repository
-
Last release
1 year ago

@wines/gallery

Gallery 画廊

用于预览图片或其他操作。

使用指南

在 page.json 中引入组件

{
  "navigationBarTitleText": "Gallery",
  "usingComponents": {
    "wux-gallery": "@wines/gallery"
  }
}

示例

该组件主要依靠 JavaScript 主动调用,所以一般只需在 wxml 中添加一个组件,并设置 id 为 #wux-gallery 或其他,之后在 page.js 中调用 $wuxGallery(this, id) 获取匹配到的第一个组件实例对象。

<wux-gallery id="wux-gallery" />
<view class="page">
	<view class="page__hd">
		<view class="page__title">Gallery</view>
		<view class="page__desc">画廊</view>
	</view>
	<view class="page__bd">
		<view class="sub-title">基于小程序原生的wx.previewImage</view>
		<view class="uploader__files">
			<block wx:for="{{ urls }}" wx:key="index">
				<view class="uploader__file" bindtap="previewImage" data-current="{{ item }}">
					<image class="uploader__img" src="{{ item }}" />
				</view>
			</block>
		</view>
		<view class="sub-title">自定义gallery</view>
		<view class="uploader__files">
			<block wx:for="{{ urls }}" wx:key="index">
				<view class="uploader__file" bindtap="showGallery" data-current="{{ index }}">
					<image class="uploader__img" src="{{ item }}" />
				</view>
			</block>
		</view>
		<view class="sub-title">带说明文案 & 自定义图标</view>
		<view class="uploader__files">
			<block wx:for="{{ urls }}" wx:key="index">
				<view class="uploader__file" bindtap="showGallery2" data-current="{{ index }}">
					<image class="uploader__img" src="{{ item }}" />
				</view>
			</block>
		</view>
	</view>
</view>
import './index.less';
import { $wuxGallery } from '@wines/gallery';
import { PageCustom, PageData } from '@wines/core';

Page<PageData, PageCustom>({
  data: {
    urls: [
      'http://cdn.skyvow.cn/logo.png',
      'http://cdn.skyvow.cn/logo.png',
      'http://cdn.skyvow.cn/logo.png',
      'http://cdn.skyvow.cn/logo.png',
    ],
  },
  onLoad() {
    /** */
  },
  showGallery(e) {
    const { current } = e.currentTarget.dataset;
    const { urls } = this.data;

    const $gallery = $wuxGallery();
    $gallery.show({
      current,
      urls,
      onDelete: (current, urls) => {
        urls.splice(current, 1);
        this.setData({
          urls,
        });
        return true;
      },
      onCancel() {
        console.log('Close gallery');
      },
      onTap(current, urls) {
        console.log(current, urls);
        return true;
      },
      onChange(e) {
        console.log(e);
      },
    });
  },
  showGallery2(e) {
    const { current } = e.currentTarget.dataset;
    const { urls } = this.data;

    $wuxGallery().show({
      current,
      urls: urls.map((n) => ({ image: n, remark: n })),
      indicatorDots: true,
      indicatorColor: '#fff',
      indicatorActiveColor: '#04BE02',
      icon: 'http://cdn.skyvow.cn/logo.png',
      onDelete: (current, urls) => {
        console.log('onIconClick', current, urls);
        return true;
      },
    });
  },
  previewImage(e) {
    const { current } = e.currentTarget.dataset;
    const { urls } = this.data;
    void wx.previewImage({
      current,
      urls,
    });
  },
});

API

参数类型描述默认值
optionsobject配置项-
options.prefixClsstring自定义类名前缀wux-gallery
options.classNamesany过渡的类名,更多内置过渡效果请参考 AnimationGroupwux-animate--slideInRight
options.indicatorDotsboolean是否显示面板指示点false
options.indicatorColorstring指示点颜色rgba(0, 0, 0, .3)
options.indicatorActiveColorstring当前选中的指示点颜色#000000
options.autoplayboolean是否自动切换false
options.intervalnumber自动切换时间间隔5000
options.durationnumber滑动动画时长500
options.circularboolean是否采用衔接滑动false
options.verticalboolean滑动方向是否为纵向false
options.showDeleteboolean是否显示删除按钮true
options.iconstring自定义图标-
options.allowScaleboolean是否支持手势缩放true
options.currentnumber当前显示图片的索引值0
options.urlsarray需要预览的图片链接列表[]
options.onDeletefunction点击删除的回调函数,返回值为 true 时将会关闭组件-
options.onCancelfunction点击关闭的回调函数-
options.onTapfunction图片点击事件,返回值为 true 时将会关闭组件-

Gallery.method

  • Gallery.show
  • Gallery.hide
  • Gallery.slideTo
  • Gallery.slideNext
  • Gallery.slidePrev
1.5.1

1 year ago

1.5.0

1 year ago

1.3.5

2 years ago

1.4.0

2 years ago

1.3.2

3 years ago

1.3.1

3 years ago

1.3.0

3 years ago