@neatui/vue 2.17.2 → 2.17.5
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/package.json +1 -1
- package/src/components/basic/IFollowView.vue +124 -41
- package/src/components/basic/IScrollView.vue +115 -110
- package/src/components/form/Checkbox.vue +61 -46
- package/src/components/form/CheckboxGroup.vue +74 -0
- package/src/components/form/CheckboxItem.vue +87 -0
- package/src/components/form/DateView@v3.vue +38 -19
- package/src/components/form/Input@v3.vue +34 -34
- package/src/components/form/InputNumber.vue +46 -25
- package/src/components/form/TextArea.vue +227 -147
- package/src/components/form/index.ts +5 -3
- package/src/components/loader/FormLoader/FormLoader.vue +422 -0
- package/src/components/form/DateRangePicker@v2.vue.backup +0 -224
- package/src/components/form/Input.vue.backup +0 -230
- package/src/components/form/MoreSelect.vue.backup +0 -144
- package/src/components/form/SearchSelect.vue.backup +0 -194
- package/src/components/form/Textarea@v2.vue +0 -275
- package/src/components/form/date.ts +0 -321
- package/src/components/loader/FormLoader/FormLoader@v3.vue.backup +0 -399
- package/src/components/loader/FormLoader/FormRender@v3.vue.backup +0 -4
|
@@ -1,275 +0,0 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<div
|
|
3
|
-
:ui-form="`${theme} sz:${sz} ${state.error.co} type:textarea ${block ? ' :block' : ''} ${disabled ? 'disabled' : ''} ${readonly ? 'readonly' : ''}`"
|
|
4
|
-
@click="emits('click', $event)"
|
|
5
|
-
>
|
|
6
|
-
<div :ui-form-tips="state.error.ontips">{{ state.error.tips }}</div>
|
|
7
|
-
<div ui-form-prefix="">
|
|
8
|
-
<template v-for="(item, idx) in prefix" :key="idx">
|
|
9
|
-
<div v-if="isObject(item)" v-bind="item.attrs" v-on="event(item, props.modelValue)">
|
|
10
|
-
<div v-html="isFunction(item.value) ? item.value(props.modelValue) : item.value"></div>
|
|
11
|
-
</div>
|
|
12
|
-
<div v-else v-html="isFunction(item) ? item(props.modelValue) : item"></div>
|
|
13
|
-
</template>
|
|
14
|
-
<slot name="prefix"></slot>
|
|
15
|
-
</div>
|
|
16
|
-
<slot>
|
|
17
|
-
<textarea
|
|
18
|
-
ref="el"
|
|
19
|
-
:title="props.modelValue"
|
|
20
|
-
:value="props.modelValue"
|
|
21
|
-
:placeholder="placeholder"
|
|
22
|
-
:disabled="disabled"
|
|
23
|
-
:readonly="readonly"
|
|
24
|
-
:rows="rows"
|
|
25
|
-
ui-scroll=":y"
|
|
26
|
-
dir="auto"
|
|
27
|
-
@focus="emits('focus', $event, state)"
|
|
28
|
-
@input="input($event)"
|
|
29
|
-
@change="emits('change', $event, state)"
|
|
30
|
-
@blur="blur($event)"
|
|
31
|
-
></textarea>
|
|
32
|
-
</slot>
|
|
33
|
-
<div ui-form-suffix="">
|
|
34
|
-
<i ui-form-clean="" v-if="clearable && props.modelValue && !readonly && !disabled" @click.stop="clear"></i>
|
|
35
|
-
<slot name="suffix"></slot>
|
|
36
|
-
<template v-for="(item, idx) in suffix" :key="idx">
|
|
37
|
-
<div v-if="isObject(item)" v-bind="item.attrs" v-on="event(item, props.modelValue)">
|
|
38
|
-
<div v-html="isFunction(item.value) ? item.value(props.modelValue) : item.value"></div>
|
|
39
|
-
</div>
|
|
40
|
-
<div v-else v-html="isFunction(item) ? item(props.modelValue) : item"></div>
|
|
41
|
-
</template>
|
|
42
|
-
</div>
|
|
43
|
-
<i v-if="verify && state.interacted" :ui-form-verify="state.error.verify"></i>
|
|
44
|
-
</div>
|
|
45
|
-
</template>
|
|
46
|
-
|
|
47
|
-
<script setup lang="ts">
|
|
48
|
-
import { reactive, watch, ref, nextTick, onMounted } from 'vue';
|
|
49
|
-
import { isObject, isFunction } from '@fekit/utils';
|
|
50
|
-
|
|
51
|
-
const emits = defineEmits(['update:modelValue', 'click', 'blur', 'focus', 'change', 'input', 'clear']);
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* 入参说明
|
|
55
|
-
*
|
|
56
|
-
* modelValue 值
|
|
57
|
-
* theme 主题
|
|
58
|
-
* sz 尺寸
|
|
59
|
-
* co 颜色
|
|
60
|
-
* block 撑满
|
|
61
|
-
* ready 准备就绪
|
|
62
|
-
* tips 提示文案
|
|
63
|
-
* placeholder 内容占位
|
|
64
|
-
* maxlength 最大长度
|
|
65
|
-
* minlength 最小长度
|
|
66
|
-
* disabled 是否禁用
|
|
67
|
-
* readonly 是否只读
|
|
68
|
-
* clearable 是否显示清除按钮
|
|
69
|
-
* rules 校验规则
|
|
70
|
-
* verify 是否是示校验图标 2=tips 3=text 4=icon 5=tips+text 6=text+icon 7=text+icon
|
|
71
|
-
* prefix 前缀内容
|
|
72
|
-
* suffix 后缀内容
|
|
73
|
-
* interacted 用户是否交互
|
|
74
|
-
* autoHeight 是否自动调整高度
|
|
75
|
-
* rows 初始行数
|
|
76
|
-
*/
|
|
77
|
-
|
|
78
|
-
// 类型
|
|
79
|
-
interface Props {
|
|
80
|
-
modelValue?: string | number;
|
|
81
|
-
placeholder?: string;
|
|
82
|
-
rules?: Array<object>;
|
|
83
|
-
theme?: string;
|
|
84
|
-
sz?: '' | 'xs' | 's' | 'm' | 'l' | 'xl';
|
|
85
|
-
co?: string;
|
|
86
|
-
block?: boolean;
|
|
87
|
-
ready?: boolean;
|
|
88
|
-
tips?: string;
|
|
89
|
-
maxlength?: null | number;
|
|
90
|
-
minlength?: null | number;
|
|
91
|
-
disabled?: boolean;
|
|
92
|
-
readonly?: boolean;
|
|
93
|
-
clearable?: boolean;
|
|
94
|
-
verify?: boolean;
|
|
95
|
-
prefix?: Array<any>;
|
|
96
|
-
suffix?: Array<any>;
|
|
97
|
-
interacted?: boolean;
|
|
98
|
-
autoHeight?: boolean;
|
|
99
|
-
rows?: number;
|
|
100
|
-
}
|
|
101
|
-
const props: any = withDefaults(defineProps<Props>(), {
|
|
102
|
-
modelValue: '',
|
|
103
|
-
placeholder: '',
|
|
104
|
-
rules: () => [],
|
|
105
|
-
theme: '@a',
|
|
106
|
-
sz: '',
|
|
107
|
-
co: '',
|
|
108
|
-
block: true,
|
|
109
|
-
ready: false,
|
|
110
|
-
tips: '',
|
|
111
|
-
maxlength: null,
|
|
112
|
-
minlength: null,
|
|
113
|
-
disabled: false,
|
|
114
|
-
readonly: false,
|
|
115
|
-
clearable: true,
|
|
116
|
-
verify: false,
|
|
117
|
-
prefix: () => [],
|
|
118
|
-
suffix: () => [],
|
|
119
|
-
interacted: false,
|
|
120
|
-
// textarea 特有属性默认值
|
|
121
|
-
autoHeight: false,
|
|
122
|
-
rows: 3,
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
const state: any = reactive({
|
|
126
|
-
// 用户是否交互
|
|
127
|
-
interacted: false,
|
|
128
|
-
// 值
|
|
129
|
-
value: props.modelValue,
|
|
130
|
-
// 错误
|
|
131
|
-
error: {},
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
// textarea 元素引用
|
|
135
|
-
const el: any = ref(null);
|
|
136
|
-
|
|
137
|
-
// 自动高度功能
|
|
138
|
-
const fAutoHeight = () => {
|
|
139
|
-
nextTick(() => {
|
|
140
|
-
if (props.autoHeight && el.value) {
|
|
141
|
-
el.value.style.height = 'auto';
|
|
142
|
-
el.value.style.height = el.value.scrollHeight + 1 + 'px';
|
|
143
|
-
}
|
|
144
|
-
});
|
|
145
|
-
};
|
|
146
|
-
|
|
147
|
-
// 外部传入交互标识,主要用于外部没有输入但点击了提交
|
|
148
|
-
watch(
|
|
149
|
-
() => props.interacted,
|
|
150
|
-
(interacted: any) => {
|
|
151
|
-
if (interacted) {
|
|
152
|
-
state.interacted = interacted;
|
|
153
|
-
}
|
|
154
|
-
},
|
|
155
|
-
{ deep: true, immediate: true },
|
|
156
|
-
);
|
|
157
|
-
|
|
158
|
-
// 校验
|
|
159
|
-
watch(
|
|
160
|
-
[() => state.interacted, () => props.modelValue],
|
|
161
|
-
async () => {
|
|
162
|
-
if (state.interacted) {
|
|
163
|
-
// 提示文案
|
|
164
|
-
let tips = '';
|
|
165
|
-
// 错误类型
|
|
166
|
-
let type = '';
|
|
167
|
-
// 验证结果
|
|
168
|
-
let verify = '';
|
|
169
|
-
|
|
170
|
-
if (props.modelValue) {
|
|
171
|
-
// 有值
|
|
172
|
-
let hasError = false;
|
|
173
|
-
// 遍历校验规则
|
|
174
|
-
for (const rule of props.rules) {
|
|
175
|
-
if (rule && rule.validator) {
|
|
176
|
-
const yes = !(await rule.validator(props.modelValue));
|
|
177
|
-
if (yes) {
|
|
178
|
-
tips = rule.msg;
|
|
179
|
-
type = rule.type;
|
|
180
|
-
hasError = true;
|
|
181
|
-
break;
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
verify = hasError ? 'no' : 'ok';
|
|
186
|
-
} else {
|
|
187
|
-
// 无值
|
|
188
|
-
let hasError = false;
|
|
189
|
-
// 遍历校验规则
|
|
190
|
-
for (const rule of props.rules) {
|
|
191
|
-
if (rule) {
|
|
192
|
-
tips = rule.msg;
|
|
193
|
-
type = rule.type;
|
|
194
|
-
if (rule.required) {
|
|
195
|
-
hasError = true;
|
|
196
|
-
break;
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
verify = hasError ? 'no' : '';
|
|
201
|
-
}
|
|
202
|
-
if (verify !== 'no' && props.tips) {
|
|
203
|
-
tips = props.tips;
|
|
204
|
-
}
|
|
205
|
-
// 是否显示提示
|
|
206
|
-
const ontips = (verify === 'no' && tips) || props.tips ? 'show' : '';
|
|
207
|
-
// 状态颜色
|
|
208
|
-
const co = verify === 'no' ? 'co:' + type : props.co ? 'co:' + props.co : '';
|
|
209
|
-
state.error = { tips, ontips, verify, co };
|
|
210
|
-
} else {
|
|
211
|
-
state.error = { tips: props.tips, ontips: props.tips ? 'show' : '', verify: '', co: '' };
|
|
212
|
-
}
|
|
213
|
-
},
|
|
214
|
-
{ deep: true, immediate: true },
|
|
215
|
-
);
|
|
216
|
-
|
|
217
|
-
// 清空
|
|
218
|
-
function clear() {
|
|
219
|
-
emits('update:modelValue', null);
|
|
220
|
-
emits('clear');
|
|
221
|
-
}
|
|
222
|
-
// 输入
|
|
223
|
-
const input = (e: any) => {
|
|
224
|
-
// 用户交互
|
|
225
|
-
if (!state.interacted) {
|
|
226
|
-
setTimeout(() => {
|
|
227
|
-
state.interacted = true;
|
|
228
|
-
}, 50);
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
// 长度限制
|
|
232
|
-
const value = e?.target?.value || '';
|
|
233
|
-
if (props.maxlength && value.length > props.maxlength) {
|
|
234
|
-
e.target.value = props.modelValue;
|
|
235
|
-
return false;
|
|
236
|
-
}
|
|
237
|
-
// 输入事件
|
|
238
|
-
emits('input', e, state);
|
|
239
|
-
emits('update:modelValue', value || null);
|
|
240
|
-
|
|
241
|
-
// 自动高度
|
|
242
|
-
fAutoHeight();
|
|
243
|
-
};
|
|
244
|
-
// 失焦
|
|
245
|
-
const blur = (e: any) => {
|
|
246
|
-
if (!state.interacted) {
|
|
247
|
-
setTimeout(() => {
|
|
248
|
-
state.interacted = true;
|
|
249
|
-
}, 50);
|
|
250
|
-
}
|
|
251
|
-
emits('blur', e, state);
|
|
252
|
-
};
|
|
253
|
-
|
|
254
|
-
// 事件处理
|
|
255
|
-
const event: any = (item: any, data: any): object => {
|
|
256
|
-
const _event: any = {};
|
|
257
|
-
if (isObject(item.event)) {
|
|
258
|
-
for (const key in item.event) {
|
|
259
|
-
const fun = item.event[key];
|
|
260
|
-
if (isFunction(fun)) {
|
|
261
|
-
_event[key] = (...args: any) => {
|
|
262
|
-
return fun({ data }, ...args);
|
|
263
|
-
};
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
return { ..._event };
|
|
268
|
-
};
|
|
269
|
-
|
|
270
|
-
// 组件挂载后初始化自动高度
|
|
271
|
-
onMounted(() => {
|
|
272
|
-
// 自动高度
|
|
273
|
-
fAutoHeight();
|
|
274
|
-
});
|
|
275
|
-
</script>
|
|
@@ -1,321 +0,0 @@
|
|
|
1
|
-
import { isDate, isDateString, isNumber, isString } from './type';
|
|
2
|
-
import { numfill } from './number';
|
|
3
|
-
|
|
4
|
-
interface UpdateParam {
|
|
5
|
-
y?: number;
|
|
6
|
-
m?: number;
|
|
7
|
-
d?: number;
|
|
8
|
-
h?: number;
|
|
9
|
-
n?: number;
|
|
10
|
-
s?: number;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
interface CalendarParam {
|
|
14
|
-
group?: boolean;
|
|
15
|
-
value?: Array<string>;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export default class IDate {
|
|
19
|
-
source: any = '';
|
|
20
|
-
attr: any;
|
|
21
|
-
lang: any;
|
|
22
|
-
date: any;
|
|
23
|
-
time: any;
|
|
24
|
-
year: any;
|
|
25
|
-
month: any;
|
|
26
|
-
days: number;
|
|
27
|
-
valid: boolean;
|
|
28
|
-
constructor(lang: any = 'zh') {
|
|
29
|
-
this.lang = lang;
|
|
30
|
-
this.days = 0;
|
|
31
|
-
this.valid = false;
|
|
32
|
-
}
|
|
33
|
-
// 生成日期
|
|
34
|
-
create(obj?: any, opts: any = {}) {
|
|
35
|
-
const zone = opts.zone || '';
|
|
36
|
-
|
|
37
|
-
// 统一预处理:如果是字符串就先把-替换成/,解决iOS兼容性
|
|
38
|
-
if (isString(obj)) {
|
|
39
|
-
obj = obj.replace(/-/g, '/');
|
|
40
|
-
|
|
41
|
-
// 明确格式处理
|
|
42
|
-
if (opts.format) {
|
|
43
|
-
const [a1, a2, a3] = obj.split(/[-/]/).map((i: any) => i.length);
|
|
44
|
-
const [b1, b2, b3] = opts.format?.split(/[-/]/).map((i: any) => i.length);
|
|
45
|
-
if (a1 === b1 && a2 === b2 && a3 === b3) {
|
|
46
|
-
obj = `${a1 || '01'}/${a2 || '01'}/${a3 || '01'}`;
|
|
47
|
-
} else {
|
|
48
|
-
console.warn(`${obj} is not a valid date`);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
// 不合法日期是否应该抛出错误?
|
|
54
|
-
if (!isDate(obj) && !isDateString(obj)) {
|
|
55
|
-
console.log(53, obj);
|
|
56
|
-
console.warn(`${obj} is not a valid date`);
|
|
57
|
-
} else {
|
|
58
|
-
this.valid = true;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
function utc(obj: any) {
|
|
62
|
-
if (!isString(obj)) {
|
|
63
|
-
return new Date();
|
|
64
|
-
}
|
|
65
|
-
const parts = obj.split(/[-/]/).map(Number);
|
|
66
|
-
const [year, month, day] = parts;
|
|
67
|
-
return new Date(Date.UTC(year, month - 1, day));
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
// 如果是10位时间戳
|
|
71
|
-
if (isNumber(obj)) {
|
|
72
|
-
const _len = obj?.toString()?.length;
|
|
73
|
-
if (_len === 10) {
|
|
74
|
-
obj = obj * 1000;
|
|
75
|
-
} else if (_len === 11) {
|
|
76
|
-
obj = obj * 100;
|
|
77
|
-
} else if (_len === 12) {
|
|
78
|
-
obj = obj * 10;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
// 判断是否有入参
|
|
82
|
-
if (obj === undefined) {
|
|
83
|
-
obj = new Date();
|
|
84
|
-
}
|
|
85
|
-
// 判断是否是日期
|
|
86
|
-
if (obj) {
|
|
87
|
-
this.source = obj;
|
|
88
|
-
const date = isDate(obj) ? obj : isDateString(obj) ? (isString(obj) ? (zone === 'utc' ? utc(obj) : new Date(obj)) : new Date(obj)) : new Date();
|
|
89
|
-
|
|
90
|
-
this.date = date;
|
|
91
|
-
const cnWeek = ['日', '一', '二', '三', '四', '五', '六'];
|
|
92
|
-
this.time = date.getTime();
|
|
93
|
-
|
|
94
|
-
this.attr = {
|
|
95
|
-
time: date.getTime(),
|
|
96
|
-
year: date.getFullYear(),
|
|
97
|
-
YYYY: date.getFullYear(),
|
|
98
|
-
yyyy: date.getFullYear(),
|
|
99
|
-
YY: `${date.getFullYear()}`.slice(-2),
|
|
100
|
-
yy: `${date.getFullYear()}`.slice(-2),
|
|
101
|
-
Y: date.getFullYear(),
|
|
102
|
-
y: date.getFullYear(),
|
|
103
|
-
month: date.getMonth() + 1,
|
|
104
|
-
MM: numfill(date.getMonth() + 1),
|
|
105
|
-
M: date.getMonth() + 1,
|
|
106
|
-
DD: numfill(date.getDate()),
|
|
107
|
-
dd: numfill(date.getDate()),
|
|
108
|
-
D: date.getDate(),
|
|
109
|
-
date: date.getDate(),
|
|
110
|
-
d: date.getDate(),
|
|
111
|
-
H: date.getHours(),
|
|
112
|
-
h: date.getHours() > 12 ? date.getHours() - 12 : date.getHours(),
|
|
113
|
-
HH: numfill(date.getHours()),
|
|
114
|
-
hh: numfill(date.getHours()),
|
|
115
|
-
mm: numfill(date.getMinutes()),
|
|
116
|
-
m: date.getMinutes(),
|
|
117
|
-
ss: numfill(date.getSeconds()),
|
|
118
|
-
s: date.getSeconds(),
|
|
119
|
-
w: date.getDay(),
|
|
120
|
-
W: cnWeek[date.getDay()],
|
|
121
|
-
};
|
|
122
|
-
// 本月天数
|
|
123
|
-
this.days = new Date(this.attr.y, this.attr.M, 0).getDate();
|
|
124
|
-
}
|
|
125
|
-
return this;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
// 日期格式
|
|
129
|
-
format(format = 'YYYY-MM-DD') {
|
|
130
|
-
if (this.date) {
|
|
131
|
-
return format.replace(/(YYYY|yyyy|YY|yy|MM|M|DD|dd|D|d|HH|hh|H|h|mm|m|ss|s|w)/g, (_: any, key: any) => this.attr[key]);
|
|
132
|
-
} else {
|
|
133
|
-
return this.source;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
// 时间更新
|
|
138
|
-
update(obj: UpdateParam) {
|
|
139
|
-
if (this.date) {
|
|
140
|
-
const { y = 0, m = 0, d = 0, h = 0, n = 0, s = 0 }: any = obj || {};
|
|
141
|
-
if (y) {
|
|
142
|
-
this.date.setFullYear(this.date.getFullYear() + y);
|
|
143
|
-
}
|
|
144
|
-
if (m) {
|
|
145
|
-
this.date.setMonth(this.date.getMonth() + m);
|
|
146
|
-
}
|
|
147
|
-
if (d) {
|
|
148
|
-
this.date.setDate(this.date.getDate() + d);
|
|
149
|
-
}
|
|
150
|
-
if (h) {
|
|
151
|
-
this.date.setHours(this.date.getHours() + h);
|
|
152
|
-
}
|
|
153
|
-
if (n) {
|
|
154
|
-
this.date.setMinutes(this.date.getMinutes() + n);
|
|
155
|
-
}
|
|
156
|
-
if (s) {
|
|
157
|
-
this.date.setSeconds(this.date.getSeconds() + s);
|
|
158
|
-
}
|
|
159
|
-
this.create(this.date);
|
|
160
|
-
}
|
|
161
|
-
return this;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
// 人性化
|
|
165
|
-
humanized(words: any = {}) {
|
|
166
|
-
if (this.date) {
|
|
167
|
-
const now = new Date();
|
|
168
|
-
const diff = now.getTime() - this.date.getTime();
|
|
169
|
-
const minute = 60 * 1000;
|
|
170
|
-
const hour = 60 * minute;
|
|
171
|
-
const day = 24 * hour;
|
|
172
|
-
const week = 7 * day;
|
|
173
|
-
const month = 30 * day;
|
|
174
|
-
const year = 365 * day;
|
|
175
|
-
|
|
176
|
-
const {
|
|
177
|
-
NOW = 'Just now',
|
|
178
|
-
MIN = ' minute ago',
|
|
179
|
-
HRS = ' hour ago',
|
|
180
|
-
DAY = ' day ago',
|
|
181
|
-
WKS = ' week ago',
|
|
182
|
-
MON = ' month ago',
|
|
183
|
-
YRS = ' year ago',
|
|
184
|
-
MINS = ' minutes ago',
|
|
185
|
-
HRSS = ' hours ago',
|
|
186
|
-
DAYS = ' days ago',
|
|
187
|
-
WKSS = ' weeks ago',
|
|
188
|
-
MONS = ' months ago',
|
|
189
|
-
YRSS = ' years ago',
|
|
190
|
-
}: any = words || {};
|
|
191
|
-
|
|
192
|
-
if (diff < minute) {
|
|
193
|
-
return NOW;
|
|
194
|
-
} else if (diff < hour) {
|
|
195
|
-
const minutes = Math.floor(diff / minute);
|
|
196
|
-
return `${minutes}${minutes > 1 ? MINS : MIN}`;
|
|
197
|
-
} else if (diff < day) {
|
|
198
|
-
const hours = Math.floor(diff / hour);
|
|
199
|
-
return `${hours}${hours > 1 ? HRSS : HRS}`;
|
|
200
|
-
} else if (diff < week) {
|
|
201
|
-
const days = Math.floor(diff / day);
|
|
202
|
-
return `${days}${days > 1 ? DAYS : DAY}`;
|
|
203
|
-
} else if (diff < month) {
|
|
204
|
-
const weeks = Math.floor(diff / week);
|
|
205
|
-
return `${weeks}${weeks > 1 ? WKSS : WKS}`;
|
|
206
|
-
} else if (diff < year) {
|
|
207
|
-
const months = Math.floor(diff / month);
|
|
208
|
-
return `${months}${months > 1 ? MONS : MON}`;
|
|
209
|
-
} else {
|
|
210
|
-
const years = Math.floor(diff / year);
|
|
211
|
-
return `${years}${years > 1 ? YRSS : YRS}`;
|
|
212
|
-
}
|
|
213
|
-
} else {
|
|
214
|
-
return this.source;
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
// 日历
|
|
219
|
-
calendar(param: CalendarParam = {}) {
|
|
220
|
-
if (!this.date) {
|
|
221
|
-
this.create(new Date());
|
|
222
|
-
}
|
|
223
|
-
const { group = false, value = [] }: any = param;
|
|
224
|
-
const values: any = value
|
|
225
|
-
.filter((day: any) => {
|
|
226
|
-
return day && isDateString(day);
|
|
227
|
-
})
|
|
228
|
-
.sort((a: any, b: any) => {
|
|
229
|
-
return idate(a).time - idate(b).time;
|
|
230
|
-
})
|
|
231
|
-
.map((day: any) => idate(day).format('YYYY-MM-DD'));
|
|
232
|
-
|
|
233
|
-
// 年
|
|
234
|
-
const y: any = this.date?.getFullYear();
|
|
235
|
-
// 月
|
|
236
|
-
const m: any = this.date?.getMonth() + 1;
|
|
237
|
-
// 本月第一天星期几
|
|
238
|
-
const w = new Date(y, m - 1, 1).getDay();
|
|
239
|
-
// 当前月份一共几天
|
|
240
|
-
const days = new Date(y, m, 0).getDate();
|
|
241
|
-
|
|
242
|
-
// 当前
|
|
243
|
-
const curr = new Date();
|
|
244
|
-
const curr_y = curr.getFullYear();
|
|
245
|
-
const curr_m = curr.getMonth() + 1;
|
|
246
|
-
const curr_d = curr.getDate();
|
|
247
|
-
|
|
248
|
-
// 上月
|
|
249
|
-
const last = new Date(y, m - 1, 0);
|
|
250
|
-
const last_y = last.getFullYear();
|
|
251
|
-
const last_m = last.getMonth() + 1;
|
|
252
|
-
let prevdays = last.getDate();
|
|
253
|
-
|
|
254
|
-
// 下月
|
|
255
|
-
const next = new Date(y, m + 1, 0);
|
|
256
|
-
const next_y = next.getFullYear();
|
|
257
|
-
const next_m = next.getMonth() + 1;
|
|
258
|
-
const _calendar: any = [];
|
|
259
|
-
|
|
260
|
-
// 上月的日期
|
|
261
|
-
for (let i = 0; i < w; i++) {
|
|
262
|
-
_calendar.unshift({
|
|
263
|
-
date: `${last_y}-${numfill(last_m)}-${numfill(prevdays)}`,
|
|
264
|
-
day: prevdays,
|
|
265
|
-
isLastMonth: true,
|
|
266
|
-
});
|
|
267
|
-
prevdays = prevdays - 1;
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
// 本月的日期
|
|
271
|
-
for (let d = 1; d <= days; d++) {
|
|
272
|
-
_calendar.push({
|
|
273
|
-
date: `${y}-${numfill(m)}-${numfill(d)}`,
|
|
274
|
-
day: d,
|
|
275
|
-
today: curr_y === y && curr_m === m && curr_d === d,
|
|
276
|
-
isCurrMonth: true,
|
|
277
|
-
});
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
// 下月的日期
|
|
281
|
-
for (let i = 1; _calendar.length < 42; i++) {
|
|
282
|
-
const _i = i;
|
|
283
|
-
_calendar.push({
|
|
284
|
-
date: `${next_y}-${numfill(next_m)}-${numfill(_i)}`,
|
|
285
|
-
day: _i,
|
|
286
|
-
isNextMonth: true,
|
|
287
|
-
});
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
let calendar = _calendar.map((item: any) => {
|
|
291
|
-
const _idx = values.indexOf(idate(item.date).format('YYYY-MM-DD'));
|
|
292
|
-
// 判断是否在选
|
|
293
|
-
if (_idx !== -1) {
|
|
294
|
-
if (item.isCurrMonth) {
|
|
295
|
-
item.selected = true;
|
|
296
|
-
}
|
|
297
|
-
if (_idx === 0) {
|
|
298
|
-
item.sta = true;
|
|
299
|
-
}
|
|
300
|
-
if (_idx === values.length - 1) {
|
|
301
|
-
item.end = true;
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
// 判断是否在范围内
|
|
305
|
-
if (values.length > 1) {
|
|
306
|
-
if (item.isCurrMonth && idate(item.date).time >= idate(values[0]).time && idate(item.date).time <= idate(values[values.length - 1]).time) {
|
|
307
|
-
item.range = true;
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
return item;
|
|
311
|
-
});
|
|
312
|
-
// 是否按周分组
|
|
313
|
-
if (group) {
|
|
314
|
-
calendar = Array.from({ length: Math.ceil(_calendar.length / 7) }, (_v, index) => _calendar.slice(index * 7, index * 7 + 7));
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
return calendar;
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
export const idate = (obj?: any) => new IDate().create(obj);
|