@ecolovo/uniapp-components 1.0.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/components/aspect/aspect.vue +43 -0
- package/components/badge/badge.vue +88 -0
- package/components/button/button.vue +409 -0
- package/components/checkbox/checkbox.vue +183 -0
- package/components/checkbox-group/checkbox-group.vue +101 -0
- package/components/checkbox-group2/checkbox-group2.vue +138 -0
- package/components/checkbox-group2/checkbox.vue +103 -0
- package/components/data-list/data-list.vue +130 -0
- package/components/date-picker/date-picker-view.vue +181 -0
- package/components/date-picker/date-picker.vue +237 -0
- package/components/datetime-picker/datetime-picker-view.vue +209 -0
- package/components/datetime-picker/datetime-picker.vue +235 -0
- package/components/dialog/dialog-content.vue +162 -0
- package/components/dialog/dialog.vue +166 -0
- package/components/dropdown/dropdown.vue +145 -0
- package/components/empty/empty.vue +102 -0
- package/components/flex/flex.vue +76 -0
- package/components/form/form.vue +43 -0
- package/components/form/mixin.js +13 -0
- package/components/form-item/form-item.vue +141 -0
- package/components/icon/icon.vue +114 -0
- package/components/image/image.vue +61 -0
- package/components/input/input.vue +154 -0
- package/components/input/password-input.vue +95 -0
- package/components/list-page/list-page.js +10 -0
- package/components/list-page/list-page.vue +150 -0
- package/components/load-more/load-more.vue +97 -0
- package/components/loading/animations/loading-animation1.vue +92 -0
- package/components/loading/animations/loading-animation2.vue +28 -0
- package/components/loading/animations/loading-animation3.vue +81 -0
- package/components/loading/animations/loading-animation4.vue +74 -0
- package/components/loading/loading.vue +91 -0
- package/components/message-box/message-box.vue +60 -0
- package/components/number-dialog/number-dialog.vue +360 -0
- package/components/number-input/number-input.vue +352 -0
- package/components/numpad/numpad.vue +224 -0
- package/components/page/page-body.vue +227 -0
- package/components/page/page-footer.vue +75 -0
- package/components/page/page-header.vue +222 -0
- package/components/page/page.vue +128 -0
- package/components/picker/picker-popup.vue +295 -0
- package/components/picker/picker.vue +151 -0
- package/components/popover/popover-content.vue +255 -0
- package/components/popover/popover-mask.vue +113 -0
- package/components/popover/popover.vue +84 -0
- package/components/popup/popup-content.vue +162 -0
- package/components/popup/popup.vue +168 -0
- package/components/price/price.vue +104 -0
- package/components/search/search.vue +220 -0
- package/components/searching/searching.vue +86 -0
- package/components/selector/selector.vue +86 -0
- package/components/switch/switch.vue +180 -0
- package/components/tab/tab.vue +235 -0
- package/components/table/table.vue +112 -0
- package/components/textarea/textarea.vue +192 -0
- package/components/time-picker/time-picker-view.vue +127 -0
- package/components/time-picker/time-picker.vue +140 -0
- package/components/uploader/download.js +81 -0
- package/components/uploader/file-uploader.vue +52 -0
- package/components/uploader/files.js +225 -0
- package/components/uploader/media-uploader.vue +133 -0
- package/components/uploader/mixin.js +106 -0
- package/components/uploader/uni.js +38 -0
- package/components/uploader/upload-button.vue +29 -0
- package/components/uploader/uploader copy.vue +547 -0
- package/components/uploader/uploader.vue +117 -0
- package/configs/index.js +41 -0
- package/easyCom.js +25 -0
- package/init.js +17 -0
- package/mixins/componentName.js +32 -0
- package/mixins/listPage.js +1 -0
- package/mixins/windowInfo.js +1 -0
- package/package.json +12 -0
- package/resources/iconfont/uniapp_ui_icon/demo.css +539 -0
- package/resources/iconfont/uniapp_ui_icon/demo_index.html +555 -0
- package/resources/iconfont/uniapp_ui_icon/iconfont.css +78 -0
- package/resources/iconfont/uniapp_ui_icon/iconfont.js +1 -0
- package/resources/iconfont/uniapp_ui_icon/iconfont.json +121 -0
- package/resources/iconfont/uniapp_ui_icon/iconfont.woff2 +0 -0
- package/resources/image/empty.svg +13 -0
- package/styles/global.scss +24 -0
- package/styles/index.scss +2 -0
- package/styles/utils/css-var.scss +87 -0
- package/styles/utils/ellipsis.scss +26 -0
- package/styles/utils/global-var.scss +11 -0
- package/styles/utils/index.scss +5 -0
- package/styles/utils/selector.scss +5 -0
- package/styles/utils/z-index.scss +10 -0
- package/styles/var/component.scss +242 -0
- package/styles/var/index.scss +2 -0
- package/styles/var/theme.scss +40 -0
- package/utils/date.js +151 -0
- package/utils/floor.js +20 -0
- package/utils/freezeDeep.js +19 -0
- package/utils/price.js +32 -0
- package/utils/round.js +22 -0
- package/utils/windowInfo.js +77 -0
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<view :class="componentClassNames">
|
|
3
|
+
<slot></slot>
|
|
4
|
+
</view>
|
|
5
|
+
</template>
|
|
6
|
+
|
|
7
|
+
<script>
|
|
8
|
+
import componentName from '../../mixins/componentName';
|
|
9
|
+
|
|
10
|
+
export default {
|
|
11
|
+
name: 'AppCheckboxGroup',
|
|
12
|
+
options: {
|
|
13
|
+
virtualHost: true,
|
|
14
|
+
styleIsolation: 'shared',
|
|
15
|
+
},
|
|
16
|
+
mixins: [componentName],
|
|
17
|
+
provide() {
|
|
18
|
+
return {
|
|
19
|
+
checkboxGroupCheck: this.check,
|
|
20
|
+
checkboxGroupProps: this.$props,
|
|
21
|
+
checkboxGroupData: this.$data,
|
|
22
|
+
};
|
|
23
|
+
},
|
|
24
|
+
props: {
|
|
25
|
+
/** 值 */
|
|
26
|
+
value: {
|
|
27
|
+
type: [Number, String, Boolean, Array, null],
|
|
28
|
+
default: null,
|
|
29
|
+
},
|
|
30
|
+
/** 类型 */
|
|
31
|
+
radio: {
|
|
32
|
+
type: Boolean,
|
|
33
|
+
default: false,
|
|
34
|
+
},
|
|
35
|
+
/** 选中时的图标 */
|
|
36
|
+
checkedIcon: {
|
|
37
|
+
type: String,
|
|
38
|
+
default: '',
|
|
39
|
+
},
|
|
40
|
+
/** 未选中时的图标 */
|
|
41
|
+
uncheckedIcon: {
|
|
42
|
+
type: String,
|
|
43
|
+
default: '',
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
data() {
|
|
47
|
+
return {
|
|
48
|
+
checkedValue: null,
|
|
49
|
+
};
|
|
50
|
+
},
|
|
51
|
+
computed: {
|
|
52
|
+
currentValue: {
|
|
53
|
+
get: function () {
|
|
54
|
+
return this.value === null ? this.checkedValue : this.value;
|
|
55
|
+
},
|
|
56
|
+
set: function (value) {
|
|
57
|
+
this.$emit('input', value);
|
|
58
|
+
this.checkedValue = value;
|
|
59
|
+
this.$emit('change', this.checkedValue);
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
watch: {
|
|
64
|
+
value: {
|
|
65
|
+
handler: function (value) {
|
|
66
|
+
this.checkedValue = value;
|
|
67
|
+
},
|
|
68
|
+
immediate: true,
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
methods: {
|
|
72
|
+
check(value) {
|
|
73
|
+
if (this.radio) {
|
|
74
|
+
this.currentValue = value;
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (!Array.isArray(this.currentValue)) {
|
|
79
|
+
this.currentValue = [value];
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (this.currentValue.includes(value)) {
|
|
84
|
+
this.currentValue = this.currentValue.filter((item) => item !== value);
|
|
85
|
+
} else {
|
|
86
|
+
this.currentValue.push(value);
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
</script>
|
|
92
|
+
|
|
93
|
+
<style lang="scss" module>
|
|
94
|
+
@use '../../styles/index' as *;
|
|
95
|
+
|
|
96
|
+
.CheckboxGroup {
|
|
97
|
+
flex: 1;
|
|
98
|
+
display: flex;
|
|
99
|
+
flex-wrap: wrap;
|
|
100
|
+
}
|
|
101
|
+
</style>
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<view :class="componentClassNames">
|
|
3
|
+
<checkbox-cpn
|
|
4
|
+
v-for="(item, index) in options"
|
|
5
|
+
:key="index"
|
|
6
|
+
:value="radio ? item.value === currentValue : currentValue && currentValue.includes(item.value)"
|
|
7
|
+
:checked-icon="checkedIcon || (radio ? 'radio-checked' : 'checkbox-checked')"
|
|
8
|
+
:unchecked-icon="uncheckedIcon || (radio ? 'radio-unchecked' : 'checkbox-unchecked')"
|
|
9
|
+
:class="$style['CheckboxGroup2--item']"
|
|
10
|
+
@change="check(item.value)"
|
|
11
|
+
>
|
|
12
|
+
{{ item.label }}
|
|
13
|
+
</checkbox-cpn>
|
|
14
|
+
</view>
|
|
15
|
+
</template>
|
|
16
|
+
|
|
17
|
+
<script>
|
|
18
|
+
import componentName from '../../mixins/componentName';
|
|
19
|
+
import CheckboxCpn from './checkbox.vue';
|
|
20
|
+
|
|
21
|
+
export default {
|
|
22
|
+
name: 'AppCheckboxGroup2',
|
|
23
|
+
options: {
|
|
24
|
+
virtualHost: true,
|
|
25
|
+
styleIsolation: 'shared',
|
|
26
|
+
},
|
|
27
|
+
components: { CheckboxCpn },
|
|
28
|
+
mixins: [componentName],
|
|
29
|
+
props: {
|
|
30
|
+
/** 值 */
|
|
31
|
+
value: {
|
|
32
|
+
type: [Number, String, Boolean, Array, null],
|
|
33
|
+
default: null,
|
|
34
|
+
},
|
|
35
|
+
/** 类型 */
|
|
36
|
+
options: {
|
|
37
|
+
type: Array,
|
|
38
|
+
default: () => [],
|
|
39
|
+
},
|
|
40
|
+
/** 类型 */
|
|
41
|
+
radio: {
|
|
42
|
+
type: Boolean,
|
|
43
|
+
default: true,
|
|
44
|
+
},
|
|
45
|
+
/** 选中时的图标 */
|
|
46
|
+
checkedIcon: {
|
|
47
|
+
type: String,
|
|
48
|
+
default: '',
|
|
49
|
+
},
|
|
50
|
+
/** 未选中时的图标 */
|
|
51
|
+
uncheckedIcon: {
|
|
52
|
+
type: String,
|
|
53
|
+
default: '',
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
data() {
|
|
57
|
+
return {
|
|
58
|
+
checkedValue: null,
|
|
59
|
+
};
|
|
60
|
+
},
|
|
61
|
+
computed: {
|
|
62
|
+
currentValue: {
|
|
63
|
+
get() {
|
|
64
|
+
return this.value === null ? this.checkedValue : this.value;
|
|
65
|
+
},
|
|
66
|
+
set(value) {
|
|
67
|
+
this.$emit('input', value);
|
|
68
|
+
this.checkedValue = value;
|
|
69
|
+
this.$emit('change', this.checkedValue);
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
optionsValue() {
|
|
73
|
+
return this.options.map((item) => item.value);
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
methods: {
|
|
77
|
+
check(value) {
|
|
78
|
+
if (this.radio) {
|
|
79
|
+
this.currentValue = value;
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (!Array.isArray(this.currentValue)) {
|
|
84
|
+
this.currentValue = [value];
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (this.currentValue.includes(value)) {
|
|
89
|
+
this.currentValue = this.currentValue.filter((item) => item !== value);
|
|
90
|
+
} else {
|
|
91
|
+
this.currentValue.push(value);
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
/** 切换全选
|
|
95
|
+
* @param {boolean | Array} isSelectedAll
|
|
96
|
+
*/
|
|
97
|
+
toggle(isSelectedAll) {
|
|
98
|
+
if (this.radio) return;
|
|
99
|
+
|
|
100
|
+
if (typeof isSelectedAll === 'boolean') {
|
|
101
|
+
if (isSelectedAll) {
|
|
102
|
+
this.currentValue = this.optionsValue;
|
|
103
|
+
} else {
|
|
104
|
+
this.currentValue = [];
|
|
105
|
+
}
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if (Array.isArray(isSelectedAll)) {
|
|
110
|
+
this.currentValue = isSelectedAll.filter((item) => this.optionsValue.includes(item));
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
if (Array.isArray(this.currentValue) && this.currentValue.length === this.options.length) {
|
|
115
|
+
this.currentValue = [];
|
|
116
|
+
} else {
|
|
117
|
+
this.currentValue = this.optionsValue;
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
};
|
|
122
|
+
</script>
|
|
123
|
+
|
|
124
|
+
<style lang="scss" module>
|
|
125
|
+
@use '../../styles/index' as *;
|
|
126
|
+
|
|
127
|
+
.CheckboxGroup2 {
|
|
128
|
+
display: flex;
|
|
129
|
+
flex-wrap: wrap;
|
|
130
|
+
column-gap: 20rpx;
|
|
131
|
+
|
|
132
|
+
.CheckboxGroup2--item {
|
|
133
|
+
height: 50rpx;
|
|
134
|
+
width: calc((100% + 20rpx) / 3 - 20rpx);
|
|
135
|
+
flex: none;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
</style>
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<view :class="componentClassNames" @click="toggle()">
|
|
3
|
+
<icon-cpn
|
|
4
|
+
:icon="currentValue ? checkedIcon || 'checkbox-checked' : uncheckedIcon || 'checkbox-unchecked'"
|
|
5
|
+
tap-size="50rpx"
|
|
6
|
+
:class="[$style['Checkbox2--icon'], { [$style['Checkbox2--checked']]: currentValue }]"
|
|
7
|
+
/>
|
|
8
|
+
<view :class="$style['Checkbox2--text']">
|
|
9
|
+
<slot></slot>
|
|
10
|
+
</view>
|
|
11
|
+
</view>
|
|
12
|
+
</template>
|
|
13
|
+
|
|
14
|
+
<script>
|
|
15
|
+
import componentName from '../../mixins/componentName';
|
|
16
|
+
import IconCpn from '../icon/icon.vue';
|
|
17
|
+
|
|
18
|
+
export default {
|
|
19
|
+
name: 'AppCheckbox2',
|
|
20
|
+
options: {
|
|
21
|
+
virtualHost: true,
|
|
22
|
+
styleIsolation: 'shared',
|
|
23
|
+
},
|
|
24
|
+
components: { IconCpn },
|
|
25
|
+
mixins: [componentName],
|
|
26
|
+
props: {
|
|
27
|
+
/** 值 */
|
|
28
|
+
value: {
|
|
29
|
+
type: [Boolean, null],
|
|
30
|
+
default: null,
|
|
31
|
+
},
|
|
32
|
+
/** 选中时的图标 */
|
|
33
|
+
checkedIcon: {
|
|
34
|
+
type: String,
|
|
35
|
+
default: '',
|
|
36
|
+
},
|
|
37
|
+
/** 未选中时的图标 */
|
|
38
|
+
uncheckedIcon: {
|
|
39
|
+
type: String,
|
|
40
|
+
default: '',
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
data() {
|
|
44
|
+
return {
|
|
45
|
+
innerValue: false,
|
|
46
|
+
};
|
|
47
|
+
},
|
|
48
|
+
computed: {
|
|
49
|
+
currentValue: {
|
|
50
|
+
get: function () {
|
|
51
|
+
return this.value === null ? this.innerValue : this.value;
|
|
52
|
+
},
|
|
53
|
+
set: function (value) {
|
|
54
|
+
this.$emit('input', value);
|
|
55
|
+
this.innerValue = value;
|
|
56
|
+
this.$emit('change', this.innerValue);
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
methods: {
|
|
61
|
+
/** 切换选择 */
|
|
62
|
+
toggle(isSelected) {
|
|
63
|
+
if (isSelected === undefined || isSelected === null) {
|
|
64
|
+
this.currentValue = !this.currentValue;
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (this.currentValue !== !!isSelected) {
|
|
69
|
+
this.currentValue = !!isSelected;
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
</script>
|
|
75
|
+
|
|
76
|
+
<style lang="scss" module>
|
|
77
|
+
@use '../../styles/index' as *;
|
|
78
|
+
|
|
79
|
+
// 定义外部变量
|
|
80
|
+
$component-name: 'checkbox';
|
|
81
|
+
$component-vars: $checkbox;
|
|
82
|
+
%external-vars {
|
|
83
|
+
@include UTILS__DEFINE_COMPONENT_VARS();
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
.Checkbox2 {
|
|
87
|
+
@extend %external-vars;
|
|
88
|
+
display: flex;
|
|
89
|
+
align-items: center;
|
|
90
|
+
|
|
91
|
+
.Checkbox2--icon {
|
|
92
|
+
flex: none;
|
|
93
|
+
color: UTILS__LOCAL_VAR(unchecked-color);
|
|
94
|
+
}
|
|
95
|
+
.Checkbox2--checked {
|
|
96
|
+
color: UTILS__LOCAL_VAR(checked-color);
|
|
97
|
+
}
|
|
98
|
+
.Checkbox2--text {
|
|
99
|
+
flex: 0 1 auto;
|
|
100
|
+
margin-left: 12rpx;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
</style>
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<view :class="componentClassNames">
|
|
3
|
+
<slot></slot>
|
|
4
|
+
|
|
5
|
+
<load-more-cpn
|
|
6
|
+
v-if="showLoadMore && pagingData && pagingData.totalCount"
|
|
7
|
+
:loading="loadingMore"
|
|
8
|
+
:end="!pagingData.hasMore"
|
|
9
|
+
:class="$style['DataList--load-more']"
|
|
10
|
+
@load-more="$emit('load-more')"
|
|
11
|
+
/>
|
|
12
|
+
|
|
13
|
+
<view v-if="pagingData && pagingData.hasMore" :class="$style['DataList--observe-view']"></view>
|
|
14
|
+
</view>
|
|
15
|
+
</template>
|
|
16
|
+
|
|
17
|
+
<script>
|
|
18
|
+
import componentName from '../../mixins/componentName';
|
|
19
|
+
import LoadMoreCpn from '../load-more/load-more.vue';
|
|
20
|
+
|
|
21
|
+
export default {
|
|
22
|
+
name: 'AppDataList',
|
|
23
|
+
options: {
|
|
24
|
+
virtualHost: true,
|
|
25
|
+
styleIsolation: 'shared',
|
|
26
|
+
},
|
|
27
|
+
components: { LoadMoreCpn },
|
|
28
|
+
mixins: [componentName],
|
|
29
|
+
props: {
|
|
30
|
+
/** 是否正在加载更多数据 */
|
|
31
|
+
loadingMore: {
|
|
32
|
+
type: Boolean,
|
|
33
|
+
default: false,
|
|
34
|
+
},
|
|
35
|
+
/** 分页大小 */
|
|
36
|
+
pagingData: {
|
|
37
|
+
type: Object,
|
|
38
|
+
default: null,
|
|
39
|
+
},
|
|
40
|
+
/** 是否显示加载更多 */
|
|
41
|
+
showLoadMore: {
|
|
42
|
+
type: Boolean,
|
|
43
|
+
default: true,
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
mounted() {
|
|
47
|
+
// 使用以下方式可持续自动触发加载更多
|
|
48
|
+
// this._stopHasMoreWatcher = this.$watch(
|
|
49
|
+
// 'pagingData',
|
|
50
|
+
// () => {
|
|
51
|
+
// this.startObserver();
|
|
52
|
+
// },
|
|
53
|
+
// { immediate: true, deep: true }
|
|
54
|
+
// );
|
|
55
|
+
this._stopHasMoreWatcher = this.$watch(
|
|
56
|
+
'pagingData.hasMore',
|
|
57
|
+
(hasMore) => {
|
|
58
|
+
if (hasMore) {
|
|
59
|
+
this.startObserver();
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
{ immediate: true }
|
|
63
|
+
);
|
|
64
|
+
},
|
|
65
|
+
beforeDestroy() {
|
|
66
|
+
this.stopObserver();
|
|
67
|
+
this._stopHasMoreWatcher?.();
|
|
68
|
+
},
|
|
69
|
+
methods: {
|
|
70
|
+
startObserver() {
|
|
71
|
+
this.stopObserver();
|
|
72
|
+
|
|
73
|
+
this._observer = uni
|
|
74
|
+
.createIntersectionObserver(this, { nativeMode: true })
|
|
75
|
+
.relativeToViewport({
|
|
76
|
+
bottom: 0,
|
|
77
|
+
})
|
|
78
|
+
.observe('.' + this.$style['DataList--observe-view'], (res) => {
|
|
79
|
+
if (res.intersectionRatio === 0) return;
|
|
80
|
+
this.$emit('load-more');
|
|
81
|
+
});
|
|
82
|
+
},
|
|
83
|
+
stopObserver() {
|
|
84
|
+
this._observer?.disconnect();
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
</script>
|
|
89
|
+
|
|
90
|
+
<style lang="scss" module>
|
|
91
|
+
@use '../../styles/index' as *;
|
|
92
|
+
|
|
93
|
+
// 定义外部变量
|
|
94
|
+
$component-name: 'data-list';
|
|
95
|
+
$component-vars: $data-list;
|
|
96
|
+
%external-vars {
|
|
97
|
+
@include UTILS__DEFINE_COMPONENT_VARS();
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
:host {
|
|
101
|
+
position: relative;
|
|
102
|
+
display: block;
|
|
103
|
+
width: 100%;
|
|
104
|
+
|
|
105
|
+
flex: 1;
|
|
106
|
+
display: flex;
|
|
107
|
+
flex-direction: column;
|
|
108
|
+
}
|
|
109
|
+
.DataList {
|
|
110
|
+
@extend %external-vars;
|
|
111
|
+
flex: 1;
|
|
112
|
+
display: flex;
|
|
113
|
+
flex-direction: column;
|
|
114
|
+
width: 100%;
|
|
115
|
+
min-height: 100%;
|
|
116
|
+
}
|
|
117
|
+
.DataList--load-more {
|
|
118
|
+
position: sticky;
|
|
119
|
+
top: 100%;
|
|
120
|
+
}
|
|
121
|
+
.DataList--observe-view {
|
|
122
|
+
position: absolute;
|
|
123
|
+
z-index: -1;
|
|
124
|
+
left: 0;
|
|
125
|
+
bottom: 0;
|
|
126
|
+
width: 100%;
|
|
127
|
+
height: UTILS__LOCAL_VAR(observer-height);
|
|
128
|
+
pointer-events: none;
|
|
129
|
+
}
|
|
130
|
+
</style>
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<picker-view
|
|
3
|
+
immediate-change
|
|
4
|
+
:value="pickerValue"
|
|
5
|
+
:class="componentClassNames"
|
|
6
|
+
@change="handlePickerChange"
|
|
7
|
+
@pickend="onPickEnd"
|
|
8
|
+
>
|
|
9
|
+
<picker-view-column>
|
|
10
|
+
<view v-for="item in yearOptions" :key="item" :class="$style['DatePickerView--option']">
|
|
11
|
+
{{ item }} 年
|
|
12
|
+
</view>
|
|
13
|
+
</picker-view-column>
|
|
14
|
+
<picker-view-column>
|
|
15
|
+
<view v-for="item in monthOptions" :key="item" :class="$style['DatePickerView--option']">
|
|
16
|
+
{{ item }} 月
|
|
17
|
+
</view>
|
|
18
|
+
</picker-view-column>
|
|
19
|
+
<picker-view-column>
|
|
20
|
+
<view v-for="item in dateOptions" :key="item" :class="$style['DatePickerView--option']">
|
|
21
|
+
{{ item }} 日
|
|
22
|
+
</view>
|
|
23
|
+
</picker-view-column>
|
|
24
|
+
</picker-view>
|
|
25
|
+
</template>
|
|
26
|
+
|
|
27
|
+
<script>
|
|
28
|
+
import range from 'lodash-es/range';
|
|
29
|
+
import componentName from '../../mixins/componentName';
|
|
30
|
+
import { formatDate, toDate } from '../../utils/date';
|
|
31
|
+
|
|
32
|
+
/** 年份选项 */
|
|
33
|
+
const yearOptions = (function () {
|
|
34
|
+
const arr = [];
|
|
35
|
+
for (let i = 1900; i <= 2099; i++) {
|
|
36
|
+
arr.push(i);
|
|
37
|
+
}
|
|
38
|
+
return arr;
|
|
39
|
+
})();
|
|
40
|
+
|
|
41
|
+
/** 获取指定日期所在月份的日期选项列表 */
|
|
42
|
+
function getDateOptions(date) {
|
|
43
|
+
date = new Date(date);
|
|
44
|
+
date.setMonth(date.getMonth() + 1, 0);
|
|
45
|
+
const max = date.getDate();
|
|
46
|
+
return range(1, max + 1);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export default {
|
|
50
|
+
name: 'AppDatePickerView',
|
|
51
|
+
options: {
|
|
52
|
+
virtualHost: true,
|
|
53
|
+
styleIsolation: 'shared',
|
|
54
|
+
},
|
|
55
|
+
mixins: [componentName],
|
|
56
|
+
props: {
|
|
57
|
+
/** 绑定值 */
|
|
58
|
+
value: {
|
|
59
|
+
type: [String, null],
|
|
60
|
+
default: null,
|
|
61
|
+
},
|
|
62
|
+
/** 最小日期 */
|
|
63
|
+
min: {
|
|
64
|
+
type: String,
|
|
65
|
+
default: '',
|
|
66
|
+
},
|
|
67
|
+
/** 最大日期 */
|
|
68
|
+
max: {
|
|
69
|
+
type: String,
|
|
70
|
+
default: '',
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
data() {
|
|
74
|
+
return {
|
|
75
|
+
innerValue: '',
|
|
76
|
+
/** 年份选项列表 */
|
|
77
|
+
yearOptions: yearOptions,
|
|
78
|
+
/** 月份选项列表 */
|
|
79
|
+
monthOptions: range(1, 13),
|
|
80
|
+
/** 日期选项列表 */
|
|
81
|
+
dateOptions: [],
|
|
82
|
+
/** picker-view 绑定值 */
|
|
83
|
+
pickerValue: [0, 0, 0],
|
|
84
|
+
};
|
|
85
|
+
},
|
|
86
|
+
computed: {
|
|
87
|
+
currentValue: {
|
|
88
|
+
get: function () {
|
|
89
|
+
return this.value === null ? this.innerValue : this.value;
|
|
90
|
+
},
|
|
91
|
+
set: function (value) {
|
|
92
|
+
this.$emit('input', value);
|
|
93
|
+
this.innerValue = value;
|
|
94
|
+
this.$emit('change', value);
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
mounted() {
|
|
99
|
+
this.$nextTick(() => {
|
|
100
|
+
this.syncPickerValue(this.currentValue || new Date());
|
|
101
|
+
});
|
|
102
|
+
},
|
|
103
|
+
methods: {
|
|
104
|
+
/** 同步 picker-view 选中索引 */
|
|
105
|
+
syncPickerValue(date) {
|
|
106
|
+
const [y, m, d] = formatDate(toDate(date)).split('-');
|
|
107
|
+
this.dateOptions = getDateOptions(toDate(date));
|
|
108
|
+
const i = this.yearOptions.indexOf(Number(y));
|
|
109
|
+
const j = this.monthOptions.indexOf(Number(m));
|
|
110
|
+
const k = this.dateOptions.indexOf(Number(d));
|
|
111
|
+
this.$nextTick(() => {
|
|
112
|
+
this.pickerValue =
|
|
113
|
+
typeof this.pickerValue[0] === 'number' ? [i, j, k].map((item) => item.toString()) : [i, j, k];
|
|
114
|
+
});
|
|
115
|
+
},
|
|
116
|
+
/** picker-view 选项值变化处理 */
|
|
117
|
+
handlePickerChange(e) {
|
|
118
|
+
const newPickerValue = e.detail.value;
|
|
119
|
+
/** 获取变化的列 */
|
|
120
|
+
const col = this.pickerValue.findIndex((item, index) => Number(item) !== Number(newPickerValue[index]));
|
|
121
|
+
const year = this.yearOptions[newPickerValue[0]];
|
|
122
|
+
const month = this.monthOptions[newPickerValue[1]];
|
|
123
|
+
// 如果改变的是年份或月份,需要重新获取日期列表
|
|
124
|
+
if (col === 0 || col === 1) {
|
|
125
|
+
this.dateOptions = getDateOptions(toDate(`${year}-${month}-01`));
|
|
126
|
+
newPickerValue[2] = Math.min(
|
|
127
|
+
newPickerValue[2] === -1 ? this.dateOptions.length - 1 : newPickerValue[2],
|
|
128
|
+
this.dateOptions.length - 1
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
const date = this.dateOptions[newPickerValue[2]];
|
|
132
|
+
|
|
133
|
+
this.pickerValue = newPickerValue;
|
|
134
|
+
const dateValue = new Date(year, month - 1, date);
|
|
135
|
+
let dateStr = formatDate(dateValue);
|
|
136
|
+
if (this.min && dateStr < this.min) {
|
|
137
|
+
let minDate;
|
|
138
|
+
|
|
139
|
+
if (this.min === 'today') minDate = formatDate(new Date());
|
|
140
|
+
else if (this.min === 'tomorrow') minDate = formatDate(new Date(Date.now() + 8.64e7));
|
|
141
|
+
else if (this.min === 'yesterday') minDate = formatDate(new Date(Date.now() - 8.64e7));
|
|
142
|
+
else minDate = this.min;
|
|
143
|
+
|
|
144
|
+
dateStr = minDate;
|
|
145
|
+
}
|
|
146
|
+
if (this.max && dateStr > this.max) {
|
|
147
|
+
let maxDate;
|
|
148
|
+
|
|
149
|
+
if (this.max === 'today') maxDate = formatDate(new Date());
|
|
150
|
+
else if (this.max === 'tomorrow') maxDate = formatDate(new Date(Date.now() + 8.64e7));
|
|
151
|
+
else if (this.max === 'yesterday') maxDate = formatDate(new Date(Date.now() - 8.64e7));
|
|
152
|
+
else maxDate = this.max;
|
|
153
|
+
|
|
154
|
+
dateStr = maxDate;
|
|
155
|
+
}
|
|
156
|
+
this.currentValue = dateStr;
|
|
157
|
+
},
|
|
158
|
+
/** 滑动结束处理,保持选择器显示值与输入框值一致 */
|
|
159
|
+
onPickEnd() {
|
|
160
|
+
this.$nextTick(() => {
|
|
161
|
+
this.syncPickerValue(this.currentValue);
|
|
162
|
+
});
|
|
163
|
+
},
|
|
164
|
+
},
|
|
165
|
+
};
|
|
166
|
+
</script>
|
|
167
|
+
|
|
168
|
+
<style lang="scss" module>
|
|
169
|
+
@use '../../styles/index' as *;
|
|
170
|
+
|
|
171
|
+
.DatePickerView {
|
|
172
|
+
margin-top: 24rpx;
|
|
173
|
+
height: 300rpx;
|
|
174
|
+
}
|
|
175
|
+
.DatePickerView--option {
|
|
176
|
+
display: flex;
|
|
177
|
+
align-items: center;
|
|
178
|
+
justify-content: center;
|
|
179
|
+
white-space: nowrap;
|
|
180
|
+
}
|
|
181
|
+
</style>
|