sadais-piui 1.2.7-beta137 → 1.2.7-beta139

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.
@@ -1,247 +1,260 @@
1
- <template>
2
- <pi-popup-select
3
- :value="val"
4
- :custom-style="getPopupSelect.customStyle"
5
- :custom-class="getPopupSelect.customClass"
6
- :height="getPopupSelect.height"
7
- :show-title="getPopupSelect.showTitle"
8
- :title="getPopupSelect.title"
9
- :title-padding="getPopupSelect.titlePadding"
10
- :toolbar-position="getPopupSelect.toolbarPosition"
11
- :on-confirm-close="getPopupSelect.onConfirmClose"
12
- :on-cancel-close="getPopupSelect.onCancelClose"
13
- :confirm-btn="getPopupSelect.confirmBtn"
14
- :cancel-btn="getPopupSelect.cancelBtn"
15
- :popup="getPopup"
16
- @close="handlePopupClose"
17
- @cancel="handleCancel"
18
- @confirm="handleConfirm"
19
- >
20
- <slot name="header" />
21
- <!-- 描述列 -->
22
- <view
23
- v-if="description"
24
- class="pi-solid-bottom-2 pi-align-center pi-pd-32 pi-light-gray"
25
- :style="[getItemAlignStyle]"
26
- >
27
- {{ description }}
28
- </view>
29
- <view
30
- v-for="item in items"
31
- :id="`id-${item[keyField]}`"
32
- :key="item[keyField]"
33
- :style="[itemStyle, getItemStyle, getItemAlignStyle, { color: item.color }]"
34
- :class="{
35
- 'pi-solid-bottom-1': showItemBottomBorder,
36
- 'pi-disabled': item.disabled
37
- }"
38
- class="pi-align-center pi-fz-30 pi-pd-lr-32"
39
- hover-class="pi-hover-class"
40
- @tap.stop="handleSelectItem(item)"
41
- >
42
- <!-- 自定义列表项 -->
43
- <slot name="item" :item="item" class="pi-w-100P">
44
- <template v-if="!item.loading">
45
- {{ item[displayField] }}
46
- </template>
47
- <pi-loading v-else show />
48
- </slot>
49
- </view>
50
- <!-- 取消action -->
51
- <template v-if="cancelText">
52
- <pi-gap height="20" />
53
- <view
54
- class="pi-align-center pi-fz-30 pi-pd-32 pi-light-gray"
55
- hover-class="pi-hover-class"
56
- :style="[getItemAlignStyle]"
57
- @tap="handleCancel"
58
- >
59
- {{ cancelText }}
60
- </view>
61
- </template>
62
-
63
- <slot name="footer" />
64
- </pi-popup-select>
65
- </template>
66
-
67
- <script>
68
- import ValueSync from '../../mixin/value-sync'
69
- import { getConfig } from '../../config'
70
-
71
- const TAG = 'PiActionSheet'
72
- const { actionSheet } = getConfig()
73
-
74
- const alignFlexMap = {
75
- left: 'flex-start',
76
- center: 'center',
77
- right: 'flex-end'
78
- }
79
-
80
- export default {
81
- name: 'PiActionSheet',
82
- // 混入v-model
83
- mixins: [ValueSync],
84
- props: {
85
- // 初始值
86
- value: {
87
- required: false
88
- },
89
- // 自定义样式
90
- customStyle: {
91
- type: Object,
92
- // {}
93
- default() {
94
- return actionSheet.customStyle
95
- }
96
- },
97
- // 自定义样式类
98
- customClass: {
99
- type: String,
100
- // ''
101
- default() {
102
- return actionSheet.customClass
103
- }
104
- },
105
- // 选项列表
106
- items: {
107
- type: Array,
108
- // []
109
- default() {
110
- return actionSheet.items
111
- }
112
- },
113
- // 选项id字段
114
- keyField: {
115
- type: String,
116
- // 'id'
117
- default: actionSheet.keyField
118
- },
119
- // 选项显示字段
120
- displayField: {
121
- type: String,
122
- // 'text'
123
- default: actionSheet.displayField
124
- },
125
- // 自定义多列联动模式的children属性名
126
- childField: {
127
- type: String,
128
- // 'children'
129
- default: actionSheet.childField
130
- },
131
- // 行高 单位默认rpx
132
- itemHeight: {
133
- type: [String, Number],
134
- // 110
135
- default: actionSheet.itemHeight
136
- },
137
- // 是否显示item下边框
138
- showItemBottomBorder: {
139
- type: Boolean,
140
- // true
141
- default: actionSheet.showItemBottomBorder
142
- },
143
- // 行样式
144
- itemStyle: {
145
- type: Object,
146
- // {}
147
- default() {
148
- return actionSheet.itemStyle
149
- }
150
- },
151
- itemAlign: {
152
- type: String,
153
- // 'center'
154
- default: actionSheet.itemAlign,
155
- validator: function(value) {
156
- return ['left', 'center', 'right'].includes(value)
157
- }
158
- },
159
- // 弹窗选择参数设置
160
- popupSelect: {
161
- type: Object,
162
- default() {
163
- // 参照popup
164
- return actionSheet.popupSelect
165
- }
166
- },
167
- // 弹窗参数设置
168
- popup: {
169
- type: Object,
170
- default() {
171
- // 参照popup
172
- return actionSheet.popup
173
- }
174
- },
175
- // 选项上方的描述信息,不填则不显示
176
- description: {
177
- type: String,
178
- // ''
179
- default: actionSheet.description
180
- },
181
- // 取消按钮文字,不填则不显示
182
- cancelText: {
183
- type: String,
184
- // ''
185
- default: actionSheet.cancelText
186
- }
187
- },
188
- data() {
189
- return {}
190
- },
191
- computed: {
192
- getPopupSelect() {
193
- return this.$pi.lang.mergeDeep(actionSheet.popupSelect, this.popupSelect)
194
- },
195
- getPopup() {
196
- const actionSheetPopup = this.$pi.lang.mergeDeep(actionSheet.popup, this.popupSelect.popup)
197
- return this.$pi.lang.mergeDeep(actionSheetPopup, this.popup)
198
- },
199
- getItemAlignStyle() {
200
- return {
201
- justifyContent: alignFlexMap[this.itemAlign]
202
- }
203
- },
204
- getItemStyle() {
205
- const itemHeight = this.$pi.common.addUnit(this.itemHeight)
206
- return {
207
- height: itemHeight,
208
- lineHeight: itemHeight
209
- }
210
- },
211
- indicatorStyle() {
212
- const itemHeight = uni.upx2px(this.itemHeight)
213
- return `height: ${itemHeight}px;line-height: ${itemHeight}px;`
214
- }
215
- },
216
- methods: {
217
- handlePopupClose() {
218
- this.val = false
219
- // 弹窗关闭
220
- this.$emit('close')
221
- this.handleEmitChange()
222
- },
223
- /**
224
- * @vuese
225
- * 取消选择
226
- */
227
- handleCancel() {
228
- this.$emit('cancel')
229
- this.getPopupSelect.onConfirmClose && this.handlePopupClose()
230
- },
231
- /**
232
- * @vuese
233
- * 确认选择
234
- */
235
- handleSelectItem(item) {
236
- if (item.disabled) return
237
- this.$emit('select', item)
238
- this.getPopupSelect.onConfirmClose && this.handlePopupClose()
239
- }
240
- }
241
- }
242
- </script>
243
-
244
- <style lang="scss" scoped>
245
- .pi-action-sheet {
246
- }
247
- </style>
1
+ <template>
2
+ <pi-popup-select
3
+ :value="val"
4
+ :custom-style="getPopupSelect.customStyle"
5
+ :custom-class="getPopupSelect.customClass"
6
+ :height="getPopupSelect.height"
7
+ :show-title="getPopupSelect.showTitle"
8
+ :title="getPopupSelect.title"
9
+ :title-padding="getPopupSelect.titlePadding"
10
+ :toolbar-position="getPopupSelect.toolbarPosition"
11
+ :on-confirm-close="getPopupSelect.onConfirmClose"
12
+ :on-cancel-close="getPopupSelect.onCancelClose"
13
+ :confirm-btn="getPopupSelect.confirmBtn"
14
+ :cancel-btn="getPopupSelect.cancelBtn"
15
+ :popup="getPopup"
16
+ @close="handlePopupClose"
17
+ @cancel="handleCancel"
18
+ @confirm="handleConfirm"
19
+ >
20
+ <slot name="header" />
21
+ <!-- 描述列 -->
22
+ <view
23
+ v-if="description"
24
+ class="pi-solid-bottom-2 pi-align-center pi-pd-32 pi-light-gray"
25
+ :style="[getItemAlignStyle]"
26
+ >
27
+ {{ description }}
28
+ </view>
29
+ <view
30
+ v-for="item in items"
31
+ :id="`id-${item[keyField]}`"
32
+ :key="item[keyField]"
33
+ :style="[
34
+ itemStyle,
35
+ getItemStyle,
36
+ getItemAlignStyle,
37
+ { color: item.color }
38
+ ]"
39
+ :class="{
40
+ 'pi-solid-bottom-1': showItemBottomBorder,
41
+ 'pi-disabled': item.disabled
42
+ }"
43
+ class="pi-align-center pi-fz-30 pi-pd-lr-32"
44
+ hover-class="pi-hover-class"
45
+ @tap.stop="handleSelectItem(item)"
46
+ >
47
+ <!-- 自定义列表项 -->
48
+ <slot name="item" :item="item" class="pi-w-100P">
49
+ <template v-if="!item.loading">
50
+ {{ item[displayField] }}
51
+ </template>
52
+ <pi-loading v-else show />
53
+ </slot>
54
+ </view>
55
+ <!-- 取消action -->
56
+ <template v-if="cancelText">
57
+ <pi-gap height="20" />
58
+ <view
59
+ class="pi-align-center pi-fz-30 pi-pd-32 pi-light-gray"
60
+ hover-class="pi-hover-class"
61
+ :style="[getItemAlignStyle]"
62
+ @tap="handleCancel"
63
+ >
64
+ {{ cancelText }}
65
+ </view>
66
+ </template>
67
+
68
+ <slot name="footer" />
69
+ </pi-popup-select>
70
+ </template>
71
+
72
+ <script>
73
+ import ValueSync from '../../mixin/value-sync'
74
+ import { getConfig } from '../../config'
75
+
76
+ const TAG = 'PiActionSheet'
77
+ const { actionSheet } = getConfig()
78
+
79
+ const alignFlexMap = {
80
+ left: 'flex-start',
81
+ center: 'center',
82
+ right: 'flex-end'
83
+ }
84
+
85
+ export default {
86
+ name: 'PiActionSheet',
87
+ // 混入v-model
88
+ mixins: [ValueSync],
89
+ props: {
90
+ // 初始值
91
+ value: {
92
+ required: false
93
+ },
94
+ // 自定义样式
95
+ customStyle: {
96
+ type: Object,
97
+ // {}
98
+ default() {
99
+ return actionSheet.customStyle
100
+ }
101
+ },
102
+ // 自定义样式类
103
+ customClass: {
104
+ type: String,
105
+ // ''
106
+ default() {
107
+ return actionSheet.customClass
108
+ }
109
+ },
110
+ // 选项列表
111
+ items: {
112
+ type: Array,
113
+ // []
114
+ default() {
115
+ return actionSheet.items
116
+ }
117
+ },
118
+ // 选项id字段
119
+ keyField: {
120
+ type: String,
121
+ // 'id'
122
+ default: actionSheet.keyField
123
+ },
124
+ // 选项显示字段
125
+ displayField: {
126
+ type: String,
127
+ // 'text'
128
+ default: actionSheet.displayField
129
+ },
130
+ // 自定义多列联动模式的children属性名
131
+ childField: {
132
+ type: String,
133
+ // 'children'
134
+ default: actionSheet.childField
135
+ },
136
+ // 行高 单位默认rpx
137
+ itemHeight: {
138
+ type: [String, Number],
139
+ // 110
140
+ default: actionSheet.itemHeight
141
+ },
142
+ // 是否显示item下边框
143
+ showItemBottomBorder: {
144
+ type: Boolean,
145
+ // true
146
+ default: actionSheet.showItemBottomBorder
147
+ },
148
+ // 行样式
149
+ itemStyle: {
150
+ type: Object,
151
+ // {}
152
+ default() {
153
+ return actionSheet.itemStyle
154
+ }
155
+ },
156
+ itemAlign: {
157
+ type: String,
158
+ // 'center'
159
+ default: actionSheet.itemAlign,
160
+ validator: function(value) {
161
+ return ['left', 'center', 'right'].includes(value)
162
+ }
163
+ },
164
+ // 弹窗选择参数设置
165
+ popupSelect: {
166
+ type: Object,
167
+ default() {
168
+ // 参照popup
169
+ return actionSheet.popupSelect
170
+ }
171
+ },
172
+ // 弹窗参数设置
173
+ popup: {
174
+ type: Object,
175
+ default() {
176
+ // 参照popup
177
+ return actionSheet.popup
178
+ }
179
+ },
180
+ // 选项上方的描述信息,不填则不显示
181
+ description: {
182
+ type: String,
183
+ // ''
184
+ default: actionSheet.description
185
+ },
186
+ // 取消按钮文字,不填则不显示
187
+ cancelText: {
188
+ type: String,
189
+ // ''
190
+ default: actionSheet.cancelText
191
+ }
192
+ },
193
+ data() {
194
+ return {}
195
+ },
196
+ computed: {
197
+ getPopupSelect() {
198
+ return this.$pi.lang.mergeDeep(actionSheet.popupSelect, this.popupSelect)
199
+ },
200
+ getPopup() {
201
+ const actionSheetPopup = this.$pi.lang.mergeDeep(
202
+ actionSheet.popup,
203
+ this.popupSelect.popup
204
+ )
205
+ return this.$pi.lang.mergeDeep(actionSheetPopup, this.popup)
206
+ },
207
+ getItemAlignStyle() {
208
+ return {
209
+ justifyContent: alignFlexMap[this.itemAlign]
210
+ }
211
+ },
212
+ getItemStyle() {
213
+ const itemHeight = this.$pi.common.addUnit(this.itemHeight)
214
+ return {
215
+ height: itemHeight,
216
+ lineHeight: itemHeight
217
+ }
218
+ },
219
+ indicatorStyle() {
220
+ const itemHeight = uni.upx2px(this.itemHeight)
221
+ return `height: ${itemHeight}px;line-height: ${itemHeight}px;`
222
+ }
223
+ },
224
+ methods: {
225
+ handlePopupClose() {
226
+ this.val = false
227
+ // 弹窗关闭
228
+ this.$emit('close')
229
+ this.handleEmitChange()
230
+ },
231
+ /**
232
+ * @vuese
233
+ * 取消选择
234
+ */
235
+ handleCancel() {
236
+ this.$emit('cancel')
237
+ this.getPopupSelect.onCancelClose && this.handlePopupClose()
238
+ },
239
+ /**
240
+ * @vuese
241
+ * 确认选择
242
+ */
243
+ handleConfirm() {
244
+ this.$emit('confirm')
245
+ this.getPopupSelect.onConfirmClose && this.handlePopupClose()
246
+ },
247
+ /**
248
+ * @vuese
249
+ * 确认选择
250
+ */
251
+ handleSelectItem(item) {
252
+ if (item.disabled) return
253
+ this.$emit('select', item)
254
+ this.getPopupSelect.onConfirmClose && this.handlePopupClose()
255
+ }
256
+ }
257
+ }
258
+ </script>
259
+
260
+ <style lang="scss" scoped></style>
@@ -27,6 +27,7 @@
27
27
  :focus="focus"
28
28
  :disabled="getDisabled"
29
29
  :confirm-hold="confirmHold"
30
+ :confirm-type="confirmType"
30
31
  :cursor="cursor"
31
32
  :selection-start="selectionStart"
32
33
  :selection-end="selectionEnd"
@@ -60,6 +61,7 @@
60
61
  :focus="focus"
61
62
  :disabled="getDisabled"
62
63
  :confirm-hold="confirmHold"
64
+ :confirm-type="confirmType"
63
65
  :cursor="cursor"
64
66
  :selection-start="selectionStart"
65
67
  :selection-end="selectionEnd"
@@ -1,317 +1,332 @@
1
- <template>
2
- <pi-popup-select
3
- :value="val"
4
- :custom-style="getPopupSelect.customStyle"
5
- :custom-class="getPopupSelect.customClass"
6
- :height="getPopupSelect.height"
7
- :show-title="getPopupSelect.showTitle"
8
- :title="getPopupSelect.title"
9
- :title-padding="getPopupSelect.titlePadding"
10
- :toolbar-position="getPopupSelect.toolbarPosition"
11
- :on-confirm-close="getPopupSelect.onConfirmClose"
12
- :on-cancel-close="getPopupSelect.onCancelClose"
13
- :confirm-btn="getConfirmBtn"
14
- :cancel-btn="getCancelBtn"
15
- :popup="getPopup"
16
- @close="handlePopupClose"
17
- @cancel="handleCancel"
18
- @confirm="handleConfirm"
19
- >
20
- <slot name="header" />
21
- <picker-view
22
- v-if="val"
23
- class="pi-text-center pi-h-100P"
24
- :style="[customStyle]"
25
- :class="[customClass]"
26
- :indicator-style="indicatorStyle"
27
- :value="pickerValue"
28
- @pickstart="handlePickstart"
29
- @pickend="handlePickend"
30
- @change="handlePickerChange"
31
- >
32
- <picker-view-column v-for="(column, index) in columns" :key="index">
33
- <view v-for="item in column" :key="item[keyField]" :style="indicatorStyle">
34
- {{ item[displayField] }}
35
- </view>
36
- </picker-view-column>
37
- </picker-view>
38
- <slot name="footer" />
39
- </pi-popup-select>
40
- </template>
41
-
42
- <script>
43
- import ValueSync from '../../mixin/value-sync'
44
- import { getConfig } from '../../config'
45
-
46
- const TAG = 'PiPicker'
47
- const { picker } = getConfig()
48
-
49
- /**
50
- * 注意: default-value数组的长度,必须与列数相同,否则无效。
51
- * 单列模式 如设置default-value为[1]表示默认选中第2个(从0开始),[5]表示选中第6个。
52
- * 多列模式 如设置default-value为[1, 3]表示第一列默认选中第2个,第二列默认选中第4个。
53
- */
54
- export default {
55
- name: 'PiPicker',
56
- // 混入v-model
57
- mixins: [ValueSync],
58
- props: {
59
- // 初始值
60
- value: {
61
- required: false
62
- },
63
- // 自定义样式
64
- customStyle: {
65
- type: Object,
66
- // {}
67
- default() {
68
- return picker.customStyle
69
- }
70
- },
71
- // 自定义样式类
72
- customClass: {
73
- type: String,
74
- // ''
75
- default() {
76
- return picker.customClass
77
- }
78
- },
79
- // 选项列表
80
- items: {
81
- type: Array,
82
- // []
83
- default() {
84
- return picker.items
85
- }
86
- },
87
- // 选项id字段
88
- keyField: {
89
- type: String,
90
- // 'id'
91
- default: picker.keyField
92
- },
93
- // 选项显示字段
94
- displayField: {
95
- type: String,
96
- // 'text'
97
- default: picker.displayField
98
- },
99
- // 自定义多列联动模式的children属性名
100
- childField: {
101
- type: String,
102
- // 'children'
103
- default: picker.childField
104
- },
105
- // 默认值,单选是传Object,多选时传Array
106
- defaultValue: {
107
- type: Array,
108
- // null
109
- default: picker.defaultValue
110
- },
111
- // 选择器类型
112
- type: {
113
- // 'single', 'multi', 'multi-auto'
114
- type: String,
115
- // 'single'
116
- default: picker.type,
117
- validator: function(value) {
118
- return ['single', 'multi', 'multi-auto'].includes(value)
119
- }
120
- },
121
- // 行高 单位默认rpx
122
- itemHeight: {
123
- type: [String, Number],
124
- // 110
125
- default: picker.itemHeight
126
- },
127
- // 是否显示item下边框
128
- showItemBottomBorder: {
129
- type: Boolean,
130
- // true
131
- default: picker.showItemBottomBorder
132
- },
133
- // 行样式
134
- itemStyle: {
135
- type: Object,
136
- // {}
137
- default() {
138
- return picker.itemStyle
139
- }
140
- },
141
- // 弹窗选择参数设置
142
- popupSelect: {
143
- type: Object,
144
- default() {
145
- // 参照popup
146
- return picker.popupSelect
147
- }
148
- },
149
- // 确认按钮配置
150
- confirmBtn: {
151
- type: Object,
152
- default() {
153
- return picker.confirmBtn
154
- }
155
- },
156
- // 取消按钮配置
157
- cancelBtn: {
158
- type: Object,
159
- default() {
160
- return picker.cancelBtn
161
- }
162
- },
163
- // 弹窗参数设置
164
- popup: {
165
- type: Object,
166
- default() {
167
- // 参照popup
168
- return picker.popup
169
- }
170
- }
171
- },
172
- data() {
173
- return {
174
- pickerValue: [],
175
- scrolling: false // picker是否在滚动中,小程序在scrolling中点确定,选择的项目不正确
176
- }
177
- },
178
- computed: {
179
- getPopupSelect() {
180
- return this.$pi.lang.mergeDeep(picker.popupSelect, this.popupSelect)
181
- },
182
- getConfirmBtn() {
183
- const pickerConfirmBtn = this.$pi.lang.mergeDeep(
184
- picker.confirmBtn,
185
- this.popupSelect.confirmBtn
186
- )
187
- const mergeConfirmBtn = this.$pi.lang.mergeDeep(pickerConfirmBtn, this.confirmBtn)
188
- if (!mergeConfirmBtn.disabled) {
189
- mergeConfirmBtn.disabled = this.scrolling
190
- }
191
- return mergeConfirmBtn
192
- },
193
- getCancelBtn() {
194
- const pickerCancelBtn = this.$pi.lang.mergeDeep(picker.cancelBtn, this.popupSelect.cancelBtn)
195
- return this.$pi.lang.mergeDeep(pickerCancelBtn, this.cancelBtn)
196
- },
197
- getPopup() {
198
- const pickerPopup = this.$pi.lang.mergeDeep(picker.popup, this.popupSelect.popup)
199
- return this.$pi.lang.mergeDeep(pickerPopup, this.popup)
200
- },
201
- getItemStyle() {
202
- const itemHeight = this.$pi.common.addUnit(this.itemHeight)
203
- return {
204
- height: itemHeight,
205
- lineHeight: itemHeight
206
- }
207
- },
208
- indicatorStyle() {
209
- const itemHeight = uni.upx2px(this.itemHeight)
210
- return `height: ${itemHeight}px;line-height: ${itemHeight}px;`
211
- },
212
- columns() {
213
- if (this.type === 'single') return [this.items]
214
- if (this.type === 'multi') return this.items
215
- if (this.type === 'multi-auto') {
216
- let columns = this.items
217
- return this.pickerValue.map((value, index) => {
218
- const returnValue = [...columns]
219
- const column = columns[value]
220
- if (column[this.childField] && column[this.childField].length) {
221
- columns = column[this.childField]
222
- }
223
- return returnValue
224
- })
225
- }
226
-
227
- return this.items
228
- }
229
- },
230
- watch: {
231
- value: {
232
- deep: true,
233
- immediate: true,
234
- handler(value) {
235
- // 每次弹窗显示,进行数据初始化
236
- value && this.init()
237
- }
238
- }
239
- },
240
- methods: {
241
- init() {
242
- if (this.defaultValue) {
243
- this.pickerValue = this.defaultValue
244
- } else {
245
- if (this.type === 'single') this.pickerValue = [0]
246
- if (this.type === 'multi') return (this.pickerValue = [0, 0])
247
- if (this.type === 'multi-auto') {
248
- let count = 1
249
- let column = this.items
250
- // 只要有元素并且第一个元素有children属性,继续历遍
251
- while (column[0][this.childField]) {
252
- column = column[0] ? column[0][this.childField] : {}
253
- count++
254
- }
255
- this.pickerValue = new Array(count).fill(0)
256
- }
257
- }
258
- },
259
- handlePickstart() {
260
- this.scrolling = true
261
- },
262
- // 标识滑动结束
263
- handlePickend() {
264
- this.scrolling = false
265
- },
266
- handlePopupClose() {
267
- this.val = false
268
- // 弹窗关闭
269
- this.$emit('close')
270
- this.handleEmitChange()
271
- },
272
- handlePickerChange(e) {
273
- let pickerValue = e.detail.value
274
-
275
- if (this.type === 'multi-auto') {
276
- // 如果是多列联动,pickerValue的值需要重新生成
277
- // 第几列发生变化
278
- let columnIndex = this.pickerValue.findIndex((p, i) => pickerValue[i] !== p)
279
- pickerValue = pickerValue.slice(0, columnIndex + 1)
280
- let columnValue = pickerValue[columnIndex]
281
- let columns = this.columns[columnIndex]
282
- let column = columns[columnValue]
283
- while (column[this.childField]) {
284
- columns = column[this.childField]
285
- column = columns[0]
286
- columnIndex++
287
- pickerValue[columnIndex] = 0
288
- }
289
- }
290
- this.pickerValue = pickerValue
291
- },
292
- /**
293
- * @vuese
294
- * 取消选择
295
- */
296
- handleCancel() {
297
- this.$emit('cancel')
298
- this.onCancelClose && this.handlePopupClose()
299
- },
300
- /**
301
- * @vuese
302
- * 确认选择
303
- */
304
- handleConfirm() {
305
- if (this.scrolling) return
306
- this.$emit('confirm', this.pickerValue)
307
- this.onConfirmClose && this.handlePopupClose()
308
- }
309
- }
310
- }
311
- </script>
312
-
313
- <style lang="scss" scoped>
314
- .pi-picker {
315
- height: 50vh;
316
- }
317
- </style>
1
+ <template>
2
+ <pi-popup-select
3
+ :value="val"
4
+ :custom-style="getPopupSelect.customStyle"
5
+ :custom-class="getPopupSelect.customClass"
6
+ :height="getPopupSelect.height"
7
+ :show-title="getPopupSelect.showTitle"
8
+ :title="getPopupSelect.title"
9
+ :title-padding="getPopupSelect.titlePadding"
10
+ :toolbar-position="getPopupSelect.toolbarPosition"
11
+ :on-confirm-close="getPopupSelect.onConfirmClose"
12
+ :on-cancel-close="getPopupSelect.onCancelClose"
13
+ :confirm-btn="getConfirmBtn"
14
+ :cancel-btn="getCancelBtn"
15
+ :popup="getPopup"
16
+ @close="handlePopupClose"
17
+ @cancel="handleCancel"
18
+ @confirm="handleConfirm"
19
+ >
20
+ <slot name="header" />
21
+ <picker-view
22
+ v-if="val"
23
+ class="pi-text-center pi-h-100P"
24
+ :style="[customStyle]"
25
+ :class="[customClass]"
26
+ :indicator-style="indicatorStyle"
27
+ :value="pickerValue"
28
+ @pickstart="handlePickstart"
29
+ @pickend="handlePickend"
30
+ @change="handlePickerChange"
31
+ >
32
+ <picker-view-column v-for="(column, index) in columns" :key="index">
33
+ <view
34
+ v-for="item in column"
35
+ :key="item[keyField]"
36
+ :style="indicatorStyle"
37
+ >
38
+ {{ item[displayField] }}
39
+ </view>
40
+ </picker-view-column>
41
+ </picker-view>
42
+ <slot name="footer" />
43
+ </pi-popup-select>
44
+ </template>
45
+
46
+ <script>
47
+ import ValueSync from '../../mixin/value-sync'
48
+ import { getConfig } from '../../config'
49
+
50
+ const TAG = 'PiPicker'
51
+ const { picker } = getConfig()
52
+
53
+ /**
54
+ * 注意: default-value数组的长度,必须与列数相同,否则无效。
55
+ * 单列模式 如设置default-value为[1]表示默认选中第2个(从0开始),[5]表示选中第6个。
56
+ * 多列模式 如设置default-value为[1, 3]表示第一列默认选中第2个,第二列默认选中第4个。
57
+ */
58
+ export default {
59
+ name: 'PiPicker',
60
+ // 混入v-model
61
+ mixins: [ValueSync],
62
+ props: {
63
+ // 初始值
64
+ value: {
65
+ required: false
66
+ },
67
+ // 自定义样式
68
+ customStyle: {
69
+ type: Object,
70
+ // {}
71
+ default() {
72
+ return picker.customStyle
73
+ }
74
+ },
75
+ // 自定义样式类
76
+ customClass: {
77
+ type: String,
78
+ // ''
79
+ default() {
80
+ return picker.customClass
81
+ }
82
+ },
83
+ // 选项列表
84
+ items: {
85
+ type: Array,
86
+ // []
87
+ default() {
88
+ return picker.items
89
+ }
90
+ },
91
+ // 选项id字段
92
+ keyField: {
93
+ type: String,
94
+ // 'id'
95
+ default: picker.keyField
96
+ },
97
+ // 选项显示字段
98
+ displayField: {
99
+ type: String,
100
+ // 'text'
101
+ default: picker.displayField
102
+ },
103
+ // 自定义多列联动模式的children属性名
104
+ childField: {
105
+ type: String,
106
+ // 'children'
107
+ default: picker.childField
108
+ },
109
+ // 默认值,单选是传Object,多选时传Array
110
+ defaultValue: {
111
+ type: Array,
112
+ // null
113
+ default: picker.defaultValue
114
+ },
115
+ // 选择器类型
116
+ type: {
117
+ // 'single', 'multi', 'multi-auto'
118
+ type: String,
119
+ // 'single'
120
+ default: picker.type,
121
+ validator: function(value) {
122
+ return ['single', 'multi', 'multi-auto'].includes(value)
123
+ }
124
+ },
125
+ // 行高 单位默认rpx
126
+ itemHeight: {
127
+ type: [String, Number],
128
+ // 110
129
+ default: picker.itemHeight
130
+ },
131
+ // 是否显示item下边框
132
+ showItemBottomBorder: {
133
+ type: Boolean,
134
+ // true
135
+ default: picker.showItemBottomBorder
136
+ },
137
+ // 行样式
138
+ itemStyle: {
139
+ type: Object,
140
+ // {}
141
+ default() {
142
+ return picker.itemStyle
143
+ }
144
+ },
145
+ // 弹窗选择参数设置
146
+ popupSelect: {
147
+ type: Object,
148
+ default() {
149
+ // 参照popup
150
+ return picker.popupSelect
151
+ }
152
+ },
153
+ // 确认按钮配置
154
+ confirmBtn: {
155
+ type: Object,
156
+ default() {
157
+ return picker.confirmBtn
158
+ }
159
+ },
160
+ // 取消按钮配置
161
+ cancelBtn: {
162
+ type: Object,
163
+ default() {
164
+ return picker.cancelBtn
165
+ }
166
+ },
167
+ // 弹窗参数设置
168
+ popup: {
169
+ type: Object,
170
+ default() {
171
+ // 参照popup
172
+ return picker.popup
173
+ }
174
+ }
175
+ },
176
+ data() {
177
+ return {
178
+ pickerValue: [],
179
+ scrolling: false // picker是否在滚动中,小程序在scrolling中点确定,选择的项目不正确
180
+ }
181
+ },
182
+ computed: {
183
+ getPopupSelect() {
184
+ return this.$pi.lang.mergeDeep(picker.popupSelect, this.popupSelect)
185
+ },
186
+ getConfirmBtn() {
187
+ const pickerConfirmBtn = this.$pi.lang.mergeDeep(
188
+ picker.confirmBtn,
189
+ this.popupSelect.confirmBtn
190
+ )
191
+ const mergeConfirmBtn = this.$pi.lang.mergeDeep(
192
+ pickerConfirmBtn,
193
+ this.confirmBtn
194
+ )
195
+ if (!mergeConfirmBtn.disabled) {
196
+ mergeConfirmBtn.disabled = this.scrolling
197
+ }
198
+ return mergeConfirmBtn
199
+ },
200
+ getCancelBtn() {
201
+ const pickerCancelBtn = this.$pi.lang.mergeDeep(
202
+ picker.cancelBtn,
203
+ this.popupSelect.cancelBtn
204
+ )
205
+ return this.$pi.lang.mergeDeep(pickerCancelBtn, this.cancelBtn)
206
+ },
207
+ getPopup() {
208
+ const pickerPopup = this.$pi.lang.mergeDeep(
209
+ picker.popup,
210
+ this.popupSelect.popup
211
+ )
212
+ return this.$pi.lang.mergeDeep(pickerPopup, this.popup)
213
+ },
214
+ getItemStyle() {
215
+ const itemHeight = this.$pi.common.addUnit(this.itemHeight)
216
+ return {
217
+ height: itemHeight,
218
+ lineHeight: itemHeight
219
+ }
220
+ },
221
+ indicatorStyle() {
222
+ const itemHeight = uni.upx2px(this.itemHeight)
223
+ return `height: ${itemHeight}px;line-height: ${itemHeight}px;`
224
+ },
225
+ columns() {
226
+ if (this.type === 'single') return [this.items]
227
+ if (this.type === 'multi') return this.items
228
+ if (this.type === 'multi-auto') {
229
+ let columns = this.items
230
+ return this.pickerValue.map((value, index) => {
231
+ const returnValue = [...columns]
232
+ const column = columns[value]
233
+ if (column[this.childField] && column[this.childField].length) {
234
+ columns = column[this.childField]
235
+ }
236
+ return returnValue
237
+ })
238
+ }
239
+
240
+ return this.items
241
+ }
242
+ },
243
+ watch: {
244
+ value: {
245
+ deep: true,
246
+ immediate: true,
247
+ handler(value) {
248
+ // 每次弹窗显示,进行数据初始化
249
+ value && this.init()
250
+ }
251
+ }
252
+ },
253
+ methods: {
254
+ init() {
255
+ if (this.defaultValue) {
256
+ this.pickerValue = this.defaultValue
257
+ } else {
258
+ if (this.type === 'single') this.pickerValue = [0]
259
+ if (this.type === 'multi') return (this.pickerValue = [0, 0])
260
+ if (this.type === 'multi-auto') {
261
+ let count = 1
262
+ let column = this.items
263
+ // 只要有元素并且第一个元素有children属性,继续历遍
264
+ while (column[0][this.childField]) {
265
+ column = column[0] ? column[0][this.childField] : {}
266
+ count++
267
+ }
268
+ this.pickerValue = new Array(count).fill(0)
269
+ }
270
+ }
271
+ },
272
+ handlePickstart() {
273
+ this.scrolling = true
274
+ },
275
+ // 标识滑动结束
276
+ handlePickend() {
277
+ this.scrolling = false
278
+ },
279
+ handlePopupClose() {
280
+ this.val = false
281
+ // 弹窗关闭
282
+ this.$emit('close')
283
+ this.handleEmitChange()
284
+ },
285
+ handlePickerChange(e) {
286
+ let pickerValue = e.detail.value
287
+
288
+ if (this.type === 'multi-auto') {
289
+ // 如果是多列联动,pickerValue的值需要重新生成
290
+ // 第几列发生变化
291
+ let columnIndex = this.pickerValue.findIndex(
292
+ (p, i) => pickerValue[i] !== p
293
+ )
294
+ pickerValue = pickerValue.slice(0, columnIndex + 1)
295
+ let columnValue = pickerValue[columnIndex]
296
+ let columns = this.columns[columnIndex]
297
+ let column = columns[columnValue]
298
+ while (column[this.childField]) {
299
+ columns = column[this.childField]
300
+ column = columns[0]
301
+ columnIndex++
302
+ pickerValue[columnIndex] = 0
303
+ }
304
+ }
305
+ this.pickerValue = pickerValue
306
+ },
307
+ /**
308
+ * @vuese
309
+ * 取消选择
310
+ */
311
+ handleCancel() {
312
+ this.$emit('cancel')
313
+ this.onCancelClose && this.handlePopupClose()
314
+ },
315
+ /**
316
+ * @vuese
317
+ * 确认选择
318
+ */
319
+ handleConfirm() {
320
+ if (this.scrolling) return
321
+ this.$emit('confirm', this.pickerValue)
322
+ this.onConfirmClose && this.handlePopupClose()
323
+ }
324
+ }
325
+ }
326
+ </script>
327
+
328
+ <style lang="scss" scoped>
329
+ .pi-picker {
330
+ height: 50vh;
331
+ }
332
+ </style>
@@ -280,7 +280,7 @@ export default {
280
280
  * 确认选择
281
281
  */
282
282
  handleConfirm() {
283
- this.$emit('confirm', this.popupSelected)
283
+ this.$emit('confirm')
284
284
  this.onConfirmClose && this.handlePopupClose()
285
285
  }
286
286
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sadais-piui",
3
- "version": "1.2.7-beta137",
3
+ "version": "1.2.7-beta139",
4
4
  "description": "piui组件库",
5
5
  "main": "index.js",
6
6
  "scripts": {