sadais-piui 1.2.7-beta2 → 1.2.7-beta20

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,114 @@
1
+ <template>
2
+ <view class="pi-collapse" :class="[customClass]" :style="[customStyle]">
3
+ <pi-divider v-if="border" />
4
+ <slot />
5
+ </view>
6
+ </template>
7
+
8
+ <script>
9
+ import { getConfig } from '../../config'
10
+ const { collapse } = getConfig()
11
+ /**
12
+ * collapse 折叠面板
13
+ * @description 通过折叠面板收纳内容区域
14
+ * @tutorial http://piui.sadais.com/docs/components/collapse.html
15
+ * @event {Function} change 当前激活面板展开时触发(如果是手风琴模式,参数activeNames类型为String,否则为Array)
16
+ * @example <pi-collapse />
17
+ */
18
+ export default {
19
+ name: 'PiCollapse',
20
+ props: {
21
+ // 当前展开面板的name,非手风琴模式:[<string | number>],手风琴模式:string | number
22
+ value: {
23
+ type: [String, Number, Array],
24
+ default: collapse.value
25
+ },
26
+ // 是否手风琴模式
27
+ accordion: {
28
+ type: Boolean,
29
+ // false
30
+ default: collapse.accordion
31
+ },
32
+ // 是否显示外边框
33
+ border: {
34
+ type: Boolean,
35
+ // true
36
+ default: collapse.border
37
+ },
38
+ // 自定义折叠面板的样式类名
39
+ customClass: {
40
+ type: String,
41
+ default: collapse.customClass
42
+ },
43
+ // 自定义折叠面板的样式
44
+ customStyle: {
45
+ type: Object,
46
+ default: () => {
47
+ return collapse.customStyle
48
+ }
49
+ }
50
+ },
51
+ computed: {
52
+ needInit() {
53
+ // 通过computed,同时监听accordion和value值的变化
54
+ // 再通过watch去执行init()方法,进行再一次的初始化
55
+ return [this.accordion, this.value]
56
+ }
57
+ },
58
+ watch: {
59
+ needInit() {
60
+ this.init()
61
+ },
62
+ // 当父组件需要子组件需要共享的参数发生了变化,手动通知子组件
63
+ parentData() {
64
+ if (this.children.length) {
65
+ this.children.map(child => {
66
+ // 判断子组件(pi-collapse-item)如果有updateParentData方法的话,就就执行(执行的结果是子组件重新从父组件拉取了最新的值)
67
+ typeof child.updateParentData === 'function' && child.updateParentData()
68
+ })
69
+ }
70
+ }
71
+ },
72
+ created() {
73
+ this.children = []
74
+ },
75
+ methods: {
76
+ // 重新初始化一次内部的所有子元素
77
+ init() {
78
+ this.children.map(child => {
79
+ child.init()
80
+ })
81
+ },
82
+ /**
83
+ * collapse-item被点击时触发,由collapse统一处理各子组件的状态
84
+ * @param {Object} target 被操作的面板的实例
85
+ */
86
+ onChange(target) {
87
+ let changeArr = []
88
+ this.children.map((child, index) => {
89
+ // 如果是手风琴模式,将其他的折叠面板收起来
90
+ if (this.accordion) {
91
+ child.expanded = child === target ? !target.expanded : false
92
+ child.setContentAnimate()
93
+ } else {
94
+ if (child === target) {
95
+ child.expanded = !child.expanded
96
+ child.setContentAnimate()
97
+ }
98
+ }
99
+ // 拼接change事件中,数组元素的状态
100
+ changeArr.push({
101
+ // 如果没有定义name属性,则默认返回组件的index索引
102
+ name: child.name || index,
103
+ status: child.expanded ? 'open' : 'close'
104
+ })
105
+ })
106
+ // 触发change事件
107
+ this.$emit('change', changeArr)
108
+ this.$emit(target.expanded ? 'open' : 'close', target.name)
109
+ }
110
+ }
111
+ }
112
+ </script>
113
+
114
+ <style lang="scss" scoped></style>
@@ -0,0 +1,347 @@
1
+ <template>
2
+ <view
3
+ class="pi-collapse-item"
4
+ :class="[customClass]"
5
+ :style="[customStyle]"
6
+ @click="clickHandler"
7
+ >
8
+ <!-- 标题 -->
9
+ <view
10
+ class="pi-collapse-item__title pi-justify-between pi-align-center"
11
+ :class="{ disabled: disabled, border: border }"
12
+ >
13
+ <!-- 左侧 -->
14
+ <view class="pi-flex-column pi-lh-44">
15
+ <!-- 一级标题 -->
16
+ <slot name="title">
17
+ <text v-if="title" class="text">{{ title }}</text>
18
+ </slot>
19
+ <!-- 二级标题 -->
20
+ <text v-if="checkDesc" class="desc">{{ desc }}</text>
21
+ </view>
22
+ <!-- 右侧 -->
23
+ <view class="pi-align-center pi-lh-44">
24
+ <!-- 自定义内容 -->
25
+ <slot name="value">
26
+ <text v-if="checkValue" class="value">{{ value }}</text>
27
+ </slot>
28
+ <!-- 图标 -->
29
+ <view class="icon pi-mg-left-8" :class="getIconClass">
30
+ <pi-icon name="right" />
31
+ </view>
32
+ </view>
33
+ </view>
34
+ <!-- 内容 -->
35
+ <view ref="animation" class="pi-collapse-item__content" :animation="animationData">
36
+ <view :id="elId" :ref="elId" class="pi-collapse-item__content__text content-class">
37
+ <slot />
38
+ </view>
39
+ </view>
40
+ <pi-divider v-if="expanded && border" />
41
+ </view>
42
+ </template>
43
+
44
+ <script>
45
+ // #ifdef APP-NVUE
46
+ const animation = uni.requireNativePlugin('animation')
47
+ const dom = uni.requireNativePlugin('dom')
48
+ // #endif
49
+ import { getConfig } from '../../config'
50
+ const { collapseItem } = getConfig()
51
+
52
+ /**
53
+ * collapseItem 折叠面板Item
54
+ * @description 通过折叠面板收纳内容区域(搭配pi-collapse使用)
55
+ * @tutorial http://piui.sadais.com/docs/components/collapse.html
56
+ * @event {Function} change 某个item被打开或者收起时触发
57
+ * @example <pi-collapse-item :title="item.head" v-for="(item, index) in itemList" :key="index">{{item.body}}</pi-collapse-item>
58
+ */
59
+ export default {
60
+ name: 'PiCollapseItem',
61
+ props: {
62
+ // 标题
63
+ title: {
64
+ type: String,
65
+ default: collapseItem.title
66
+ },
67
+ // 自定义内容
68
+ value: {
69
+ type: String,
70
+ default: collapseItem.value
71
+ },
72
+ // 唯一标识
73
+ name: {
74
+ type: [Number, String],
75
+ default: collapseItem.name
76
+ },
77
+ // 描述
78
+ desc: {
79
+ type: String,
80
+ default: collapseItem.desc
81
+ },
82
+ // 是否禁用折叠面板
83
+ disabled: {
84
+ type: Boolean,
85
+ default: collapseItem.disabled
86
+ },
87
+ // 是否显示内边框
88
+ border: {
89
+ type: Boolean,
90
+ default: collapseItem.border
91
+ },
92
+ // 面板展开收起的过渡时间,单位ms
93
+ duration: {
94
+ type: Number,
95
+ default: collapseItem.duration
96
+ },
97
+ // 自定义折叠面板列表的样式类名
98
+ customClass: {
99
+ type: String,
100
+ default: collapseItem.customClass
101
+ },
102
+ // 自定义折叠面板列表的样式
103
+ customStyle: {
104
+ type: Object,
105
+ default: () => {
106
+ return collapseItem.customStyle
107
+ }
108
+ }
109
+ },
110
+ data() {
111
+ return {
112
+ elId: this.$pi.guid(), // 全局唯一标识符
113
+ // uni.createAnimation的导出数据
114
+ animationData: {},
115
+ // 是否展开状态
116
+ expanded: false,
117
+ // 根据expanded确定是否显示border,为了控制展开时,cell的下划线更好的显示效果,进行一定时间的延时
118
+ showBorder: false,
119
+ // 是否动画中,如果是则不允许继续触发点击
120
+ animating: false,
121
+ // 父组件pi-collapse的参数
122
+ parentData: {
123
+ accordion: false,
124
+ border: false
125
+ }
126
+ }
127
+ },
128
+ computed: {
129
+ // 动态改变折叠面板的展开收起状态
130
+ getIconClass() {
131
+ return this.expanded ? 'up' : 'down'
132
+ },
133
+ // 检查自定义内容是否为空
134
+ checkValue() {
135
+ return !this.$pi.lang.isEmpty(this.value)
136
+ },
137
+ // 检查自定义描述是否为空
138
+ checkDesc() {
139
+ return !this.$pi.lang.isEmpty(this.desc)
140
+ }
141
+ },
142
+ watch: {
143
+ expanded(n) {
144
+ clearTimeout(this.timer)
145
+ this.timer = null
146
+ // 这里根据expanded的值来进行一定的延时,是为了cell的下划线更好的显示效果
147
+ this.timer = setTimeout(
148
+ () => {
149
+ this.showBorder = n
150
+ },
151
+ n ? 10 : 290
152
+ )
153
+ }
154
+ },
155
+ mounted() {
156
+ this.init()
157
+ },
158
+ methods: {
159
+ // 异步获取内容,或者动态修改了内容时,需要重新初始化
160
+ init() {
161
+ // 初始化数据
162
+ this.updateParentData()
163
+ if (!this.parent) {
164
+ return console.error('pi-collapse-item必须要搭配pi-collapse组件使用')
165
+ }
166
+ const { value, accordion } = this.parent
167
+ if (accordion) {
168
+ if (this.$pi.lang.isArray(value)) {
169
+ return console.error('手风琴模式下,pi-collapse组件的value参数不能为数组')
170
+ }
171
+ this.expanded = this.name == value
172
+ } else {
173
+ if (!this.$pi.lang.isArray(value) && value !== null) {
174
+ return console.error('非手风琴模式下,pi-collapse组件的value参数必须为数组')
175
+ }
176
+ this.expanded = (value || []).some(item => item == this.name)
177
+ }
178
+ // 设置组件的展开或收起状态
179
+ this.$nextTick(function () {
180
+ this.setContentAnimate()
181
+ })
182
+ },
183
+ updateParentData() {
184
+ // 传组件Name给父组件,用于组件展开或收起时,改变父组件的值
185
+ this.getParentData('PiCollapse')
186
+ },
187
+ async setContentAnimate() {
188
+ // 每次面板打开或者收起时,都查询元素尺寸
189
+ // 好处是,父组件从服务端获取内容后,变更折叠面板后可以获得最新的高度
190
+ const rect = await this.queryRect()
191
+ const height = this.expanded ? rect.height : 0
192
+ this.animating = true
193
+ // #ifdef APP-NVUE
194
+ const ref = this.$refs['animation'].ref
195
+ animation.transition(
196
+ ref,
197
+ {
198
+ styles: {
199
+ height: height + 'px'
200
+ },
201
+ duration: this.duration,
202
+ // 必须设置为true,否则会到面板收起或展开时,页面其他元素不会随之调整它们的布局
203
+ needLayout: true,
204
+ timingFunction: 'ease-in-out'
205
+ },
206
+ () => {
207
+ this.animating = false
208
+ }
209
+ )
210
+ // #endif
211
+
212
+ // #ifndef APP-NVUE
213
+ const animation = uni.createAnimation({
214
+ timingFunction: 'ease-in-out'
215
+ })
216
+ animation
217
+ .height(height)
218
+ .step({
219
+ duration: this.duration
220
+ })
221
+ .step()
222
+ // 导出动画数据给面板的animationData值
223
+ this.animationData = animation.export()
224
+ // 标识动画结束
225
+ this.sleep(this.duration).then(() => {
226
+ this.animating = false
227
+ })
228
+ // #endif
229
+ },
230
+ // 点击collapsehead头部
231
+ clickHandler() {
232
+ if (this.disabled || this.animating) return
233
+ // 设置本组件为相反的状态
234
+ this.parent && this.parent.onChange(this)
235
+ },
236
+ /**
237
+ * @description 进行延时,以达到可以简写代码的目的
238
+ * @param {number} value 堵塞时间 单位ms 毫秒
239
+ * @returns {Promise} 返回promise
240
+ */
241
+ sleep(value) {
242
+ return new Promise(resolve => {
243
+ setTimeout(() => {
244
+ resolve()
245
+ }, value)
246
+ })
247
+ },
248
+ // 查询内容高度
249
+ queryRect() {
250
+ return new Promise(resolve => {
251
+ // #ifndef APP-NVUE
252
+ this.$pi.common.queryRect(this, `#${this.elId}`).then(size => {
253
+ resolve(size)
254
+ })
255
+ // #endif
256
+
257
+ // #ifdef APP-NVUE
258
+ // nvue下,使用dom模块查询元素高度
259
+ // 返回一个promise,让调用此方法的主体能使用then回调
260
+ dom.getComponentRect(this.$refs[this.elId], res => {
261
+ resolve(res.size)
262
+ })
263
+ // #endif
264
+ })
265
+ },
266
+ getParentData(parentName = '') {
267
+ // 避免在created中去定义parent变量
268
+ if (!this.parent) this.parent = {}
269
+ this.parent = this.$pi.parent(this, parentName)
270
+ if (this.parent.children) {
271
+ // 如果父组件的children不存在本组件的实例,才将本实例添加到父组件的children中
272
+ this.parent.children.indexOf(this) === -1 && this.parent.children.push(this)
273
+ }
274
+ if (this.parent && this.parentData) {
275
+ // 历遍parentData中的属性,将parent中的同名属性赋值给parentData
276
+ Object.keys(this.parentData).map(key => {
277
+ this.parentData[key] = this.parent[key]
278
+ })
279
+ }
280
+ }
281
+ }
282
+ }
283
+ </script>
284
+
285
+ <style lang="scss" scoped>
286
+ .pi-collapse-item {
287
+ &__title {
288
+ padding: 15px;
289
+ // 边框
290
+ &.border {
291
+ position: relative;
292
+ &:after {
293
+ content: ' ';
294
+ position: absolute;
295
+ left: 0;
296
+ bottom: 0;
297
+ right: 0;
298
+ height: 1px;
299
+ border-bottom: 1px solid rgb(214, 228, 239);
300
+ color: rgb(214, 228, 239);
301
+ -webkit-transform-origin: 0 0;
302
+ transform-origin: 0 0;
303
+ -webkit-transform: scaleY(0.5);
304
+ transform: scaleY(0.5);
305
+ }
306
+ }
307
+ &:active {
308
+ background-color: #f3f4f6;
309
+ }
310
+ .text {
311
+ color: #303133;
312
+ }
313
+ .desc {
314
+ font-size: 24rpx;
315
+ color: #8c8c8c;
316
+ }
317
+ .icon {
318
+ color: #909399;
319
+ transition: transform 0.3s;
320
+ &.up {
321
+ transform: rotate(-90deg);
322
+ }
323
+
324
+ &.down {
325
+ transform: rotate(90deg);
326
+ }
327
+ }
328
+ &.disabled {
329
+ cursor: not-allowed;
330
+ .text,
331
+ .icon {
332
+ color: #cccccc;
333
+ }
334
+ }
335
+ }
336
+ &__content {
337
+ overflow: hidden;
338
+ height: 0;
339
+
340
+ &__text {
341
+ padding: 24rpx 30rpx;
342
+ color: #606266;
343
+ line-height: 36rpx;
344
+ }
345
+ }
346
+ }
347
+ </style>
@@ -119,6 +119,13 @@ export default {
119
119
  // ''
120
120
  default: datePicker.defaultValue
121
121
  },
122
+ // 单位数组,默认值:['年', '月', '日', '时', '分', '秒']
123
+ units: {
124
+ type: Array,
125
+ default() {
126
+ return datePicker.units
127
+ }
128
+ },
122
129
  // 返回的日期格式
123
130
  format: {
124
131
  type: String,
@@ -227,33 +234,40 @@ export default {
227
234
  const itemHeight = uni.upx2px(this.itemHeight)
228
235
  return `height: ${itemHeight}px;line-height: ${itemHeight}px;`
229
236
  },
237
+ getUnits() {
238
+ return this.$pi.mergeDeep(datePicker.units, this.units, {
239
+ arrayMerge: (target, source, options) => {
240
+ return target.map((t, index) => source[index] || t)
241
+ }
242
+ })
243
+ },
230
244
  columns() {
231
245
  const monthDays = new Date(this.date.year, this.date.month, 0).getDate()
232
246
  let columns = [
233
247
  {
234
248
  field: 'year',
235
- unit: '年',
249
+ unit: this.getUnits[0],
236
250
  key: 'year',
237
251
  setMethod: 'setYear',
238
252
  items: this.$pi.common.generateArray(this.startYear, this.endYear)
239
253
  },
240
254
  {
241
255
  field: 'month',
242
- unit: '月',
256
+ unit: this.getUnits[1],
243
257
  key: 'month',
244
258
  setMethod: 'setMonth',
245
259
  items: this.$pi.common.generateArray(1, 12)
246
260
  },
247
261
  {
248
262
  field: 'day',
249
- unit: '日',
263
+ unit: this.getUnits[2],
250
264
  key: 'date',
251
265
  setMethod: 'setDate',
252
266
  items: this.$pi.common.generateArray(1, monthDays)
253
267
  },
254
268
  {
255
269
  field: 'hour',
256
- unit: '时',
270
+ unit: this.getUnits[3],
257
271
  key: 'hour',
258
272
  setMethod: 'setHours',
259
273
  type: 'time',
@@ -261,7 +275,7 @@ export default {
261
275
  },
262
276
  {
263
277
  field: 'minute',
264
- unit: '分',
278
+ unit: this.getUnits[4],
265
279
  key: 'minute',
266
280
  setMethod: 'setMinutes',
267
281
  type: 'time',
@@ -269,7 +283,7 @@ export default {
269
283
  },
270
284
  {
271
285
  field: 'second',
272
- unit: '秒',
286
+ unit: this.getUnits[5],
273
287
  key: 'second',
274
288
  setMethod: 'setSeconds',
275
289
  type: 'time',
@@ -2,7 +2,7 @@
2
2
  <view class="dropdown-tab-item" :class="[{ opened: item.opened }]">
3
3
  <!-- 注意:slot内不能使用父组件data -->
4
4
  <view
5
- class="pi-align-center"
5
+ class="pi-justify-center pi-align-center"
6
6
  :style="{ color: item.opened && item.activeColor ? item.activeColor : 'inherit' }"
7
7
  @tap.stop="handleClick"
8
8
  >
@@ -18,10 +18,10 @@
18
18
  :custom-class="`pi-mg-right-8 ${item.iconOption.customClass}`"
19
19
  />
20
20
 
21
- <text class=" pi-pd-right-8 pi-fz-28">
21
+ <text class="pi-pd-right-12 pi-fz-28">
22
22
  {{ item.text }}
23
23
  </text>
24
- <pi-icon :class="{ rotate: item.opened }" name="unfold" size="26" />
24
+ <pi-icon :class="{ rotate: item.opened }" name="arrow-down_fill" size="26" color="#999" />
25
25
  </view>
26
26
  </view>
27
27
  </template>
@@ -49,7 +49,6 @@ export default {
49
49
 
50
50
  <style lang="scss" scoped>
51
51
  .dropdown-tab-item {
52
- font-size: 33rpx;
53
52
  &.opened {
54
53
  color: $pi-primary-color;
55
54
  }
@@ -6,18 +6,22 @@
6
6
  :items="tabs"
7
7
  :show-slider-bar="false"
8
8
  show-item-split-line
9
+ :stretch="stretch"
9
10
  active-text-color="inherit"
10
11
  >
11
- <view slot="item" slot-scope="{ item, index }">
12
- <!-- 注意:slot内不能使用父组件data -->
13
- <dropdown-tab :item="item" @click="handleClickTab(item, index)" />
14
- </view>
12
+ <!-- 注意:slot内不能使用父组件data -->
13
+ <dropdown-tab
14
+ slot="item"
15
+ slot-scope="{ item, index }"
16
+ :item="item"
17
+ @click="handleClickTab(item, index)"
18
+ />
15
19
  </pi-tabs>
16
20
  </view>
17
21
  <!-- 展示dropdownItem下的数据 -->
18
22
  <view
19
- class="pi-dropdown-content pi-mg-top-12"
20
- :class="[contentClass, show ? 'pi-ani-slide-top-show' : 'pi-ani-slide-top-hide']"
23
+ class="pi-dropdown-content"
24
+ :class="[contentClass, show ? 'pi-ani-slide-bottom-show' : 'pi-ani-slide-bottom-hide']"
21
25
  :style="[contentStyle, contentCombinationStyle]"
22
26
  >
23
27
  <slot />
@@ -26,11 +30,12 @@
26
30
  <!-- 遮罩层 -->
27
31
  <view
28
32
  v-if="!closed"
29
- class="pi-abso pi-dropdown-mask"
33
+ class="pi-fixed pi-dropdown-mask"
30
34
  :class="[show ? getMask.animationShow : getMask.animationHide]"
31
35
  :style="[
32
36
  {
33
37
  'z-index': getMask.zIndex,
38
+ 'top': maskAlignTop ? containerRect.top + containerRect.height + 'px' : '-9999px',
34
39
  'background': getMask.background,
35
40
  'animation-duration': getDuration.css
36
41
  }
@@ -158,11 +163,27 @@ export default {
158
163
  },
159
164
  // 选中checkbox配置
160
165
  selectedCheckbox: {
161
- type: Object,
166
+ type: [Object, String],
162
167
  default() {
163
168
  // 参照checkbox
164
169
  return dropdown.selectedCheckbox
165
170
  }
171
+ },
172
+ // 标签是否均分布局,可选值 `true`
173
+ stretch: {
174
+ type: Boolean,
175
+ // `false`
176
+ default() {
177
+ return dropdown.stretch
178
+ }
179
+ },
180
+ // 是否需要蒙层顶部对齐组件,可选值 `false`
181
+ maskAlignTop: {
182
+ type: Boolean,
183
+ // `true`
184
+ default() {
185
+ return dropdown.maskAlignTop
186
+ }
166
187
  }
167
188
  },
168
189
  data() {
@@ -182,8 +203,8 @@ export default {
182
203
  const { containerRect, closed } = this
183
204
  return {
184
205
  top: `${containerRect.height}px`,
185
- left: 0,
186
- width: `${containerRect.width}px`,
206
+ left: `-${containerRect.left}px`,
207
+ width: `${this.$pi.system.systemInfo.windowWidth}px`,
187
208
  zIndex: !closed ? 101 : -1
188
209
  }
189
210
  },
@@ -218,15 +239,11 @@ export default {
218
239
  // 同步父子组件的值
219
240
  if (this.val[index] !== item.val) {
220
241
  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
- }
242
+ item.emitChange(this.val[index])
228
243
  }
229
- const currentOption = item.options?.find(opt => opt[item.getKeyField] === this.val[index])
244
+ const currentOption = item.options?.find(
245
+ opt => !opt.clearable && opt[item.getKeyField] === this.val[index]
246
+ )
230
247
  const newItem = {
231
248
  showIcon: item.showIcon,
232
249
  iconOption: item.getIconOption,
@@ -246,6 +263,10 @@ export default {
246
263
  // 显示当前Tab
247
264
  async handleClickTab(item) {
248
265
  if (item.disabled) return
266
+ if (this.show && item.id === this.activeItem.id) {
267
+ this.closeMask()
268
+ return
269
+ }
249
270
  // 更新打开的tab标志
250
271
  this.tabs = this.tabs.map(tab => {
251
272
  tab.opened = tab.id === item.id
@@ -304,10 +325,8 @@ export default {
304
325
  .pi-dropdown-content {
305
326
  position: absolute;
306
327
  background: #ffffff;
307
- border-radius: 12rpx;
308
328
  }
309
329
  .pi-dropdown-mask {
310
- top: -9999px;
311
330
  left: -9999px;
312
331
  right: -9999px;
313
332
  bottom: -9999px;