@xtdev/xt-miniprogram-ui 1.2.60 → 1.2.61
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/libs/package.json +1 -0
- package/libs/xt-button/README.md +60 -0
- package/libs/xt-button/index.js +116 -0
- package/libs/xt-button/index.json +7 -0
- package/libs/xt-button/index.wxml +31 -0
- package/libs/xt-button/index.wxss +70 -0
- package/libs/xt-card-cell/README.md +67 -0
- package/libs/xt-card-cell/index.js +43 -0
- package/libs/xt-card-cell/index.json +6 -0
- package/libs/xt-card-cell/index.wxml +34 -0
- package/libs/xt-card-cell/index.wxss +89 -0
- package/libs/xt-cell/README.md +41 -0
- package/libs/xt-cell/index.js +42 -0
- package/libs/xt-cell/index.json +7 -0
- package/libs/xt-cell/index.wxml +12 -0
- package/libs/xt-cell/index.wxss +50 -0
- package/libs/xt-date-picker/README.md +77 -0
- package/libs/xt-date-picker/index.js +443 -0
- package/libs/xt-date-picker/index.json +7 -0
- package/libs/xt-date-picker/index.wxml +58 -0
- package/libs/xt-date-picker/index.wxss +118 -0
- package/libs/xt-date-picker-loop/README.md +77 -0
- package/libs/xt-date-picker-loop/index.js +684 -0
- package/libs/xt-date-picker-loop/index.json +8 -0
- package/libs/xt-date-picker-loop/index.wxml +61 -0
- package/libs/xt-date-picker-loop/index.wxss +117 -0
- package/libs/xt-dialog/README.md +157 -0
- package/libs/xt-dialog/index.js +142 -0
- package/libs/xt-dialog/index.json +5 -0
- package/libs/xt-dialog/index.wxml +64 -0
- package/libs/xt-dialog/index.wxss +129 -0
- package/libs/xt-form/index.js +83 -0
- package/libs/xt-form/index.json +5 -0
- package/libs/xt-form/index.wxml +67 -0
- package/libs/xt-form/index.wxss +141 -0
- package/libs/xt-icon/README.md +39 -0
- package/libs/xt-icon/index.js +25 -0
- package/libs/xt-icon/index.json +5 -0
- package/libs/xt-icon/index.wxml +2 -0
- package/libs/xt-icon/index.wxss +159 -0
- package/libs/xt-popover/README.md +71 -0
- package/libs/xt-popover/index.js +209 -0
- package/libs/xt-popover/index.json +7 -0
- package/libs/xt-popover/index.wxml +43 -0
- package/libs/xt-popover/index.wxss +135 -0
- package/libs/xt-preview-image/README.md +46 -0
- package/libs/xt-preview-image/index.js +111 -0
- package/libs/xt-preview-image/index.json +4 -0
- package/libs/xt-preview-image/index.wxml +25 -0
- package/libs/xt-preview-image/index.wxss +82 -0
- package/libs/xt-search/README.md +55 -0
- package/libs/xt-search/index.js +88 -0
- package/libs/xt-search/index.json +7 -0
- package/libs/xt-search/index.wxml +17 -0
- package/libs/xt-search/index.wxss +82 -0
- package/libs/xt-stepper/README.md +52 -0
- package/libs/xt-stepper/index.js +158 -0
- package/libs/xt-stepper/index.json +5 -0
- package/libs/xt-stepper/index.wxml +11 -0
- package/libs/xt-stepper/index.wxss +77 -0
- package/libs/xt-steps/README.md +79 -0
- package/libs/xt-steps/index.js +37 -0
- package/libs/xt-steps/index.json +7 -0
- package/libs/xt-steps/index.wxml +34 -0
- package/libs/xt-steps/index.wxss +186 -0
- package/libs/xt-tabs/README.md +98 -0
- package/libs/xt-tabs/index.js +35 -0
- package/libs/xt-tabs/index.json +6 -0
- package/libs/xt-tabs/index.wxml +10 -0
- package/libs/xt-tabs/index.wxss +76 -0
- package/libs/xt-tag/README.md +65 -0
- package/libs/xt-tag/index.js +38 -0
- package/libs/xt-tag/index.json +7 -0
- package/libs/xt-tag/index.wxml +5 -0
- package/libs/xt-tag/index.wxss +36 -0
- package/libs/xt-toast/README.md +65 -0
- package/libs/xt-toast/index.js +85 -0
- package/libs/xt-toast/index.json +7 -0
- package/libs/xt-toast/index.wxml +6 -0
- package/libs/xt-toast/index.wxss +27 -0
- package/libs/xt-uploader/README.md +46 -0
- package/libs/xt-uploader/index.js +233 -0
- package/libs/xt-uploader/index.json +7 -0
- package/libs/xt-uploader/index.wxml +15 -0
- package/libs/xt-uploader/index.wxss +68 -0
- package/libs/xt-uploader/utils.js +69 -0
- package/package.json +1 -1
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
Component({
|
|
2
|
+
behaviors: [],
|
|
3
|
+
observers: {},
|
|
4
|
+
properties: {
|
|
5
|
+
zIndx: {
|
|
6
|
+
type: Number,
|
|
7
|
+
value: 999,
|
|
8
|
+
observer: function () {},
|
|
9
|
+
},
|
|
10
|
+
// 弹窗标题
|
|
11
|
+
title: {
|
|
12
|
+
type: String,
|
|
13
|
+
value: "",
|
|
14
|
+
observer: function () {},
|
|
15
|
+
},
|
|
16
|
+
// 弹窗类型
|
|
17
|
+
type: {
|
|
18
|
+
type: String,
|
|
19
|
+
value: "operate",
|
|
20
|
+
observer: function () {},
|
|
21
|
+
},
|
|
22
|
+
show: {
|
|
23
|
+
type: Boolean,
|
|
24
|
+
value: false,
|
|
25
|
+
observer: async function (val) {
|
|
26
|
+
if (val) {
|
|
27
|
+
const res = await this.findIntersection();
|
|
28
|
+
this.setData({
|
|
29
|
+
sourceData: res,
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
showCloseIcon: {
|
|
35
|
+
type: Boolean,
|
|
36
|
+
value: true,
|
|
37
|
+
observer: function (val) {},
|
|
38
|
+
},
|
|
39
|
+
|
|
40
|
+
// 文本内容
|
|
41
|
+
textContent: {
|
|
42
|
+
type: String,
|
|
43
|
+
value: "",
|
|
44
|
+
observer: function () {},
|
|
45
|
+
},
|
|
46
|
+
// 列表每一项标题内容
|
|
47
|
+
itemTextKey: {
|
|
48
|
+
type: String,
|
|
49
|
+
value: "",
|
|
50
|
+
observer: function () {},
|
|
51
|
+
},
|
|
52
|
+
// 操作
|
|
53
|
+
operates: {
|
|
54
|
+
type: Array,
|
|
55
|
+
value: [],
|
|
56
|
+
observer: function () {},
|
|
57
|
+
},
|
|
58
|
+
// 源数据
|
|
59
|
+
sourceData: {
|
|
60
|
+
type: Array,
|
|
61
|
+
value: [],
|
|
62
|
+
observer: function (val) {},
|
|
63
|
+
},
|
|
64
|
+
// 选中数据
|
|
65
|
+
selectData: {
|
|
66
|
+
type: Array,
|
|
67
|
+
value: [],
|
|
68
|
+
observer: async function () {},
|
|
69
|
+
},
|
|
70
|
+
// 数据对比字段,用于找出选中的数据
|
|
71
|
+
contrastId: {
|
|
72
|
+
type: String,
|
|
73
|
+
value: "",
|
|
74
|
+
observer: function () {},
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
data: {
|
|
78
|
+
sourceData: [],
|
|
79
|
+
multipleChooseData: [],
|
|
80
|
+
},
|
|
81
|
+
methods: {
|
|
82
|
+
closePopover() {
|
|
83
|
+
this.triggerEvent("onClose");
|
|
84
|
+
this.resetSourceData();
|
|
85
|
+
},
|
|
86
|
+
|
|
87
|
+
async findIntersection() {
|
|
88
|
+
const { sourceData, selectData, contrastId, type } = this.data;
|
|
89
|
+
|
|
90
|
+
for (const selectItem of selectData) {
|
|
91
|
+
for (const sourceItem of sourceData) {
|
|
92
|
+
if (type === "multiple") {
|
|
93
|
+
if (selectItem[contrastId] == sourceItem[contrastId]) {
|
|
94
|
+
sourceItem.selected = true;
|
|
95
|
+
}
|
|
96
|
+
} else {
|
|
97
|
+
if (selectItem[contrastId] == sourceItem[contrastId]) {
|
|
98
|
+
sourceItem.selected = true;
|
|
99
|
+
} else {
|
|
100
|
+
sourceItem.selected = false;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return this.deepClone(sourceData);
|
|
106
|
+
},
|
|
107
|
+
// 重置数据
|
|
108
|
+
async resetSourceData() {
|
|
109
|
+
const { sourceData } = this.data;
|
|
110
|
+
for (const sourceItem of sourceData) {
|
|
111
|
+
delete sourceItem.selected;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
this.setData({
|
|
115
|
+
sourceData: this.deepClone(sourceData),
|
|
116
|
+
});
|
|
117
|
+
},
|
|
118
|
+
|
|
119
|
+
async formatSourceData(chooseItem) {
|
|
120
|
+
const { sourceData, contrastId } = this.data;
|
|
121
|
+
for (const sourceItem of sourceData) {
|
|
122
|
+
if (
|
|
123
|
+
chooseItem[contrastId] == sourceItem[contrastId] &&
|
|
124
|
+
sourceItem.selected
|
|
125
|
+
) {
|
|
126
|
+
sourceItem.selected = false;
|
|
127
|
+
} else if (
|
|
128
|
+
chooseItem[contrastId] == sourceItem[contrastId] &&
|
|
129
|
+
!sourceItem.selected
|
|
130
|
+
) {
|
|
131
|
+
sourceItem.selected = true;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return sourceData;
|
|
135
|
+
},
|
|
136
|
+
|
|
137
|
+
confirm() {
|
|
138
|
+
const { sourceData } = this.data;
|
|
139
|
+
const chooseData = sourceData.filter((item) => item.selected);
|
|
140
|
+
|
|
141
|
+
const deleteSelected = chooseData.map((item) => {
|
|
142
|
+
delete item.selected;
|
|
143
|
+
return item;
|
|
144
|
+
});
|
|
145
|
+
this.triggerEvent("onConfirm", { chooseData: deleteSelected });
|
|
146
|
+
},
|
|
147
|
+
|
|
148
|
+
async chooseItemClick(event) {
|
|
149
|
+
const chooseItem = event.currentTarget.dataset.item;
|
|
150
|
+
const { type } = this.data;
|
|
151
|
+
|
|
152
|
+
if (type == "single") {
|
|
153
|
+
delete chooseItem.selected;
|
|
154
|
+
this.triggerEvent("onChooseItemClick", { chooseItem });
|
|
155
|
+
} else if (type == "multiple") {
|
|
156
|
+
const res = await this.formatSourceData(chooseItem);
|
|
157
|
+
|
|
158
|
+
this.setData({
|
|
159
|
+
sourceData: this.deepClone(res),
|
|
160
|
+
});
|
|
161
|
+
} else {
|
|
162
|
+
this.triggerEvent("onChooseItemClick", { chooseItem });
|
|
163
|
+
}
|
|
164
|
+
},
|
|
165
|
+
|
|
166
|
+
deepClone(target, map = new Map()) {
|
|
167
|
+
if (typeof target === "object") {
|
|
168
|
+
const isArray = Array.isArray(target);
|
|
169
|
+
let cloneTarget = isArray ? [] : {};
|
|
170
|
+
|
|
171
|
+
if (map.get(target)) {
|
|
172
|
+
return map.get(target);
|
|
173
|
+
}
|
|
174
|
+
map.set(target, cloneTarget);
|
|
175
|
+
|
|
176
|
+
const keys = isArray ? undefined : Object.keys(target);
|
|
177
|
+
this.forEach(keys || target, (value, key) => {
|
|
178
|
+
if (keys) {
|
|
179
|
+
key = value;
|
|
180
|
+
}
|
|
181
|
+
cloneTarget[key] = this.deepClone(target[key], map);
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
return cloneTarget;
|
|
185
|
+
} else {
|
|
186
|
+
return target;
|
|
187
|
+
}
|
|
188
|
+
},
|
|
189
|
+
forEach(array, iteratee) {
|
|
190
|
+
let index = -1;
|
|
191
|
+
const length = array.length;
|
|
192
|
+
while (++index < length) {
|
|
193
|
+
iteratee(array[index], index);
|
|
194
|
+
}
|
|
195
|
+
return array;
|
|
196
|
+
},
|
|
197
|
+
},
|
|
198
|
+
pageLifetimes: {
|
|
199
|
+
// 组件所在页面的生命周期函数
|
|
200
|
+
show: function () {},
|
|
201
|
+
hide: function () {},
|
|
202
|
+
resize: function () {},
|
|
203
|
+
},
|
|
204
|
+
created: function () {},
|
|
205
|
+
attached: function () {},
|
|
206
|
+
ready: function () {},
|
|
207
|
+
moved: function () {},
|
|
208
|
+
detached: function () {},
|
|
209
|
+
});
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
<view wx:if="{{show}}" class="xt-popover-popup" style="z-index:{{zIndx}}">
|
|
2
|
+
<view class="xt-popover">
|
|
3
|
+
<view wx:if="{{ type == 'operate'}}" class="operate-wrapper">
|
|
4
|
+
<view class="operate-content font40rpx">
|
|
5
|
+
<block wx:for="{{operates}}" wx:for-item="operate" wx:for-index="idx" wx:key="idx">
|
|
6
|
+
<view bindtap="chooseItemClick" data-item="{{operate}}" class="flex-center operate">
|
|
7
|
+
{{operate[itemTextKey]}}
|
|
8
|
+
</view>
|
|
9
|
+
</block>
|
|
10
|
+
</view>
|
|
11
|
+
<view bindtap="closePopover" class="font40rpx flex-center cancel">取消</view>
|
|
12
|
+
</view>
|
|
13
|
+
<view wx:else class="content-wrapper">
|
|
14
|
+
<view class="header">
|
|
15
|
+
<view class="header-title">{{title}}</view>
|
|
16
|
+
<image wx:if="{{showCloseIcon}}" bindtap="closePopover" class="close-icon" src="https://img.tanjiu.cn/home/zGMfEx8iJBb6JewsFrYXNWs8R8KRwjzD.png" mode="widthFix"></image>
|
|
17
|
+
</view>
|
|
18
|
+
<scroll-view scroll-y="true" class="content font40rpx {{ type == 'single' ? 'spec-content':''}}">
|
|
19
|
+
<view class="content-info">
|
|
20
|
+
<block wx:if="{{type == 'text'}}">{{textContent}}</block>
|
|
21
|
+
<view wx:else class="list">
|
|
22
|
+
<block wx:for="{{sourceData}}" wx:for-item="listItem" wx:for-index="idx" wx:key="idx">
|
|
23
|
+
<view class="list-item" bindtap="chooseItemClick" data-item="{{listItem}}">
|
|
24
|
+
<view class="list-item-label">{{listItem[itemTextKey]}}</view>
|
|
25
|
+
<block wx:if="{{type == 'multiple'}}">
|
|
26
|
+
<xt-icon wx:if="{{listItem.selected}}" icon="tongguo" size="44" style="color:#30BF67"></xt-icon>
|
|
27
|
+
<xt-icon wx:else icon="weixuanzhong1" size="44" style="color:#999999"></xt-icon>
|
|
28
|
+
</block>
|
|
29
|
+
<block wx:if="{{type == 'single'}}">
|
|
30
|
+
<xt-icon wx:if="{{listItem.selected}}" icon="zhengque" size="44" style="color:#30BF67"></xt-icon>
|
|
31
|
+
</block>
|
|
32
|
+
</view>
|
|
33
|
+
</block>
|
|
34
|
+
</view>
|
|
35
|
+
<slot ></slot>
|
|
36
|
+
</view>
|
|
37
|
+
</scroll-view>
|
|
38
|
+
<view wx:if="{{type == 'text' || type == 'multiple'}}" class="btn-wrapper">
|
|
39
|
+
<view bindtap="confirm" class="confirm flex-center">确定</view>
|
|
40
|
+
</view>
|
|
41
|
+
</view>
|
|
42
|
+
</view>
|
|
43
|
+
</view>
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
.xt-popover-popup {
|
|
2
|
+
position: fixed;
|
|
3
|
+
top: 0;
|
|
4
|
+
left: 0;
|
|
5
|
+
width: 100vw;
|
|
6
|
+
height: 100vh;
|
|
7
|
+
background: rgba(0, 0, 0, 0.7);
|
|
8
|
+
|
|
9
|
+
transition-property: opacity;
|
|
10
|
+
transition-timing-function: ease;
|
|
11
|
+
}
|
|
12
|
+
.xt-popover-popup .xt-popover {
|
|
13
|
+
position: absolute;
|
|
14
|
+
bottom: 0;
|
|
15
|
+
width: 100%;
|
|
16
|
+
background-color: #ffffff;
|
|
17
|
+
border-radius: 20rpx 20rpx 0 0;
|
|
18
|
+
overflow: hidden;
|
|
19
|
+
box-sizing: border-box;
|
|
20
|
+
|
|
21
|
+
padding-bottom: calc(constant(safe-area-inset-bottom) + 0rpx);
|
|
22
|
+
padding-bottom: calc(env(safe-area-inset-bottom) + 0rpx);
|
|
23
|
+
|
|
24
|
+
transition: all 0.5s ease-in;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
.xt-popover .operate-wrapper {
|
|
28
|
+
overflow: hidden;
|
|
29
|
+
background: #ededed;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
.xt-popover .operate-content {
|
|
33
|
+
background-color: #ffffff;
|
|
34
|
+
margin-bottom: 16rpx;
|
|
35
|
+
box-sizing: border-box;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
.xt-popover .operate {
|
|
39
|
+
box-sizing: border-box;
|
|
40
|
+
width: 100%;
|
|
41
|
+
height: 120rpx;
|
|
42
|
+
box-shadow: inset 0px -2rpx 0rpx 0rpx #ededed;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
.xt-popover .cancel {
|
|
46
|
+
width: 100%;
|
|
47
|
+
min-height: 120rpx;
|
|
48
|
+
background-color: #ffffff;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
.xt-popover .flex-center {
|
|
52
|
+
display: flex;
|
|
53
|
+
align-items: center;
|
|
54
|
+
justify-content: center;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
.xt-popover .font40rpx {
|
|
58
|
+
font-size: 40rpx;
|
|
59
|
+
font-weight: 400;
|
|
60
|
+
color: #000000;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
.content-wrapper {
|
|
64
|
+
box-sizing: border-box;
|
|
65
|
+
background-color: #ffffff;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
.xt-popover-popup .header {
|
|
69
|
+
display: flex;
|
|
70
|
+
flex-direction: row;
|
|
71
|
+
align-items: center;
|
|
72
|
+
justify-content: space-between;
|
|
73
|
+
box-sizing: border-box;
|
|
74
|
+
padding: 0 32rpx;
|
|
75
|
+
|
|
76
|
+
width: 100%;
|
|
77
|
+
height: 120rpx;
|
|
78
|
+
background: #ffffff;
|
|
79
|
+
box-shadow: inset 0px -2rpx 0rpx 0rpx #f5f5f5;
|
|
80
|
+
font-size: 40rpx;
|
|
81
|
+
font-weight: 600;
|
|
82
|
+
color: #222222;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
.xt-popover-popup .content {
|
|
86
|
+
box-sizing: border-box;
|
|
87
|
+
height: 924rpx;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
.xt-popover-popup .spec-content {
|
|
91
|
+
height: 1084rpx;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
.xt-popover-popup .content-info {
|
|
95
|
+
box-sizing: border-box;
|
|
96
|
+
padding: 32rpx;
|
|
97
|
+
text-align: justify;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
.xt-popover-popup .close-icon {
|
|
101
|
+
width: 48rpx;
|
|
102
|
+
height: 48rpx;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
.xt-popover-popup .btn-wrapper {
|
|
106
|
+
box-sizing: border-box;
|
|
107
|
+
width: 100%;
|
|
108
|
+
padding: 32rpx;
|
|
109
|
+
height: 160rpx;
|
|
110
|
+
background: #ffffff;
|
|
111
|
+
box-shadow: inset 0px 2rpx 0rpx 0rpx #ededed;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
.xt-popover-popup .confirm {
|
|
115
|
+
width: 100%;
|
|
116
|
+
height: 100%;
|
|
117
|
+
background: #6722ab;
|
|
118
|
+
border-radius: 120rpx;
|
|
119
|
+
|
|
120
|
+
font-size: 40rpx;
|
|
121
|
+
font-weight: 600;
|
|
122
|
+
color: #ffffff;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
.xt-popover-popup .list-item {
|
|
126
|
+
display: flex;
|
|
127
|
+
flex-direction: row;
|
|
128
|
+
justify-content: space-between;
|
|
129
|
+
padding: 32rpx 0;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
.xt-popover-popup .list-item-label {
|
|
133
|
+
flex: 1;
|
|
134
|
+
margin-right: 20rpx;
|
|
135
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# PreviewImage 图片预览
|
|
2
|
+
|
|
3
|
+
### 介绍
|
|
4
|
+
自定义图片预览
|
|
5
|
+
|
|
6
|
+
###效果图
|
|
7
|
+

|
|
8
|
+
|
|
9
|
+
### 引入
|
|
10
|
+
在app.json或页面配置json中引入
|
|
11
|
+
```
|
|
12
|
+
"usingComponents": {
|
|
13
|
+
"xt-preview-image": "@xtdev/xt-miniprogram-ui/xt-preview-image",
|
|
14
|
+
}
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## 代码演示
|
|
18
|
+
|
|
19
|
+
### 基础用法
|
|
20
|
+
|
|
21
|
+
#### 操作样式
|
|
22
|
+
|
|
23
|
+
```
|
|
24
|
+
<image-preview id="imagePreview" show="{{showPreviewPop}}" images="{{previewImages}}" current-index="0" bind:close="onPreviewClose" />
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## API
|
|
28
|
+
|
|
29
|
+
#### xt-popover props
|
|
30
|
+
|
|
31
|
+
| 参数 | 说明 | 类型 | 默认值 |
|
|
32
|
+
| ----------- | ----------- | ---------- | ------------ |
|
|
33
|
+
| show | 是否显示预览,可选值为 `true` `false` | boolean | `false`
|
|
34
|
+
| images | 图片列表 | array | `[]`
|
|
35
|
+
| currentIndex | 当前显示的图片索引 | number | `0`
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
####Events
|
|
40
|
+
|
|
41
|
+
| 事件名 | 说明 | 回调参数 |
|
|
42
|
+
| ---------------- | ------------- | ---------------------- |
|
|
43
|
+
| bind:imageload | 图片加载完成 | event.detail
|
|
44
|
+
| bind:imagetap | 点击图片 | event
|
|
45
|
+
| bind:change | 切换图片 | currentIndex 当前示的图片索引
|
|
46
|
+
| bind:close | 关闭预览 | event
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
Component({
|
|
2
|
+
properties: {
|
|
3
|
+
// 是否显示预览
|
|
4
|
+
show: {
|
|
5
|
+
type: Boolean,
|
|
6
|
+
value: false,
|
|
7
|
+
},
|
|
8
|
+
// 图片列表
|
|
9
|
+
images: {
|
|
10
|
+
type: Array,
|
|
11
|
+
value: [],
|
|
12
|
+
},
|
|
13
|
+
// 当前显示的图片索引
|
|
14
|
+
currentIndex: {
|
|
15
|
+
type: Number,
|
|
16
|
+
value: 0,
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
|
|
20
|
+
data: {
|
|
21
|
+
current: 0, // 当前显示图片索引
|
|
22
|
+
startX: 0, // 手势开始X坐标
|
|
23
|
+
isSwiping: false, // 是否正在滑动
|
|
24
|
+
},
|
|
25
|
+
|
|
26
|
+
observers: {
|
|
27
|
+
images: function (newVal) {
|
|
28
|
+
this.setData({
|
|
29
|
+
current: 0,
|
|
30
|
+
});
|
|
31
|
+
},
|
|
32
|
+
currentIndex: function (newVal) {
|
|
33
|
+
this.setData({
|
|
34
|
+
current: newVal,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
|
|
39
|
+
methods: {
|
|
40
|
+
// 图片加载完成
|
|
41
|
+
onImageLoad(e) {
|
|
42
|
+
this.triggerEvent('imageload', e.detail);
|
|
43
|
+
},
|
|
44
|
+
|
|
45
|
+
// 点击图片
|
|
46
|
+
onImageTap() {
|
|
47
|
+
this.triggerEvent('imagetap');
|
|
48
|
+
},
|
|
49
|
+
|
|
50
|
+
// 切换上一张
|
|
51
|
+
onPrev(e) {
|
|
52
|
+
if (this.data.current > 0) {
|
|
53
|
+
const newIndex = this.data.current - 1;
|
|
54
|
+
this.setData({
|
|
55
|
+
current: newIndex,
|
|
56
|
+
});
|
|
57
|
+
console.log('hadel prev', newIndex);
|
|
58
|
+
this.triggerEvent('change', { current: newIndex });
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
|
|
62
|
+
// 切换下一张
|
|
63
|
+
onNext(e) {
|
|
64
|
+
if (this.data.current < this.data.images.length - 1) {
|
|
65
|
+
const newIndex = this.data.current + 1;
|
|
66
|
+
this.setData({
|
|
67
|
+
current: newIndex,
|
|
68
|
+
});
|
|
69
|
+
console.log('hadel next', newIndex);
|
|
70
|
+
this.triggerEvent('change', { current: newIndex });
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
|
|
74
|
+
// swiper切换事件
|
|
75
|
+
onSwiperChange(e) {
|
|
76
|
+
const newIndex = e.detail.current;
|
|
77
|
+
this.setData({
|
|
78
|
+
current: newIndex,
|
|
79
|
+
});
|
|
80
|
+
this.triggerEvent('change', { current: newIndex });
|
|
81
|
+
},
|
|
82
|
+
|
|
83
|
+
// 动画结束事件
|
|
84
|
+
onAnimationFinish(e) {
|
|
85
|
+
this.setData({
|
|
86
|
+
isSwiping: false,
|
|
87
|
+
});
|
|
88
|
+
},
|
|
89
|
+
|
|
90
|
+
// 关闭预览
|
|
91
|
+
onClose() {
|
|
92
|
+
this.triggerEvent('close');
|
|
93
|
+
},
|
|
94
|
+
|
|
95
|
+
// 外部调用方法:打开预览
|
|
96
|
+
open(images, index = 0) {
|
|
97
|
+
this.setData({
|
|
98
|
+
show: true,
|
|
99
|
+
images: images,
|
|
100
|
+
current: index,
|
|
101
|
+
});
|
|
102
|
+
},
|
|
103
|
+
|
|
104
|
+
// 外部调用方法:关闭预览
|
|
105
|
+
close() {
|
|
106
|
+
this.setData({
|
|
107
|
+
show: false,
|
|
108
|
+
});
|
|
109
|
+
},
|
|
110
|
+
},
|
|
111
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
<view wx:if="{{show}}">
|
|
2
|
+
<view class="preview-container" bindtap="onClose">
|
|
3
|
+
<!-- 顶部指示器 -->
|
|
4
|
+
<view class="indicator">{{current + 1}}/{{images.length}}</view>
|
|
5
|
+
<!-- 图片滑动区域 -->
|
|
6
|
+
<swiper class="image-swiper" current="{{current}}" duration="300" bindchange="onSwiperChange" bindanimationfinish="onAnimationFinish">
|
|
7
|
+
<block wx:for="{{images}}" wx:key="*this">
|
|
8
|
+
<swiper-item>
|
|
9
|
+
<view class="image-container">
|
|
10
|
+
<image class="preview-image" src="{{item}}" mode="widthFix" bindload="onImageLoad" bindtap="onImageTap" />
|
|
11
|
+
</view>
|
|
12
|
+
</swiper-item>
|
|
13
|
+
</block>
|
|
14
|
+
</swiper>
|
|
15
|
+
<!-- 左右箭头导航 -->
|
|
16
|
+
<view class="nav-arrow left-arrow" catch:tap="onPrev" wx:if="{{current > 0}}">
|
|
17
|
+
<image class="arrow-icon" src="https://img.tanjiu.cn/home/P2EQ2zaa5izYWX8W7F2TfnnxxX2ByiKD.png" mode="aspectFit" />
|
|
18
|
+
</view>
|
|
19
|
+
<view class="nav-arrow right-arrow" catch:tap="onNext" wx:if="{{current < images.length - 1}}">
|
|
20
|
+
<image class="arrow-icon" src="https://img.tanjiu.cn/home/kNny7B8ymAdta2fWSEkPysZHfRWXSjHA.png" mode="aspectFit" />
|
|
21
|
+
</view>
|
|
22
|
+
<!-- 关闭按钮 -->
|
|
23
|
+
<view class="close-btn" catch:tap="onClose"></view>
|
|
24
|
+
</view>
|
|
25
|
+
</view>
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
.preview-container {
|
|
2
|
+
position: fixed;
|
|
3
|
+
top: 0;
|
|
4
|
+
left: 0;
|
|
5
|
+
right: 0;
|
|
6
|
+
bottom: 0;
|
|
7
|
+
background-color: rgba(0, 0, 0, 0.9);
|
|
8
|
+
z-index: 99;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
.indicator {
|
|
12
|
+
position: absolute;
|
|
13
|
+
top: 148rpx;
|
|
14
|
+
left: 0;
|
|
15
|
+
right: 0;
|
|
16
|
+
text-align: center;
|
|
17
|
+
color: #fff;
|
|
18
|
+
font-size: 32rpx;
|
|
19
|
+
z-index: 100;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
.image-swiper {
|
|
23
|
+
width: 100%;
|
|
24
|
+
height: 100%;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
.image-container {
|
|
28
|
+
width: 100%;
|
|
29
|
+
height: 100%;
|
|
30
|
+
display: flex;
|
|
31
|
+
justify-content: center;
|
|
32
|
+
align-items: center;
|
|
33
|
+
overflow: hidden;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
.preview-image {
|
|
37
|
+
width: 100%;
|
|
38
|
+
display: block;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
.nav-arrow {
|
|
42
|
+
position: absolute;
|
|
43
|
+
top: 50%;
|
|
44
|
+
transform: translateY(-50%);
|
|
45
|
+
width: 80rpx;
|
|
46
|
+
height: 80rpx;
|
|
47
|
+
z-index: 100;
|
|
48
|
+
display: flex;
|
|
49
|
+
align-items: center;
|
|
50
|
+
justify-content: center;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
.left-arrow {
|
|
54
|
+
left: 20rpx;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
.right-arrow {
|
|
58
|
+
right: 20rpx;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
.arrow-icon {
|
|
62
|
+
width: 56rpx;
|
|
63
|
+
height: 56rpx;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
.close-btn {
|
|
67
|
+
position: absolute;
|
|
68
|
+
bottom: 148rpx;
|
|
69
|
+
left: 50%;
|
|
70
|
+
transform: translateX(-50%);
|
|
71
|
+
background-image: url("https://img.tanjiu.cn/home/mZ2k3nw6FMc5besY7yHW3JKibXi7Ehmh.png");
|
|
72
|
+
background-size: cover;
|
|
73
|
+
width: 80rpx;
|
|
74
|
+
height: 80rpx;
|
|
75
|
+
border-radius: 40rpx;
|
|
76
|
+
display: flex;
|
|
77
|
+
justify-content: center;
|
|
78
|
+
align-items: center;
|
|
79
|
+
color: #fff;
|
|
80
|
+
font-size: 32rpx;
|
|
81
|
+
z-index: 100;
|
|
82
|
+
}
|