@gm-mobile/swiper 1.1.12 → 1.1.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -0,0 +1,121 @@
1
+ # @gm-mobile/swiper
2
+
3
+ ## 简介
4
+
5
+ @gm-mobile/swiper 是基于 Swiper 库封装的轮播组件包,提供了多个轮播场景的解决方案,包括图片轮播、分类导航和图片预览等功能。
6
+
7
+ ## 安装
8
+
9
+ ```bash
10
+ npm install @gm-mobile/swiper
11
+ # 或
12
+ yarn add @gm-mobile/swiper
13
+ ```
14
+
15
+ ## 包含的组件
16
+
17
+ ### 1. SwiperImg
18
+ 图片轮播组件,支持自动播放、循环滚动、图片懒加载等功能。
19
+
20
+ - **适用场景**:商品展示、广告轮播、Banner 轮播
21
+ - **主要功能**:
22
+ - 自动播放和循环模式
23
+ - 图片懒加载
24
+ - 分页器指示
25
+ - 点击事件回调
26
+ - **详细文档**:[SwiperImg README](src/swiper_img/README.md)
27
+
28
+ ### 2. SwiperCategory
29
+ 分类轮播组件,用于展示分类导航的轮播容器。
30
+
31
+ - **适用场景**:分类菜单、导航选项、标签页
32
+ - **主要功能**:
33
+ - 自定义轮播内容
34
+ - 支持多个分类页
35
+ - 滑动交互
36
+ - Swiper 配置定制
37
+ - **详细文档**:[SwiperCategory README](src/swiper_category/README.md)
38
+
39
+ ### 3. PreviewImage
40
+ 图片预览组件,支持单张和多张图片的全屏预览。
41
+
42
+ - **适用场景**:商品详情、相册查看、图片浏览
43
+ - **主要功能**:
44
+ - 全屏图片预览
45
+ - 多图滑动切换
46
+ - 页码显示
47
+ - 静态方法调用
48
+ - **详细文档**:[PreviewImage README](src/preview_image/README.md)
49
+
50
+ ## 使用示例
51
+
52
+ ### 引入样式
53
+
54
+ 在使用组件前,需要先引入 Swiper 的样式文件:
55
+
56
+ ```jsx
57
+ import 'swiper/css/swiper.css'
58
+ ```
59
+
60
+ ### 基础用法
61
+
62
+ ```jsx
63
+ import { SwiperImg, SwiperCategory, PreviewImage } from '@gm-mobile/swiper'
64
+ import 'swiper/css/swiper.css'
65
+
66
+ // 图片轮播
67
+ const imageData = [
68
+ { img: 'https://example.com/image1.jpg' },
69
+ { img: 'https://example.com/image2.jpg' },
70
+ ]
71
+
72
+ <SwiperImg data={imageData} />
73
+
74
+ // 分类轮播
75
+ <SwiperCategory>
76
+ <div>
77
+ <div>分类1</div>
78
+ <div>分类2</div>
79
+ </div>
80
+ <div>
81
+ <div>分类3</div>
82
+ <div>分类4</div>
83
+ </div>
84
+ </SwiperCategory>
85
+
86
+ // 图片预览
87
+ PreviewImage.render({
88
+ images: [
89
+ { img: 'https://example.com/image1.jpg' },
90
+ { img: 'https://example.com/image2.jpg' },
91
+ ],
92
+ defaultIndex: 0,
93
+ })
94
+ ```
95
+
96
+ ## 开发依赖
97
+
98
+ - **React**: ^16.13.1
99
+ - **Swiper**: ^5.3.8
100
+ - **@gm-mobile/react**: ^1.1.11
101
+
102
+ ## 相关包
103
+
104
+ - [@gm-mobile/react](../react/README.md) - 基础组件库
105
+ - [@gm-mobile/business](../business/README.md) - 业务组件库
106
+ - [@gm-mobile/service_time](../service_time/README.md) - 服务时间组件库
107
+
108
+ ## 快速链接
109
+
110
+ - [SwiperImg 组件文档](src/swiper_img/README.md)
111
+ - [SwiperCategory 组件文档](src/swiper_category/README.md)
112
+ - [PreviewImage 组件文档](src/preview_image/README.md)
113
+
114
+ ## 许可证
115
+
116
+ ISC
117
+
118
+ ---
119
+
120
+ **版本**: v1.1.12
121
+ **最后更新**: 2026-03-27
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gm-mobile/swiper",
3
- "version": "1.1.12",
3
+ "version": "1.1.13",
4
4
  "description": "> TODO: description",
5
5
  "author": "liyatang <liyatang@qq.com>",
6
6
  "homepage": "https://github.com/gmfe/gm-mobile#readme",
@@ -21,12 +21,12 @@
21
21
  "url": "https://github.com/gmfe/gm-mobile/issues"
22
22
  },
23
23
  "dependencies": {
24
- "@gm-mobile/react": "^1.1.11",
24
+ "@gm-mobile/react": "^1.1.13",
25
25
  "swiper": "^5.3.8"
26
26
  },
27
27
  "peerDependencies": {
28
28
  "react": "^16.13.1",
29
29
  "react-dom": "^16.13.1"
30
30
  },
31
- "gitHead": "6be0c5a0fc3a049330b084dfa5e945784e29c4b2"
31
+ "gitHead": "99f7babda660876d45627b0f0c9378ce655de360"
32
32
  }
@@ -0,0 +1,161 @@
1
+ # PreviewImage
2
+
3
+ ## 简介
4
+ 图片预览组件 - 全屏图片预览组件,支持单张和多张图片的滑动浏览,适用于商品详情、相册查看等场景
5
+
6
+ ## API
7
+
8
+ ### Props
9
+
10
+ | 属性 | 说明 | 类型 | 默认值 | 必填 |
11
+ |------|------|------|--------|------|
12
+ | images | 图片数组,每个元素包含 img(图片URL)和 onClick(点击回调)属性 | array | - | 是 |
13
+ | onHide | 关闭预览的回调函数 | function | _.noop | 否 |
14
+ | defaultIndex | 多张图片预览时,默认显示的图片索引 | number | 0 | 否 |
15
+ | className | 自定义类名 | string | - | 否 |
16
+ | style | 自定义样式 | object | - | 否 |
17
+
18
+ ### 方法
19
+
20
+ | 方法名 | 说明 | 参数 | 返回值 |
21
+ |--------|------|------|--------|
22
+ | PreviewImage.render | 静态方法,全屏渲染图片预览组件 | options (object) - 包含 images、defaultIndex、onHide 等属性 | void |
23
+ | PreviewImage.hide | 静态方法,隐藏当前显示的图片预览 | 无 | void |
24
+
25
+ ## 示例
26
+
27
+ ### 基础用法
28
+
29
+ ```jsx
30
+ import { PreviewImage } from '@gm-mobile/swiper'
31
+
32
+ // 单张图片预览
33
+ PreviewImage.render({
34
+ images: [
35
+ {
36
+ img: 'https://example.com/image1.jpg'
37
+ }
38
+ ]
39
+ })
40
+
41
+ // 多张图片预览
42
+ PreviewImage.render({
43
+ images: [
44
+ {
45
+ img: 'https://example.com/image1.jpg'
46
+ },
47
+ {
48
+ img: 'https://example.com/image2.jpg'
49
+ },
50
+ {
51
+ img: 'https://example.com/image3.jpg'
52
+ }
53
+ ],
54
+ defaultIndex: 1
55
+ })
56
+ ```
57
+
58
+ ### 常见用法
59
+
60
+ ```jsx
61
+ import { PreviewImage } from '@gm-mobile/swiper'
62
+
63
+ // 带关闭回调的预览
64
+ PreviewImage.render({
65
+ images: [
66
+ {
67
+ img: 'https://example.com/image1.jpg',
68
+ onClick: () => {
69
+ console.log('图片被点击')
70
+ }
71
+ }
72
+ ],
73
+ onHide: () => {
74
+ console.log('预览已关闭')
75
+ }
76
+ })
77
+
78
+ // 点击图片缩略图触发预览
79
+ const handleImageClick = (imageList, currentIndex) => {
80
+ PreviewImage.render({
81
+ images: imageList,
82
+ defaultIndex: currentIndex
83
+ })
84
+ }
85
+
86
+ // 在组件中使用
87
+ <div>
88
+ {images.map((image, index) => (
89
+ <img
90
+ key={index}
91
+ src={image.img}
92
+ onClick={() => handleImageClick(images, index)}
93
+ />
94
+ ))}
95
+ </div>
96
+ ```
97
+
98
+ ### 高级用法
99
+
100
+ ```jsx
101
+ import { PreviewImage } from '@gm-mobile/swiper'
102
+
103
+ // 手动控制预览的显示和隐藏
104
+ const showPreview = () => {
105
+ PreviewImage.render({
106
+ images: imageList,
107
+ defaultIndex: 0,
108
+ onHide: () => {
109
+ console.log('用户关闭了预览')
110
+ }
111
+ })
112
+ }
113
+
114
+ const hidePreview = () => {
115
+ PreviewImage.hide()
116
+ }
117
+
118
+ // 结合业务场景
119
+ const ProductImageGallery = ({ images }) => {
120
+ return (
121
+ <div>
122
+ {images.map((image, index) => (
123
+ <div
124
+ key={index}
125
+ className="thumbnail"
126
+ onClick={() => {
127
+ PreviewImage.render({
128
+ images: images.map(img => ({
129
+ img: img.url,
130
+ onClick: () => {
131
+ // 图片点击事件
132
+ console.log('点击了图片:', img.url)
133
+ }
134
+ })),
135
+ defaultIndex: index
136
+ })
137
+ }}
138
+ >
139
+ <img src={image.thumbnail} alt={`商品图片 ${index + 1}`} />
140
+ </div>
141
+ ))}
142
+ </div>
143
+ )
144
+ }
145
+ ```
146
+
147
+ ## 注意事项
148
+
149
+ - 组件使用 `LayoutRoot.renderWith()` 渲染到 POPUP 层,确保在应用中已正确配置 LayoutRoot
150
+ - `images` 数组中的每个元素必须包含 `img` 属性(图片 URL)
151
+ - `onClick` 是可选的,用于在预览时点击图片的回调处理
152
+ - 多张图片预览时,支持滑动切换和当前页码显示(格式:当前页/总页数)
153
+ - 点击预览区域背景会自动关闭预览(触发 `onHide` 回调)
154
+ - 单张图片预览时不显示页码计数器
155
+ - `PreviewImage.render()` 是静态方法,不需要实例化组件即可使用
156
+ - 确保 images 数组不为空,否则会导致组件异常
157
+
158
+ ## 相关组件
159
+
160
+ - [SwiperImg](../swiper_img/) - 图片轮播组件
161
+ - [SwiperCategory](../swiper_category/) - 分类轮播组件
@@ -0,0 +1,88 @@
1
+ # SwiperCategory
2
+
3
+ ## 简介
4
+ 分类轮播组件 - 用于展示分类导航的轮播容器,支持自定义内容和滑动交互,适用于分类菜单、导航选项等场景。
5
+
6
+ ## API
7
+
8
+ ### Props
9
+ | 属性 | 说明 | 类型 | 默认值 | 必填 |
10
+ |------|------|------|--------|------|
11
+ | options | Swiper 配置对象,用于自定义轮播行为(如 autoplay、speed 等) | object | - | 否 |
12
+ | className | 自定义类名,用于添加额外的样式类 | string | - | 否 |
13
+ | style | 自定义内联样式 | object | - | 否 |
14
+ | children | 轮播内容,每个直接子元素会成为一个滑动页面 | node | - | 是 |
15
+
16
+ ## 示例
17
+
18
+ ### 基础用法
19
+ ```jsx
20
+ import { SwiperCategory } from '@gm-mobile/react'
21
+
22
+ <SwiperCategory>
23
+ <div>
24
+ <div onClick={() => console.log('点击收藏')}>我的收藏</div>
25
+ <div onClick={() => console.log('点击蔬菜')}>蔬菜</div>
26
+ <div onClick={() => console.log('点击肉类')}>肉类</div>
27
+ </div>
28
+ <div>
29
+ <div onClick={() => console.log('点击冻品')}>冻品</div>
30
+ <div onClick={() => console.log('点击水果')}>水果</div>
31
+ </div>
32
+ </SwiperCategory>
33
+ ```
34
+
35
+ ### 自定义轮播配置
36
+ ```jsx
37
+ import { SwiperCategory } from '@gm-mobile/react'
38
+
39
+ <SwiperCategory
40
+ options={{
41
+ autoplay: {
42
+ delay: 3000,
43
+ disableOnInteraction: false,
44
+ },
45
+ speed: 500,
46
+ }}
47
+ >
48
+ <div>
49
+ <div>分类1</div>
50
+ <div>分类2</div>
51
+ </div>
52
+ <div>
53
+ <div>分类3</div>
54
+ <div>分类4</div>
55
+ </div>
56
+ </SwiperCategory>
57
+ ```
58
+
59
+ ### 自定义样式
60
+ ```jsx
61
+ import { SwiperCategory } from '@gm-mobile/react'
62
+
63
+ <SwiperCategory
64
+ className="custom-category"
65
+ style={{ height: '200px' }}
66
+ >
67
+ <div style={{ background: '#f5f5f5' }}>
68
+ <div>首页</div>
69
+ <div>分类</div>
70
+ <div>购物车</div>
71
+ </div>
72
+ <div style={{ background: '#e8e8e8' }}>
73
+ <div>我的</div>
74
+ <div>设置</div>
75
+ </div>
76
+ </SwiperCategory>
77
+ ```
78
+
79
+ ## 注意事项
80
+ - 组件基于 Swiper 库实现,options 支持所有 Swiper 的配置选项
81
+ - 当只有一个子元素时,不会显示分页器
82
+ - 每个 slide 内可以包含多个交互元素,支持点击等事件
83
+ - 默认开启循环模式(loop: true)
84
+ - 确保已正确引入 Swiper 的样式文件
85
+
86
+ ## 相关组件
87
+ - [SwiperImg](../swiper_img/README.md) - 图片轮播组件
88
+ - [PreviewImage](../preview_image/README.md) - 图片预览组件
@@ -0,0 +1,113 @@
1
+ # SwiperImg
2
+
3
+ ## 简介
4
+ 图片轮播组件 - 基于 Swiper 库实现,支持自动播放、循环滚动、图片懒加载等功能,适用于商品展示、广告轮播等场景。
5
+
6
+ ## API
7
+
8
+ ### Props
9
+ | 属性 | 说明 | 类型 | 默认值 | 必填 |
10
+ |------|------|------|--------|------|
11
+ | data | 轮播图片数据数组,每个元素包含 img(图片地址,必填)和 onClick(点击回调,可选) | array | - | 是 |
12
+ | options | Swiper 配置项,用于覆盖默认配置(默认已配置 loop、autoplay、lazy、pagination) | object | - | 否 |
13
+ | className | 自定义类名 | string | - | 否 |
14
+ | style | 自定义样式 | object | - | 否 |
15
+
16
+ **data 数据结构:**
17
+ ```typescript
18
+ {
19
+ img: string // 图片地址,必填
20
+ onClick?: (item: any) => void // 点击回调函数,可选
21
+ [key: string]: any // 其他自定义字段
22
+ }
23
+ ```
24
+
25
+ **默认配置:**
26
+ 组件已默认配置以下 Swiper 选项,可通过 options 覆盖:
27
+ - `loop: true` - 循环播放
28
+ - `autoplay: true` - 自动播放
29
+ - `disableOnInteraction: false` - 用户操作后继续自动播放
30
+ - `lazy.loadPrevNext: true` - 懒加载前后图片
31
+ - `pagination.el: '.swiper-pagination'` - 显示分页器
32
+
33
+ ## 示例
34
+
35
+ ### 基础用法
36
+ ```jsx
37
+ import { SwiperImg } from '@gm-mobile/react'
38
+
39
+ const imageData = [
40
+ {
41
+ onClick: (item) => {
42
+ console.log('点击了第1张图片', item)
43
+ },
44
+ img: 'https://img.guanmai.cn/station_pic/sha1_eb0e548b7a574fcb3069a91a1dd816a1d8dddef8.jpg',
45
+ },
46
+ {
47
+ img: 'https://img.guanmai.cn/station_pic/sha1_6f6bd1497f8e5c1db37593110af99437589a570f.jpg',
48
+ },
49
+ {
50
+ img: 'https://img.guanmai.cn/station_pic/sha1_d9600fa7ed07af43313992501128e7cbd13f6b58.jpg',
51
+ },
52
+ ]
53
+
54
+ <SwiperImg data={imageData} />
55
+ ```
56
+
57
+ ### 自定义配置
58
+ ```jsx
59
+ import { SwiperImg } from '@gm-mobile/react'
60
+
61
+ const imageData = [
62
+ {
63
+ onClick: () => console.log('点击图片'),
64
+ img: 'https://img.guanmai.cn/station_pic/xxx.jpg',
65
+ },
66
+ ]
67
+
68
+ // 自定义 Swiper 配置
69
+ const swiperOptions = {
70
+ autoplay: {
71
+ delay: 3000, // 自动播放间隔 3 秒
72
+ },
73
+ loop: false, // 关闭循环播放
74
+ pagination: {
75
+ clickable: true, // 分页器可点击
76
+ },
77
+ }
78
+
79
+ <SwiperImg data={imageData} options={swiperOptions} />
80
+ ```
81
+
82
+ ### 自定义样式
83
+ ```jsx
84
+ import { SwiperImg } from '@gm-mobile/react'
85
+
86
+ const imageData = [
87
+ {
88
+ img: 'https://img.guanmai.cn/station_pic/xxx.jpg',
89
+ },
90
+ ]
91
+
92
+ const customStyle = {
93
+ height: '200px',
94
+ borderRadius: '8px',
95
+ }
96
+
97
+ <SwiperImg
98
+ data={imageData}
99
+ className="my-custom-swiper"
100
+ style={customStyle}
101
+ />
102
+ ```
103
+
104
+ ## 注意事项
105
+ - 必须确保已引入 Swiper 的样式文件:`import 'swiper/css/swiper.css'`
106
+ - data 数组中每个对象必须包含 `img` 字段(图片地址)
107
+ - 在 loop 模式下(默认开启),点击事件已做特殊处理,可正常触发 onClick 回调
108
+ - 图片懒加载功能默认开启,有利于提升性能
109
+ - 如需关闭自动播放或修改播放间隔,请通过 options 配置 `autoplay` 属性
110
+
111
+ ## 相关组件
112
+ - [PreviewImage](../preview_image/README.md) - 图片预览组件
113
+ - [SwiperCategory](../swiper_category/README.md) - 分类轮播组件