@ecolovo/uniapp-components 1.0.10 → 2.0.1
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/README.md +202 -66
- package/components/aspect/aspect.vue +24 -15
- package/components/badge/badge.scss +20 -0
- package/components/badge/badge.vue +49 -40
- package/components/button/button.scss +15 -0
- package/components/button/button.vue +121 -177
- package/components/checkbox/checkbox.scss +10 -0
- package/components/checkbox/checkbox.vue +118 -146
- package/components/checkbox-group/checkbox-group.vue +79 -85
- package/components/checkbox-group2/checkbox-group2.vue +111 -107
- package/components/checkbox-group2/checkbox2.vue +104 -0
- package/components/data-list/data-list.scss +9 -0
- package/components/data-list/data-list.vue +70 -79
- package/components/date-picker/date-picker-view.vue +125 -124
- package/components/date-picker/date-picker.vue +145 -146
- package/components/dialog/dialog-content.vue +39 -47
- package/components/dialog/dialog.scss +11 -0
- package/components/dialog/dialog.vue +125 -138
- package/components/dropdown/dropdown.scss +11 -0
- package/components/dropdown/dropdown.vue +55 -97
- package/components/empty/empty.scss +14 -0
- package/components/empty/empty.vue +42 -41
- package/components/flex/flex.vue +45 -54
- package/components/form/form.vue +29 -24
- package/components/form-item/form-item.scss +11 -0
- package/components/form-item/form-item.vue +43 -40
- package/components/icon/icon.vue +70 -85
- package/components/image/image.vue +35 -38
- package/components/input/input.vue +65 -79
- package/components/input/password-input.vue +34 -42
- package/components/list-page/list-page.vue +73 -99
- package/components/load-more/load-more.scss +12 -0
- package/components/load-more/load-more.vue +29 -29
- package/components/loading/animations/loading-animation1.vue +8 -8
- package/components/loading/animations/loading-animation2.vue +8 -9
- package/components/loading/animations/loading-animation3.vue +11 -11
- package/components/loading/animations/loading-animation4.vue +8 -8
- package/components/loading/loading.vue +19 -20
- package/components/message-box/message-box.vue +59 -41
- package/components/number-dialog/number-dialog.scss +9 -0
- package/components/number-dialog/number-dialog.vue +209 -204
- package/components/number-input/number-input.scss +9 -0
- package/components/number-input/number-input.vue +233 -232
- package/components/numpad/numpad.scss +9 -0
- package/components/numpad/numpad.vue +133 -150
- package/components/page/page-body.scss +15 -0
- package/components/page/page-body.vue +137 -119
- package/components/page/page-footer.scss +13 -0
- package/components/page/page-footer.vue +31 -33
- package/components/page/page-header.scss +17 -0
- package/components/page/page-header.vue +89 -94
- package/components/page/page.scss +9 -0
- package/components/page/page.vue +105 -81
- package/components/picker/picker-popup.vue +218 -209
- package/components/picker/picker.vue +99 -104
- package/components/popover/popover-content.vue +54 -63
- package/components/popover/popover-mask.vue +63 -63
- package/components/popover/popover.scss +28 -0
- package/components/popover/popover.vue +49 -47
- package/components/popup/popup-content.vue +49 -53
- package/components/popup/popup.scss +11 -0
- package/components/popup/popup.vue +117 -132
- package/components/price/price.scss +20 -0
- package/components/price/price.vue +31 -42
- package/components/search/search.scss +12 -0
- package/components/search/search.vue +93 -117
- package/components/searching/searching.vue +33 -40
- package/components/selector/selector.vue +43 -48
- package/components/switch/switch.scss +12 -0
- package/components/switch/switch.vue +99 -96
- package/components/tab/tab.scss +19 -0
- package/components/tab/tab.vue +151 -145
- package/components/textarea/textarea.vue +104 -101
- package/composable/component-name.d.ts +2 -0
- package/composable/component-name.js +8 -0
- package/composable/component-name.ts +10 -0
- package/configs/index.d.ts +25 -10
- package/configs/index.js +14 -23
- package/configs/index.ts +82 -0
- package/easyCom.d.ts +9 -0
- package/easyCom.js +1 -2
- package/easyCom.ts +31 -0
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/index.ts +1 -0
- package/init.d.ts +4 -7
- package/init.js +5 -4
- package/init.ts +34 -0
- package/package.json +14 -4
- package/styles/utils/css-var.scss +12 -15
- package/styles/utils/ellipsis.scss +0 -7
- package/styles/utils/z-index.scss +1 -1
- package/styles/var/component.scss +21 -245
- package/utils/date.d.ts +47 -0
- package/utils/date.js +23 -43
- package/utils/date.ts +153 -0
- package/utils/freezeDeep.d.ts +1 -0
- package/utils/freezeDeep.js +4 -14
- package/utils/freezeDeep.ts +9 -0
- package/utils/price.d.ts +24 -0
- package/utils/price.js +14 -8
- package/utils/price.ts +57 -0
- package/utils/round.d.ts +2 -0
- package/utils/round.js +2 -14
- package/utils/round.ts +11 -0
- package/utils/windowInfo.d.ts +24 -0
- package/utils/windowInfo.js +8 -36
- package/utils/windowInfo.ts +50 -0
- package/components/checkbox-group2/checkbox.vue +0 -109
- package/components/datetime-picker/datetime-picker-view.vue +0 -209
- package/components/datetime-picker/datetime-picker.vue +0 -235
- package/components/form/mixin.js +0 -13
- package/components/list-page/list-page.js +0 -10
- package/components/table/table.vue +0 -112
- package/components/time-picker/time-picker-view.vue +0 -127
- package/components/time-picker/time-picker.vue +0 -140
- package/components/uploader/download.js +0 -81
- package/components/uploader/file-uploader.vue +0 -52
- package/components/uploader/files.js +0 -225
- package/components/uploader/media-uploader.vue +0 -189
- package/components/uploader/mixin.js +0 -171
- package/components/uploader/uni.js +0 -38
- package/components/uploader/upload-button.vue +0 -29
- package/components/uploader/uploader copy.vue +0 -547
- package/components/uploader/uploader.vue +0 -117
- package/mixins/componentName.js +0 -32
- package/mixins/listPage.js +0 -1
- package/mixins/windowInfo.js +0 -1
- package/utils/fileSize.js +0 -39
- package/utils/floor.js +0 -20
|
@@ -1,235 +0,0 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<view :class="componentClassNames">
|
|
3
|
-
<selector-cpn
|
|
4
|
-
:value="showText"
|
|
5
|
-
:readonly="isReadonly"
|
|
6
|
-
:disabled="disabled"
|
|
7
|
-
:placeholder="placeholder"
|
|
8
|
-
@click="showPicker"
|
|
9
|
-
/>
|
|
10
|
-
|
|
11
|
-
<!-- 选择器弹框 -->
|
|
12
|
-
<popup-cpn
|
|
13
|
-
v-if="isShowPopup"
|
|
14
|
-
ref="popup"
|
|
15
|
-
v-model="isShowPopup"
|
|
16
|
-
:cancel="false"
|
|
17
|
-
title="选择时间"
|
|
18
|
-
@click.native.stop.prevent="doNothing"
|
|
19
|
-
@confirm="onConfirm"
|
|
20
|
-
>
|
|
21
|
-
<view v-show="checkedDateType === 'start'">
|
|
22
|
-
<datetime-picker-view-cpn
|
|
23
|
-
v-model="startStr"
|
|
24
|
-
:min="min"
|
|
25
|
-
:max="max"
|
|
26
|
-
:minute-step="minuteStep"
|
|
27
|
-
@change="onChangeStart"
|
|
28
|
-
/>
|
|
29
|
-
</view>
|
|
30
|
-
<view v-if="range" v-show="checkedDateType === 'end'">
|
|
31
|
-
<datetime-picker-view-cpn
|
|
32
|
-
v-model="endStr"
|
|
33
|
-
:min="min"
|
|
34
|
-
:max="max"
|
|
35
|
-
:minute-step="minuteStep"
|
|
36
|
-
@change="onChangeEnd"
|
|
37
|
-
/>
|
|
38
|
-
</view>
|
|
39
|
-
</popup-cpn>
|
|
40
|
-
</view>
|
|
41
|
-
</template>
|
|
42
|
-
|
|
43
|
-
<script>
|
|
44
|
-
import componentName from '../../mixins/componentName';
|
|
45
|
-
import { isFormReadonly } from '../form/mixin';
|
|
46
|
-
import { formatDate, toDate } from '../../utils/date';
|
|
47
|
-
import PopupCpn from '../popup/popup.vue';
|
|
48
|
-
import SelectorCpn from '../selector/selector.vue';
|
|
49
|
-
import DatetimePickerViewCpn from './datetime-picker-view.vue';
|
|
50
|
-
|
|
51
|
-
const DATE_FORMAT = formatDate.DATE_MINUTE_WITH_YEAR;
|
|
52
|
-
|
|
53
|
-
export default {
|
|
54
|
-
name: 'DatetimePicker',
|
|
55
|
-
options: {
|
|
56
|
-
virtualHost: true,
|
|
57
|
-
styleIsolation: 'shared',
|
|
58
|
-
},
|
|
59
|
-
components: { PopupCpn, SelectorCpn, DatetimePickerViewCpn },
|
|
60
|
-
mixins: [componentName, isFormReadonly],
|
|
61
|
-
props: {
|
|
62
|
-
/** 绑定值 */
|
|
63
|
-
value: {
|
|
64
|
-
type: [String, null, Array],
|
|
65
|
-
default: null,
|
|
66
|
-
},
|
|
67
|
-
/** 是否禁用 */
|
|
68
|
-
disabled: {
|
|
69
|
-
type: Boolean,
|
|
70
|
-
default: false,
|
|
71
|
-
},
|
|
72
|
-
/** 是否只读 */
|
|
73
|
-
readonly: {
|
|
74
|
-
type: Boolean,
|
|
75
|
-
default: false,
|
|
76
|
-
},
|
|
77
|
-
/** 占位文本 */
|
|
78
|
-
placeholder: {
|
|
79
|
-
type: String,
|
|
80
|
-
default: '请选择',
|
|
81
|
-
},
|
|
82
|
-
/** 是否日期范围选择器 */
|
|
83
|
-
range: {
|
|
84
|
-
type: Boolean,
|
|
85
|
-
default: false,
|
|
86
|
-
},
|
|
87
|
-
/** 是否在选择开始日期时,同步修改结束日期,且保持时间差 */
|
|
88
|
-
keepDiff: {
|
|
89
|
-
type: Boolean,
|
|
90
|
-
default: false,
|
|
91
|
-
},
|
|
92
|
-
/** 结束日期是否可以与开始日期相同 */
|
|
93
|
-
canSame: {
|
|
94
|
-
type: Boolean,
|
|
95
|
-
default: true,
|
|
96
|
-
},
|
|
97
|
-
/** 在选择的日期后面拼接时间字符串,如果传入的是数组,会分别对应添加到范围日期值后 */
|
|
98
|
-
timeAppend: {
|
|
99
|
-
type: [String, Array],
|
|
100
|
-
default: '',
|
|
101
|
-
},
|
|
102
|
-
/** 最小日期 */
|
|
103
|
-
min: {
|
|
104
|
-
type: String,
|
|
105
|
-
default: '',
|
|
106
|
-
},
|
|
107
|
-
/** 最大日期 */
|
|
108
|
-
max: {
|
|
109
|
-
type: String,
|
|
110
|
-
default: '',
|
|
111
|
-
},
|
|
112
|
-
/** 分钟步长 */
|
|
113
|
-
minuteStep: {
|
|
114
|
-
type: Number,
|
|
115
|
-
default: 5,
|
|
116
|
-
},
|
|
117
|
-
},
|
|
118
|
-
data() {
|
|
119
|
-
return {
|
|
120
|
-
/** 选择框是否可见 */
|
|
121
|
-
isShowPopup: false,
|
|
122
|
-
/** 开始日期 */
|
|
123
|
-
startStr: '',
|
|
124
|
-
/** 结束日期 */
|
|
125
|
-
endStr: '',
|
|
126
|
-
/** 当前选中的日期类型 */
|
|
127
|
-
checkedDateType: 'start',
|
|
128
|
-
};
|
|
129
|
-
},
|
|
130
|
-
computed: {
|
|
131
|
-
isReadonly() {
|
|
132
|
-
return this.readonly || this.isFormReadonly;
|
|
133
|
-
},
|
|
134
|
-
startDate() {
|
|
135
|
-
return formatDate(
|
|
136
|
-
toDate(this.range && Array.isArray(this.value) ? this.value[0] : this.value),
|
|
137
|
-
DATE_FORMAT
|
|
138
|
-
);
|
|
139
|
-
},
|
|
140
|
-
endDate() {
|
|
141
|
-
return formatDate(toDate(this.range && Array.isArray(this.value) ? this.value[1] : ''), DATE_FORMAT);
|
|
142
|
-
},
|
|
143
|
-
showText() {
|
|
144
|
-
return this.range && this.startDate && this.endDate
|
|
145
|
-
? `${this.startDate} 至 ${this.endDate}`
|
|
146
|
-
: this.startDate;
|
|
147
|
-
},
|
|
148
|
-
},
|
|
149
|
-
methods: {
|
|
150
|
-
doNothing() {},
|
|
151
|
-
/** 显示选择器弹出框 */
|
|
152
|
-
showPicker() {
|
|
153
|
-
if (this.disabled || this.isReadonly) {
|
|
154
|
-
return;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
this.checkedDateType = 'start';
|
|
158
|
-
|
|
159
|
-
let [start, end] = [this.startDate, this.endDate];
|
|
160
|
-
this.startStr = start || formatDate(new Date(), DATE_FORMAT);
|
|
161
|
-
this.endStr = end || formatDate(new Date(Date.now() + (this.canSame ? 0 : 8.64e7)), DATE_FORMAT);
|
|
162
|
-
|
|
163
|
-
this.isShowPopup = true;
|
|
164
|
-
this.$emit('show');
|
|
165
|
-
},
|
|
166
|
-
/** 选中日期类型 */
|
|
167
|
-
selectDateType(type) {
|
|
168
|
-
if (this.checkedDateType !== type) this.checkedDateType = type;
|
|
169
|
-
},
|
|
170
|
-
onChangeStart(dateStr) {
|
|
171
|
-
if (!this.range) return;
|
|
172
|
-
|
|
173
|
-
const timeDiff = toDate(this.endStr).getTime() - toDate(dateStr).getTime();
|
|
174
|
-
if (this.endStr <= dateStr || this.keepDiff) {
|
|
175
|
-
if (this.keepDiff) {
|
|
176
|
-
this.endStr = formatDate(new Date(toDate(dateStr).getTime() + timeDiff), DATE_FORMAT);
|
|
177
|
-
} else if (!this.canSame) {
|
|
178
|
-
this.endStr = formatDate(new Date(toDate(dateStr).getTime() + 8.64e7), DATE_FORMAT);
|
|
179
|
-
} else {
|
|
180
|
-
this.endStr = dateStr;
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
},
|
|
184
|
-
onChangeEnd(dateStr) {
|
|
185
|
-
if (dateStr <= this.startStr) {
|
|
186
|
-
if (this.canSame) {
|
|
187
|
-
this.endStr = this.startStr;
|
|
188
|
-
} else {
|
|
189
|
-
this.endStr = formatDate(new Date(toDate(this.startStr).getTime() + 8.64e7), DATE_FORMAT);
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
},
|
|
193
|
-
onConfirm() {
|
|
194
|
-
this.$refs.popup.close();
|
|
195
|
-
const startAppend = Array.isArray(this.timeAppend) ? this.timeAppend[0] : this.timeAppend;
|
|
196
|
-
const endAppend = Array.isArray(this.timeAppend) ? this.timeAppend[1] : this.timeAppend;
|
|
197
|
-
const start = startAppend ? `${this.startStr} ${startAppend}` : this.startStr;
|
|
198
|
-
const end = endAppend ? `${this.endStr} ${endAppend}` : this.endStr;
|
|
199
|
-
this.$emit('input', this.range ? [start, end] : start);
|
|
200
|
-
this.$emit('change', this.range ? [start, end] : start);
|
|
201
|
-
},
|
|
202
|
-
},
|
|
203
|
-
};
|
|
204
|
-
</script>
|
|
205
|
-
|
|
206
|
-
<style lang="scss" module>
|
|
207
|
-
@use '../../styles/index' as *;
|
|
208
|
-
|
|
209
|
-
.DatetimePicker {
|
|
210
|
-
width: 100%;
|
|
211
|
-
height: 100%;
|
|
212
|
-
}
|
|
213
|
-
.DatetimePicker--date-input {
|
|
214
|
-
flex: 1;
|
|
215
|
-
display: flex;
|
|
216
|
-
justify-content: center;
|
|
217
|
-
align-items: center;
|
|
218
|
-
height: 72rpx;
|
|
219
|
-
background: UTILS__GLOBAL_VAR(color, background);
|
|
220
|
-
border-radius: 12rpx;
|
|
221
|
-
transition: color 0.3s, background 0.3s;
|
|
222
|
-
&.DatetimePicker--date-checked {
|
|
223
|
-
background: UTILS__GLOBAL_VAR(theme, primary);
|
|
224
|
-
color: #fff;
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
.DatetimePicker--date-separator {
|
|
228
|
-
margin: 0 20rpx;
|
|
229
|
-
}
|
|
230
|
-
.DatetimePicker--date-selector {
|
|
231
|
-
margin-top: 20rpx;
|
|
232
|
-
display: flex;
|
|
233
|
-
align-items: center;
|
|
234
|
-
}
|
|
235
|
-
</style>
|
package/components/form/mixin.js
DELETED
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<view :class="componentClassNames">
|
|
3
|
-
<view :class="[$style['Table--row'], $style['Table--header']]">
|
|
4
|
-
<view
|
|
5
|
-
v-for="(h, i) in headers"
|
|
6
|
-
:key="i"
|
|
7
|
-
:class="[$style['Table--cell'], $style['Table--cell-align'] + (aligns[i] || 2)]"
|
|
8
|
-
>
|
|
9
|
-
<view>{{ h }}</view>
|
|
10
|
-
</view>
|
|
11
|
-
</view>
|
|
12
|
-
<view v-for="(row, i) in value" :key="i" :class="$style['Table--row']">
|
|
13
|
-
<view
|
|
14
|
-
v-for="(col, j) in row"
|
|
15
|
-
:key="j"
|
|
16
|
-
:class="[$style['Table--cell'], $style['Table--cell-align'] + (aligns[j] || 2)]"
|
|
17
|
-
:style="i === 0 && j < row.length - 1 ? { width: widths[j] || colWidth } : ''"
|
|
18
|
-
>
|
|
19
|
-
<view>{{ col }}</view>
|
|
20
|
-
</view>
|
|
21
|
-
</view>
|
|
22
|
-
</view>
|
|
23
|
-
</template>
|
|
24
|
-
|
|
25
|
-
<script>
|
|
26
|
-
import componentName from '../../mixins/componentName';
|
|
27
|
-
import { floor2 } from '../../utils/floor';
|
|
28
|
-
|
|
29
|
-
export default {
|
|
30
|
-
name: 'Table',
|
|
31
|
-
options: {
|
|
32
|
-
virtualHost: true,
|
|
33
|
-
styleIsolation: 'shared',
|
|
34
|
-
},
|
|
35
|
-
mixins: [componentName],
|
|
36
|
-
props: {
|
|
37
|
-
/** 各个列的数据 */
|
|
38
|
-
value: {
|
|
39
|
-
type: Array,
|
|
40
|
-
default: () => [],
|
|
41
|
-
},
|
|
42
|
-
/** 定义各个列的表头 */
|
|
43
|
-
headers: {
|
|
44
|
-
type: Array,
|
|
45
|
-
default: () => [],
|
|
46
|
-
},
|
|
47
|
-
/** 定义各个列的对齐方式,默认居中对齐,1左对齐,2居中,3右对齐 */
|
|
48
|
-
aligns: {
|
|
49
|
-
type: Array,
|
|
50
|
-
default: () => [],
|
|
51
|
-
},
|
|
52
|
-
/** 定义各个列的宽度百分比 */
|
|
53
|
-
widths: {
|
|
54
|
-
type: Array,
|
|
55
|
-
default: () => [],
|
|
56
|
-
},
|
|
57
|
-
},
|
|
58
|
-
computed: {
|
|
59
|
-
/** 总列数 */
|
|
60
|
-
colCount() {
|
|
61
|
-
return this.value[0]?.length || 0;
|
|
62
|
-
},
|
|
63
|
-
/** 每列所占宽度百分比 */
|
|
64
|
-
colWidth() {
|
|
65
|
-
return floor2(100 / this.colCount) + '%';
|
|
66
|
-
},
|
|
67
|
-
},
|
|
68
|
-
};
|
|
69
|
-
</script>
|
|
70
|
-
|
|
71
|
-
<style lang="scss" module>
|
|
72
|
-
@use '../../styles/index' as *;
|
|
73
|
-
|
|
74
|
-
// 自定义样式变量前缀,与组件名称一致
|
|
75
|
-
$component-prefix: '#{$ec-component-prefix}-table';
|
|
76
|
-
// 自定义样式变量
|
|
77
|
-
%external-vars {
|
|
78
|
-
@include define-component-vars($cell-padding: get-value('size-l') get-value('size-xxs'));
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
.Table {
|
|
82
|
-
@extend %external-vars;
|
|
83
|
-
display: table;
|
|
84
|
-
width: 100%;
|
|
85
|
-
border: 2rpx solid get-value('color-background');
|
|
86
|
-
border-radius: get-value('size-radius-s');
|
|
87
|
-
overflow: hidden;
|
|
88
|
-
}
|
|
89
|
-
.Table--header {
|
|
90
|
-
color: get-value('color-info-6');
|
|
91
|
-
}
|
|
92
|
-
.Table--row {
|
|
93
|
-
display: table-row;
|
|
94
|
-
&:nth-child(odd) {
|
|
95
|
-
background: get-value('color-background');
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
.Table--cell {
|
|
99
|
-
display: table-cell;
|
|
100
|
-
padding: var(--cell-padding);
|
|
101
|
-
vertical-align: middle;
|
|
102
|
-
}
|
|
103
|
-
.Table--cell-align1 {
|
|
104
|
-
text-align: start;
|
|
105
|
-
}
|
|
106
|
-
.Table--cell-align2 {
|
|
107
|
-
text-align: center;
|
|
108
|
-
}
|
|
109
|
-
.Table--cell-align3 {
|
|
110
|
-
text-align: end;
|
|
111
|
-
}
|
|
112
|
-
</style>
|
|
@@ -1,127 +0,0 @@
|
|
|
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 hourOptions" :key="item" :class="$style['TimePickerView--option']">
|
|
11
|
-
{{ item }} 时
|
|
12
|
-
</view>
|
|
13
|
-
</picker-view-column>
|
|
14
|
-
<picker-view-column>
|
|
15
|
-
<view v-for="item in minuteOptions" :key="item" :class="$style['TimePickerView--option']">
|
|
16
|
-
{{ item }} 分
|
|
17
|
-
</view>
|
|
18
|
-
</picker-view-column>
|
|
19
|
-
</picker-view>
|
|
20
|
-
</template>
|
|
21
|
-
|
|
22
|
-
<script>
|
|
23
|
-
import range from 'lodash-es/range';
|
|
24
|
-
import componentName from '../../mixins/componentName';
|
|
25
|
-
import { formatDate } from '../../utils/date';
|
|
26
|
-
|
|
27
|
-
const hourOptions = range(0, 24).map((item) => ('' + item).padStart(2, '0'));
|
|
28
|
-
|
|
29
|
-
export default {
|
|
30
|
-
name: 'TimePickerView',
|
|
31
|
-
options: {
|
|
32
|
-
virtualHost: true,
|
|
33
|
-
styleIsolation: 'shared',
|
|
34
|
-
},
|
|
35
|
-
mixins: [componentName],
|
|
36
|
-
props: {
|
|
37
|
-
/** 绑定值 */
|
|
38
|
-
value: {
|
|
39
|
-
type: [String, null],
|
|
40
|
-
default: null,
|
|
41
|
-
},
|
|
42
|
-
/** 分钟步长 */
|
|
43
|
-
step: {
|
|
44
|
-
type: Number,
|
|
45
|
-
default: 5,
|
|
46
|
-
},
|
|
47
|
-
},
|
|
48
|
-
data() {
|
|
49
|
-
return {
|
|
50
|
-
innerValue: '',
|
|
51
|
-
/** 小时选项列表 */
|
|
52
|
-
hourOptions,
|
|
53
|
-
/** 分钟选项列表 */
|
|
54
|
-
minuteOptions: [],
|
|
55
|
-
/** picker-view 绑定值 */
|
|
56
|
-
pickerValue: [0, 0],
|
|
57
|
-
};
|
|
58
|
-
},
|
|
59
|
-
computed: {
|
|
60
|
-
currentValue: {
|
|
61
|
-
get: function () {
|
|
62
|
-
return this.value === null ? this.innerValue : this.value;
|
|
63
|
-
},
|
|
64
|
-
set: function (value) {
|
|
65
|
-
this.$emit('input', value);
|
|
66
|
-
this.innerValue = value;
|
|
67
|
-
this.$emit('change', value);
|
|
68
|
-
},
|
|
69
|
-
},
|
|
70
|
-
},
|
|
71
|
-
created() {
|
|
72
|
-
this.minuteOptions = range(0, 60, this.step);
|
|
73
|
-
},
|
|
74
|
-
mounted() {
|
|
75
|
-
this.$nextTick(() => {
|
|
76
|
-
this.syncPickerValue(this.currentValue || new Date());
|
|
77
|
-
});
|
|
78
|
-
},
|
|
79
|
-
methods: {
|
|
80
|
-
/** 同步 picker-view 选中索引 */
|
|
81
|
-
syncPickerValue(time) {
|
|
82
|
-
const [h, m] = time.split(':');
|
|
83
|
-
const i1 = this.hourOptions.indexOf(h);
|
|
84
|
-
const i2 = Math.max(this.minuteOptions.indexOf(Math.round(Number(m) / this.step) * this.step), 0);
|
|
85
|
-
this.$nextTick(() => {
|
|
86
|
-
this.pickerValue =
|
|
87
|
-
typeof this.pickerValue[0] === 'number' ? [i1, i2].map((item) => item.toString()) : [i1, i2];
|
|
88
|
-
});
|
|
89
|
-
},
|
|
90
|
-
/** picker-view 选项值变化处理 */
|
|
91
|
-
handlePickerChange(e) {
|
|
92
|
-
const newPickerValue = e.detail.value;
|
|
93
|
-
const hour = this.hourOptions[newPickerValue[0]];
|
|
94
|
-
const minute = this.step >= 0 ? this.minuteOptions[newPickerValue[1]] : '00';
|
|
95
|
-
this.pickerValue = newPickerValue;
|
|
96
|
-
const dateValue = new Date(0, 0, 1, hour, minute, 0, 0);
|
|
97
|
-
let dateStr = formatDate(dateValue, formatDate.TIME_MINUTE);
|
|
98
|
-
this.currentValue = dateStr;
|
|
99
|
-
},
|
|
100
|
-
/** 滑动结束处理,保持选择器显示值与输入框值一致 */
|
|
101
|
-
onPickEnd() {
|
|
102
|
-
this.$nextTick(() => {
|
|
103
|
-
this.syncPickerValue(this.currentValue);
|
|
104
|
-
});
|
|
105
|
-
},
|
|
106
|
-
},
|
|
107
|
-
};
|
|
108
|
-
</script>
|
|
109
|
-
|
|
110
|
-
<style lang="scss" module>
|
|
111
|
-
@use '../../styles/index' as *;
|
|
112
|
-
|
|
113
|
-
:host {
|
|
114
|
-
display: flex;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
.TimePickerView {
|
|
118
|
-
margin-top: 24rpx;
|
|
119
|
-
height: 300rpx;
|
|
120
|
-
}
|
|
121
|
-
.TimePickerView--option {
|
|
122
|
-
display: flex;
|
|
123
|
-
align-items: center;
|
|
124
|
-
justify-content: center;
|
|
125
|
-
white-space: nowrap;
|
|
126
|
-
}
|
|
127
|
-
</style>
|
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<view :class="componentClassNames">
|
|
3
|
-
<selector-cpn
|
|
4
|
-
:value="showText"
|
|
5
|
-
:readonly="isReadonly"
|
|
6
|
-
:disabled="disabled"
|
|
7
|
-
:placeholder="placeholder"
|
|
8
|
-
@click="showPicker"
|
|
9
|
-
/>
|
|
10
|
-
|
|
11
|
-
<!-- 选择器弹框 -->
|
|
12
|
-
<popup-cpn
|
|
13
|
-
v-if="isShowPopup"
|
|
14
|
-
ref="popup"
|
|
15
|
-
v-model="isShowPopup"
|
|
16
|
-
:cancel="false"
|
|
17
|
-
title="选择时间"
|
|
18
|
-
@click.native.stop.prevent="doNothing"
|
|
19
|
-
@confirm="onConfirm"
|
|
20
|
-
>
|
|
21
|
-
<view class="TimePicker--picker-area">
|
|
22
|
-
<time-picker-view-cpn v-model="startStr" :step="step" />
|
|
23
|
-
<template v-if="range">
|
|
24
|
-
<view>至</view>
|
|
25
|
-
<time-picker-view-cpn v-model="endStr" :step="step" />
|
|
26
|
-
</template>
|
|
27
|
-
</view>
|
|
28
|
-
</popup-cpn>
|
|
29
|
-
</view>
|
|
30
|
-
</template>
|
|
31
|
-
|
|
32
|
-
<script>
|
|
33
|
-
import componentName from '../../mixins/componentName';
|
|
34
|
-
import { isFormReadonly } from '../form/mixin';
|
|
35
|
-
import PopupCpn from '../popup/popup.vue';
|
|
36
|
-
import SelectorCpn from '../selector/selector.vue';
|
|
37
|
-
import TimePickerViewCpn from './time-picker-view.vue';
|
|
38
|
-
|
|
39
|
-
export default {
|
|
40
|
-
name: 'TimePicker',
|
|
41
|
-
options: {
|
|
42
|
-
virtualHost: true,
|
|
43
|
-
styleIsolation: 'shared',
|
|
44
|
-
},
|
|
45
|
-
components: { PopupCpn, SelectorCpn, TimePickerViewCpn },
|
|
46
|
-
mixins: [componentName, isFormReadonly],
|
|
47
|
-
props: {
|
|
48
|
-
/** 绑定值 */
|
|
49
|
-
value: {
|
|
50
|
-
type: [String, null, Array],
|
|
51
|
-
default: null,
|
|
52
|
-
},
|
|
53
|
-
/** 是否禁用 */
|
|
54
|
-
disabled: {
|
|
55
|
-
type: Boolean,
|
|
56
|
-
default: false,
|
|
57
|
-
},
|
|
58
|
-
/** 是否只读 */
|
|
59
|
-
readonly: {
|
|
60
|
-
type: Boolean,
|
|
61
|
-
default: false,
|
|
62
|
-
},
|
|
63
|
-
/** 占位文本 */
|
|
64
|
-
placeholder: {
|
|
65
|
-
type: String,
|
|
66
|
-
default: '请选择',
|
|
67
|
-
},
|
|
68
|
-
/** 是否时间范围选择器 */
|
|
69
|
-
range: {
|
|
70
|
-
type: Boolean,
|
|
71
|
-
default: false,
|
|
72
|
-
},
|
|
73
|
-
/** 分钟步长 */
|
|
74
|
-
step: {
|
|
75
|
-
type: Number,
|
|
76
|
-
default: 5,
|
|
77
|
-
},
|
|
78
|
-
},
|
|
79
|
-
data() {
|
|
80
|
-
return {
|
|
81
|
-
/** 选择框是否可见 */
|
|
82
|
-
isShowPopup: false,
|
|
83
|
-
/** 开始日期 */
|
|
84
|
-
startStr: '',
|
|
85
|
-
/** 结束日期 */
|
|
86
|
-
endStr: '',
|
|
87
|
-
};
|
|
88
|
-
},
|
|
89
|
-
computed: {
|
|
90
|
-
isReadonly() {
|
|
91
|
-
return this.readonly || this.isFormReadonly;
|
|
92
|
-
},
|
|
93
|
-
startTime() {
|
|
94
|
-
return this.range && Array.isArray(this.value) ? this.value[0] : this.value;
|
|
95
|
-
},
|
|
96
|
-
endTime() {
|
|
97
|
-
return this.range && Array.isArray(this.value) ? this.value[1] : '';
|
|
98
|
-
},
|
|
99
|
-
showText() {
|
|
100
|
-
return this.range && this.startTime && this.endTime
|
|
101
|
-
? `${this.startTime} 至 ${this.endTime}`
|
|
102
|
-
: this.startTime;
|
|
103
|
-
},
|
|
104
|
-
},
|
|
105
|
-
methods: {
|
|
106
|
-
doNothing() {},
|
|
107
|
-
/** 显示选择器弹出框 */
|
|
108
|
-
showPicker() {
|
|
109
|
-
if (this.disabled || this.isReadonly) {
|
|
110
|
-
return;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
this.startStr = this.startTime;
|
|
114
|
-
this.endStr = this.endTime;
|
|
115
|
-
|
|
116
|
-
this.isShowPopup = true;
|
|
117
|
-
this.$emit('show');
|
|
118
|
-
},
|
|
119
|
-
onConfirm() {
|
|
120
|
-
this.$refs.popup.close();
|
|
121
|
-
this.$emit('input', this.range ? [this.startStr, this.endStr] : this.startStr);
|
|
122
|
-
this.$emit('change', this.range ? [this.startStr, this.endStr] : this.startStr);
|
|
123
|
-
},
|
|
124
|
-
},
|
|
125
|
-
};
|
|
126
|
-
</script>
|
|
127
|
-
|
|
128
|
-
<style lang="scss" module>
|
|
129
|
-
@use '../../styles/index' as *;
|
|
130
|
-
|
|
131
|
-
.TimePicker {
|
|
132
|
-
width: 100%;
|
|
133
|
-
height: 100%;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
.TimePicker--picker-area {
|
|
137
|
-
display: flex;
|
|
138
|
-
align-items: center;
|
|
139
|
-
}
|
|
140
|
-
</style>
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
const STORAGE_KEY = 'cached_files';
|
|
2
|
-
|
|
3
|
-
function hasFile(url) {
|
|
4
|
-
const files = uni.getStorageSync(STORAGE_KEY);
|
|
5
|
-
if (!files || !files[url]) {
|
|
6
|
-
return false;
|
|
7
|
-
}
|
|
8
|
-
try {
|
|
9
|
-
uni.getFileSystemManager().accessSync(files[url]);
|
|
10
|
-
return files[url];
|
|
11
|
-
} catch {
|
|
12
|
-
return false;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* 缓存文件
|
|
18
|
-
* @param {string} url 文件下载路径
|
|
19
|
-
* @param {string} name 带后缀的文件名
|
|
20
|
-
* @returns 缓存后的路口
|
|
21
|
-
*/
|
|
22
|
-
function cacheFile(url, name) {
|
|
23
|
-
const filePath = hasFile(url);
|
|
24
|
-
if (filePath) {
|
|
25
|
-
return Promise.resolve(filePath);
|
|
26
|
-
}
|
|
27
|
-
return download(url).then((res) => {
|
|
28
|
-
let filePath = uni.getFileSystemManager().saveFileSync(
|
|
29
|
-
res.filePath,
|
|
30
|
-
/* #ifdef MP-WEIXIN */
|
|
31
|
-
`${wx.env.USER_DATA_PATH}/${name}`,
|
|
32
|
-
/* #endif */
|
|
33
|
-
/* #ifdef MP-ALIPAY */
|
|
34
|
-
`${my.env.USER_DATA_PATH}/${name}`
|
|
35
|
-
/* #endif */
|
|
36
|
-
);
|
|
37
|
-
const files = uni.getStorageSync(STORAGE_KEY) || {};
|
|
38
|
-
/* #ifdef MP-ALIPAY */
|
|
39
|
-
filePath = filePath.savedFilePath;
|
|
40
|
-
/* #endif */
|
|
41
|
-
files[url] = filePath;
|
|
42
|
-
uni.setStorageSync(STORAGE_KEY, files);
|
|
43
|
-
|
|
44
|
-
return filePath;
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* 下载文件
|
|
50
|
-
* @param {string} url 文件下载路径
|
|
51
|
-
* @param {string} name 文件下载后名称
|
|
52
|
-
* @returns 下载后的临时路径
|
|
53
|
-
*/
|
|
54
|
-
function download(url, name) {
|
|
55
|
-
return new Promise((resolve, reject) => {
|
|
56
|
-
uni.downloadFile({
|
|
57
|
-
url,
|
|
58
|
-
filePath: name ? `${wx.env.USER_DATA_PATH}/${name}` : undefined,
|
|
59
|
-
success: function (res) {
|
|
60
|
-
const filePath = res.filePath || res.tempFilePath;
|
|
61
|
-
let fileName = name || '';
|
|
62
|
-
// 从响应头获取文件名
|
|
63
|
-
if (!fileName && res.header) {
|
|
64
|
-
const match = /(filename=(.*))|(filename\*=[^']*'[^']*'(.*))/.exec(
|
|
65
|
-
res.header['Content-Disposition']
|
|
66
|
-
);
|
|
67
|
-
if (match) {
|
|
68
|
-
fileName = decodeURI(match[2] || match[4]);
|
|
69
|
-
fileName = fileName.replace(/^["']*|["']*$/g, '');
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
resolve({ res, filePath, fileName });
|
|
73
|
-
},
|
|
74
|
-
fail: function (error) {
|
|
75
|
-
reject(error);
|
|
76
|
-
},
|
|
77
|
-
});
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
export { download, cacheFile };
|