sadais-piui 1.2.7-beta13 → 1.2.7-beta131

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 (71) hide show
  1. package/.prettierrc +8 -0
  2. package/components/pi-badge/index.vue +11 -1
  3. package/components/pi-bottom-bar/index.vue +1 -1
  4. package/components/pi-calendar/index.vue +207 -182
  5. package/components/pi-calendar-input/index.vue +61 -30
  6. package/components/pi-calendar-panel/components/calendar-days/index.vue +91 -52
  7. package/components/pi-calendar-panel/index.vue +28 -12
  8. package/components/pi-canvas/index.vue +8 -1
  9. package/components/pi-cascader/index.vue +601 -0
  10. package/components/pi-checkbox/index.vue +8 -4
  11. package/components/pi-checkbox-group/index.vue +12 -11
  12. package/components/pi-circle-progress/index.vue +108 -21
  13. package/components/pi-code-input/index.vue +11 -3
  14. package/components/pi-collapse/index.vue +124 -0
  15. package/components/pi-collapse-item/index.vue +360 -0
  16. package/components/pi-date-picker/index.vue +512 -391
  17. package/components/pi-date-picker-input/index.vue +61 -30
  18. package/components/pi-dropdown/components/dropdown-tab.vue +33 -23
  19. package/components/pi-dropdown/index.vue +34 -19
  20. package/components/pi-dropdown-item/index.vue +70 -58
  21. package/components/pi-form-item/index.vue +99 -21
  22. package/components/pi-grid/index.vue +1 -1
  23. package/components/pi-grid-item/index.vue +4 -4
  24. package/components/pi-img/index.vue +275 -267
  25. package/components/pi-img-cropper/index.vue +110 -110
  26. package/components/pi-input/index.vue +95 -34
  27. package/components/pi-list-item/index.vue +1 -1
  28. package/components/pi-mask/index.vue +3 -1
  29. package/components/pi-pagination/index.vue +13 -0
  30. package/components/pi-popup/index.vue +4 -1
  31. package/components/pi-popup-select/index.vue +8 -1
  32. package/components/pi-radio/index.vue +12 -11
  33. package/components/pi-radio-group/index.vue +25 -5
  34. package/components/pi-regions-select/index.vue +6 -1
  35. package/components/pi-regions-select-input/index.vue +69 -31
  36. package/components/pi-search/index.vue +37 -2
  37. package/components/pi-section/index.vue +1 -1
  38. package/components/pi-select/index.vue +237 -22
  39. package/components/pi-select-input/index.vue +106 -41
  40. package/components/pi-stepper/index.vue +135 -121
  41. package/components/pi-steps/index.vue +115 -36
  42. package/components/pi-swiper/index.vue +22 -7
  43. package/components/pi-switch/index.vue +5 -1
  44. package/components/pi-table/index.vue +351 -0
  45. package/components/pi-tabs/index.vue +46 -10
  46. package/components/pi-tag/index.vue +488 -0
  47. package/components/pi-upload-img/index.vue +541 -37
  48. package/components/pi-webview/index.vue +95 -82
  49. package/config/actionSheet.js +0 -1
  50. package/config/calendarInput.js +2 -1
  51. package/config/calendarPanel.js +2 -1
  52. package/config/cascader.js +22 -0
  53. package/config/circleProgress.js +17 -10
  54. package/config/codeInput.js +2 -1
  55. package/config/collapse.js +7 -0
  56. package/config/collapseItem.js +11 -0
  57. package/config/datePicker.js +29 -24
  58. package/config/datePickerInput.js +2 -1
  59. package/config/dropdown.js +3 -1
  60. package/config/input.js +5 -3
  61. package/config/regionsSelectInput.js +2 -1
  62. package/config/select.js +13 -1
  63. package/config/selectInput.js +2 -1
  64. package/config/steps.js +1 -1
  65. package/config/table.js +9 -0
  66. package/config/tag.js +21 -0
  67. package/config/uploadImg.js +30 -11
  68. package/package.json +5 -2
  69. package/scss/common.scss +11 -14
  70. package/scss/icon/icon.scss +2 -1
  71. package/scss/mixin.scss +5 -5
@@ -0,0 +1,360 @@
1
+ <template>
2
+ <view class="pi-collapse-item" :class="[customClass]" :style="[customStyle]">
3
+ <!-- 标题 -->
4
+ <view
5
+ class="pi-collapse-item__title pi-justify-between pi-align-center"
6
+ :class="{ disabled: disabled, border: border }"
7
+ @tap="handleCollapseItemClick"
8
+ >
9
+ <!-- 左侧 -->
10
+ <view class="pi-flex-column pi-lh-44">
11
+ <!-- 一级标题 -->
12
+ <slot name="title">
13
+ <text v-if="title" class="text">{{ title }}</text>
14
+ </slot>
15
+ <!-- 二级标题 -->
16
+ <text v-if="checkDesc" class="desc">{{ desc }}</text>
17
+ </view>
18
+ <!-- 右侧 -->
19
+ <view class="pi-align-center pi-lh-44">
20
+ <!-- 自定义内容 -->
21
+ <slot name="value">
22
+ <text v-if="checkValue" class="value">{{ value }}</text>
23
+ </slot>
24
+ <!-- 图标 -->
25
+ <view class="icon pi-mg-left-8" :class="getIconClass">
26
+ <pi-icon name="right" />
27
+ </view>
28
+ </view>
29
+ </view>
30
+ <!-- 内容 -->
31
+ <view
32
+ ref="animation"
33
+ class="pi-collapse-item__content"
34
+ :animation="animationData"
35
+ @tap="handleContentClick"
36
+ >
37
+ <view
38
+ :id="elId"
39
+ :ref="elId"
40
+ class="pi-collapse-item__content__text content-class"
41
+ >
42
+ <slot />
43
+ </view>
44
+ </view>
45
+ <pi-divider v-if="expanded && border" />
46
+ </view>
47
+ </template>
48
+
49
+ <script>
50
+ // #ifdef APP-NVUE
51
+ const animation = uni.requireNativePlugin('animation')
52
+ const dom = uni.requireNativePlugin('dom')
53
+ // #endif
54
+ import { getConfig } from '../../config'
55
+ const { collapseItem } = getConfig()
56
+
57
+ /**
58
+ * collapseItem 折叠面板Item
59
+ * @description 通过折叠面板收纳内容区域(搭配pi-collapse使用)
60
+ * @tutorial http://piui.sadais.com/docs/components/collapse.html
61
+ * @event {Function} change 某个item被打开或者收起时触发
62
+ * @example <pi-collapse-item :title="item.head" v-for="(item, index) in itemList" :key="index">{{item.body}}</pi-collapse-item>
63
+ */
64
+ export default {
65
+ name: 'PiCollapseItem',
66
+ props: {
67
+ // 标题
68
+ title: {
69
+ type: String,
70
+ default: collapseItem.title
71
+ },
72
+ // 自定义内容
73
+ value: {
74
+ type: String,
75
+ default: collapseItem.value
76
+ },
77
+ // 唯一标识
78
+ name: {
79
+ type: [Number, String],
80
+ default: collapseItem.name
81
+ },
82
+ // 描述
83
+ desc: {
84
+ type: String,
85
+ default: collapseItem.desc
86
+ },
87
+ // 是否禁用折叠面板
88
+ disabled: {
89
+ type: Boolean,
90
+ default: collapseItem.disabled
91
+ },
92
+ // 是否显示内边框
93
+ border: {
94
+ type: Boolean,
95
+ default: collapseItem.border
96
+ },
97
+ // 面板展开收起的过渡时间,单位ms
98
+ duration: {
99
+ type: Number,
100
+ default: collapseItem.duration
101
+ },
102
+ // 自定义折叠面板列表的样式类名
103
+ customClass: {
104
+ type: String,
105
+ default: collapseItem.customClass
106
+ },
107
+ // 自定义折叠面板列表的样式
108
+ customStyle: {
109
+ type: Object,
110
+ default: () => {
111
+ return collapseItem.customStyle
112
+ }
113
+ }
114
+ },
115
+ data() {
116
+ return {
117
+ elId: this.$pi.guid(), // 全局唯一标识符
118
+ // uni.createAnimation的导出数据
119
+ animationData: {},
120
+ // 是否展开状态
121
+ expanded: true,
122
+ // 根据expanded确定是否显示border,为了控制展开时,cell的下划线更好的显示效果,进行一定时间的延时
123
+ showBorder: false,
124
+ // 是否动画中,如果是则不允许继续触发点击
125
+ animating: false,
126
+ // 父组件pi-collapse的参数
127
+ parentData: {
128
+ accordion: false,
129
+ border: false
130
+ }
131
+ }
132
+ },
133
+ computed: {
134
+ // 动态改变折叠面板的展开收起状态
135
+ getIconClass() {
136
+ return this.expanded ? 'up' : 'down'
137
+ },
138
+ // 检查自定义内容是否为空
139
+ checkValue() {
140
+ return !this.$pi.lang.isEmpty(this.value)
141
+ },
142
+ // 检查自定义描述是否为空
143
+ checkDesc() {
144
+ return !this.$pi.lang.isEmpty(this.desc)
145
+ }
146
+ },
147
+ watch: {
148
+ expanded(n) {
149
+ clearTimeout(this.timer)
150
+ this.timer = null
151
+ // 这里根据expanded的值来进行一定的延时,是为了cell的下划线更好的显示效果
152
+ this.timer = setTimeout(
153
+ () => {
154
+ this.showBorder = n
155
+ },
156
+ n ? 10 : 290
157
+ )
158
+ }
159
+ },
160
+ mounted() {
161
+ this.init()
162
+ },
163
+ methods: {
164
+ // 异步获取内容,或者动态修改了内容时,需要重新初始化
165
+ init() {
166
+ // 初始化数据
167
+ this.updateParentData()
168
+ if (!this.parent) {
169
+ return console.error('pi-collapse-item必须要搭配pi-collapse组件使用')
170
+ }
171
+ const { val, accordion } = this.parent
172
+ if (accordion) {
173
+ if (this.$pi.lang.isArray(val)) {
174
+ return console.error(
175
+ '手风琴模式下,pi-collapse组件的value参数不能为数组'
176
+ )
177
+ }
178
+ this.expanded = this.name == val
179
+ } else {
180
+ if (!this.$pi.lang.isArray(val) && val !== null) {
181
+ return console.error(
182
+ '非手风琴模式下,pi-collapse组件的value参数必须为数组'
183
+ )
184
+ }
185
+ this.expanded = (val || []).some(item => item == this.name)
186
+ }
187
+ console.log('折叠面板item初始化', val, accordion, this.expanded)
188
+ // 设置组件的展开或收起状态
189
+ setTimeout(() => {
190
+ this.setContentAnimate()
191
+ }, 200)
192
+ },
193
+ updateParentData() {
194
+ // 传组件Name给父组件,用于组件展开或收起时,改变父组件的值
195
+ this.getParentData('PiCollapse')
196
+ },
197
+ async setContentAnimate() {
198
+ // 每次面板打开或者收起时,都查询元素尺寸
199
+ // 好处是,父组件从服务端获取内容后,变更折叠面板后可以获得最新的高度
200
+ const rect = await this.queryRect()
201
+ const height = this.expanded ? rect.height : 0
202
+ this.animating = true
203
+ // #ifdef APP-NVUE
204
+ const ref = this.$refs['animation'].ref
205
+ animation.transition(
206
+ ref,
207
+ {
208
+ styles: {
209
+ height: height + 'px'
210
+ },
211
+ duration: this.duration,
212
+ // 必须设置为true,否则会到面板收起或展开时,页面其他元素不会随之调整它们的布局
213
+ needLayout: true,
214
+ timingFunction: 'ease-in-out'
215
+ },
216
+ () => {
217
+ this.animating = false
218
+ }
219
+ )
220
+ // #endif
221
+
222
+ // #ifndef APP-NVUE
223
+ const animation = uni.createAnimation({
224
+ timingFunction: 'ease-in-out'
225
+ })
226
+ animation
227
+ .height(height)
228
+ .step({
229
+ duration: this.duration
230
+ })
231
+ .step()
232
+ // 导出动画数据给面板的animationData值
233
+ this.animationData = animation.export()
234
+ // 标识动画结束
235
+ this.sleep(this.duration).then(() => {
236
+ this.animating = false
237
+ })
238
+ // #endif
239
+ },
240
+ handleContentClick() {
241
+ this.$emit('content-click')
242
+ },
243
+ // 点击collapsehead头部
244
+ handleCollapseItemClick() {
245
+ if (this.disabled || this.animating) return
246
+ // 设置本组件为相反的状态
247
+ this.parent && this.parent.onChange(this)
248
+ },
249
+ /**
250
+ * @description 进行延时,以达到可以简写代码的目的
251
+ * @param {number} value 堵塞时间 单位ms 毫秒
252
+ * @returns {Promise} 返回promise
253
+ */
254
+ sleep(value) {
255
+ return new Promise(resolve => {
256
+ setTimeout(() => {
257
+ resolve()
258
+ }, value)
259
+ })
260
+ },
261
+ // 查询内容高度
262
+ queryRect() {
263
+ return new Promise(resolve => {
264
+ // #ifndef APP-NVUE
265
+ this.$pi.common.queryRect(this, `#${this.elId}`).then(size => {
266
+ resolve(size)
267
+ })
268
+ // #endif
269
+
270
+ // #ifdef APP-NVUE
271
+ // nvue下,使用dom模块查询元素高度
272
+ // 返回一个promise,让调用此方法的主体能使用then回调
273
+ dom.getComponentRect(this.$refs[this.elId], res => {
274
+ resolve(res.size)
275
+ })
276
+ // #endif
277
+ })
278
+ },
279
+ getParentData(parentName = '') {
280
+ // 避免在created中去定义parent变量
281
+ if (!this.parent) this.parent = {}
282
+ this.parent = this.$pi.parent(this, parentName)
283
+ if (this.parent.children) {
284
+ // 如果父组件的children不存在本组件的实例,才将本实例添加到父组件的children中
285
+ this.parent.children.indexOf(this) === -1 &&
286
+ this.parent.children.push(this)
287
+ }
288
+ if (this.parent && this.parentData) {
289
+ // 历遍parentData中的属性,将parent中的同名属性赋值给parentData
290
+ Object.keys(this.parentData).map(key => {
291
+ this.parentData[key] = this.parent[key]
292
+ })
293
+ }
294
+ }
295
+ }
296
+ }
297
+ </script>
298
+
299
+ <style lang="scss" scoped>
300
+ .pi-collapse-item {
301
+ &__title {
302
+ padding: 15px;
303
+ // 边框
304
+ &.border {
305
+ position: relative;
306
+ &:after {
307
+ content: ' ';
308
+ position: absolute;
309
+ left: 0;
310
+ bottom: 0;
311
+ right: 0;
312
+ height: 1px;
313
+ border-bottom: 1px solid rgb(214, 228, 239);
314
+ color: rgb(214, 228, 239);
315
+ -webkit-transform-origin: 0 0;
316
+ transform-origin: 0 0;
317
+ -webkit-transform: scaleY(0.5);
318
+ transform: scaleY(0.5);
319
+ }
320
+ }
321
+ &:active {
322
+ background-color: #f3f4f6;
323
+ }
324
+ .text {
325
+ color: #303133;
326
+ }
327
+ .desc {
328
+ font-size: 24rpx;
329
+ color: #8c8c8c;
330
+ }
331
+ .icon {
332
+ color: #909399;
333
+ transition: transform 0.3s;
334
+ &.up {
335
+ transform: rotate(-90deg);
336
+ }
337
+
338
+ &.down {
339
+ transform: rotate(90deg);
340
+ }
341
+ }
342
+ &.disabled {
343
+ .text,
344
+ .icon {
345
+ color: #cccccc;
346
+ }
347
+ }
348
+ }
349
+ &__content {
350
+ overflow: hidden;
351
+ height: auto;
352
+
353
+ &__text {
354
+ padding: 24rpx 30rpx;
355
+ color: #606266;
356
+ line-height: 36rpx;
357
+ }
358
+ }
359
+ }
360
+ </style>