sadais-piui 1.2.6-beta1 → 1.2.6-beta2

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.
@@ -29,8 +29,10 @@ export default {
29
29
  'labelWidth',
30
30
  'labelAlign',
31
31
  'labelStyle',
32
+ 'itemVerticalAlign',
32
33
  'inputAlign',
33
34
  'wrap',
35
+ 'wrapBottomGap',
34
36
  'labelWrapBorder',
35
37
  'colon',
36
38
  'disabled',
@@ -129,6 +131,18 @@ export default {
129
131
  return form.labelStyle
130
132
  }
131
133
  },
134
+ // 表单项垂直对齐方式,可选值为 top center bottom
135
+ itemVerticalAlign: {
136
+ // `'top'` `'center'` `'bottom'`
137
+ type: String,
138
+ // 'center'
139
+ default() {
140
+ return form.itemVerticalAlign
141
+ },
142
+ validator: function(value) {
143
+ return [null, 'top', 'center', 'bottom'].includes(value)
144
+ }
145
+ },
132
146
  // 表单输入区域 label 对齐方式
133
147
  inputAlign: {
134
148
  // `'left'` `'center'` `'right'`
@@ -147,6 +161,12 @@ export default {
147
161
  // null
148
162
  default: form.wrap
149
163
  },
164
+ // wrap模式下是否在底部增加表单项之间的间距
165
+ wrapBottomGap: {
166
+ type: Boolean,
167
+ // null
168
+ default: form.wrapBottomGap
169
+ },
150
170
  // wrap样式label是否显示边框
151
171
  labelWrapBorder: {
152
172
  type: Boolean,
@@ -6,6 +6,7 @@
6
6
  { disabled: getDisabled },
7
7
  { border: getBorder },
8
8
  { 'pi-align-center': !getWrap },
9
+ getFormItemClass,
9
10
  customClass
10
11
  ]"
11
12
  @tap="handleItemClick"
@@ -13,7 +14,7 @@
13
14
  <!-- 表单标题 -->
14
15
  <view
15
16
  v-if="label || $slots.label"
16
- class="form-label pi-align-start pi-flex-nowrap"
17
+ class="form-label pi-pd-tb-8 pi-align-start pi-flex-nowrap"
17
18
  :style="[computedLabelStyle, getLabelStyle]"
18
19
  :class="[{ border: getWrap && getLabelWrapBorder }]"
19
20
  >
@@ -30,7 +31,11 @@
30
31
  <!-- 内容区域 -->
31
32
  <view
32
33
  class="content-wrap"
33
- :class="[{ 'pi-flex-sub': !getWrap }, getInputAlign, { wrap: getWrap, nowrap: !getWrap }]"
34
+ :class="[
35
+ { 'pi-flex-sub': !getWrap },
36
+ getInputAlign,
37
+ { 'wrap': getWrap, 'nowrap': !getWrap, 'wrap-bottom': getWrap && getWrapBottomGap }
38
+ ]"
34
39
  :style="[contentWrapStyle]"
35
40
  >
36
41
  <view
@@ -86,6 +91,12 @@ const alignFlexMap = {
86
91
  right: 'flex-end'
87
92
  }
88
93
 
94
+ const verticalAlignFlexMap = {
95
+ top: 'flex-start',
96
+ center: 'center',
97
+ bottom: 'flex-end'
98
+ }
99
+
89
100
  export default {
90
101
  name: 'PiFormItem',
91
102
  mixins: [extendPiFrom, Emitter], // 注入inheritProps
@@ -166,6 +177,18 @@ export default {
166
177
  return formItem.labelStyle
167
178
  }
168
179
  },
180
+ // 表单项垂直对齐方式,可选值为 top center bottom
181
+ itemVerticalAlign: {
182
+ // `'top'` `'center'` `'bottom'`
183
+ type: String,
184
+ // 'center'
185
+ default() {
186
+ return formItem.itemVerticalAlign
187
+ },
188
+ validator: function(value) {
189
+ return [null, 'top', 'center', 'bottom'].includes(value)
190
+ }
191
+ },
169
192
  // 表单label区域 label 对齐方式
170
193
  labelAlign: {
171
194
  // `'left'` `'center'` `'right'`
@@ -196,6 +219,12 @@ export default {
196
219
  // false
197
220
  default: formItem.wrap
198
221
  },
222
+ // wrap模式下是否在底部增加表单项之间的间距
223
+ wrapBottomGap: {
224
+ type: Boolean,
225
+ // null
226
+ default: formItem.wrapBottomGap
227
+ },
199
228
  // wrap样式label是否显示边框
200
229
  labelWrapBorder: {
201
230
  type: Boolean,
@@ -258,6 +287,9 @@ export default {
258
287
  getWrap() {
259
288
  return this.$pi.expand.getPropValue(this.inheritProps.wrap, this.wrap)
260
289
  },
290
+ getWrapBottomGap() {
291
+ return this.$pi.expand.getPropValue(this.inheritProps.wrapBottomGap, this.wrapBottomGap)
292
+ },
261
293
  getLabelWrapBorder() {
262
294
  return this.inheritProps.labelWrapBorder !== null
263
295
  ? this.inheritProps.labelWrapBorder
@@ -296,6 +328,12 @@ export default {
296
328
  getLabelStyle() {
297
329
  return this.$pi.expand.getPropValue(this.inheritProps.labelStyle, this.labelStyle)
298
330
  },
331
+ getItemVerticalAlign() {
332
+ return this.$pi.expand.getPropValue(
333
+ this.inheritProps.itemVerticalAlign,
334
+ this.itemVerticalAlign
335
+ )
336
+ },
299
337
  computedLabelStyle() {
300
338
  const style = {}
301
339
  if (this.getWrap) {
@@ -324,6 +362,19 @@ export default {
324
362
  return {
325
363
  justifyContent: alignFlexMap[this.getInputAlign]
326
364
  }
365
+ },
366
+ getFormItemClass() {
367
+ const classList = {}
368
+ if (this.getDisabled) {
369
+ classList.disabled = true
370
+ }
371
+ if (this.getBorder) {
372
+ classList.border = true
373
+ }
374
+ if (!this.getWrap && this.getItemVerticalAlign) {
375
+ classList[verticalAlignFlexMap[this.itemVerticalAlign]] = true
376
+ }
377
+ return classList
327
378
  }
328
379
  },
329
380
  mounted() {
@@ -462,7 +513,7 @@ export default {
462
513
  &.nowrap {
463
514
  margin-left: 24rpx;
464
515
  }
465
- &.wrap {
516
+ &.wrap-bottom {
466
517
  margin-bottom: 24rpx;
467
518
  }
468
519
  .form-valid {
@@ -3,7 +3,7 @@
3
3
  class="section pi-align-center"
4
4
  :style="[itemStyle, customStyle]"
5
5
  :class="[{ border }, customClass]"
6
- @tap.stop="handleSectionClick"
6
+ @tap="handleSectionClick"
7
7
  >
8
8
  <view v-if="line" class="line" :style="[lineStyle]" />
9
9
  <!-- 左侧区域 -->
@@ -0,0 +1,382 @@
1
+ <template>
2
+ <view
3
+ ref="pi-subsection"
4
+ class="pi-subsection"
5
+ :class="[`pi-subsection--${mode}`, { round: round }, customClass]"
6
+ :style="[customStyle, wrapperStyle]"
7
+ >
8
+ <view
9
+ ref="pi-subsection__bar"
10
+ class="pi-subsection__bar"
11
+ :style="[barStyle]"
12
+ :class="[
13
+ mode === 'button' && 'pi-subsection--button__bar',
14
+ current === 0 && mode === 'subsection' && 'pi-subsection__bar--first',
15
+ current > 0 &&
16
+ current < items.length - 1 &&
17
+ mode === 'subsection' &&
18
+ 'pi-subsection__bar--center',
19
+ current === items.length - 1 && mode === 'subsection' && 'pi-subsection__bar--last'
20
+ ]"
21
+ />
22
+ <view
23
+ v-for="(item, index) in items"
24
+ :ref="`pi-subsection__item--${index}`"
25
+ :key="index"
26
+ class="pi-subsection__item"
27
+ :class="[
28
+ `pi-subsection__item--${index}`,
29
+ index < items.length - 1 && 'pi-subsection__item--no-border-right',
30
+ index === 0 && 'pi-subsection__item--first',
31
+ index === items.length - 1 && 'pi-subsection__item--last'
32
+ ]"
33
+ :style="[itemStyle(index)]"
34
+ @tap="clickHandler(index)"
35
+ >
36
+ <text class="pi-subsection__item__text" :style="[textStyle(index)]">{{ getText(item) }}</text>
37
+ </view>
38
+ </view>
39
+ </template>
40
+
41
+ <script>
42
+ // #ifdef APP-NVUE
43
+ const dom = uni.requireNativePlugin('dom')
44
+ const animation = uni.requireNativePlugin('animation')
45
+ // #endif
46
+ import { getConfig } from '../../config'
47
+ const { subsection } = getConfig()
48
+ /**
49
+ * Subsection 分段器
50
+ * @description 该分段器一般用于用户从几个选项中选择某一个的场景
51
+ * @tutorial http://piui.sadais.com/docs/components/Subsection.html
52
+ * @event {Function} change 分段器选项发生改变时触发 回调 index:选项的index索引值,从0开始
53
+ * @example <pi-subsection :items="items" :current="curNow" @change="sectionChange" />
54
+ */
55
+ export default {
56
+ name: 'PiSubsection',
57
+ props: {
58
+ // 自定义样式,对象形式
59
+ customStyle: {
60
+ type: Object,
61
+ // `{}`
62
+ default() {
63
+ return subsection.customStyle
64
+ }
65
+ },
66
+ // 自定义样式类,字符串形式
67
+ customClass: {
68
+ type: String,
69
+ // ''
70
+ default() {
71
+ return subsection.customClass
72
+ }
73
+ },
74
+ // tab的数据
75
+ items: {
76
+ type: Array,
77
+ // []
78
+ default() {
79
+ return subsection.items
80
+ }
81
+ },
82
+ // 当前活动的tab的index
83
+ current: {
84
+ type: [String, Number],
85
+ // 0
86
+ default() {
87
+ return subsection.current
88
+ }
89
+ },
90
+ // 激活时的颜色
91
+ activeColor: {
92
+ type: String,
93
+ // #5a7dff
94
+ default() {
95
+ return subsection.activeColor
96
+ }
97
+ },
98
+ // 未激活时的颜色
99
+ inactiveColor: {
100
+ type: String,
101
+ // #303133
102
+ default() {
103
+ return subsection.inactiveColor
104
+ }
105
+ },
106
+ // 模式选择,mode=button为按钮形式,mode=subsection时为分段模式
107
+ mode: {
108
+ type: String,
109
+ // button
110
+ default() {
111
+ return subsection.mode
112
+ }
113
+ },
114
+ // 圆角模式
115
+ round: {
116
+ type: Boolean,
117
+ // false
118
+ default() {
119
+ return subsection.round
120
+ }
121
+ },
122
+ // 字体大小,单位px
123
+ fontSize: {
124
+ type: [String, Number],
125
+ // 24rpx
126
+ default() {
127
+ return subsection.fontSize
128
+ }
129
+ },
130
+ // 激活选项的字体是否加粗
131
+ bold: {
132
+ type: Boolean,
133
+ // true
134
+ default() {
135
+ return subsection.bold
136
+ }
137
+ },
138
+ // 组件背景颜色,mode为button时有效
139
+ bgColor: {
140
+ type: String,
141
+ // #eeeeef
142
+ default() {
143
+ return subsection.bgColor
144
+ }
145
+ },
146
+ // 从`items`元素对象中读取的键名
147
+ keyName: {
148
+ type: String,
149
+ // name
150
+ default() {
151
+ return subsection.keyName
152
+ }
153
+ }
154
+ },
155
+ data() {
156
+ return {
157
+ // 组件尺寸
158
+ itemRect: {
159
+ width: 0,
160
+ height: 0
161
+ }
162
+ }
163
+ },
164
+ computed: {
165
+ wrapperStyle() {
166
+ const style = {}
167
+ // button模式时,设置背景色
168
+ if (this.mode === 'button') {
169
+ style.backgroundColor = this.bgColor
170
+ }
171
+ return style
172
+ },
173
+ // 滑块的样式
174
+ barStyle() {
175
+ const style = {}
176
+ style.width = `${this.itemRect.width}px`
177
+ style.height = `${this.itemRect.height}px`
178
+ // 通过translateX移动滑块,其移动的距离为索引*item的宽度
179
+ // #ifndef APP-NVUE
180
+ style.transform = `translateX(${this.current * this.itemRect.width}px)`
181
+ // #endif
182
+ if (this.mode === 'subsection') {
183
+ // 在subsection模式下,需要动态设置滑块的圆角,因为移动滑块使用的是translateX,无法通过父元素设置overflow: hidden隐藏滑块的直角
184
+ style.backgroundColor = this.activeColor
185
+ }
186
+ // 按钮圆角模式 按钮模式生效
187
+ if (this.round && this.mode === 'button') {
188
+ style.borderRadius = `${this.itemRect.height}px`
189
+ }
190
+ return style
191
+ },
192
+ // 分段器item的样式
193
+ itemStyle(index) {
194
+ return (index) => {
195
+ const style = {}
196
+ if (this.mode === 'subsection') {
197
+ // 设置border的样式
198
+ style.borderColor = this.activeColor
199
+ style.borderWidth = '2rpx'
200
+ style.borderStyle = 'solid'
201
+ if (this.round) {
202
+ if (index === 0) {
203
+ style.borderTopLeftRadius = `${this.itemRect.height}px`
204
+ style.borderBottomLeftRadius = `${this.itemRect.height}px`
205
+ } else if (index === this.items.length - 1) {
206
+ // 最后一个
207
+ style.borderTopRightRadius = `${this.itemRect.height}px`
208
+ style.borderBottomRightRadius = `${this.itemRect.height}px`
209
+ }
210
+ }
211
+ }
212
+ return style
213
+ }
214
+ },
215
+ // 分段器文字颜色
216
+ textStyle(index) {
217
+ return (index) => {
218
+ const style = {}
219
+ style.fontWeight = this.bold && this.current === index ? 'bold' : 'normal'
220
+ style.fontSize = this.$pi.common.addUnit(this.fontSize)
221
+ // subsection模式下,激活时默认为白色的文字
222
+ if (this.mode === 'subsection') {
223
+ style.color = this.current === index ? '#fff' : this.inactiveColor
224
+ } else {
225
+ // button模式下,激活时文字颜色默认为activeColor
226
+ style.color = this.current === index ? this.activeColor : this.inactiveColor
227
+ }
228
+ return style
229
+ }
230
+ }
231
+ },
232
+ watch: {
233
+ items(newValue, oldValue) {
234
+ this.init()
235
+ },
236
+ current: {
237
+ immediate: true,
238
+ handler(n) {
239
+ // #ifdef APP-NVUE
240
+ // 在安卓nvue上,如果通过translateX进行位移,到最后一个时,会导致右侧无法绘制圆角
241
+ // 故用animation模块进行位移
242
+ const ref = this.$refs?.['pi-subsection__bar']?.ref
243
+ // 不存在ref的时候(理解为第一次初始化时,需要渲染dom,进行一定延时再获取ref),这里的100ms是经过测试得出的结果(某些安卓需要延时久一点),勿随意修改
244
+ this.sleep(ref ? 0 : 100).then(() => {
245
+ animation.transition(this.$refs['pi-subsection__bar'].ref, {
246
+ styles: {
247
+ transform: `translateX(${n * this.itemRect.width}px)`,
248
+ transformOrigin: 'center center'
249
+ },
250
+ duration: 300
251
+ })
252
+ })
253
+ // #endif
254
+ }
255
+ }
256
+ },
257
+ mounted() {
258
+ this.init()
259
+ },
260
+ methods: {
261
+ init() {
262
+ this.sleep().then(() => this.getRect())
263
+ },
264
+ // 判断展示文本
265
+ getText(item) {
266
+ return typeof item === 'object' ? item[this.keyName] : item
267
+ },
268
+ // 获取组件的尺寸
269
+ getRect() {
270
+ // #ifndef APP-NVUE
271
+ this.$pi.common.queryRect(this, '.pi-subsection__item--0', false).then((size) => {
272
+ this.itemRect = size
273
+ })
274
+ // #endif
275
+ // #ifdef APP-NVUE
276
+ const ref = this.$refs['pi-subsection__item--0'][0]
277
+ ref &&
278
+ dom.getComponentRect(ref, (res) => {
279
+ this.itemRect = res.size
280
+ })
281
+ // #endif
282
+ },
283
+ /**
284
+ * @description 进行延时,以达到可以简写代码的目的
285
+ * @param {number} value 堵塞时间 单位ms 毫秒
286
+ * @returns {Promise} 返回promise
287
+ */
288
+ sleep(value = 30) {
289
+ return new Promise((resolve) => {
290
+ setTimeout(() => {
291
+ resolve()
292
+ }, value)
293
+ })
294
+ },
295
+
296
+ clickHandler(index) {
297
+ this.$emit('change', index)
298
+ }
299
+ }
300
+ }
301
+ </script>
302
+ <style lang="scss" scoped>
303
+ .pi-subsection {
304
+ display: flex;
305
+ position: relative;
306
+ overflow: hidden;
307
+ /* #ifndef APP-NVUE */
308
+ width: 100%;
309
+ box-sizing: border-box;
310
+ /* #endif */
311
+ &.round {
312
+ border-radius: 60rpx;
313
+ }
314
+ &--button {
315
+ height: 64rpx;
316
+ background-color: rgb(238, 238, 239);
317
+ padding: 6rpx;
318
+ border-radius: 6rpx;
319
+ align-items: stretch;
320
+ &__bar {
321
+ background-color: #ffffff;
322
+ border-radius: 6rpx;
323
+ }
324
+ }
325
+ &--subsection {
326
+ height: 60rpx;
327
+ }
328
+ &__bar {
329
+ position: absolute;
330
+ /* #ifndef APP-NVUE */
331
+ transition-property: transform, color;
332
+ transition-duration: 0.3s;
333
+ transition-timing-function: ease-in-out;
334
+ /* #endif */
335
+ &--first {
336
+ border-top-left-radius: 6rpx;
337
+ border-bottom-left-radius: 6rpx;
338
+ border-top-right-radius: 0px;
339
+ border-bottom-right-radius: 0px;
340
+ }
341
+ &--center {
342
+ border-top-left-radius: 0px;
343
+ border-bottom-left-radius: 0px;
344
+ border-top-right-radius: 0px;
345
+ border-bottom-right-radius: 0px;
346
+ }
347
+ &--last {
348
+ border-top-left-radius: 0px;
349
+ border-bottom-left-radius: 0px;
350
+ border-top-right-radius: 6rpx;
351
+ border-bottom-right-radius: 6rpx;
352
+ }
353
+ }
354
+ &__item {
355
+ display: flex;
356
+ flex: 1;
357
+ justify-content: center;
358
+ align-items: center;
359
+ // vue环境下,需要设置相对定位,因为滑块为绝对定位,item需要在滑块的上面
360
+ position: relative;
361
+ &--no-border-right {
362
+ border-right-width: 0 !important;
363
+ }
364
+ &--first {
365
+ border-top-left-radius: 6rpx;
366
+ border-bottom-left-radius: 6rpx;
367
+ }
368
+ &--last {
369
+ border-top-right-radius: 6rpx;
370
+ border-bottom-right-radius: 6rpx;
371
+ }
372
+ &__text {
373
+ font-size: 24rpx;
374
+ line-height: 24rpx;
375
+ display: flex;
376
+ align-items: center;
377
+ transition-property: color;
378
+ transition-duration: 0.3s;
379
+ }
380
+ }
381
+ }
382
+ </style>
package/config/form.js CHANGED
@@ -9,10 +9,12 @@ export default {
9
9
  height: 100, // 表单项高度
10
10
  padding: '32rpx', // padding
11
11
  labelWidth: 120, // 表单项 label 宽度,默认单位为rpx
12
+ itemVerticalAlign: 'center', // 表单项垂直对齐方式,可选值为 top center bottom
12
13
  labelAlign: 'left', // 表单项 label 对齐方式,可选值为 left center right
13
14
  labelStyle: {}, // 表单项 label样式
14
15
  inputAlign: 'right', // 表单输入区域 label 对齐方式,可选值为 left center right
15
16
  wrap: false, // 是否以换行样式显示表单
17
+ wrapBottomGap: false, // wrap模式下是否在底部增加表单项之间的间距
16
18
  labelWrapBorder: false, // wrap样式label是否显示边框
17
19
  colon: false, // 是否在 label 后面添加冒号
18
20
  disabled: false, // 是否禁用
@@ -8,10 +8,12 @@ export default {
8
8
  height: null, // 高度
9
9
  padding: null, // padding
10
10
  labelWidth: null, // 表单项 label 宽度,默认单位为rpx
11
+ itemVerticalAlign: null, // 表单项垂直对齐方式,可选值为 top center bottom
11
12
  labelAlign: null, // 表单项 label 对齐方式,可选值为 left center right
12
13
  labelStyle: null, // 表单项 label样式
13
14
  inputAlign: null, // 表单输入区域 label 对齐方式,可选值为 left center right
14
15
  wrap: null, // 是否以换行样式显示表单
16
+ wrapBottomGap: null, // wrap模式下是否在底部增加表单项之间的间距
15
17
  labelWrapBorder: null, // wrap样式label是否显示边框
16
18
  colon: null, // 是否在 label 后面添加冒号
17
19
  disabled: null, // 是否禁用
@@ -0,0 +1,14 @@
1
+ export default {
2
+ items: [], // tab的数据
3
+ current: 0, // 当前活动的tab的index(默认 0 )
4
+ activeColor: '#5a7dff', // 激活时的颜色(默认 '#5a7dff' )
5
+ inactiveColor: '#303133', // 未激活时的颜色(默认 '#303133' )
6
+ mode: 'button', // 模式选择,mode=button为按钮形式,mode=subsection时为分段模式(默认 'button' )
7
+ round: false, // 圆角模式 默认 false
8
+ fontSize: 24, // 字体大小,单位px(默认 24rpx )
9
+ bold: true, // 激活选项的字体是否加粗(默认 true )
10
+ bgColor: '', // 组件背景颜色,mode为button时有效(默认 '#eeeeef' )
11
+ keyName: 'name', // 从`list`元素对象中读取的键名(默认 'name' )
12
+ customClass: '', // 自定义样式类,字符串形式('')
13
+ customStyle: {} // 自定义样式,对象形式(默认值:{})
14
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sadais-piui",
3
- "version": "1.2.6beta1",
3
+ "version": "1.2.6beta2",
4
4
  "description": "piui组件库",
5
5
  "main": "index.js",
6
6
  "scripts": {