sadais-piui 1.2.6-beta8 → 1.2.7-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.
@@ -0,0 +1,174 @@
1
+ <template>
2
+ <view
3
+ class="pi-bubble pi-rela pi-flex pi-align-center pi-justify-center"
4
+ :style="[customStyle]"
5
+ :class="customClass"
6
+ @longpress.stop="handleLongpress"
7
+ >
8
+ <slot />
9
+ <view v-show="showBubble" class="pi-bubble-wrapper" :class="[bubbleClass]">
10
+ <view
11
+ ref="bubble"
12
+ class="pi-bubble-content pi-abso pi-bg-white pi-radius-4 pi-pd-20"
13
+ :style="[bubbleStyle]"
14
+ >
15
+ <slot name="bubble" />
16
+ <view class="pi-bubble-angle pi-abso" />
17
+ </view>
18
+ </view>
19
+ <pi-mask v-model="showMaks" background="transparent" @close="showBubble = false" />
20
+ </view>
21
+ </template>
22
+
23
+ <script>
24
+ /**
25
+ * bubble 气泡弹窗
26
+ */
27
+ import { getConfig } from '../../config'
28
+ const TAG = 'PiBubble'
29
+ const { bubble } = getConfig()
30
+
31
+ // 底部栏
32
+ export default {
33
+ name: 'PiBubble',
34
+ props: {
35
+ // 自定义样式,对象形式
36
+ customStyle: {
37
+ type: Object,
38
+ // {}
39
+ default() {
40
+ return bubble.customStyle
41
+ }
42
+ },
43
+ customClass: {
44
+ type: String,
45
+ // ''
46
+ default() {
47
+ return bubble.customClass
48
+ }
49
+ },
50
+ position: {
51
+ type: String,
52
+ default() {
53
+ return bubble.position
54
+ }
55
+ },
56
+ zIndex: {
57
+ type: Number,
58
+ default() {
59
+ return bubble.zIndex
60
+ }
61
+ }
62
+ },
63
+ data() {
64
+ return {
65
+ showBubble: false,
66
+ showMaks: false,
67
+ bubleWidth: 0,
68
+ sysInfo: {},
69
+ bublePosition: {
70
+ top: 0,
71
+ left: 0
72
+ }
73
+ }
74
+ },
75
+ computed: {
76
+ rpxRatio() {
77
+ return 750 / this.screenWidth
78
+ },
79
+ screenWidth() {
80
+ return this.sysInfo.screenWidth
81
+ },
82
+ bubblePosition() {
83
+ return this.position === 'bottom' ? 'top' : 'bottom'
84
+ },
85
+ bubbleStyle() {
86
+ return {
87
+ zIndex: this.zIndex,
88
+ ...this.bublePosition
89
+ }
90
+ },
91
+ bubbleClass() {
92
+ return this.position === 'top' ? 'isTop' : ''
93
+ }
94
+ },
95
+ mounted() {
96
+ this.init()
97
+ },
98
+ methods: {
99
+ init() {
100
+ this.sysInfo = uni.getSystemInfoSync()
101
+ },
102
+ async handleLongpress(e) {
103
+ await this.calcBubblePosition()
104
+ this.showBubble = true
105
+ this.showMaks = true
106
+ },
107
+ getBubbleWidth() {
108
+ return new Promise(reslove => {
109
+ this.$set(this, 'bublePosition', { top: '-9999vh', left: 0 })
110
+ this.showBubble = true
111
+ setTimeout(() => {
112
+ reslove(this.$refs.bubble ? this.$refs.bubble.$el.getBoundingClientRect().width : 0)
113
+ this.showBubble = false
114
+ }, 500)
115
+ })
116
+ },
117
+ async calcBubblePosition() {
118
+ let bublePosition = this.$el.getBoundingClientRect()
119
+ this.bubleWidth = await this.getBubbleWidth()
120
+ const lengthGap = (this.bubleWidth - bublePosition.width) / 2
121
+ const compRight = this.screenWidth - bublePosition.x - bublePosition.width
122
+ const posRes = {}
123
+ if (lengthGap <= 0 || (lengthGap < bublePosition.x && lengthGap < compRight)) {
124
+ posRes.left = -Math.abs(lengthGap) + 'px'
125
+ } else {
126
+ posRes.right = 4 - Math.min(bublePosition.x, compRight) + 'px'
127
+ }
128
+ posRes[this.bubblePosition] = 'calc(100% + 18rpx)'
129
+ this.$set(this, 'bublePosition', posRes)
130
+ }
131
+ }
132
+ }
133
+ </script>
134
+
135
+ <style lang="scss" scoped>
136
+ .pi-bubble {
137
+ width: fit-content;
138
+ height: fit-content;
139
+ .pi-bubble-wrapper {
140
+ filter: drop-shadow(0 0 2rpx #000);
141
+ z-index: 9999;
142
+ position: absolute;
143
+ width: 100%;
144
+ height: 0;
145
+ top: 100%;
146
+ &.isTop {
147
+ top: 0;
148
+ .pi-bubble-content {
149
+ .pi-bubble-angle {
150
+ top: initial;
151
+ bottom: -10rpx;
152
+ }
153
+ }
154
+ }
155
+ .pi-bubble-content {
156
+ max-width: 98vw;
157
+ line-height: 30rpx;
158
+ color: #fff;
159
+ z-index: 9999;
160
+ background-color: #000;
161
+ .pi-bubble-angle {
162
+ top: -10rpx;
163
+ left: 50%;
164
+ z-index: 9999;
165
+ width: 0rpx;
166
+ height: 0rpx;
167
+ border: 12rpx solid #000;
168
+ transform: translateX(-50%) rotate(45deg);
169
+ transform-origin: center;
170
+ }
171
+ }
172
+ }
173
+ }
174
+ </style>
@@ -9,7 +9,7 @@
9
9
  v-if="getShape !== 'text'"
10
10
  class="check-icon"
11
11
  :style="[checkStyle]"
12
- @tap="handleCheckboxToggle(false)"
12
+ @tap.stop="handleCheckboxToggle(false)"
13
13
  >
14
14
  <view v-if="getShape === 'dot'" class="dot" :style="[dotStyle]" />
15
15
  <pi-icon v-else name="blod-check" :size="getIconSize" />
@@ -259,6 +259,8 @@ $unactive-color: #cccccc;
259
259
  .pi-check-wrap {
260
260
  display: inline-flex;
261
261
  align-items: center;
262
+ cursor: pointer;
263
+
262
264
  .check-icon {
263
265
  position: relative;
264
266
  display: inline-flex;
@@ -324,7 +326,7 @@ $unactive-color: #cccccc;
324
326
  opacity: $pi-disabled-opacity;
325
327
  }
326
328
  &.active {
327
- .radio-label {
329
+ .check-label {
328
330
  color: $pi-primary-color;
329
331
  }
330
332
  &.line,
@@ -218,17 +218,32 @@ export default {
218
218
  default() {
219
219
  return form.rightIcon
220
220
  }
221
+ },
222
+ // 表单校验规则
223
+ rules: {
224
+ type: Object,
225
+ default() {
226
+ return {}
227
+ }
221
228
  }
222
229
  },
223
230
  data() {
224
231
  return {
225
- rules: {}
232
+ validRules: {}
233
+ }
234
+ },
235
+ watch: {
236
+ rules: {
237
+ handler(val) {
238
+ this.validRules = val
239
+ },
240
+ deep: true
226
241
  }
227
242
  },
228
243
  methods: {
229
244
  // 由于跨平台限制,无法通过props传递方法,通过refs方式在onReady生命周期设置校验规则
230
245
  setRules(rules) {
231
- this.rules = rules
246
+ this.validRules = rules
232
247
  },
233
248
  // 校验数据
234
249
  async validation() {
@@ -400,7 +400,7 @@ export default {
400
400
  // 从pi-form的rules属性中,取出当前pi-form-item的校验规则
401
401
  getRules() {
402
402
  // 父组件的所有规则
403
- const parentRules = this._parent ? this._parent.rules : undefined
403
+ const parentRules = this._parent && (this._parent.validRules || this._parent.rules)
404
404
  const rules = parentRules ? parentRules[this.prop] : []
405
405
  return [].concat(rules || [])
406
406
  },
@@ -14,7 +14,6 @@
14
14
  :maxlength="maxlength"
15
15
  :cursor-spacing="cursorSpacing"
16
16
  :focus="focus"
17
- :confirmType="confirmType"
18
17
  :confirm-hold="confirmHold"
19
18
  :cursor="cursor"
20
19
  :selection-start="selectionStart"
@@ -48,7 +47,6 @@
48
47
  :maxlength="maxlength"
49
48
  :cursor-spacing="cursorSpacing"
50
49
  :focus="focus"
51
- :confirmType="confirmType"
52
50
  :confirm-hold="confirmHold"
53
51
  :cursor="cursor"
54
52
  :selection-start="selectionStart"
@@ -16,7 +16,7 @@
16
16
  v-if="!['text', 'button'].includes(getShape)"
17
17
  class="radio-icon"
18
18
  :style="[radioStyle]"
19
- @tap="handleRadioToggle(false)"
19
+ @tap.stop="handleRadioToggle(false)"
20
20
  >
21
21
  <view v-if="getShape === 'dot'" class="dot" />
22
22
  <pi-icon v-else name="blod-check" :size="getIconSize" />
@@ -260,6 +260,8 @@ $unactive-color: #cccccc;
260
260
  .pi-radio-wrap {
261
261
  display: inline-flex;
262
262
  align-items: center;
263
+ cursor: pointer;
264
+
263
265
  .radio-icon {
264
266
  position: relative;
265
267
  display: inline-flex;
@@ -18,7 +18,7 @@
18
18
  class="pi-subsection__item"
19
19
  :class="[itemClass(index)]"
20
20
  :style="[itemStyle(index)]"
21
- @tap="clickHandler(index)"
21
+ @tap="handleSelectItem(index)"
22
22
  >
23
23
  <text class="pi-subsection__item__text" :style="[textStyle(index)]">{{ getText(item) }}</text>
24
24
  </view>
@@ -30,6 +30,7 @@
30
30
  const dom = uni.requireNativePlugin('dom')
31
31
  const animation = uni.requireNativePlugin('animation')
32
32
  // #endif
33
+ import ValueSync from '../../mixin/value-sync'
33
34
  import { getConfig } from '../../config'
34
35
  const { subsection } = getConfig()
35
36
  /**
@@ -37,11 +38,21 @@ const { subsection } = getConfig()
37
38
  * @description 该分段器一般用于用户从几个选项中选择某一个的场景
38
39
  * @tutorial http://piui.sadais.com/docs/components/Subsection.html
39
40
  * @event {Function} change 分段器选项发生改变时触发 回调 index:选项的index索引值,从0开始
40
- * @example <pi-subsection :items="items" :current="curNow" @change="sectionChange" />
41
+ * @example <pi-subsection v-model="current" :items="items" @change="sectionChange" />
41
42
  */
42
43
  export default {
43
44
  name: 'PiSubsection',
45
+ // 混入v-model
46
+ mixins: [ValueSync],
44
47
  props: {
48
+ // 当前活动的tab的index
49
+ value: {
50
+ type: Number,
51
+ // 0
52
+ default() {
53
+ return subsection.value
54
+ }
55
+ },
45
56
  // 自定义样式,对象形式
46
57
  customStyle: {
47
58
  type: Object,
@@ -66,14 +77,6 @@ export default {
66
77
  return subsection.items
67
78
  }
68
79
  },
69
- // 当前活动的tab的index
70
- current: {
71
- type: [String, Number],
72
- // 0
73
- default() {
74
- return subsection.current
75
- }
76
- },
77
80
  // 激活时的颜色
78
81
  activeColor: {
79
82
  type: String,
@@ -131,11 +134,11 @@ export default {
131
134
  }
132
135
  },
133
136
  // 从`items`元素对象中读取的键名
134
- keyName: {
137
+ keyField: {
135
138
  type: String,
136
139
  // name
137
140
  default() {
138
- return subsection.keyName
141
+ return subsection.keyField
139
142
  }
140
143
  }
141
144
  },
@@ -155,11 +158,11 @@ export default {
155
158
  let className = 'pi-subsection--button__bar'
156
159
  // 分段器模式
157
160
  if (this.mode === 'subsection') {
158
- if (this.current === 0) {
161
+ if (this.val === 0) {
159
162
  className = 'pi-subsection__bar--first'
160
- } else if (this.current > 0 && this.current < this.items.length - 1) {
163
+ } else if (this.val > 0 && this.val < this.items.length - 1) {
161
164
  className = 'pi-subsection__bar--center'
162
- } else if (this.current === this.items.length - 1) {
165
+ } else if (this.val === this.items.length - 1) {
163
166
  className = 'pi-subsection__bar--last'
164
167
  }
165
168
  }
@@ -169,7 +172,7 @@ export default {
169
172
  const style = {}
170
173
  // button模式时,设置背景色
171
174
  if (this.mode === 'button') {
172
- style.backgroundColor = this.bgColor
175
+ style.background = this.bgColor
173
176
  }
174
177
  return style
175
178
  },
@@ -180,11 +183,11 @@ export default {
180
183
  style.height = `${this.itemRect.height}px`
181
184
  // 通过translateX移动滑块,其移动的距离为索引*item的宽度
182
185
  // #ifndef APP-NVUE
183
- style.transform = `translateX(${this.current * this.itemRect.width}px)`
186
+ style.transform = `translateX(${this.val * this.itemRect.width}px)`
184
187
  // #endif
185
188
  if (this.mode === 'subsection') {
186
189
  // 在subsection模式下,需要动态设置滑块的圆角,因为移动滑块使用的是translateX,无法通过父元素设置overflow: hidden隐藏滑块的直角
187
- style.backgroundColor = this.activeColor
190
+ style.background = this.activeColor
188
191
  }
189
192
  // 按钮圆角模式 按钮模式生效
190
193
  if (this.round && this.mode === 'button') {
@@ -194,7 +197,7 @@ export default {
194
197
  },
195
198
  // 分段器item的样式
196
199
  itemStyle(index) {
197
- return (index) => {
200
+ return index => {
198
201
  const style = {}
199
202
  if (this.mode === 'subsection') {
200
203
  // 设置border的样式
@@ -217,12 +220,12 @@ export default {
217
220
  },
218
221
  // 分段器item的class
219
222
  itemClass(index) {
220
- return (index) => {
223
+ return index => {
221
224
  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
+ if (index < this.items.length - 1) {
225
226
  className += ' pi-subsection__item--no-border-right'
227
+ } else if (index === 0) {
228
+ className += ' pi-subsection__item--first'
226
229
  } else if (index === this.items.length - 1) {
227
230
  className += ' pi-subsection__item--last'
228
231
  }
@@ -231,16 +234,16 @@ export default {
231
234
  },
232
235
  // 分段器文字颜色
233
236
  textStyle(index) {
234
- return (index) => {
237
+ return index => {
235
238
  const style = {}
236
- style.fontWeight = this.bold && this.current === index ? 'bold' : 'normal'
239
+ style.fontWeight = this.bold && this.val === index ? 'bold' : 'normal'
237
240
  style.fontSize = this.$pi.common.addUnit(this.fontSize)
238
241
  // subsection模式下,激活时默认为白色的文字
239
242
  if (this.mode === 'subsection') {
240
- style.color = this.current === index ? '#fff' : this.inactiveColor
243
+ style.color = this.val === index ? '#fff' : this.inactiveColor
241
244
  } else {
242
245
  // button模式下,激活时文字颜色默认为activeColor
243
- style.color = this.current === index ? this.activeColor : this.inactiveColor
246
+ style.color = this.val === index ? this.activeColor : this.inactiveColor
244
247
  }
245
248
  return style
246
249
  }
@@ -280,19 +283,19 @@ export default {
280
283
  },
281
284
  // 判断展示文本
282
285
  getText(item) {
283
- return typeof item === 'object' ? item[this.keyName] : item
286
+ return typeof item === 'object' ? item[this.keyField] : item
284
287
  },
285
288
  // 获取组件的尺寸
286
289
  getRect() {
287
290
  // #ifndef APP-NVUE
288
- this.$pi.common.queryRect(this, '.pi-subsection__item--0', false).then((size) => {
291
+ this.$pi.common.queryRect(this, '.pi-subsection__item--0', false).then(size => {
289
292
  this.itemRect = size
290
293
  })
291
294
  // #endif
292
295
  // #ifdef APP-NVUE
293
296
  const ref = this.$refs['pi-subsection__item--0'][0]
294
297
  ref &&
295
- dom.getComponentRect(ref, (res) => {
298
+ dom.getComponentRect(ref, res => {
296
299
  this.itemRect = res.size
297
300
  })
298
301
  // #endif
@@ -303,15 +306,16 @@ export default {
303
306
  * @returns {Promise} 返回promise
304
307
  */
305
308
  sleep(value = 30) {
306
- return new Promise((resolve) => {
309
+ return new Promise(resolve => {
307
310
  setTimeout(() => {
308
311
  resolve()
309
312
  }, value)
310
313
  })
311
314
  },
312
315
 
313
- clickHandler(index) {
314
- this.$emit('change', index)
316
+ handleSelectItem(index) {
317
+ this.val = index
318
+ this.handleEmitChange()
315
319
  }
316
320
  }
317
321
  }
@@ -0,0 +1,6 @@
1
+ export default {
2
+ customClass: '', // 自定义样式类,字符串形式('')
3
+ customStyle: {}, // 自定义样式,对象形式(默认值:{})
4
+ zIndex: 9999,
5
+ position: 'top'
6
+ }
@@ -1,6 +1,6 @@
1
1
  export default {
2
2
  items: [], // tab的数据
3
- current: 0, // 当前活动的tab的index(默认 0 )
3
+ value: 0, // 当前活动的tab的index(默认 0 )
4
4
  activeColor: '#5a7dff', // 激活时的颜色(默认 '#5a7dff' )
5
5
  inactiveColor: '#303133', // 未激活时的颜色(默认 '#303133' )
6
6
  mode: 'button', // 模式选择,mode=button为按钮形式,mode=subsection时为分段模式(默认 'button' )
@@ -8,7 +8,7 @@ export default {
8
8
  fontSize: 24, // 字体大小,单位px(默认 24rpx )
9
9
  bold: true, // 激活选项的字体是否加粗(默认 true )
10
10
  bgColor: '', // 组件背景颜色,mode为button时有效(默认 '#eeeeef' )
11
- keyName: 'name', // 从`list`元素对象中读取的键名(默认 'name' )
11
+ keyField: 'name', // 从`list`元素对象中读取的键名(默认 'name' )
12
12
  customClass: '', // 自定义样式类,字符串形式('')
13
13
  customStyle: {} // 自定义样式,对象形式(默认值:{})
14
14
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sadais-piui",
3
- "version": "1.2.6beta8",
3
+ "version": "1.2.7beta2",
4
4
  "description": "piui组件库",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -11,7 +11,7 @@
11
11
  "url": "git+https://github.com/sadais-org/piui.git"
12
12
  },
13
13
  "peerDependencies": {
14
- "@sadais/piui-tool": "^0.0.18"
14
+ "@sadais/piui-tool": ">=0.0.21"
15
15
  },
16
16
  "keywords": [
17
17
  "piui sadais-piui"
@@ -23,4 +23,3 @@
23
23
  },
24
24
  "homepage": "https://github.com/sadais-org/piui#readme"
25
25
  }
26
-