hy-app 0.1.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 +42 -0
- package/api/http.ts +138 -0
- package/api/index.ts +1 -0
- package/common/index.ts +1 -0
- package/common/versionControl.ts +102 -0
- package/components/dialog/TheDialog.vue +128 -0
- package/components/dialog/index.ts +38 -0
- package/components/hy-address-picker/hy-address-picker.vue +262 -0
- package/components/hy-address-picker/props.ts +27 -0
- package/components/hy-address-picker/typing.d.ts +98 -0
- package/components/hy-avatar/hy-avatar.vue +217 -0
- package/components/hy-avatar/props.ts +20 -0
- package/components/hy-avatar/typing.d.ts +64 -0
- package/components/hy-back-top/hy-back-top.vue +71 -0
- package/components/hy-back-top/props.ts +23 -0
- package/components/hy-back-top/typing.d.ts +49 -0
- package/components/hy-badge/hy-badge.vue +155 -0
- package/components/hy-badge/props.ts +19 -0
- package/components/hy-badge/typing.d.ts +60 -0
- package/components/hy-button/hy-button.vue +394 -0
- package/components/hy-button/props.ts +36 -0
- package/components/hy-button/typing.d.ts +125 -0
- package/components/hy-card/hy-card.vue +198 -0
- package/components/hy-card/props.ts +29 -0
- package/components/hy-card/typing.d.ts +112 -0
- package/components/hy-cell/hy-cell.vue +268 -0
- package/components/hy-cell/props.ts +20 -0
- package/components/hy-cell/typing.d.ts +98 -0
- package/components/hy-check-button/hy-check-button.vue +71 -0
- package/components/hy-check-button/props.ts +20 -0
- package/components/hy-check-button/typing.d.ts +79 -0
- package/components/hy-checkbox/hy-checkbox.vue +299 -0
- package/components/hy-checkbox/props.ts +28 -0
- package/components/hy-checkbox/typing.d.ts +77 -0
- package/components/hy-datetime-picker/hy-datetime-picker.vue +584 -0
- package/components/hy-datetime-picker/props.ts +36 -0
- package/components/hy-datetime-picker/typing.d.ts +135 -0
- package/components/hy-divider/hy-divider.vue +164 -0
- package/components/hy-divider/props.ts +21 -0
- package/components/hy-divider/typing.d.ts +64 -0
- package/components/hy-empty/hy-empty.vue +122 -0
- package/components/hy-empty/props.ts +21 -0
- package/components/hy-empty/typing.d.ts +68 -0
- package/components/hy-folding-panel/hy-folding-panel.vue +94 -0
- package/components/hy-folding-panel/props.ts +17 -0
- package/components/hy-folding-panel/typing.d.ts +59 -0
- package/components/hy-form/hy-form.vue +372 -0
- package/components/hy-form/props.ts +15 -0
- package/components/hy-form/typing.d.ts +51 -0
- package/components/hy-grid/hy-grid.vue +126 -0
- package/components/hy-grid/props.ts +16 -0
- package/components/hy-grid/typing.d.ts +62 -0
- package/components/hy-icon/hy-icon.vue +207 -0
- package/components/hy-icon/props.ts +24 -0
- package/components/hy-icon/typing.d.ts +80 -0
- package/components/hy-input/hy-input.vue +402 -0
- package/components/hy-input/props.ts +41 -0
- package/components/hy-input/typing.d.ts +148 -0
- package/components/hy-line/hy-line.vue +44 -0
- package/components/hy-line/props.ts +12 -0
- package/components/hy-line/typing.d.ts +32 -0
- package/components/hy-line-progress/hy-line-progress.vue +118 -0
- package/components/hy-line-progress/props.ts +12 -0
- package/components/hy-line-progress/typing.d.ts +28 -0
- package/components/hy-list/hy-list.vue +250 -0
- package/components/hy-list/props.ts +18 -0
- package/components/hy-list/typing.d.ts +50 -0
- package/components/hy-login/ThePhoneLogin.vue +106 -0
- package/components/hy-login/TheUserLogin.vue +391 -0
- package/components/hy-login/hy-login.vue +283 -0
- package/components/hy-login/props.ts +32 -0
- package/components/hy-login/typing.d.ts +60 -0
- package/components/hy-modal/hy-modal.vue +240 -0
- package/components/hy-modal/props.ts +24 -0
- package/components/hy-modal/typing.d.ts +70 -0
- package/components/hy-navbar/hy-navbar.vue +194 -0
- package/components/hy-navbar/props.ts +24 -0
- package/components/hy-navbar/typing.d.ts +81 -0
- package/components/hy-notice-bar/hy-column-notice.vue +130 -0
- package/components/hy-notice-bar/hy-notice-bar.vue +82 -0
- package/components/hy-notice-bar/hy-row-notice.vue +182 -0
- package/components/hy-notice-bar/props.ts +19 -0
- package/components/hy-notice-bar/typing.d.ts +56 -0
- package/components/hy-number-step/hy-number-step.vue +428 -0
- package/components/hy-number-step/props.ts +29 -0
- package/components/hy-number-step/typing.d.ts +104 -0
- package/components/hy-overlay/hy-overlay.vue +54 -0
- package/components/hy-overlay/props.ts +10 -0
- package/components/hy-overlay/typing.d.ts +24 -0
- package/components/hy-picker/hy-picker.vue +499 -0
- package/components/hy-picker/props.ts +30 -0
- package/components/hy-picker/typing.d.ts +115 -0
- package/components/hy-popup/hy-popup.vue +269 -0
- package/components/hy-popup/props.ts +21 -0
- package/components/hy-popup/typing.d.ts +68 -0
- package/components/hy-price/hy-price.vue +86 -0
- package/components/hy-price/props.ts +13 -0
- package/components/hy-price/typing.d.ts +36 -0
- package/components/hy-qrcode/hy-qrcode.vue +153 -0
- package/components/hy-qrcode/props.ts +20 -0
- package/components/hy-qrcode/qrcode.js +1364 -0
- package/components/hy-qrcode/typing.d.ts +64 -0
- package/components/hy-radio/hy-radio.vue +319 -0
- package/components/hy-radio/props.ts +28 -0
- package/components/hy-radio/typing.d.ts +85 -0
- package/components/hy-rate/hy-rate.vue +261 -0
- package/components/hy-rate/props.ts +18 -0
- package/components/hy-rate/typing.d.ts +60 -0
- package/components/hy-read-more/hy-read-more.vue +134 -0
- package/components/hy-read-more/props.ts +20 -0
- package/components/hy-read-more/typing.d.ts +44 -0
- package/components/hy-safe-bottom/hy-safe-bottom.vue +64 -0
- package/components/hy-scroll-list/hy-scroll-list.vue +146 -0
- package/components/hy-scroll-list/props.ts +12 -0
- package/components/hy-scroll-list/typing.d.ts +28 -0
- package/components/hy-search/hy-search.vue +294 -0
- package/components/hy-search/props.ts +29 -0
- package/components/hy-search/typing.d.ts +109 -0
- package/components/hy-slider/hy-slider.vue +511 -0
- package/components/hy-slider/props.ts +21 -0
- package/components/hy-slider/typing.d.ts +68 -0
- package/components/hy-steps/hy-steps.vue +352 -0
- package/components/hy-steps/props.ts +15 -0
- package/components/hy-steps/typing.d.ts +58 -0
- package/components/hy-subsection/hy-subsection.vue +272 -0
- package/components/hy-subsection/props.ts +16 -0
- package/components/hy-subsection/typing.d.ts +44 -0
- package/components/hy-swiper/hy-swiper-indicator.vue +105 -0
- package/components/hy-swiper/hy-swiper.vue +242 -0
- package/components/hy-swiper/props.ts +30 -0
- package/components/hy-swiper/typing.d.ts +107 -0
- package/components/hy-switch/hy-switch.vue +168 -0
- package/components/hy-switch/props.ts +16 -0
- package/components/hy-switch/typing.d.ts +48 -0
- package/components/hy-tabs/hy-tabs.vue +416 -0
- package/components/hy-tabs/props.ts +26 -0
- package/components/hy-tabs/typing.d.ts +86 -0
- package/components/hy-tag/hy-tag.vue +374 -0
- package/components/hy-tag/props.ts +22 -0
- package/components/hy-tag/typing.d.ts +76 -0
- package/components/hy-textarea/hy-textarea.vue +229 -0
- package/components/hy-textarea/props.ts +26 -0
- package/components/hy-textarea/typing.d.ts +27 -0
- package/components/hy-tooltip/hy-tooltip.vue +332 -0
- package/components/hy-tooltip/props.ts +17 -0
- package/components/hy-tooltip/typing.d.ts +52 -0
- package/components/hy-transition/hy-transition.vue +150 -0
- package/components/hy-transition/index.scss +113 -0
- package/components/hy-transition/props.ts +10 -0
- package/components/hy-transition/typing.d.ts +36 -0
- package/components/hy-upload/hy-upload.vue +557 -0
- package/components/hy-upload/props.ts +29 -0
- package/components/hy-upload/typing.d.ts +147 -0
- package/components/hy-warn/hy-warn.vue +228 -0
- package/components/hy-warn/props.ts +14 -0
- package/components/hy-warn/typing.d.ts +40 -0
- package/components/hy-waterfall/hy-waterfall.vue +51 -0
- package/components/hy-waterfall/props.ts +10 -0
- package/components/hy-waterfall/typing.d.ts +20 -0
- package/components/index.ts +162 -0
- package/components/message/TheMessage.vue +169 -0
- package/components/message/index.ts +54 -0
- package/components/u-form/form.js +22 -0
- package/components/u-form/hy-form.vue +324 -0
- package/components/u-form/props.js +49 -0
- package/components/u-form/schema.js +1451 -0
- package/components/u-form/u-form.vue +267 -0
- package/components/u-form/utils.js +65 -0
- package/components/u-form-item/formItem.js +24 -0
- package/components/u-form-item/hy-form-item.vue +360 -0
- package/components/u-form-item/props.js +57 -0
- package/components/u-form-item/u-form-item.vue +294 -0
- package/components/yk-dialog/yk-dialog.vue +129 -0
- package/components/yk-tabbar/props.ts +49 -0
- package/components/yk-tabbar/yk-tabbar.vue +224 -0
- package/config/color.ts +6 -0
- package/config/icon.ts +366 -0
- package/config/index.ts +2 -0
- package/global/index.ts +6 -0
- package/global/register-properties.ts +37 -0
- package/index.ts +8 -0
- package/libs/css/common.scss +0 -0
- package/libs/css/iconfont.css +379 -0
- package/libs/css/iconfont.ttf +0 -0
- package/libs/css/mixin.scss +15 -0
- package/package.json +42 -0
- package/public/icons/error.png +0 -0
- package/public/icons/success.png +0 -0
- package/public/icons/warning.png +0 -0
- package/store/index.ts +1 -0
- package/store/userInfo.ts +25 -0
- package/theme.scss +94 -0
- package/typing/index.ts +7 -0
- package/typing/modules/common.d.ts +50 -0
- package/typing/modules/dialog.ts +17 -0
- package/typing/modules/enum.ts +67 -0
- package/typing/modules/form.ts +161 -0
- package/typing/modules/http.ts +68 -0
- package/typing/modules/icon.d.ts +366 -0
- package/typing/modules/img.ts +15 -0
- package/typing/modules/rect.ts +10 -0
- package/utils/address.json +5890 -0
- package/utils/base64.ts +119 -0
- package/utils/index.ts +3 -0
- package/utils/inside.ts +310 -0
- package/utils/utils.ts +446 -0
|
@@ -0,0 +1,584 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<view class="u-datetime-picker">
|
|
3
|
+
<view
|
|
4
|
+
v-if="hasInput"
|
|
5
|
+
class="u-datetime-picker__has-input"
|
|
6
|
+
@click="onShowByClickInput"
|
|
7
|
+
>
|
|
8
|
+
<slot name="trigger" :value="inputValue">
|
|
9
|
+
<HyInput
|
|
10
|
+
:placeholder="placeholder"
|
|
11
|
+
:readonly="!!showByClickInput"
|
|
12
|
+
v-model="inputValue"
|
|
13
|
+
:disabled="disabled"
|
|
14
|
+
:disabledColor="disabledColor"
|
|
15
|
+
:shape="shape"
|
|
16
|
+
:border="border"
|
|
17
|
+
:customStyle="customStyle"
|
|
18
|
+
></HyInput>
|
|
19
|
+
<view class="input-cover"></view>
|
|
20
|
+
</slot>
|
|
21
|
+
</view>
|
|
22
|
+
<HyPicker
|
|
23
|
+
ref="picker"
|
|
24
|
+
:show="show || (hasInput && showByClickInput)"
|
|
25
|
+
:popupMode="popupMode"
|
|
26
|
+
:closeOnClickOverlay="closeOnClickOverlay"
|
|
27
|
+
:columns="columns"
|
|
28
|
+
:title="title"
|
|
29
|
+
:itemHeight="itemHeight"
|
|
30
|
+
:loading="loading"
|
|
31
|
+
:showToolbar="showToolbar"
|
|
32
|
+
:visibleItemCount="visibleItemCount"
|
|
33
|
+
:defaultIndex="innerDefaultIndex"
|
|
34
|
+
:cancelText="cancelText"
|
|
35
|
+
:cancelColor="cancelColor"
|
|
36
|
+
:confirmColor="confirmColor"
|
|
37
|
+
:toolbarRightSlot="toolbarRightSlot"
|
|
38
|
+
@close="close"
|
|
39
|
+
@cancel="cancel"
|
|
40
|
+
@confirm="confirm"
|
|
41
|
+
@change="change"
|
|
42
|
+
>
|
|
43
|
+
<template #toolbar-right>
|
|
44
|
+
<slot name="toolbar-right">
|
|
45
|
+
{{ confirmText }}
|
|
46
|
+
</slot>
|
|
47
|
+
</template>
|
|
48
|
+
<template #toolbar-bottom>
|
|
49
|
+
<slot name="toolbar-bottom"> </slot>
|
|
50
|
+
</template>
|
|
51
|
+
</HyPicker>
|
|
52
|
+
</view>
|
|
53
|
+
</template>
|
|
54
|
+
|
|
55
|
+
<script setup lang="ts">
|
|
56
|
+
import { computed, onMounted, ref, toRefs, watch } from "vue";
|
|
57
|
+
import defaultProps from "./props";
|
|
58
|
+
import IProps from "./typing";
|
|
59
|
+
import dayjs from "dayjs/esm";
|
|
60
|
+
import { error, padZero } from "../../utils";
|
|
61
|
+
import { DateModeEnum } from "../../typing";
|
|
62
|
+
// 组件
|
|
63
|
+
import HyInput from "../hy-input/hy-input.vue";
|
|
64
|
+
import HyPicker from "../hy-picker/hy-picker.vue";
|
|
65
|
+
|
|
66
|
+
const props = withDefaults(defineProps<IProps>(), defaultProps);
|
|
67
|
+
const {
|
|
68
|
+
show,
|
|
69
|
+
modelValue,
|
|
70
|
+
hasInput,
|
|
71
|
+
disabled,
|
|
72
|
+
formatter,
|
|
73
|
+
filter,
|
|
74
|
+
format,
|
|
75
|
+
mode,
|
|
76
|
+
closeOnClickOverlay,
|
|
77
|
+
maxDate,
|
|
78
|
+
minDate,
|
|
79
|
+
minHour,
|
|
80
|
+
maxHour,
|
|
81
|
+
minMinute,
|
|
82
|
+
maxMinute
|
|
83
|
+
} = toRefs(props);
|
|
84
|
+
const emit = defineEmits([
|
|
85
|
+
"close",
|
|
86
|
+
"cancel",
|
|
87
|
+
"confirm",
|
|
88
|
+
"change",
|
|
89
|
+
"update:modelValue"
|
|
90
|
+
]);
|
|
91
|
+
|
|
92
|
+
// 原来的日期选择器不方便,这里增加一个hasInput选项支持类似element的自带输入框的功能。
|
|
93
|
+
const inputValue = ref<string | number>(""); // 表单显示值
|
|
94
|
+
const innerValue = ref<string | number>(""); // 表单显示值
|
|
95
|
+
const showByClickInput = ref<boolean>(false); // 是否在hasInput模式下显示日期选择弹唱
|
|
96
|
+
const columns = ref<any[]>([]);
|
|
97
|
+
const innerDefaultIndex = ref<number[]>([]);
|
|
98
|
+
let innerFormatter = (type: any, value: any) => value;
|
|
99
|
+
const validModes = new Set([
|
|
100
|
+
DateModeEnum.TIME,
|
|
101
|
+
DateModeEnum.MONTH_DAY,
|
|
102
|
+
DateModeEnum.HOUR_MINUTE,
|
|
103
|
+
DateModeEnum.MINUTE_SECOND
|
|
104
|
+
]);
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* @description 更新各列的值
|
|
108
|
+
* */
|
|
109
|
+
const updateColumns = () => {
|
|
110
|
+
const formatterFn = formatter.value || innerFormatter;
|
|
111
|
+
// 获取各列的值,并且map后,对各列的具体值进行补0操作
|
|
112
|
+
columns.value = getOriginColumns().map((column) =>
|
|
113
|
+
column.values.map((value) => formatterFn(column.type, value))
|
|
114
|
+
);
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* @description 更新各列的值,进行补0、格式化等操作
|
|
119
|
+
* */
|
|
120
|
+
const updateColumnValue = (value: string | number) => {
|
|
121
|
+
innerValue.value = value;
|
|
122
|
+
updateColumns();
|
|
123
|
+
// 延迟执行,等待u-picker组件列数据更新完后再设置选中值索引
|
|
124
|
+
setTimeout(() => {
|
|
125
|
+
updateIndexs(value);
|
|
126
|
+
}, 100);
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
const init = () => {
|
|
130
|
+
// 获取当前值
|
|
131
|
+
innerValue.value = correctValue(modelValue.value);
|
|
132
|
+
// 更新列表
|
|
133
|
+
updateColumnValue(innerValue.value);
|
|
134
|
+
|
|
135
|
+
// 初始化hasInput展示
|
|
136
|
+
getInputValue(innerValue.value);
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
watch(
|
|
140
|
+
() => show.value,
|
|
141
|
+
(newValue) => {
|
|
142
|
+
if (newValue) {
|
|
143
|
+
updateColumnValue(innerValue.value);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
);
|
|
147
|
+
|
|
148
|
+
watch(
|
|
149
|
+
() => modelValue.value,
|
|
150
|
+
() => init()
|
|
151
|
+
);
|
|
152
|
+
|
|
153
|
+
const propsChange = computed(() => {
|
|
154
|
+
return [
|
|
155
|
+
mode.value,
|
|
156
|
+
maxDate.value,
|
|
157
|
+
minDate.value,
|
|
158
|
+
minHour.value,
|
|
159
|
+
maxHour.value,
|
|
160
|
+
minMinute.value,
|
|
161
|
+
maxMinute.value,
|
|
162
|
+
filter.value
|
|
163
|
+
];
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
watch(
|
|
167
|
+
() => propsChange.value,
|
|
168
|
+
() => init()
|
|
169
|
+
);
|
|
170
|
+
|
|
171
|
+
onMounted(() => {
|
|
172
|
+
init();
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
const getInputValue = (newValue: string | number) => {
|
|
176
|
+
if (newValue == "" || !newValue) {
|
|
177
|
+
inputValue.value = "";
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
if (mode.value === "time") {
|
|
181
|
+
inputValue.value = newValue;
|
|
182
|
+
} else {
|
|
183
|
+
if (format.value) {
|
|
184
|
+
inputValue.value = dayjs(newValue).format(format.value);
|
|
185
|
+
} else {
|
|
186
|
+
let format = "";
|
|
187
|
+
switch (mode.value) {
|
|
188
|
+
case DateModeEnum.DATE:
|
|
189
|
+
format = "YYYY-MM-DD";
|
|
190
|
+
break;
|
|
191
|
+
case DateModeEnum.YEAR_MONTH:
|
|
192
|
+
format = "YYYY-MM";
|
|
193
|
+
break;
|
|
194
|
+
case DateModeEnum.DATETIME:
|
|
195
|
+
format = "YYYY-MM-DD HH:mm:ss";
|
|
196
|
+
break;
|
|
197
|
+
case DateModeEnum.MONTH_DAY:
|
|
198
|
+
format = "MM-DD";
|
|
199
|
+
break;
|
|
200
|
+
case DateModeEnum.HOUR_MINUTE:
|
|
201
|
+
format = "HH:mm";
|
|
202
|
+
break;
|
|
203
|
+
case DateModeEnum.MINUTE_SECOND:
|
|
204
|
+
format = "mm:ss";
|
|
205
|
+
break;
|
|
206
|
+
default:
|
|
207
|
+
break;
|
|
208
|
+
}
|
|
209
|
+
inputValue.value = dayjs(newValue).isValid()
|
|
210
|
+
? dayjs(newValue).format(format)
|
|
211
|
+
: newValue;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
const times = (n: number, iteratee: Function) => {
|
|
216
|
+
let index = -1;
|
|
217
|
+
const result = Array(n < 0 ? 0 : n);
|
|
218
|
+
while (++index < n) {
|
|
219
|
+
result[index] = iteratee(index);
|
|
220
|
+
}
|
|
221
|
+
return result;
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* @description 关闭选择器
|
|
226
|
+
* */
|
|
227
|
+
const close = () => {
|
|
228
|
+
if (closeOnClickOverlay.value) {
|
|
229
|
+
if (hasInput.value) {
|
|
230
|
+
showByClickInput.value = false;
|
|
231
|
+
}
|
|
232
|
+
emit("close");
|
|
233
|
+
}
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* @description 点击工具栏的取消按钮
|
|
238
|
+
* */
|
|
239
|
+
const cancel = () => {
|
|
240
|
+
if (hasInput.value) {
|
|
241
|
+
showByClickInput.value = false;
|
|
242
|
+
}
|
|
243
|
+
emit("cancel");
|
|
244
|
+
};
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* @description 点击工具栏的确定按钮
|
|
248
|
+
* */
|
|
249
|
+
const confirm = () => {
|
|
250
|
+
emit("update:modelValue", innerValue.value);
|
|
251
|
+
if (hasInput.value) {
|
|
252
|
+
getInputValue(innerValue.value);
|
|
253
|
+
showByClickInput.value = false;
|
|
254
|
+
}
|
|
255
|
+
emit("confirm", {
|
|
256
|
+
value: innerValue.value,
|
|
257
|
+
mode: mode.value
|
|
258
|
+
});
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* @description 用正则截取输出值,当出现多组数字时,抛出错误
|
|
263
|
+
* */
|
|
264
|
+
const intercept = (e: any, type?: string) => {
|
|
265
|
+
let judge = e.match(/\d+/g);
|
|
266
|
+
//判断是否掺杂数字
|
|
267
|
+
if (judge.length > 1) {
|
|
268
|
+
error("请勿在过滤或格式化函数时添加数字");
|
|
269
|
+
return 0;
|
|
270
|
+
} else if (type && judge[0].length == 4) {
|
|
271
|
+
//判断是否是年份
|
|
272
|
+
return judge[0];
|
|
273
|
+
} else if (judge[0].length > 2) {
|
|
274
|
+
error("请勿在过滤或格式化函数时添加数字");
|
|
275
|
+
return 0;
|
|
276
|
+
} else {
|
|
277
|
+
return judge[0];
|
|
278
|
+
}
|
|
279
|
+
};
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* @description 列发生变化时触发
|
|
283
|
+
* */
|
|
284
|
+
const change = (e: any) => {
|
|
285
|
+
const { indexs, values } = e;
|
|
286
|
+
let selectValue: string | number = "";
|
|
287
|
+
if (validModes.has(mode.value) && mode.value !== DateModeEnum.MONTH_DAY) {
|
|
288
|
+
// 根据value各列索引,从各列数组中,取出当前时间的选中值
|
|
289
|
+
selectValue = `${intercept(values[0][indexs[0]])}:${intercept(
|
|
290
|
+
values[1][indexs[1]]
|
|
291
|
+
)}`;
|
|
292
|
+
} else if (mode.value === DateModeEnum.MONTH_DAY) {
|
|
293
|
+
// 根据value各列索引,从各列数组中,取出当前时间的选中值
|
|
294
|
+
selectValue = `${intercept(values[0][indexs[0]])}-${intercept(
|
|
295
|
+
values[1][indexs[1]]
|
|
296
|
+
)}`;
|
|
297
|
+
} else {
|
|
298
|
+
// 将选择的值转为数值,比如'03'转为数值的3,'2019'转为数值的2019
|
|
299
|
+
const year = parseInt(intercept(values[0][indexs[0]], "year"));
|
|
300
|
+
const month = parseInt(intercept(values[1][indexs[1]]));
|
|
301
|
+
let date = parseInt(values[2] ? intercept(values[2][indexs[2]]) : 1);
|
|
302
|
+
let hour = 0,
|
|
303
|
+
minute = 0,
|
|
304
|
+
second = 0;
|
|
305
|
+
// 此月份的最大天数
|
|
306
|
+
const maxDate = dayjs(`${year}-${month}`).daysInMonth();
|
|
307
|
+
// 不允许超过maxDate值
|
|
308
|
+
date = Math.min(maxDate, date);
|
|
309
|
+
if (mode.value === DateModeEnum.DATETIME) {
|
|
310
|
+
hour = parseInt(intercept(values[3][indexs[3]]));
|
|
311
|
+
minute = parseInt(intercept(values[4][indexs[4]]));
|
|
312
|
+
second = parseInt(intercept(values[5][indexs[5]]));
|
|
313
|
+
}
|
|
314
|
+
// 转为时间模式
|
|
315
|
+
selectValue = Number(new Date(year, month - 1, date, hour, minute, second));
|
|
316
|
+
}
|
|
317
|
+
// 取出准确的合法值,防止超越边界的情况
|
|
318
|
+
selectValue = correctValue(selectValue);
|
|
319
|
+
innerValue.value = selectValue;
|
|
320
|
+
updateColumnValue(selectValue);
|
|
321
|
+
// 发出change时间,value为当前选中的时间戳
|
|
322
|
+
emit("change", {
|
|
323
|
+
value: selectValue,
|
|
324
|
+
// #ifndef MP-WEIXIN
|
|
325
|
+
// 微信小程序不能传递this实例,会因为循环引用而报错
|
|
326
|
+
// picker: this.$refs.picker,
|
|
327
|
+
// #endif
|
|
328
|
+
mode: mode.value
|
|
329
|
+
});
|
|
330
|
+
};
|
|
331
|
+
|
|
332
|
+
/**
|
|
333
|
+
* @description 更新索引
|
|
334
|
+
* */
|
|
335
|
+
const updateIndexs = (value: number | string) => {
|
|
336
|
+
let values = [];
|
|
337
|
+
let timeArr: string[] = [];
|
|
338
|
+
const formatterFn = formatter.value || innerFormatter;
|
|
339
|
+
|
|
340
|
+
switch (mode.value) {
|
|
341
|
+
case DateModeEnum.TIME:
|
|
342
|
+
timeArr = value.toString().split(":");
|
|
343
|
+
// 使用formatter格式化方法进行管道处理
|
|
344
|
+
values = [
|
|
345
|
+
formatterFn("hour", timeArr[0]),
|
|
346
|
+
formatterFn("minute", timeArr[1])
|
|
347
|
+
];
|
|
348
|
+
break;
|
|
349
|
+
case DateModeEnum.MONTH_DAY:
|
|
350
|
+
timeArr = value.toString().split("-");
|
|
351
|
+
// 使用formatter格式化方法进行管道处理
|
|
352
|
+
values = [
|
|
353
|
+
formatterFn("month", timeArr[0]),
|
|
354
|
+
formatterFn("day", timeArr[1])
|
|
355
|
+
];
|
|
356
|
+
break;
|
|
357
|
+
case DateModeEnum.HOUR_MINUTE:
|
|
358
|
+
timeArr = value.toString().split(":");
|
|
359
|
+
// 使用formatter格式化方法进行管道处理
|
|
360
|
+
values = [
|
|
361
|
+
formatterFn("hour", timeArr[0]),
|
|
362
|
+
formatterFn("minute", timeArr[1])
|
|
363
|
+
];
|
|
364
|
+
break;
|
|
365
|
+
case DateModeEnum.MINUTE_SECOND:
|
|
366
|
+
timeArr = value.toString().split(":");
|
|
367
|
+
// 使用formatter格式化方法进行管道处理
|
|
368
|
+
values = [
|
|
369
|
+
formatterFn("minute", timeArr[0]),
|
|
370
|
+
formatterFn("second", timeArr[1])
|
|
371
|
+
];
|
|
372
|
+
break;
|
|
373
|
+
default:
|
|
374
|
+
values = [
|
|
375
|
+
formatterFn("year", `${dayjs(value).year()}`),
|
|
376
|
+
// 月份补0
|
|
377
|
+
formatterFn("month", padZero(dayjs(value).month() + 1))
|
|
378
|
+
];
|
|
379
|
+
if (mode.value === DateModeEnum.DATE) {
|
|
380
|
+
// date模式,需要添加天列
|
|
381
|
+
values.push(formatterFn("day", padZero(dayjs(value).date())));
|
|
382
|
+
}
|
|
383
|
+
if (mode.value === DateModeEnum.DATETIME) {
|
|
384
|
+
// 数组的push方法,可以写入多个参数
|
|
385
|
+
values.push(
|
|
386
|
+
formatterFn("day", padZero(dayjs(value).date())),
|
|
387
|
+
formatterFn("hour", padZero(dayjs(value).hour())),
|
|
388
|
+
formatterFn("minute", padZero(dayjs(value).minute())),
|
|
389
|
+
formatterFn("second", padZero(dayjs(value).second()))
|
|
390
|
+
);
|
|
391
|
+
}
|
|
392
|
+
break;
|
|
393
|
+
}
|
|
394
|
+
// 根据当前各列的所有值,从各列默认值中找到默认值在各列中的索引
|
|
395
|
+
innerDefaultIndex.value = columns.value.map((column, index) => {
|
|
396
|
+
// 通过取大值,可以保证不会出现找不到索引的"-1"情况
|
|
397
|
+
return Math.max(
|
|
398
|
+
0,
|
|
399
|
+
column.findIndex((item: string) => item === values[index])
|
|
400
|
+
);
|
|
401
|
+
});
|
|
402
|
+
};
|
|
403
|
+
|
|
404
|
+
/**
|
|
405
|
+
* @description 获取每列数据
|
|
406
|
+
* */
|
|
407
|
+
const getOriginColumns = () => {
|
|
408
|
+
// 生成各列的值
|
|
409
|
+
return getRanges().map(({ type, range }) => {
|
|
410
|
+
let values = times(range[1] - range[0] + 1, (index: number) => {
|
|
411
|
+
let value: string | number = range[0] + index;
|
|
412
|
+
value = type === "year" ? `${value}` : padZero(value);
|
|
413
|
+
return value;
|
|
414
|
+
});
|
|
415
|
+
// 进行过滤
|
|
416
|
+
if (filter.value) {
|
|
417
|
+
values = filter.value(type, values);
|
|
418
|
+
if (!values || (values && values.length == 0)) {
|
|
419
|
+
// uni.showToast({
|
|
420
|
+
// title: '日期filter结果不能为空',
|
|
421
|
+
// icon: 'error',
|
|
422
|
+
// mask: true
|
|
423
|
+
// })
|
|
424
|
+
error("日期filter结果不能为空");
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
return { type, values };
|
|
428
|
+
});
|
|
429
|
+
};
|
|
430
|
+
|
|
431
|
+
/**
|
|
432
|
+
* @description 得出合法的时间
|
|
433
|
+
* */
|
|
434
|
+
const correctValue = (value: number | string | Date): string | number => {
|
|
435
|
+
const isDateMode = mode.value !== DateModeEnum.TIME;
|
|
436
|
+
// if (isDateMode && !test.date(value)) {
|
|
437
|
+
if (!isDateMode && !value) {
|
|
438
|
+
// 如果是时间类型,而又没有默认值的话,就用最小时间
|
|
439
|
+
value = `${padZero(minHour.value)}:${padZero(minMinute.value)}`;
|
|
440
|
+
}
|
|
441
|
+
// 时间类型
|
|
442
|
+
if (validModes.has(mode.value)) {
|
|
443
|
+
return value as string;
|
|
444
|
+
} else {
|
|
445
|
+
// 如果是日期格式,控制在最小日期和最大日期之间
|
|
446
|
+
value = dayjs(value).isBefore(dayjs(minDate.value)) ? minDate.value : value;
|
|
447
|
+
value = dayjs(value).isAfter(dayjs(maxDate.value)) ? maxDate.value : value;
|
|
448
|
+
return value as string | number;
|
|
449
|
+
}
|
|
450
|
+
};
|
|
451
|
+
/**
|
|
452
|
+
* @description 获取每列的最大和最小值
|
|
453
|
+
* */
|
|
454
|
+
const getRanges = () => {
|
|
455
|
+
if (mode.value === DateModeEnum.TIME) {
|
|
456
|
+
return [
|
|
457
|
+
{
|
|
458
|
+
type: "hour",
|
|
459
|
+
range: [props.minHour, props.maxHour]
|
|
460
|
+
},
|
|
461
|
+
{
|
|
462
|
+
type: "minute",
|
|
463
|
+
range: [props.minMinute, props.maxMinute]
|
|
464
|
+
}
|
|
465
|
+
];
|
|
466
|
+
}
|
|
467
|
+
const { maxYear, maxDate, maxMonth, maxHour, maxMinute } = getBoundary(
|
|
468
|
+
"max",
|
|
469
|
+
innerValue.value
|
|
470
|
+
);
|
|
471
|
+
const { minYear, minDate, minMonth, minHour, minMinute } = getBoundary(
|
|
472
|
+
"min",
|
|
473
|
+
innerValue.value
|
|
474
|
+
);
|
|
475
|
+
const result = [
|
|
476
|
+
{
|
|
477
|
+
type: "year",
|
|
478
|
+
range: [minYear, maxYear]
|
|
479
|
+
},
|
|
480
|
+
{
|
|
481
|
+
type: "month",
|
|
482
|
+
range: [minMonth, maxMonth]
|
|
483
|
+
},
|
|
484
|
+
{
|
|
485
|
+
type: "day",
|
|
486
|
+
range: [minDate, maxDate]
|
|
487
|
+
},
|
|
488
|
+
{
|
|
489
|
+
type: "hour",
|
|
490
|
+
range: [minHour, maxHour]
|
|
491
|
+
},
|
|
492
|
+
{
|
|
493
|
+
type: "minute",
|
|
494
|
+
range: [minMinute, maxMinute]
|
|
495
|
+
},
|
|
496
|
+
{
|
|
497
|
+
type: "second",
|
|
498
|
+
range: [minMinute, maxMinute]
|
|
499
|
+
}
|
|
500
|
+
];
|
|
501
|
+
let arr = result;
|
|
502
|
+
// 截取对应的列数
|
|
503
|
+
if (mode.value === DateModeEnum.DATE) arr = result.splice(0, 3);
|
|
504
|
+
if (mode.value === DateModeEnum.YEAR_MONTH) arr = result.splice(0, 2);
|
|
505
|
+
if (mode.value === DateModeEnum.MONTH_DAY) arr = result.splice(1, 2);
|
|
506
|
+
if (mode.value === DateModeEnum.HOUR_MINUTE) arr = result.splice(3, 2);
|
|
507
|
+
if (mode.value === DateModeEnum.MINUTE_SECOND) arr = result.splice(4, 2);
|
|
508
|
+
return arr;
|
|
509
|
+
};
|
|
510
|
+
/**
|
|
511
|
+
* @description 根据minDate、maxDate、minHour、maxHour等边界值,判断各列的开始和结束边界值
|
|
512
|
+
* */
|
|
513
|
+
const getBoundary = (type: string, innerVal: string | number) => {
|
|
514
|
+
const value = new Date(innerVal);
|
|
515
|
+
const boundary = new Date((props as any)[`${type}Date`]);
|
|
516
|
+
const year = dayjs(boundary).year();
|
|
517
|
+
let month = 1;
|
|
518
|
+
let date = 1;
|
|
519
|
+
let hour = 0;
|
|
520
|
+
let minute = 0;
|
|
521
|
+
if (type === "max") {
|
|
522
|
+
month = 12;
|
|
523
|
+
// 月份的天数
|
|
524
|
+
date = dayjs(value).daysInMonth() || 31;
|
|
525
|
+
hour = 23;
|
|
526
|
+
minute = 59;
|
|
527
|
+
}
|
|
528
|
+
// 获取边界值,逻辑是:当年达到了边界值(最大或最小年),就检查月允许的最大和最小值,以此类推
|
|
529
|
+
if (dayjs(value).year() === year) {
|
|
530
|
+
month = dayjs(boundary).month() + 1;
|
|
531
|
+
if (dayjs(value).month() + 1 === month) {
|
|
532
|
+
date = dayjs(boundary).date();
|
|
533
|
+
if (dayjs(value).date() === date) {
|
|
534
|
+
hour = dayjs(boundary).hour();
|
|
535
|
+
if (dayjs(value).hour() === hour) {
|
|
536
|
+
minute = dayjs(boundary).minute();
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
return {
|
|
542
|
+
[`${type}Year`]: year,
|
|
543
|
+
[`${type}Month`]: month,
|
|
544
|
+
[`${type}Date`]: date,
|
|
545
|
+
[`${type}Hour`]: hour,
|
|
546
|
+
[`${type}Minute`]: minute
|
|
547
|
+
};
|
|
548
|
+
};
|
|
549
|
+
const onShowByClickInput = () => {
|
|
550
|
+
if (!disabled.value) {
|
|
551
|
+
showByClickInput.value = !showByClickInput.value;
|
|
552
|
+
}
|
|
553
|
+
};
|
|
554
|
+
</script>
|
|
555
|
+
|
|
556
|
+
<style lang="scss" scoped>
|
|
557
|
+
@import "../../libs/css/mixin.scss";
|
|
558
|
+
.hy-datetime-picker {
|
|
559
|
+
flex: 1;
|
|
560
|
+
&__has-input {
|
|
561
|
+
position: relative;
|
|
562
|
+
display: flex;
|
|
563
|
+
flex-direction: column;
|
|
564
|
+
justify-content: center;
|
|
565
|
+
/* #ifndef APP-NVUE */
|
|
566
|
+
width: 100%;
|
|
567
|
+
/* #endif */
|
|
568
|
+
.input-cover {
|
|
569
|
+
opacity: 0;
|
|
570
|
+
position: absolute;
|
|
571
|
+
top: 0;
|
|
572
|
+
bottom: 0;
|
|
573
|
+
left: 0;
|
|
574
|
+
right: 0;
|
|
575
|
+
display: flex;
|
|
576
|
+
flex-direction: column;
|
|
577
|
+
justify-content: center;
|
|
578
|
+
border-radius: 4px;
|
|
579
|
+
border: 1px solid #eee;
|
|
580
|
+
padding: 0 10px;
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
</style>
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import IProps from "./typing";
|
|
2
|
+
import { DateModeEnum } from "../../typing";
|
|
3
|
+
|
|
4
|
+
const defaultProps: IProps = {
|
|
5
|
+
show: false,
|
|
6
|
+
popupMode: "bottom",
|
|
7
|
+
showToolbar: true,
|
|
8
|
+
modelValue: "",
|
|
9
|
+
title: "",
|
|
10
|
+
mode: DateModeEnum.DATETIME,
|
|
11
|
+
maxDate: new Date(new Date().getFullYear() + 10, 0, 1).getTime(),
|
|
12
|
+
minDate: new Date(new Date().getFullYear() - 10, 0, 1).getTime(),
|
|
13
|
+
minHour: 0,
|
|
14
|
+
maxHour: 23,
|
|
15
|
+
minMinute: 0,
|
|
16
|
+
maxMinute: 59,
|
|
17
|
+
filter: null,
|
|
18
|
+
formatter: null,
|
|
19
|
+
loading: false,
|
|
20
|
+
itemHeight: 44,
|
|
21
|
+
cancelText: "取消",
|
|
22
|
+
confirmText: "确认",
|
|
23
|
+
cancelColor: "#909193",
|
|
24
|
+
confirmColor: "#3c9cff",
|
|
25
|
+
visibleItemCount: 5,
|
|
26
|
+
closeOnClickOverlay: false,
|
|
27
|
+
defaultIndex: [],
|
|
28
|
+
disabled: false,
|
|
29
|
+
hasInput: false,
|
|
30
|
+
format: "",
|
|
31
|
+
placeholder: "请选择日期",
|
|
32
|
+
disabledColor: "#F5F5F5",
|
|
33
|
+
toolbarRightSlot: false
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export default defaultProps;
|