sadais-piui 1.2.6-beta1 → 1.2.6-beta4

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