sadais-piui 1.1.2-beta → 1.2.2-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.
Files changed (39) hide show
  1. package/CHANGELOG.md +482 -240
  2. package/README.md +2 -3
  3. package/components/pi-bottom-bar/index.vue +15 -2
  4. package/components/pi-canvas/index.vue +400 -0
  5. package/components/pi-circle-progress/index.vue +196 -173
  6. package/components/pi-count-up/index.vue +68 -62
  7. package/components/pi-dropdown/components/dropdown-tab.vue +62 -0
  8. package/components/pi-dropdown/index.vue +152 -151
  9. package/components/pi-dropdown-item/index.vue +169 -41
  10. package/components/pi-form-item/index.vue +13 -1
  11. package/components/pi-img/index.vue +1 -0
  12. package/components/pi-img-cropper/index.vue +20 -16
  13. package/components/pi-img-cropper/touch.js +5 -3
  14. package/components/pi-input/index.vue +9 -2
  15. package/components/pi-notify/index.vue +132 -48
  16. package/components/pi-popup/index.vue +1 -3
  17. package/components/pi-radio/index.vue +10 -1
  18. package/components/pi-radio-group/index.vue +21 -2
  19. package/components/pi-select/index.vue +13 -3
  20. package/components/pi-steps/index.vue +141 -96
  21. package/components/pi-switch/index.vue +2 -3
  22. package/components/pi-tabs/index.vue +1 -2
  23. package/components/pi-upload-img/index.vue +104 -32
  24. package/config/bottomBar.js +1 -0
  25. package/config/checkbox.js +1 -1
  26. package/config/circleProgress.js +13 -0
  27. package/config/countUp.js +13 -0
  28. package/config/dropdown.js +17 -8
  29. package/config/dropdownItem.js +23 -5
  30. package/config/form.js +3 -3
  31. package/config/imgCropper.js +4 -2
  32. package/config/notify.js +6 -2
  33. package/config/radio.js +2 -1
  34. package/config/radioGroup.js +2 -1
  35. package/config/steps.js +10 -5
  36. package/config/{upload-img.js → uploadImg.js} +6 -3
  37. package/index.js +2 -2
  38. package/package.json +3 -3
  39. package/scss/variable.scss +1 -1
@@ -0,0 +1,62 @@
1
+ <template>
2
+ <view class="dropdown-tab-item" :class="[{ opened: item.opened }]">
3
+ <!-- 注意:slot内不能使用父组件data -->
4
+ <view
5
+ class="pi-align-center"
6
+ :style="{ color: item.opened && item.activeColor ? item.activeColor : 'inherit' }"
7
+ @tap.stop="handleClick"
8
+ >
9
+ <pi-icon
10
+ v-if="item.showIcon"
11
+ :name="item.iconOption.name"
12
+ :dot="item.iconOption.dot"
13
+ :badge="item.iconOption.badge"
14
+ :color="item.iconOption.color"
15
+ :size="item.iconOption.size"
16
+ :class-prefix="item.iconOption.classPrefix"
17
+ :custom-style="item.iconOption.customStyle"
18
+ :custom-class="`pi-mg-right-8 ${item.iconOption.customClass}`"
19
+ />
20
+
21
+ <text class=" pi-pd-right-8 pi-fz-28">
22
+ {{ item.text }}
23
+ </text>
24
+ <pi-icon :class="{ rotate: item.opened }" name="unfold" size="26" />
25
+ </view>
26
+ </view>
27
+ </template>
28
+
29
+ <script>
30
+ const TAG = 'PiDropdownTab'
31
+
32
+ export default {
33
+ name: TAG,
34
+ props: {
35
+ item: {
36
+ required: true,
37
+ default() {
38
+ return {}
39
+ }
40
+ }
41
+ },
42
+ methods: {
43
+ handleClick() {
44
+ this.$emit('click', this.item)
45
+ }
46
+ }
47
+ }
48
+ </script>
49
+
50
+ <style lang="scss" scoped>
51
+ .dropdown-tab-item {
52
+ font-size: 33rpx;
53
+ &.opened {
54
+ color: $pi-primary-color;
55
+ }
56
+ }
57
+
58
+ .rotate {
59
+ transition: all $pi-animation-duration $pi-animation-timing-function;
60
+ transform: rotate(180deg);
61
+ }
62
+ </style>
@@ -1,68 +1,36 @@
1
1
  <template>
2
- <view class="pi-dropdown pi-rela pi-w-100P">
3
- <view
4
- class="pi-rela pi-w-100P pi-h-100P pi-solid-bottom-2 pi-bg-white"
5
- style="z-index: 6;"
6
- :class="[customClass]"
7
- :style="combinationStyle"
8
- >
9
- <!-- tabs从dropdownItem中获取其name的值 -->
10
- <scroll-view
11
- class="pi-srcoll pi-w-100P pi-h-100P"
12
- scroll-x
13
- :scroll-left="scrollLeft"
14
- scroll-with-animation
15
- >
16
- <view class="pi-align-center pi-h-100P">
17
- <view
18
- v-for="(item, index) in tabs"
19
- :key="item._uid"
20
- class="pi-dropdown-tab-item pi-pd-lr-20 pi-text-nowrap pi-h-100P pi-align-center"
21
- :style="[{ color: show && item._uid === currentId ? activeColor : '' }]"
22
- @tap="handleClickTab(item, index)"
23
- >
24
- <!-- todo 当前项存在value中高亮选项 目前还有问题,当插槽位置在中间时可能有问题 -->
25
- <pi-icon
26
- v-if="item.icon"
27
- class="pi-mg-right-6"
28
- :color="item.selected ? activeColor : ''"
29
- :name="item.icon"
30
- size="36"
31
- />
32
- <text
33
- class="pi-pd-right-8 pi-fz-28"
34
- :style="{ color: item.selected ? activeColor : '' }"
35
- >
36
- {{ item.name }}
37
- </text>
38
- <pi-icon :class="{ rotate: show && item._uid === currentId }" name="unfold" size="16" />
39
- </view>
40
- </view>
41
- </scroll-view>
42
- <!-- 展示dropdownItem下的数据 -->
43
- <view
44
- v-show="show"
45
- :class="[contentClass]"
46
- :style="contentCombinationStyle"
47
- class="pi-abso pi-w-100P"
2
+ <view class="pi-dropdown pi-rela pi-w-100P" :class="[customClass]" :style="[customStyle]">
3
+ <view>
4
+ <pi-tabs
5
+ :value="activeItem"
6
+ :items="tabs"
7
+ :show-slider-bar="false"
8
+ show-item-split-line
9
+ active-text-color="inherit"
48
10
  >
49
- <view class="pi-dropdown-content pi-mg-top-6">
50
- <slot />
11
+ <view slot="item" slot-scope="{ item, index }">
12
+ <!-- 注意:slot内不能使用父组件data -->
13
+ <dropdown-tab :item="item" @click="handleClickTab(item, index)" />
51
14
  </view>
52
- </view>
15
+ </pi-tabs>
16
+ </view>
17
+ <!-- 展示dropdownItem下的数据 -->
18
+ <view
19
+ class="pi-dropdown-content pi-mg-top-12"
20
+ :class="[contentClass, show ? 'pi-ani-slide-top-show' : 'pi-ani-slide-top-hide']"
21
+ :style="[contentStyle, contentCombinationStyle]"
22
+ >
23
+ <slot />
53
24
  </view>
54
25
 
55
26
  <!-- 遮罩层 -->
56
27
  <view
57
28
  v-if="!closed"
58
- class="pi-fixed pi-dropdown-mask"
59
- :class="[
60
- show ? getMask.animationShow : getMask.animationHide,
61
- getMask.hideTabBar ? 'include-tabbar' : 'exclude-tabbar'
62
- ]"
29
+ class="pi-abso pi-dropdown-mask"
30
+ :class="[show ? getMask.animationShow : getMask.animationHide]"
63
31
  :style="[
64
32
  {
65
- 'zIndex': 1,
33
+ 'z-index': getMask.zIndex,
66
34
  'background': getMask.background,
67
35
  'animation-duration': getDuration.css
68
36
  }
@@ -78,13 +46,27 @@ import ValueSync from '../../mixin/value-sync'
78
46
  import { parentInit } from '../../mixin/props-sync'
79
47
  import { getConfig } from '../../config'
80
48
  import { parseDuration } from '@sadais/piui-tool/tools/common'
49
+ import DropdownTab from './components/dropdown-tab.vue'
81
50
 
82
51
  const TAG = 'PiDropdown'
83
52
  const { dropdown } = getConfig()
84
53
 
85
54
  export default {
86
- name: TAG,
87
- mixins: [ValueSync, parentInit(['value', 'tabs'])], // 注入value与val,进行双向绑定
55
+ name: 'PiDropdown',
56
+ components: {
57
+ DropdownTab
58
+ },
59
+ mixins: [
60
+ ValueSync,
61
+ parentInit([
62
+ 'itemHeight',
63
+ 'keyField',
64
+ 'displayField',
65
+ 'disabledField',
66
+ 'selectedImg',
67
+ 'selectedCheckbox'
68
+ ])
69
+ ], // 注入value与val,进行双向绑定
88
70
  props: {
89
71
  // 初始值
90
72
  value: {
@@ -140,71 +122,76 @@ export default {
140
122
  // ''
141
123
  return dropdown.activeColor
142
124
  }
125
+ },
126
+ // -------------以下属性为子组件pi-dropdown-item继承用--------------
127
+ // 行高 值为数字,则单位默认rpx
128
+ itemHeight: {
129
+ type: [String, Number],
130
+ // 110
131
+ default: dropdown.itemHeight
132
+ },
133
+ // 选项id字段
134
+ keyField: {
135
+ type: String,
136
+ // `id`
137
+ default: dropdown.keyField
138
+ },
139
+ // 选项显示字段
140
+ displayField: {
141
+ type: String,
142
+ // `text`
143
+ default: dropdown.displayField
144
+ },
145
+ // 选项禁用字段,默认为disabled
146
+ disabledField: {
147
+ type: String,
148
+ // `text`
149
+ default: dropdown.disabledField
150
+ },
151
+ // 选中图标的配置
152
+ selectedImg: {
153
+ type: Object,
154
+ default() {
155
+ // 参照img
156
+ return dropdown.selectedImg
157
+ }
158
+ },
159
+ // 选中checkbox配置
160
+ selectedCheckbox: {
161
+ type: Object,
162
+ default() {
163
+ // 参照checkbox
164
+ return dropdown.selectedCheckbox
165
+ }
143
166
  }
144
167
  },
145
168
  data() {
146
169
  return {
170
+ containerRect: { left: 0, right: 0, top: 0 }, // 容器的位置
171
+
147
172
  tabs: [], // 下拉菜单
148
- currentId: '', // id
173
+ activeItem: {}, // 当前选中项
149
174
 
150
175
  show: false, // 是否显示节点
151
176
  showed: false, // 是否显示动画执行完毕
152
- closed: true, // 是否已关闭(用来防止val为false的情况,动画无法执行)
153
-
154
- // 位置计算
155
- tabsWidth: 0, // 组件区域宽度
156
- tabRects: [], // 标签节点信息
157
- activeIndex: 0 // 当前选中项
177
+ closed: true // 是否已关闭(用来防止val为false的情况,动画无法执行)
158
178
  }
159
179
  },
160
180
  computed: {
161
- combinationStyle() {
162
- const { customStyle, show } = this
163
- return [
164
- customStyle,
165
- {
166
- borderRadius: show
167
- ? `${customStyle.borderRadius} ${customStyle.borderRadius} 0 0`
168
- : customStyle.borderRadius
169
- }
170
- ]
171
- },
172
181
  contentCombinationStyle() {
173
- const { customStyle, contentStyle, show } = this
174
- return [
175
- { top: customStyle.height, left: 0, background: '#fff' },
176
- contentStyle,
177
- {
178
- borderRadius: show
179
- ? `0 0 ${contentStyle.borderRadius} ${contentStyle.borderRadius}`
180
- : contentStyle.borderRadius
181
- }
182
- ]
182
+ const { containerRect, closed } = this
183
+ return {
184
+ top: `${containerRect.height}px`,
185
+ left: 0,
186
+ width: `${containerRect.width}px`,
187
+ zIndex: !closed ? 101 : -1
188
+ }
183
189
  },
184
190
  getMask() {
185
191
  return this.$pi.lang.mergeDeep(dropdown.mask, this.mask)
186
192
  },
187
193
  getDuration() {
188
194
  return parseDuration(this.getMask.duration, dropdown.mask.duration)
189
- },
190
- activeRect() {
191
- const rect = {
192
- left: 0,
193
- width: 0
194
- }
195
- if (!this.tabRects.length) return rect
196
- const activeIndex =
197
- this.activeIndex >= this.tabRects.length ? this.tabRects.length - 1 : this.activeIndex
198
- rect.left = this.tabRects.slice(0, activeIndex).reduce((previous, current) => {
199
- return previous + current.width
200
- }, 0)
201
- rect.width = this.tabRects[activeIndex].width
202
- return rect
203
- },
204
- scrollLeft() {
205
- // 计算当前激活item移动到容器中心距离左边距离
206
- const scrollLeft = this.activeRect.left - this.tabsWidth / 2 + this.activeRect.width / 2
207
- return scrollLeft < 0 ? 0 : scrollLeft
208
195
  }
209
196
  },
210
197
  watch: {
@@ -218,47 +205,63 @@ export default {
218
205
  },
219
206
  mounted() {
220
207
  this.init()
221
- this.tabsInit()
222
208
  },
223
209
  methods: {
224
- async tabsInit() {
225
- const srollWrapRect = await this.$pi.common.queryRect(this, '.pi-dropdown', false)
226
- if (srollWrapRect) {
227
- this.tabsWidth = srollWrapRect.width
228
- }
229
- this.tabRects = await this.$pi.common.queryRect(this, '.pi-dropdown-tab-item', true)
230
- },
231
210
  init() {
232
- // 给下面的选项设置选中效果
233
- this._children.forEach((item, index) => {
234
- item.val = this.value[index] || ''
235
- })
236
- // 定义新的对象数组渲染界面
211
+ console.log(TAG, 'init')
212
+ let hasValueChange = false
213
+ const val = this.$pi.lang.cloneDeep(this.val)
237
214
  this.tabs = this._children.map((item, index) => {
238
- const currentItem = item.option.filter(opt => opt.id === this.value[index]) // 获取当前已被选择的项
239
-
215
+ if (this.val[index] === undefined) {
216
+ this.val[index] = ''
217
+ }
218
+ // 同步父子组件的值
219
+ if (this.val[index] !== item.val) {
220
+ console.log(TAG, 'Dropdown和DropdownItem绑定值不一致,即将同步')
221
+ if (item.val) {
222
+ // 以子组件的值为准
223
+ hasValueChange = true
224
+ val[index] = item.val
225
+ } else if (this.val[index]) {
226
+ item.emitChange(this.val[index])
227
+ }
228
+ }
229
+ const currentOption = item.options?.find(opt => opt[item.getKeyField] === this.val[index])
240
230
  const newItem = {
241
- icon: item.icon || '',
242
- _uid: item._uid,
243
- name: currentItem[0]?.name || item.name,
244
- selected: !!currentItem[0]?.id
231
+ showIcon: item.showIcon,
232
+ iconOption: item.getIconOption,
233
+ id: item._uid,
234
+ text: currentOption ? currentOption[item.getDisplayField] : item.title,
235
+ disabled: item.disabled,
236
+ opened: false,
237
+ activeColor: this.activeColor
245
238
  }
246
239
  return newItem
247
240
  })
241
+ if (hasValueChange) {
242
+ this.val = val
243
+ this.handleEmitChange()
244
+ }
248
245
  },
249
246
  // 显示当前Tab
250
- handleClickTab(item, index) {
251
- this.activeIndex = index
247
+ async handleClickTab(item) {
248
+ if (item.disabled) return
249
+ // 更新打开的tab标志
250
+ this.tabs = this.tabs.map(tab => {
251
+ tab.opened = tab.id === item.id
252
+ return tab
253
+ })
254
+ this.activeItem = item
255
+ // 每次点击都重新更新父容器的位置
256
+ this.containerRect = await this.$pi.common.queryRect(this, '.pi-dropdown', false)
252
257
  this.openMask()
253
- this.currentId = item._uid
254
258
  this._children.find(child => {
255
- const showTab = child._uid === item._uid
256
- child.showOption(showTab)
259
+ child.show = child._uid === item.id
257
260
  })
258
261
  },
259
262
  openMask() {
260
263
  if (this.show) return
261
- console.log(TAG, '显示弹窗层')
264
+ console.log(TAG, '显示下拉菜单遮罩层')
262
265
  this.closed = false
263
266
  this.show = true
264
267
  this.showed = false
@@ -270,20 +273,27 @@ export default {
270
273
  // 仅关闭窗口,不作数据操作
271
274
  closeMask() {
272
275
  if (!this.show || !this.showed) return
273
- console.log(TAG, '关闭弹窗层')
276
+ console.log(TAG, '隐藏下拉菜单遮罩层')
274
277
  this.show = false
275
278
  this.showed = false
279
+ this.tabs = this.tabs.map(tab => {
280
+ tab.opened = false
281
+ return tab
282
+ })
276
283
  setTimeout(() => {
277
284
  this.closed = true
278
285
  this.getMask.hideTabBar && uni.showTabBar()
279
286
  }, this.getDuration.js)
280
287
  },
281
288
  // 关闭弹窗并返回结果
282
- handleChangeSubmit() {
289
+ submit() {
283
290
  this.closeMask()
284
- const submitVal = this._children.map(item => item.val)
285
- this.val = submitVal // 把最终结果传给绑定的v-model值
286
- this.handleEmitChange()
291
+ setTimeout(() => {
292
+ // 延迟执行,防止父子组件的值同步不上
293
+ const submitVal = this._children.map(item => item.val)
294
+ this.val = submitVal // 把最终结果传给绑定的v-model值
295
+ this.handleEmitChange()
296
+ }, 20)
287
297
  }
288
298
  }
289
299
  }
@@ -291,25 +301,16 @@ export default {
291
301
 
292
302
  <style lang="scss" scoped>
293
303
  .pi-dropdown {
294
- z-index: 2;
295
304
  .pi-dropdown-content {
296
- left: 0;
297
- box-shadow: 0 10rpx 10rpx rgba(0, 0, 0, 0.1);
305
+ position: absolute;
306
+ background: #ffffff;
307
+ border-radius: 12rpx;
298
308
  }
299
- .pi-dropdown-tab-item {
300
- transition: all $pi-animation-duration $pi-animation-timing-function;
309
+ .pi-dropdown-mask {
310
+ top: -9999px;
311
+ left: -9999px;
312
+ right: -9999px;
313
+ bottom: -9999px;
301
314
  }
302
- .current {
303
- color: #ff9900;
304
- }
305
- .rotate {
306
- transform: rotate(180deg);
307
- }
308
- }
309
- .pi-dropdown-mask {
310
- top: 0;
311
- left: 0;
312
- width: 100%;
313
- height: 100%;
314
315
  }
315
316
  </style>