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.
- package/CHANGELOG.md +482 -240
- package/README.md +2 -3
- package/components/pi-bottom-bar/index.vue +15 -2
- package/components/pi-canvas/index.vue +400 -0
- package/components/pi-circle-progress/index.vue +196 -173
- package/components/pi-count-up/index.vue +68 -62
- package/components/pi-dropdown/components/dropdown-tab.vue +62 -0
- package/components/pi-dropdown/index.vue +152 -151
- package/components/pi-dropdown-item/index.vue +169 -41
- package/components/pi-form-item/index.vue +13 -1
- package/components/pi-img/index.vue +1 -0
- package/components/pi-img-cropper/index.vue +20 -16
- package/components/pi-img-cropper/touch.js +5 -3
- package/components/pi-input/index.vue +9 -2
- package/components/pi-notify/index.vue +132 -48
- package/components/pi-popup/index.vue +1 -3
- package/components/pi-radio/index.vue +10 -1
- package/components/pi-radio-group/index.vue +21 -2
- package/components/pi-select/index.vue +13 -3
- package/components/pi-steps/index.vue +141 -96
- package/components/pi-switch/index.vue +2 -3
- package/components/pi-tabs/index.vue +1 -2
- package/components/pi-upload-img/index.vue +104 -32
- 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 +17 -8
- package/config/dropdownItem.js +23 -5
- package/config/form.js +3 -3
- package/config/imgCropper.js +4 -2
- package/config/notify.js +6 -2
- package/config/radio.js +2 -1
- package/config/radioGroup.js +2 -1
- package/config/steps.js +10 -5
- package/config/{upload-img.js → uploadImg.js} +6 -3
- package/index.js +2 -2
- package/package.json +3 -3
- package/scss/variable.scss +1 -1
|
@@ -1,18 +1,56 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<view v-if="show" class="pi-dropdown-item pi-
|
|
3
|
-
<
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
2
|
+
<scroll-view v-if="show" scroll-y class="pi-dropdown-item pi-w-100P">
|
|
3
|
+
<slot>
|
|
4
|
+
<view
|
|
5
|
+
v-for="item in options"
|
|
6
|
+
:key="item[getKeyField]"
|
|
7
|
+
class="item-wrap pi-pd-tb-24 pi-pd-lr-32 pi-w-100P pi-justify-between pi-align-center"
|
|
8
|
+
:class="[customClass, item[getDisabledField] ? 'disabled' : '']"
|
|
9
|
+
:style="[customStyle, getItemStyle]"
|
|
10
|
+
@tap="handleSelectItem(item)"
|
|
11
|
+
>
|
|
12
|
+
<view>
|
|
13
|
+
{{ item[getDisplayField] }}
|
|
14
|
+
</view>
|
|
15
|
+
<!-- 如果配置了图片地址,使用图片 -->
|
|
16
|
+
<pi-img
|
|
17
|
+
v-if="getSelectedImg.src && item.id === val"
|
|
18
|
+
:src="getSelectedImg.src"
|
|
19
|
+
:mode="getSelectedImg.mode"
|
|
20
|
+
:width="getSelectedImg.width"
|
|
21
|
+
:height="getSelectedImg.height"
|
|
22
|
+
:dot="getSelectedImg.dot"
|
|
23
|
+
:dot-radius="getSelectedImg.dotRadius"
|
|
24
|
+
:badge="getSelectedImg.badge"
|
|
25
|
+
:shape="getSelectedImg.shape"
|
|
26
|
+
:border-radius="getSelectedImg.borderRadius"
|
|
27
|
+
:show-loading="getSelectedImg.showLoading"
|
|
28
|
+
:loading-color="getSelectedImg.loadingColor"
|
|
29
|
+
:loading-type="getSelectedImg.loadingType"
|
|
30
|
+
:loading-size="getSelectedImg.loadingSize"
|
|
31
|
+
:show-error="getSelectedImg.showError"
|
|
32
|
+
:webp="getSelectedImg.webp"
|
|
33
|
+
custom-class="pi-mg-left-24"
|
|
34
|
+
/>
|
|
35
|
+
<!-- 默认使用复选框 -->
|
|
36
|
+
<pi-checkbox
|
|
37
|
+
v-if="!getSelectedImg.src"
|
|
38
|
+
readonly
|
|
39
|
+
:value="item.id === val"
|
|
40
|
+
:name="getSelectedCheckbox.name"
|
|
41
|
+
:shape="getSelectedCheckbox.shape"
|
|
42
|
+
:border-radius="getSelectedCheckbox.borderRadius"
|
|
43
|
+
:border="getSelectedCheckbox.border"
|
|
44
|
+
:disabled="getSelectedCheckbox.disabled"
|
|
45
|
+
:size="getSelectedCheckbox.size"
|
|
46
|
+
:icon-size="getSelectedCheckbox.iconSize"
|
|
47
|
+
:active-color="getSelectedCheckbox.activeColor"
|
|
48
|
+
:active-mode="getSelectedCheckbox.activeMode"
|
|
49
|
+
custom-class="pi-mg-left-24"
|
|
50
|
+
/>
|
|
51
|
+
</view>
|
|
52
|
+
</slot>
|
|
53
|
+
</scroll-view>
|
|
16
54
|
</template>
|
|
17
55
|
|
|
18
56
|
<script>
|
|
@@ -20,13 +58,12 @@ import ValueSync from '../../mixin/value-sync'
|
|
|
20
58
|
import { childInit } from '../../mixin/props-sync'
|
|
21
59
|
import { getConfig } from '../../config'
|
|
22
60
|
|
|
23
|
-
const TAG = 'PiDropdownItem'
|
|
24
61
|
const { dropdownItem } = getConfig()
|
|
25
|
-
const
|
|
62
|
+
const extendPiDropDown = childInit('PiDropdown')
|
|
26
63
|
|
|
27
64
|
export default {
|
|
28
|
-
name:
|
|
29
|
-
mixins: [ValueSync,
|
|
65
|
+
name: 'PiDropdownItem',
|
|
66
|
+
mixins: [ValueSync, extendPiDropDown], // 注入value与val,进行双向绑定、混入自定义样式customStyle和customClass
|
|
30
67
|
props: {
|
|
31
68
|
// 初始值
|
|
32
69
|
value: {
|
|
@@ -48,57 +85,148 @@ export default {
|
|
|
48
85
|
return dropdownItem.customClass
|
|
49
86
|
}
|
|
50
87
|
},
|
|
51
|
-
//
|
|
52
|
-
|
|
53
|
-
type:
|
|
54
|
-
default:
|
|
88
|
+
// 是否显示菜单
|
|
89
|
+
showIcon: {
|
|
90
|
+
type: Boolean,
|
|
91
|
+
default: dropdownItem.showIcon
|
|
92
|
+
},
|
|
93
|
+
// 菜单图标配置
|
|
94
|
+
iconOption: {
|
|
95
|
+
type: Object,
|
|
96
|
+
default() {
|
|
97
|
+
return dropdownItem.iconOption
|
|
98
|
+
}
|
|
55
99
|
},
|
|
56
|
-
//
|
|
57
|
-
|
|
100
|
+
// 菜单标题
|
|
101
|
+
title: {
|
|
58
102
|
type: String,
|
|
59
|
-
default:
|
|
103
|
+
default: dropdownItem.title
|
|
104
|
+
},
|
|
105
|
+
// 是否禁用
|
|
106
|
+
disabled: {
|
|
107
|
+
type: Boolean,
|
|
108
|
+
default: dropdownItem.disabled
|
|
60
109
|
},
|
|
61
110
|
// 选项列表,默认
|
|
62
|
-
|
|
111
|
+
options: {
|
|
63
112
|
type: Array,
|
|
64
113
|
default() {
|
|
65
|
-
return dropdownItem.
|
|
114
|
+
return dropdownItem.options
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
// 行高 值为数字,则单位默认rpx
|
|
118
|
+
itemHeight: {
|
|
119
|
+
type: [String, Number],
|
|
120
|
+
// 110
|
|
121
|
+
default: dropdownItem.itemHeight
|
|
122
|
+
},
|
|
123
|
+
// 选项id字段
|
|
124
|
+
keyField: {
|
|
125
|
+
type: String,
|
|
126
|
+
// `id`
|
|
127
|
+
default: dropdownItem.keyField
|
|
128
|
+
},
|
|
129
|
+
// 选项显示字段
|
|
130
|
+
displayField: {
|
|
131
|
+
type: String,
|
|
132
|
+
// `text`
|
|
133
|
+
default: dropdownItem.displayField
|
|
134
|
+
},
|
|
135
|
+
// 选项禁用字段,默认为disabled
|
|
136
|
+
disabledField: {
|
|
137
|
+
type: String,
|
|
138
|
+
// `text`
|
|
139
|
+
default: dropdownItem.disabledField
|
|
140
|
+
},
|
|
141
|
+
// 选中图标的配置
|
|
142
|
+
selectedImg: {
|
|
143
|
+
type: Object,
|
|
144
|
+
default() {
|
|
145
|
+
// 参照img
|
|
146
|
+
return dropdownItem.selectedImg
|
|
66
147
|
}
|
|
67
148
|
},
|
|
68
|
-
|
|
69
|
-
|
|
149
|
+
// 选中checkbox配置
|
|
150
|
+
selectedCheckbox: {
|
|
151
|
+
type: Object,
|
|
152
|
+
default() {
|
|
153
|
+
// 参照checkbox
|
|
154
|
+
return dropdownItem.selectedCheckbox
|
|
155
|
+
}
|
|
70
156
|
}
|
|
71
157
|
},
|
|
72
158
|
data() {
|
|
73
159
|
return {
|
|
74
|
-
options: this.option,
|
|
75
160
|
show: false // 显示当前Item组件
|
|
76
161
|
}
|
|
77
162
|
},
|
|
78
163
|
computed: {
|
|
79
|
-
|
|
80
|
-
return this.
|
|
164
|
+
getIconOption() {
|
|
165
|
+
return this.$pi.lang.mergeDeep(dropdownItem.iconOption, this.iconOption)
|
|
166
|
+
},
|
|
167
|
+
getItemHeight() {
|
|
168
|
+
return this.inheritProps.itemHeight !== null ? this.inheritProps.itemHeight : this.itemHeight
|
|
169
|
+
},
|
|
170
|
+
getKeyField() {
|
|
171
|
+
return this.inheritProps.keyField !== null ? this.inheritProps.keyField : this.keyField
|
|
172
|
+
},
|
|
173
|
+
getDisplayField() {
|
|
174
|
+
return this.inheritProps.displayField !== null
|
|
175
|
+
? this.inheritProps.displayField
|
|
176
|
+
: this.displayField
|
|
177
|
+
},
|
|
178
|
+
getDisabledField() {
|
|
179
|
+
return this.inheritProps.disabledField !== null
|
|
180
|
+
? this.inheritProps.disabledField
|
|
181
|
+
: this.disabledField
|
|
182
|
+
},
|
|
183
|
+
getSelectedImg() {
|
|
184
|
+
const selectedImg = this.inheritProps.selectedImg || dropdownItem.selectedImg
|
|
185
|
+
return this.$pi.lang.mergeDeep(selectedImg, this.selectedImg)
|
|
186
|
+
},
|
|
187
|
+
getSelectedCheckbox() {
|
|
188
|
+
const selectedCheckbox = this.inheritProps.selectedCheckbox || dropdownItem.selectedCheckbox
|
|
189
|
+
return this.$pi.lang.mergeDeep(selectedCheckbox, this.selectedCheckbox)
|
|
190
|
+
},
|
|
191
|
+
getItemStyle() {
|
|
192
|
+
return {
|
|
193
|
+
height: this.$pi.common.addUnit(this.getItemHeight)
|
|
194
|
+
}
|
|
81
195
|
}
|
|
82
196
|
},
|
|
83
197
|
methods: {
|
|
84
|
-
|
|
85
|
-
this.
|
|
198
|
+
emitChange(val) {
|
|
199
|
+
this.val = val
|
|
200
|
+
this.handleEmitChange()
|
|
86
201
|
},
|
|
87
|
-
|
|
88
|
-
this.
|
|
202
|
+
handleSelectItem(item) {
|
|
203
|
+
if (item[this.getDisabledField]) {
|
|
204
|
+
return
|
|
205
|
+
}
|
|
206
|
+
this.emitChange(item.id)
|
|
89
207
|
setTimeout(() => {
|
|
90
|
-
this._parent.
|
|
91
|
-
},
|
|
208
|
+
this._parent.submit()
|
|
209
|
+
}, 300) // 延迟 可见按钮点击动画
|
|
92
210
|
}
|
|
93
211
|
}
|
|
94
212
|
}
|
|
95
213
|
</script>
|
|
96
214
|
|
|
97
215
|
<style lang="scss" scoped>
|
|
216
|
+
@import '../../scss/mixin.scss';
|
|
217
|
+
|
|
98
218
|
.pi-dropdown-item {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
219
|
+
max-height: 600rpx;
|
|
220
|
+
.item-wrap {
|
|
221
|
+
&:not(:last-child) {
|
|
222
|
+
@include pi-border;
|
|
223
|
+
&::after {
|
|
224
|
+
border: 0 solid $pi-list-border-color;
|
|
225
|
+
border-bottom-width: $pi-list-border-width;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
&.disabled {
|
|
229
|
+
opacity: $pi-disabled-opacity;
|
|
102
230
|
}
|
|
103
231
|
}
|
|
104
232
|
}
|
|
@@ -2,7 +2,12 @@
|
|
|
2
2
|
<view
|
|
3
3
|
class="pi-form-item"
|
|
4
4
|
:style="[customStyle, itemStyle]"
|
|
5
|
-
:class="[
|
|
5
|
+
:class="[
|
|
6
|
+
{ disabled: getDisabled },
|
|
7
|
+
{ border: getBorder },
|
|
8
|
+
{ 'pi-align-center': !getWrap },
|
|
9
|
+
customClass
|
|
10
|
+
]"
|
|
6
11
|
@tap.stop="handleItemClick"
|
|
7
12
|
>
|
|
8
13
|
<!-- 表单标题 -->
|
|
@@ -263,6 +268,9 @@ export default {
|
|
|
263
268
|
getColon() {
|
|
264
269
|
return this.inheritProps.colon !== null ? this.inheritProps.colon : this.colon
|
|
265
270
|
},
|
|
271
|
+
getDisabled() {
|
|
272
|
+
return this.inheritProps.disabled !== null ? this.inheritProps.disabled : this.disabled
|
|
273
|
+
},
|
|
266
274
|
getLabelAlign() {
|
|
267
275
|
return this.inheritProps.labelAlign !== null ? this.inheritProps.labelAlign : this.labelAlign
|
|
268
276
|
},
|
|
@@ -430,6 +438,10 @@ export default {
|
|
|
430
438
|
.pi-form-item {
|
|
431
439
|
overflow: hidden;
|
|
432
440
|
font-size: $pi-form-size;
|
|
441
|
+
&.disabled {
|
|
442
|
+
pointer-events: none;
|
|
443
|
+
opacity: $pi-disabled-opacity;
|
|
444
|
+
}
|
|
433
445
|
&.border {
|
|
434
446
|
@include pi-border;
|
|
435
447
|
&::after {
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<view
|
|
3
|
-
:class="[customClass, '
|
|
3
|
+
:class="[customClass, 'pi-img-cropper']"
|
|
4
4
|
:style="[customStyle]"
|
|
5
|
-
@touchstart="handleStart"
|
|
6
|
-
@touchmove="handleMove"
|
|
7
|
-
@touchcancel="handleEnd"
|
|
8
|
-
@touchend="handleEnd"
|
|
5
|
+
@touchstart.stop.prevent="handleStart"
|
|
6
|
+
@touchmove.stop.prevent="handleMove"
|
|
7
|
+
@touchcancel.stop.prevent="handleEnd"
|
|
8
|
+
@touchend.stop.prevent="handleEnd"
|
|
9
9
|
>
|
|
10
10
|
<image class="img" mode="aspectFit" :style="[imgStyle]" :src="src" />
|
|
11
11
|
<view class="crop" :style="[cropStyle]">
|
|
12
|
-
<view class="corner lt" @touchstart="setCutMode('lt')"
|
|
13
|
-
<view class="corner rt" @touchstart="setCutMode('rt')"
|
|
14
|
-
<view class="corner rb" @touchstart="setCutMode('rb')"
|
|
15
|
-
<view class="corner lb" @touchstart="setCutMode('lb')"
|
|
12
|
+
<view class="corner lt" @touchstart="setCutMode('lt')" />
|
|
13
|
+
<view class="corner rt" @touchstart="setCutMode('rt')" />
|
|
14
|
+
<view class="corner rb" @touchstart="setCutMode('rb')" />
|
|
15
|
+
<view class="corner lb" @touchstart="setCutMode('lb')" />
|
|
16
16
|
</view>
|
|
17
17
|
<canvas
|
|
18
18
|
v-if="canvasId"
|
|
@@ -105,6 +105,12 @@ export default {
|
|
|
105
105
|
type: Number,
|
|
106
106
|
// `1`
|
|
107
107
|
default: imgCropper.canvasZoom
|
|
108
|
+
},
|
|
109
|
+
// 遮罩层背景颜色
|
|
110
|
+
maskBackground: {
|
|
111
|
+
type: String,
|
|
112
|
+
// 'rgba(0, 0, 0, .5)'
|
|
113
|
+
default: imgCropper.maskBackground
|
|
108
114
|
}
|
|
109
115
|
},
|
|
110
116
|
data() {
|
|
@@ -154,15 +160,13 @@ export default {
|
|
|
154
160
|
},
|
|
155
161
|
cropStyle() {
|
|
156
162
|
const { top: t, right: r, bottom: b, left: l } = this.crop
|
|
157
|
-
// this.focus = true: 让裁剪窗口周围更暗,聚焦裁剪窗口中的内容
|
|
158
|
-
const alpha = this.focus ? 0.8 : 0.5
|
|
159
163
|
// 指定裁剪窗口的位置、大小、周边的遮罩层效果
|
|
160
164
|
return {
|
|
161
165
|
top: `${t}px`,
|
|
162
166
|
right: `${r}px`,
|
|
163
167
|
bottom: `${b}px`,
|
|
164
168
|
left: `${l}px`,
|
|
165
|
-
outline: `50000px solid
|
|
169
|
+
outline: `50000px solid ${this.maskBackground}`
|
|
166
170
|
}
|
|
167
171
|
}
|
|
168
172
|
},
|
|
@@ -194,10 +198,10 @@ export default {
|
|
|
194
198
|
getContainerSize() {
|
|
195
199
|
return new Promise(resolve => {
|
|
196
200
|
let query = uni.createSelectorQuery()
|
|
197
|
-
|
|
201
|
+
// #ifndef MP-ALIPAY
|
|
198
202
|
query = query.in(this)
|
|
199
|
-
|
|
200
|
-
const node = query.select('.
|
|
203
|
+
// #endif
|
|
204
|
+
const node = query.select('.pi-img-cropper')
|
|
201
205
|
node
|
|
202
206
|
.boundingClientRect(result => {
|
|
203
207
|
resolve(result)
|
|
@@ -303,7 +307,7 @@ export default {
|
|
|
303
307
|
</script>
|
|
304
308
|
|
|
305
309
|
<style lang="scss" scoped>
|
|
306
|
-
.
|
|
310
|
+
.pi-img-cropper {
|
|
307
311
|
position: relative;
|
|
308
312
|
width: 100%;
|
|
309
313
|
height: 100%;
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { debounce } from '@sadais/piui-tool/tools/common'
|
|
2
|
+
|
|
1
3
|
export default {
|
|
2
4
|
data() {
|
|
3
5
|
return {
|
|
@@ -133,9 +135,9 @@ export default {
|
|
|
133
135
|
crop.width = this.root.width - crop.left - crop.right
|
|
134
136
|
crop.height = this.root.height - crop.top - crop.bottom
|
|
135
137
|
},
|
|
136
|
-
detectBoundary() {
|
|
138
|
+
detectBoundary: debounce(function(e) {
|
|
137
139
|
if (this.boundaryDetect) {
|
|
138
|
-
console.log('
|
|
140
|
+
console.log('图片剪裁插件 -> 边界检查')
|
|
139
141
|
const angle = (this.img.transform.rotate * Math.PI) / 180
|
|
140
142
|
const cos = Math.cos,
|
|
141
143
|
sin = Math.sin,
|
|
@@ -156,6 +158,6 @@ export default {
|
|
|
156
158
|
y = Math.floor(y < minY ? minY : y > maxY ? maxY : y)
|
|
157
159
|
this.img.transform.y = y
|
|
158
160
|
}
|
|
159
|
-
}
|
|
161
|
+
}, 200)
|
|
160
162
|
}
|
|
161
163
|
}
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
:placeholder="placeholder"
|
|
11
11
|
:placeholder-style="placeholderStyle"
|
|
12
12
|
:placeholder-class="placeholderClass"
|
|
13
|
-
:disabled="
|
|
13
|
+
:disabled="getDisabled"
|
|
14
14
|
:maxlength="maxlength"
|
|
15
15
|
:cursor-spacing="cursorSpacing"
|
|
16
16
|
:focus="focus"
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
:placeholder="placeholder"
|
|
45
45
|
:placeholder-style="placeholderStyle"
|
|
46
46
|
:placeholder-class="placeholderClass"
|
|
47
|
-
:disabled="
|
|
47
|
+
:disabled="getDisabled"
|
|
48
48
|
:maxlength="maxlength"
|
|
49
49
|
:cursor-spacing="cursorSpacing"
|
|
50
50
|
:focus="focus"
|
|
@@ -242,6 +242,13 @@ export default {
|
|
|
242
242
|
focused: this.focus
|
|
243
243
|
}
|
|
244
244
|
},
|
|
245
|
+
computed: {
|
|
246
|
+
getDisabled() {
|
|
247
|
+
const parentFormItem = this.$pi.parent(this, 'PiFormItem')
|
|
248
|
+
const disabled = this.disabled || (parentFormItem && parentFormItem.getDisabled)
|
|
249
|
+
return disabled
|
|
250
|
+
}
|
|
251
|
+
},
|
|
245
252
|
methods: {
|
|
246
253
|
handleItemClick(e) {
|
|
247
254
|
this.$emit('click', e)
|
|
@@ -1,24 +1,32 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<view
|
|
3
|
-
v-if="
|
|
4
|
-
class="pi-notify"
|
|
5
|
-
:style="[
|
|
6
|
-
:class="[`pi-notify-${type}`,
|
|
3
|
+
v-if="!closed"
|
|
4
|
+
class="pi-notify pi-fixed-top pi-w-100P pi-text-ellipsis"
|
|
5
|
+
:style="[getNotifyStyle]"
|
|
6
|
+
:class="[`pi-notify-${type}`, getAniClass]"
|
|
7
7
|
>
|
|
8
|
+
<!-- 状态栏占位 -->
|
|
9
|
+
<pi-status-bar :background="bgColor" />
|
|
8
10
|
<!-- 内容插槽 -->
|
|
9
|
-
<
|
|
10
|
-
|
|
11
|
-
|
|
11
|
+
<div
|
|
12
|
+
class="pi-notify-container pi-text-ellipsis"
|
|
13
|
+
:style="[customStyle, getContainerStyle]"
|
|
14
|
+
:class="[customClass]"
|
|
15
|
+
>
|
|
16
|
+
<!-- message prop -->
|
|
17
|
+
<template v-if="message">{{ message }}</template>
|
|
18
|
+
<slot v-else-if="$slots.default || $slots.$default" />
|
|
19
|
+
</div>
|
|
12
20
|
</view>
|
|
13
21
|
</template>
|
|
14
22
|
|
|
15
23
|
<script>
|
|
16
24
|
import ValueSync from '../../mixin/value-sync'
|
|
17
25
|
import { getConfig } from '../../config'
|
|
26
|
+
import { parseDuration } from '@sadais/piui-tool/tools/common'
|
|
18
27
|
|
|
19
28
|
const TAG = 'PiNotify'
|
|
20
29
|
const { notify } = getConfig()
|
|
21
|
-
let timer = null
|
|
22
30
|
|
|
23
31
|
export default {
|
|
24
32
|
name: TAG,
|
|
@@ -26,7 +34,8 @@ export default {
|
|
|
26
34
|
props: {
|
|
27
35
|
// 初始值
|
|
28
36
|
value: {
|
|
29
|
-
required: false
|
|
37
|
+
required: false,
|
|
38
|
+
type: Boolean
|
|
30
39
|
},
|
|
31
40
|
// 自定义样式
|
|
32
41
|
customStyle: {
|
|
@@ -52,21 +61,13 @@ export default {
|
|
|
52
61
|
},
|
|
53
62
|
// notify 类型
|
|
54
63
|
type: {
|
|
55
|
-
// `'primary'-主要通知` `'success'-成功通知` `'base'/'danger'-危险通知` `'warning'-警告通知` `'info'-提示通知`
|
|
56
64
|
type: String,
|
|
57
|
-
//
|
|
65
|
+
// 'primary'
|
|
58
66
|
default: notify.type,
|
|
59
67
|
validator: function(value) {
|
|
60
|
-
return [
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
'success',
|
|
64
|
-
'danger',
|
|
65
|
-
'warning',
|
|
66
|
-
'info',
|
|
67
|
-
'customDuration',
|
|
68
|
-
''
|
|
69
|
-
].includes(value)
|
|
68
|
+
return ['primary', 'success', 'danger', 'warning', 'info', 'customDuration', ''].includes(
|
|
69
|
+
value
|
|
70
|
+
)
|
|
70
71
|
}
|
|
71
72
|
},
|
|
72
73
|
// 展示时长,默认单位 ms
|
|
@@ -86,28 +87,116 @@ export default {
|
|
|
86
87
|
type: String,
|
|
87
88
|
// ''
|
|
88
89
|
default: notify.bgColor
|
|
90
|
+
},
|
|
91
|
+
// 层级z-index
|
|
92
|
+
zIndex: {
|
|
93
|
+
type: [Number, String],
|
|
94
|
+
// 999
|
|
95
|
+
default: notify.zIndex
|
|
96
|
+
},
|
|
97
|
+
// 是否挂载到body下,防止嵌套层级无法遮罩的问题(仅H5环境生效)
|
|
98
|
+
appendToBody: {
|
|
99
|
+
type: Boolean,
|
|
100
|
+
// false
|
|
101
|
+
default: notify.appendToBody
|
|
102
|
+
},
|
|
103
|
+
// 是否自动隐藏,默认 true
|
|
104
|
+
autoHide: {
|
|
105
|
+
type: Boolean,
|
|
106
|
+
// true
|
|
107
|
+
default: notify.autoHide
|
|
108
|
+
},
|
|
109
|
+
// 是否单行显示,默认 false
|
|
110
|
+
singleLine: {
|
|
111
|
+
type: Boolean,
|
|
112
|
+
// false
|
|
113
|
+
default: notify.singleLine
|
|
89
114
|
}
|
|
90
115
|
},
|
|
91
116
|
data() {
|
|
92
117
|
return {
|
|
93
|
-
show: false, //
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
118
|
+
show: false, // 是否显示节点
|
|
119
|
+
showed: false, // 是否显示动画执行完毕
|
|
120
|
+
closed: true // 是否已关闭(用来防止val为false的情况,动画无法执行)
|
|
121
|
+
}
|
|
122
|
+
},
|
|
123
|
+
computed: {
|
|
124
|
+
getDuration() {
|
|
125
|
+
return parseDuration(this.duration)
|
|
126
|
+
},
|
|
127
|
+
getNotifyStyle() {
|
|
128
|
+
const { color, bgColor, zIndex } = this
|
|
129
|
+
return {
|
|
130
|
+
zIndex,
|
|
131
|
+
color,
|
|
132
|
+
background: bgColor
|
|
133
|
+
}
|
|
134
|
+
},
|
|
135
|
+
getAniClass() {
|
|
136
|
+
return this.show ? 'pi-ani-slide-top-show' : 'pi-ani-slide-top-hide'
|
|
137
|
+
},
|
|
138
|
+
getContainerStyle() {
|
|
139
|
+
const style = {}
|
|
140
|
+
style.whiteSpace = this.singleLine ? 'nowrap' : 'pre-wrap'
|
|
141
|
+
|
|
142
|
+
// #ifdef MP-WEIXIN
|
|
143
|
+
const buttonRect = wx.getMenuButtonBoundingClientRect()
|
|
144
|
+
style.paddingRight = `${buttonRect.width}px`
|
|
145
|
+
// #endif
|
|
146
|
+
|
|
147
|
+
return style
|
|
148
|
+
}
|
|
149
|
+
},
|
|
150
|
+
watch: {
|
|
151
|
+
val: {
|
|
152
|
+
deep: true,
|
|
153
|
+
immediate: true,
|
|
154
|
+
handler(value) {
|
|
155
|
+
value ? this.showNotify() : this.hideNotify()
|
|
99
156
|
}
|
|
100
157
|
}
|
|
101
158
|
},
|
|
159
|
+
destroyed() {
|
|
160
|
+
// #ifdef H5
|
|
161
|
+
if (this.appendToBody && this.$el && this.$el.parentNode) {
|
|
162
|
+
this.$el.parentNode.removeChild(this.$el)
|
|
163
|
+
}
|
|
164
|
+
// #endif
|
|
165
|
+
},
|
|
102
166
|
methods: {
|
|
103
|
-
showNotify(
|
|
104
|
-
|
|
105
|
-
|
|
167
|
+
showNotify() {
|
|
168
|
+
if (this.show) return
|
|
169
|
+
console.log(TAG, '显示通知栏')
|
|
170
|
+
this.closed = false
|
|
106
171
|
this.show = true
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
172
|
+
this.showed = false
|
|
173
|
+
this.handleEmitChange()
|
|
174
|
+
setTimeout(() => {
|
|
175
|
+
// 动画执行完毕
|
|
176
|
+
this.showed = true
|
|
177
|
+
// 自动关闭
|
|
178
|
+
this.autoHide &&
|
|
179
|
+
setTimeout(() => {
|
|
180
|
+
this.hideNotify()
|
|
181
|
+
}, this.getDuration.js)
|
|
182
|
+
}, 300)
|
|
183
|
+
// #ifdef H5
|
|
184
|
+
if (this.appendToBody) {
|
|
185
|
+
document.body.appendChild(this.$el)
|
|
186
|
+
}
|
|
187
|
+
// #endif
|
|
188
|
+
},
|
|
189
|
+
hideNotify() {
|
|
190
|
+
if (!this.show || !this.showed) return
|
|
191
|
+
console.log(TAG, '隐藏通知栏')
|
|
192
|
+
this.show = false
|
|
193
|
+
this.showed = false
|
|
194
|
+
setTimeout(() => {
|
|
195
|
+
this.$emit('closed')
|
|
196
|
+
this.closed = true
|
|
197
|
+
this.val = false
|
|
198
|
+
this.handleEmitChange()
|
|
199
|
+
}, 300)
|
|
111
200
|
}
|
|
112
201
|
}
|
|
113
202
|
}
|
|
@@ -115,20 +204,17 @@ export default {
|
|
|
115
204
|
|
|
116
205
|
<style lang="scss" scoped>
|
|
117
206
|
.pi-notify {
|
|
118
|
-
position: fixed;
|
|
119
|
-
top: 0;
|
|
120
|
-
left: 0;
|
|
121
|
-
width: 100%;
|
|
122
|
-
padding: 20rpx 30rpx;
|
|
123
207
|
color: $pi-background-color;
|
|
124
208
|
font-size: $pi-font-size;
|
|
125
|
-
|
|
126
|
-
overflow
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
209
|
+
padding: 24rpx 32rpx;
|
|
210
|
+
overflow: hidden;
|
|
211
|
+
|
|
212
|
+
transition: all $pi-animation-duration $pi-animation-timing-function;
|
|
213
|
+
|
|
214
|
+
.pi-notify-container {
|
|
215
|
+
text-align: center;
|
|
216
|
+
min-width: 0;
|
|
217
|
+
}
|
|
132
218
|
|
|
133
219
|
&-primary {
|
|
134
220
|
background: $pi-primary-color;
|
|
@@ -138,8 +224,6 @@ export default {
|
|
|
138
224
|
background: $pi-fourth-color;
|
|
139
225
|
}
|
|
140
226
|
|
|
141
|
-
&-customDuration,
|
|
142
|
-
&-base,
|
|
143
227
|
&-danger {
|
|
144
228
|
background: #e64340;
|
|
145
229
|
}
|