sadais-piui 1.2.4-beta9 → 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.
package/CHANGELOG.md CHANGED
@@ -1,10 +1,16 @@
1
1
  # Changelog
2
2
 
3
- <a name="1.2.3"></a>
4
- ## 1.2.3 (2022-03-26)
3
+ <a name="1.2.5"></a>
4
+ ## 1.2.5 (2022-04-25)
5
5
 
6
6
  ### Added
7
7
 
8
+ - ✨ feat: 增加pi-search的action事件返回参数 [d32d620]
9
+ - ✨ feat: 优化日期选择器,增加滚动中不可确认的功能 [8c6af79]
10
+ - ✨ feat: 增加了图片处理事件的抛出(remove,crop,cancelCrop,croped) [7ab0f42]
11
+ - ✨ feat: 图片上传组件增加uploaded事件 [fa84748]
12
+ - ✨ feat: 日历组件范围支持选择同一天 [76db20f]
13
+ - ✨ feat: 修复日历组件无法选中的问题 [9978654]
8
14
  - ✨ feat: pi-select增加single-confirm选项配置 [def559e]
9
15
  - ✨ feat: 增加pi-action-sheet组件 [bf179cd]
10
16
  - ✨ feat: 增加文字按钮类型 [767a4a6]
@@ -17,14 +23,41 @@
17
23
 
18
24
  ### Fixed
19
25
 
26
+ - 🐛 fix: 修复marquee组件在小程序异常的问题 #18 [a777efc]
27
+ - 🐛 fix: 修复跑马灯子元素宽度等于父元素宽度时候,没有动画的问题 [8ec77ab]
28
+ - 🐛 fix: 修复pi-img-crop运行时报错 [2c2490f]
29
+ - 🐛 fix: 修复某些sass版本解析报错的问题 [5f185a1]
30
+ - 🐛 fix: 修复表单height和padding设置无效的问题 [9d97100]
31
+ - 🐛 fix: 修复pi-form labelStyle设置无效的问题 [4dd8bcf]
32
+ - 🐛 fix: 修复pi-list-item标题过长无法换行的问题 [e5b18b0]
33
+ - 🐛 fix: 修复表单属性设置无效的问题 [55262eb]
34
+ - 🐛 fix: 修复日历组件不设置默认值的时候,需要手动确定才能同步日历的问题 [659e896]
35
+ - 🐛 fix: 修复日历组件设置最小时间展示全部禁用的问题 [02b1feb]
36
+ - 🐛 fix: 修复地区选择组件异步数据以及没有默认值无法正常显示的问题 [f4fa447]
20
37
  - 🐛 fix: 修复input组件keyboardheightchange方法没有声明的问题 [6d26acf]
21
38
  - 🐛 fix: 修复表单属性无法覆盖的问题 [b7308e5]
22
39
  - 🐛 fix: 修复主题颜色被覆盖的问题 [12666d2]
23
40
  - 🐛 fix: 修复pi-img缺失show-menu-by-longpress的问题 [be8a020]
24
41
 
25
- ### Miscellaneous
26
42
 
27
- - 📝 docs: 更新群二维码信息 [796040f]
43
+
44
+ <a name="1.2.3"></a>
45
+ ## 1.2.3 (2022-03-26)
46
+
47
+ ### Added
48
+
49
+ - ✨ feat: pi-select增加single-confirm选项配置 [def559e]
50
+ - ✨ feat: 增加pi-action-sheet组件 [bf179cd]
51
+ - ✨ feat: 增加文字按钮类型 [767a4a6]
52
+ - ✨ feat: pi-radio pi-radio-group 增加canCancel属性 [7874058]
53
+ - ✨ feat: 优化pi-bottom-bar下按钮显示字数 [a671bd6]
54
+
55
+ ### Fixed
56
+
57
+ - 🐛 fix: 修复input组件keyboardheightchange方法没有声明的问题 [6d26acf]
58
+ - 🐛 fix: 修复表单属性无法覆盖的问题 [b7308e5]
59
+ - 🐛 fix: 修复主题颜色被覆盖的问题 [12666d2]
60
+ - 🐛 fix: 修复pi-img缺失show-menu-by-longpress的问题 [be8a020]
28
61
 
29
62
 
30
63
  <a name="1.2.0"></a>
@@ -6,7 +6,10 @@
6
6
  :style="[dividerStyle]"
7
7
  />
8
8
  <!-- $slots.$default 是为了支持支付宝小程序 -->
9
- <view v-if="$slots.default || $slots.$default" :style="[{ padding: contentPadding }]">
9
+ <view
10
+ v-if="$slots.default || $slots.$default"
11
+ :style="[{ padding: contentPadding }, contentStyle]"
12
+ >
10
13
  <slot />
11
14
  </view>
12
15
  <view
@@ -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,14 +6,15 @@
6
6
  { disabled: getDisabled },
7
7
  { border: getBorder },
8
8
  { 'pi-align-center': !getWrap },
9
+ getFormItemClass,
9
10
  customClass
10
11
  ]"
11
- @tap.stop="handleItemClick"
12
+ @tap="handleItemClick"
12
13
  >
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() {
@@ -352,11 +403,11 @@ export default {
352
403
  this.validation('change')
353
404
  })
354
405
  },
355
- // 从u-form的rules属性中,取出当前u-form-item的校验规则
406
+ // 从pi-form的rules属性中,取出当前pi-form-item的校验规则
356
407
  getRules() {
357
408
  // 父组件的所有规则
358
- let rules = this._parent.rules
359
- rules = rules ? rules[this.prop] : []
409
+ const parentRules = this._parent ? this._parent.rules : undefined
410
+ const rules = parentRules ? parentRules[this.prop] : []
360
411
  return [].concat(rules || [])
361
412
  },
362
413
  // 过滤出符合要求的rule规则
@@ -380,7 +431,7 @@ export default {
380
431
  if (!this.prop || !rules || rules.length === 0) {
381
432
  return resolve(_getResolve())
382
433
  }
383
- const fieldValue = this._parent.model[this.prop]
434
+ const fieldValue = this._parent ? this._parent.model[this.prop] : undefined
384
435
  // 设置当前的装填,标识为校验中
385
436
  this.validateState = 'validating'
386
437
  // 调用async-validator的方法
@@ -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 {
@@ -1,5 +1,5 @@
1
1
  <template>
2
- <view class="pi-input-wrap">
2
+ <view class="pi-input-wrap" :style="[getInputWrapStyle]">
3
3
  <textarea
4
4
  v-if="type === 'textarea'"
5
5
  class="pi-input-textarea"
@@ -145,6 +145,12 @@ export default {
145
145
  // false
146
146
  default: input.disabled
147
147
  },
148
+ // 边框样式设置
149
+ border: {
150
+ type: [Boolean, String],
151
+ // false
152
+ default: input.border
153
+ },
148
154
  // 最大输入长度,设置为 -1 的时候不限制最大长度
149
155
  maxlength: {
150
156
  type: [Number, String],
@@ -247,6 +253,19 @@ export default {
247
253
  const parentFormItem = this.$pi.parent(this, 'PiFormItem')
248
254
  const disabled = this.disabled || (parentFormItem && parentFormItem.getDisabled)
249
255
  return disabled
256
+ },
257
+ getInputWrapStyle() {
258
+ const style = {}
259
+ if (this.border) {
260
+ style.padding = '8rpx 14rpx'
261
+ style.borderRadius = '4rpx'
262
+ if (this.$pi.lang.isString(this.border)) {
263
+ style.border = this.border
264
+ } else {
265
+ style.border = '1Px solid #d9d9d9'
266
+ }
267
+ }
268
+ return style
250
269
  }
251
270
  },
252
271
  methods: {
@@ -15,6 +15,7 @@
15
15
  :key="idx"
16
16
  class="marquee-item"
17
17
  :class="{ vertical: isVertical }"
18
+ :style="[getItemStyle]"
18
19
  >
19
20
  <!-- item插槽 -->
20
21
  <slot name="item" :item="item">
@@ -28,8 +29,10 @@
28
29
 
29
30
  <script>
30
31
  import { getConfig } from '../../config'
31
- // const TAG = 'PiMarquee'
32
+
33
+ const TAG = 'PiMarquee'
32
34
  const { marquee } = getConfig()
35
+
33
36
  export default {
34
37
  name: 'PiMarquee',
35
38
  props: {
@@ -72,11 +75,24 @@ export default {
72
75
  type: Array,
73
76
  // `[]`
74
77
  default: () => marquee.items
78
+ },
79
+ // 每个item是否占据整个宽度
80
+ itemFullWidth: {
81
+ type: Boolean,
82
+ // false
83
+ default: marquee.itemFullWidth
84
+ },
85
+ // 延迟多少毫秒后开始滚动
86
+ runDelay: {
87
+ type: [Number, String],
88
+ // 500
89
+ default: marquee.runDelay
75
90
  }
76
91
  },
77
92
  data() {
78
93
  return {
79
94
  animate: {},
95
+ containerWidth: 'auto',
80
96
  cloneItems: false
81
97
  }
82
98
  },
@@ -84,6 +100,13 @@ export default {
84
100
  isVertical() {
85
101
  return ['tb', 'bt'].includes(this.direction)
86
102
  },
103
+ getItemStyle() {
104
+ const style = {}
105
+ if (this.itemFullWidth && this.containerWidth !== 'auto') {
106
+ style.width = `${this.containerWidth}px`
107
+ }
108
+ return style
109
+ },
87
110
  getItems() {
88
111
  if (!this.cloneItems) return [this.items]
89
112
  return [this.items, this.items]
@@ -91,19 +114,19 @@ export default {
91
114
  },
92
115
  watch: {
93
116
  customStyle() {
94
- this.updateTime()
117
+ this.init()
95
118
  },
96
119
  customClass() {
97
- this.updateTime()
120
+ this.init()
98
121
  },
99
122
  direction() {
100
- this.updateTime()
123
+ this.init()
101
124
  },
102
125
  speed: {
103
126
  immediate: true,
104
127
  handler() {
105
128
  this.handlePause()
106
- this.updateTime()
129
+ this.init()
107
130
  this.handleStart()
108
131
  }
109
132
  },
@@ -111,16 +134,16 @@ export default {
111
134
  immediate: true,
112
135
  handler() {
113
136
  this.handlePause()
114
- this.updateTime()
137
+ this.init()
115
138
  this.handleStart()
116
139
  }
117
140
  }
118
141
  },
119
142
  mounted() {
120
- window && window.addEventListener('resize', this.updateTime)
143
+ window && window.addEventListener('resize', this.init)
121
144
  },
122
145
  beforeDestroy() {
123
- window && window.removeEventListener('resize', this.updateTime)
146
+ window && window.removeEventListener('resize', this.init)
124
147
  },
125
148
  methods: {
126
149
  /**
@@ -143,12 +166,14 @@ export default {
143
166
  if (!this.hoverPause) {
144
167
  return
145
168
  }
146
- this.$set(this.animate, 'animationPlayState', 'running')
169
+ setTimeout(() => {
170
+ this.$set(this.animate, 'animationPlayState', 'running')
171
+ }, parseInt(this.runDelay, 10))
147
172
  },
148
- updateTime() {
173
+ init() {
149
174
  this.$nextTick(async () => {
150
175
  const rect = await this.$pi.common.queryRect(this, '.marquee-container', false)
151
- const containerWidth = rect.width
176
+ this.containerWidth = rect.width
152
177
  const containerHeight = rect.height
153
178
  const inner = await this.$pi.common.queryRect(this, '.inner', false)
154
179
 
@@ -159,7 +184,9 @@ export default {
159
184
  return
160
185
  }
161
186
  if (!this.isVertical) {
162
- if (inner.width <= containerWidth) {
187
+ console.log(TAG, '横向滚动', inner.width, this.containerWidth)
188
+ // 横向滚动
189
+ if (!this.itemFullWidth && inner.width < this.containerWidth) {
163
190
  this.handlePause()
164
191
  this.cloneItems = false
165
192
  } else {
@@ -168,7 +195,8 @@ export default {
168
195
  this.cloneItems = true
169
196
  }
170
197
  } else {
171
- if (inner.height <= containerHeight) {
198
+ // 纵向滚动
199
+ if (inner.height < containerHeight) {
172
200
  this.$set(this.animate, 'animationPlayState', 'paused')
173
201
  this.cloneItems = false
174
202
  } else {
@@ -186,7 +214,7 @@ export default {
186
214
  <style lang="scss" scoped>
187
215
  .marquee-container {
188
216
  width: 100%;
189
- overflow: auto hidden;
217
+ overflow: hidden;
190
218
  font-size: 0;
191
219
  white-space: nowrap;
192
220
  background: #ffffff;
@@ -213,6 +241,7 @@ export default {
213
241
  .inner-wrap {
214
242
  display: inline-block;
215
243
  white-space: nowrap;
244
+
216
245
  &.lr {
217
246
  animation: roll-lr 0s linear infinite;
218
247
  }
@@ -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, // 是否禁用
package/config/input.js CHANGED
@@ -6,6 +6,7 @@ export default {
6
6
  placeholderStyle: 'color: #c0c4cc; font-weight: 400;', // 指定 placeholder 的样式
7
7
  placeholderClass: 'input-placeholder', // 指定 placeholder 的样式类,注意页面或组件的style中写了scoped时,需要在类名前写::v-deep
8
8
  disabled: false, // 是否禁用
9
+ border: false, // 边框样式设置
9
10
  maxlength: 140, // 最大输入长度,设置为 -1 的时候不限制最大长度
10
11
  password: false,
11
12
  cursorSpacing: 0, // 指定光标与键盘的距离,单位 px
package/config/marquee.js CHANGED
@@ -4,5 +4,7 @@ export default {
4
4
  hoverPause: true,
5
5
  customStyle: {},
6
6
  customClass: '',
7
- items: []
7
+ items: [],
8
+ itemFullWidth: false, // 每个item是否占据整个宽度
9
+ runDelay: 500 // 延迟多少毫秒后开始滚动
8
10
  }
@@ -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.4-beta9",
3
+ "version": "1.2.6beta2",
4
4
  "description": "piui组件库",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -23,3 +23,4 @@
23
23
  },
24
24
  "homepage": "https://github.com/sadais-org/piui#readme"
25
25
  }
26
+