sadais-piui 1.0.182 → 1.2.0
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 +482 -240
- package/README.md +27 -17
- package/components/pi-bottom-bar/index.vue +11 -2
- package/components/pi-calendar-panel/index.vue +10 -4
- package/components/pi-checkbox-group/index.vue +5 -0
- package/components/pi-circle-progress/index.vue +196 -173
- package/components/pi-count-up/index.vue +209 -0
- package/components/pi-dropdown/components/dropdown-tab.vue +62 -0
- package/components/pi-dropdown/index.vue +316 -0
- package/components/pi-dropdown-item/index.vue +233 -0
- package/components/pi-form-item/index.vue +13 -1
- package/components/pi-img-cropper/canvas.js +112 -0
- package/components/pi-img-cropper/index.vue +357 -0
- package/components/pi-img-cropper/touch.js +163 -0
- package/components/pi-img-cropper/vector.js +35 -0
- package/components/pi-input/index.vue +9 -2
- package/components/pi-line/index.vue +78 -0
- package/components/pi-notify/index.vue +239 -0
- package/components/pi-popup/index.vue +1 -3
- package/components/pi-select/index.vue +5 -5
- package/components/pi-steps/index.vue +299 -0
- package/components/pi-switch/index.vue +2 -3
- package/components/pi-tabs/index.vue +1 -1
- package/components/pi-upload-img/index.vue +145 -40
- package/config/bottomBar.js +1 -0
- package/config/checkbox.js +1 -1
- package/config/circleProgress.js +13 -0
- package/config/countUp.js +13 -0
- package/config/dropdown.js +21 -0
- package/config/dropdownItem.js +26 -0
- package/config/form.js +3 -3
- package/config/imgCropper.js +26 -0
- package/config/line.js +8 -0
- package/config/notify.js +13 -0
- package/config/steps.js +19 -0
- package/config/{upload-img.js → uploadImg.js} +5 -1
- package/index.js +2 -2
- package/package.json +3 -3
- package/scss/common.scss +4 -0
- package/scss/variable.scss +1 -1
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<view
|
|
3
|
+
class="pi-count-up-wrapper"
|
|
4
|
+
:style="{
|
|
5
|
+
fontSize: fontSize + 'rpx',
|
|
6
|
+
color: fontColor
|
|
7
|
+
}"
|
|
8
|
+
>
|
|
9
|
+
<slot :val="showingVal">{{ showingVal }}</slot>
|
|
10
|
+
</view>
|
|
11
|
+
</template>
|
|
12
|
+
|
|
13
|
+
<script>
|
|
14
|
+
import { getConfig } from '../../config'
|
|
15
|
+
const { countUp } = getConfig()
|
|
16
|
+
|
|
17
|
+
export default {
|
|
18
|
+
name: 'PiCountUp',
|
|
19
|
+
props: {
|
|
20
|
+
// 自定义样式,对象形式
|
|
21
|
+
customStyle: {
|
|
22
|
+
type: Object,
|
|
23
|
+
default() {
|
|
24
|
+
// {}
|
|
25
|
+
return countUp.customStyle
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
// 自定义样式类,字符串形式
|
|
29
|
+
customClass: {
|
|
30
|
+
type: String,
|
|
31
|
+
default() {
|
|
32
|
+
// ''
|
|
33
|
+
return countUp.customClass
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
// 开始的数值,默认从0增长到某一个数
|
|
37
|
+
startNum: {
|
|
38
|
+
type: [Number, String],
|
|
39
|
+
default: countUp.startNum
|
|
40
|
+
},
|
|
41
|
+
// 要滚动的目标数值,必须
|
|
42
|
+
endNum: {
|
|
43
|
+
type: [Number, String],
|
|
44
|
+
default: 0,
|
|
45
|
+
required: countUp.endNum
|
|
46
|
+
},
|
|
47
|
+
// 滚动到目标数值的动画持续时间,单位为毫秒(ms)
|
|
48
|
+
duration: {
|
|
49
|
+
type: [Number, String],
|
|
50
|
+
default: countUp.duration
|
|
51
|
+
},
|
|
52
|
+
// 设置数值后是否自动开始滚动
|
|
53
|
+
autoplay: {
|
|
54
|
+
type: Boolean,
|
|
55
|
+
default: countUp.autoplay
|
|
56
|
+
},
|
|
57
|
+
// 要显示的小数位数
|
|
58
|
+
decimals: {
|
|
59
|
+
type: [Number, String],
|
|
60
|
+
default: countUp.decimals
|
|
61
|
+
},
|
|
62
|
+
// 千位符分隔符,默认为空
|
|
63
|
+
thousands: {
|
|
64
|
+
type: [String],
|
|
65
|
+
default: countUp.thousands
|
|
66
|
+
},
|
|
67
|
+
// 是否在即将到达目标数值的时候,使用缓慢滚动的效果
|
|
68
|
+
isEase: {
|
|
69
|
+
type: Boolean,
|
|
70
|
+
default: countUp.isEase
|
|
71
|
+
},
|
|
72
|
+
// 字体颜色
|
|
73
|
+
fontColor: {
|
|
74
|
+
type: String,
|
|
75
|
+
default: countUp.fontColor
|
|
76
|
+
},
|
|
77
|
+
// 字体大小
|
|
78
|
+
fontSize: {
|
|
79
|
+
type: [Number, String],
|
|
80
|
+
default: countUp.fontSize
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
data() {
|
|
84
|
+
return {
|
|
85
|
+
startNumCache: this.startNum,
|
|
86
|
+
showingVal: this.formatNumber(this.startNum),
|
|
87
|
+
printVal: null,
|
|
88
|
+
isPaused: false, // 是否暂停
|
|
89
|
+
durationCache: Number(this.duration),
|
|
90
|
+
startTime: null, // 开始的时间
|
|
91
|
+
timestamp: null, // 时间戳
|
|
92
|
+
remaining: null, // 停留的时间
|
|
93
|
+
timer: null,
|
|
94
|
+
lastTime: 0 // 上一次的时间
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
computed: {
|
|
98
|
+
countDown() {
|
|
99
|
+
return this.startNum > this.endNum
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
watch: {
|
|
103
|
+
startNum() {
|
|
104
|
+
this.autoplay && this.start()
|
|
105
|
+
},
|
|
106
|
+
endNum() {
|
|
107
|
+
this.autoplay && this.start()
|
|
108
|
+
}
|
|
109
|
+
},
|
|
110
|
+
mounted() {
|
|
111
|
+
this.autoplay && this.start()
|
|
112
|
+
},
|
|
113
|
+
methods: {
|
|
114
|
+
easingFn(t, b, c, d) {
|
|
115
|
+
return (c * (-Math.pow(2, (-10 * t) / d) + 1) * 1024) / 1023 + b
|
|
116
|
+
},
|
|
117
|
+
requestTimeout(callback) {
|
|
118
|
+
const currTime = new Date().getTime()
|
|
119
|
+
// 为了使setTimteout的尽可能的接近每秒60帧的效果
|
|
120
|
+
const timeToCall = Math.max(0, 16 - (currTime - this.lastTime)) // 计算当前一帧内还剩多少时间
|
|
121
|
+
const id = setTimeout(() => {
|
|
122
|
+
callback(currTime + timeToCall)
|
|
123
|
+
}, timeToCall)
|
|
124
|
+
this.lastTime = currTime + timeToCall
|
|
125
|
+
return id
|
|
126
|
+
},
|
|
127
|
+
// 开始滚动数字
|
|
128
|
+
start() {
|
|
129
|
+
this.startNumCache = this.startNum
|
|
130
|
+
this.startTime = null
|
|
131
|
+
this.durationCache = this.duration
|
|
132
|
+
this.isPaused = false
|
|
133
|
+
this.timer = this.requestTimeout(this.count)
|
|
134
|
+
},
|
|
135
|
+
// 暂定状态,重新再开始滚动;或者滚动状态下,暂停
|
|
136
|
+
reStart() {
|
|
137
|
+
if (this.isPaused) {
|
|
138
|
+
this.resume()
|
|
139
|
+
this.isPaused = false
|
|
140
|
+
} else {
|
|
141
|
+
this.stop()
|
|
142
|
+
this.isPaused = true
|
|
143
|
+
}
|
|
144
|
+
},
|
|
145
|
+
// 暂停
|
|
146
|
+
stop() {
|
|
147
|
+
clearTimeout(this.timer)
|
|
148
|
+
},
|
|
149
|
+
// 重新开始(暂停的情况下)
|
|
150
|
+
resume() {
|
|
151
|
+
this.startTime = null
|
|
152
|
+
this.durationCache = this.remaining
|
|
153
|
+
this.startNumCache = this.printVal
|
|
154
|
+
this.requestTimeout(this.count)
|
|
155
|
+
},
|
|
156
|
+
// 重置
|
|
157
|
+
reset() {
|
|
158
|
+
this.startTime = null
|
|
159
|
+
clearTimeout(this.timer)
|
|
160
|
+
this.showingVal = this.formatNumber(this.startNum)
|
|
161
|
+
},
|
|
162
|
+
count(timestamp) {
|
|
163
|
+
if (!this.startTime) this.startTime = timestamp
|
|
164
|
+
this.timestamp = timestamp
|
|
165
|
+
const progress = timestamp - this.startTime
|
|
166
|
+
this.remaining = this.durationCache - progress
|
|
167
|
+
if (this.countDown) {
|
|
168
|
+
this.printVal =
|
|
169
|
+
this.startNumCache - this.isEase
|
|
170
|
+
? this.easingFn(progress, 0, this.startNumCache - this.endNum, this.durationCache)
|
|
171
|
+
: (this.startNumCache - this.endNum) * (progress / this.durationCache)
|
|
172
|
+
} else {
|
|
173
|
+
this.printVal = this.isEase
|
|
174
|
+
? this.easingFn(
|
|
175
|
+
progress,
|
|
176
|
+
this.startNumCache,
|
|
177
|
+
this.endNum - this.startNumCache,
|
|
178
|
+
this.durationCache
|
|
179
|
+
)
|
|
180
|
+
: this.startNumCache +
|
|
181
|
+
(this.endNum - this.startNumCache) * (progress / this.durationCache)
|
|
182
|
+
}
|
|
183
|
+
this.printVal = this.countDown
|
|
184
|
+
? Math.max(this.printVal, this.endNum)
|
|
185
|
+
: Math.min(this.printVal, this.endNum)
|
|
186
|
+
this.showingVal = this.formatNumber(this.printVal)
|
|
187
|
+
if (progress < this.durationCache) {
|
|
188
|
+
this.timer = this.requestTimeout(this.count)
|
|
189
|
+
} else {
|
|
190
|
+
this.$emit('end')
|
|
191
|
+
}
|
|
192
|
+
},
|
|
193
|
+
// 判断是否数字
|
|
194
|
+
isNumber(val) {
|
|
195
|
+
return !isNaN(parseFloat(val))
|
|
196
|
+
},
|
|
197
|
+
formatNumber(num) {
|
|
198
|
+
num = Number(num)
|
|
199
|
+
num = num.toFixed(Number(this.decimals))
|
|
200
|
+
return this.$pi.format.numFormat(num, this.decimals, this.thousands)
|
|
201
|
+
},
|
|
202
|
+
destroyed() {
|
|
203
|
+
clearTimeout(this.timer)
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
</script>
|
|
208
|
+
|
|
209
|
+
<style lang="scss" scoped></style>
|
|
@@ -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>
|
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
<template>
|
|
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"
|
|
10
|
+
>
|
|
11
|
+
<view slot="item" slot-scope="{ item, index }">
|
|
12
|
+
<!-- 注意:slot内不能使用父组件data -->
|
|
13
|
+
<dropdown-tab :item="item" @click="handleClickTab(item, index)" />
|
|
14
|
+
</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 />
|
|
24
|
+
</view>
|
|
25
|
+
|
|
26
|
+
<!-- 遮罩层 -->
|
|
27
|
+
<view
|
|
28
|
+
v-if="!closed"
|
|
29
|
+
class="pi-abso pi-dropdown-mask"
|
|
30
|
+
:class="[show ? getMask.animationShow : getMask.animationHide]"
|
|
31
|
+
:style="[
|
|
32
|
+
{
|
|
33
|
+
'z-index': getMask.zIndex,
|
|
34
|
+
'background': getMask.background,
|
|
35
|
+
'animation-duration': getDuration.css
|
|
36
|
+
}
|
|
37
|
+
]"
|
|
38
|
+
@touchmove.stop.prevent
|
|
39
|
+
@tap.stop.prevent="closeMask"
|
|
40
|
+
/>
|
|
41
|
+
</view>
|
|
42
|
+
</template>
|
|
43
|
+
|
|
44
|
+
<script>
|
|
45
|
+
import ValueSync from '../../mixin/value-sync'
|
|
46
|
+
import { parentInit } from '../../mixin/props-sync'
|
|
47
|
+
import { getConfig } from '../../config'
|
|
48
|
+
import { parseDuration } from '@sadais/piui-tool/tools/common'
|
|
49
|
+
import DropdownTab from './components/dropdown-tab.vue'
|
|
50
|
+
|
|
51
|
+
const TAG = 'PiDropdown'
|
|
52
|
+
const { dropdown } = getConfig()
|
|
53
|
+
|
|
54
|
+
export default {
|
|
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,进行双向绑定
|
|
70
|
+
props: {
|
|
71
|
+
// 初始值
|
|
72
|
+
value: {
|
|
73
|
+
required: false,
|
|
74
|
+
default() {
|
|
75
|
+
return []
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
// 自定义样式,对象形式
|
|
79
|
+
customStyle: {
|
|
80
|
+
type: Object,
|
|
81
|
+
default() {
|
|
82
|
+
// {}
|
|
83
|
+
return dropdown.customStyle
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
// 自定义样式类,字符串形式
|
|
87
|
+
customClass: {
|
|
88
|
+
type: String,
|
|
89
|
+
default() {
|
|
90
|
+
// ''
|
|
91
|
+
return dropdown.customClass
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
// 自定义样式,对象形式
|
|
95
|
+
contentStyle: {
|
|
96
|
+
type: Object,
|
|
97
|
+
default() {
|
|
98
|
+
// {}
|
|
99
|
+
return dropdown.contentStyle
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
// 自定义样式类,字符串形式
|
|
103
|
+
contentClass: {
|
|
104
|
+
type: String,
|
|
105
|
+
default() {
|
|
106
|
+
// ''
|
|
107
|
+
return dropdown.contentClass
|
|
108
|
+
}
|
|
109
|
+
},
|
|
110
|
+
// 蒙层参数设置
|
|
111
|
+
mask: {
|
|
112
|
+
type: Object,
|
|
113
|
+
default() {
|
|
114
|
+
// 参照mask
|
|
115
|
+
return dropdown.mask
|
|
116
|
+
}
|
|
117
|
+
},
|
|
118
|
+
// 默认选中色
|
|
119
|
+
activeColor: {
|
|
120
|
+
type: String,
|
|
121
|
+
default() {
|
|
122
|
+
// ''
|
|
123
|
+
return dropdown.activeColor
|
|
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
|
+
}
|
|
166
|
+
}
|
|
167
|
+
},
|
|
168
|
+
data() {
|
|
169
|
+
return {
|
|
170
|
+
containerRect: { left: 0, right: 0, top: 0 }, // 容器的位置
|
|
171
|
+
|
|
172
|
+
tabs: [], // 下拉菜单
|
|
173
|
+
activeItem: {}, // 当前选中项
|
|
174
|
+
|
|
175
|
+
show: false, // 是否显示节点
|
|
176
|
+
showed: false, // 是否显示动画执行完毕
|
|
177
|
+
closed: true // 是否已关闭(用来防止val为false的情况,动画无法执行)
|
|
178
|
+
}
|
|
179
|
+
},
|
|
180
|
+
computed: {
|
|
181
|
+
contentCombinationStyle() {
|
|
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
|
+
}
|
|
189
|
+
},
|
|
190
|
+
getMask() {
|
|
191
|
+
return this.$pi.lang.mergeDeep(dropdown.mask, this.mask)
|
|
192
|
+
},
|
|
193
|
+
getDuration() {
|
|
194
|
+
return parseDuration(this.getMask.duration, dropdown.mask.duration)
|
|
195
|
+
}
|
|
196
|
+
},
|
|
197
|
+
watch: {
|
|
198
|
+
// 界面根据值的变化而变化
|
|
199
|
+
value: {
|
|
200
|
+
immediate: false,
|
|
201
|
+
handler(val) {
|
|
202
|
+
this.init()
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
},
|
|
206
|
+
mounted() {
|
|
207
|
+
this.init()
|
|
208
|
+
},
|
|
209
|
+
methods: {
|
|
210
|
+
init() {
|
|
211
|
+
console.log(TAG, 'init')
|
|
212
|
+
let hasValueChange = false
|
|
213
|
+
const val = this.$pi.lang.cloneDeep(this.val)
|
|
214
|
+
this.tabs = this._children.map((item, index) => {
|
|
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])
|
|
230
|
+
const newItem = {
|
|
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
|
|
238
|
+
}
|
|
239
|
+
return newItem
|
|
240
|
+
})
|
|
241
|
+
if (hasValueChange) {
|
|
242
|
+
this.val = val
|
|
243
|
+
this.handleEmitChange()
|
|
244
|
+
}
|
|
245
|
+
},
|
|
246
|
+
// 显示当前Tab
|
|
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)
|
|
257
|
+
this.openMask()
|
|
258
|
+
this._children.find(child => {
|
|
259
|
+
child.show = child._uid === item.id
|
|
260
|
+
})
|
|
261
|
+
},
|
|
262
|
+
openMask() {
|
|
263
|
+
if (this.show) return
|
|
264
|
+
console.log(TAG, '显示下拉菜单遮罩层')
|
|
265
|
+
this.closed = false
|
|
266
|
+
this.show = true
|
|
267
|
+
this.showed = false
|
|
268
|
+
this.getMask.hideTabBar && uni.hideTabBar()
|
|
269
|
+
setTimeout(() => {
|
|
270
|
+
this.showed = true
|
|
271
|
+
}, this.getDuration.js)
|
|
272
|
+
},
|
|
273
|
+
// 仅关闭窗口,不作数据操作
|
|
274
|
+
closeMask() {
|
|
275
|
+
if (!this.show || !this.showed) return
|
|
276
|
+
console.log(TAG, '隐藏下拉菜单遮罩层')
|
|
277
|
+
this.show = false
|
|
278
|
+
this.showed = false
|
|
279
|
+
this.tabs = this.tabs.map(tab => {
|
|
280
|
+
tab.opened = false
|
|
281
|
+
return tab
|
|
282
|
+
})
|
|
283
|
+
setTimeout(() => {
|
|
284
|
+
this.closed = true
|
|
285
|
+
this.getMask.hideTabBar && uni.showTabBar()
|
|
286
|
+
}, this.getDuration.js)
|
|
287
|
+
},
|
|
288
|
+
// 关闭弹窗并返回结果
|
|
289
|
+
submit() {
|
|
290
|
+
this.closeMask()
|
|
291
|
+
setTimeout(() => {
|
|
292
|
+
// 延迟执行,防止父子组件的值同步不上
|
|
293
|
+
const submitVal = this._children.map(item => item.val)
|
|
294
|
+
this.val = submitVal // 把最终结果传给绑定的v-model值
|
|
295
|
+
this.handleEmitChange()
|
|
296
|
+
}, 20)
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
</script>
|
|
301
|
+
|
|
302
|
+
<style lang="scss" scoped>
|
|
303
|
+
.pi-dropdown {
|
|
304
|
+
.pi-dropdown-content {
|
|
305
|
+
position: absolute;
|
|
306
|
+
background: #ffffff;
|
|
307
|
+
border-radius: 12rpx;
|
|
308
|
+
}
|
|
309
|
+
.pi-dropdown-mask {
|
|
310
|
+
top: -9999px;
|
|
311
|
+
left: -9999px;
|
|
312
|
+
right: -9999px;
|
|
313
|
+
bottom: -9999px;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
</style>
|