@farm-investimentos/front-mfe-components 15.3.1 → 15.3.3
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/dist/front-mfe-components.common.js +216 -112
- package/dist/front-mfe-components.common.js.map +1 -1
- package/dist/front-mfe-components.css +1 -1
- package/dist/front-mfe-components.umd.js +216 -112
- package/dist/front-mfe-components.umd.js.map +1 -1
- package/dist/front-mfe-components.umd.min.js +1 -1
- package/dist/front-mfe-components.umd.min.js.map +1 -1
- package/package.json +1 -1
- package/src/components/DatePicker/DatePicker.vue +23 -23
- package/src/helpers/date.js +72 -0
package/package.json
CHANGED
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
:readonly="readonly"
|
|
45
45
|
:mask="`${readonly ? '' : '##/##/####'}`"
|
|
46
46
|
:id="inputId"
|
|
47
|
-
:rules="[checkMax, checkMin, checkRequire]"
|
|
47
|
+
:rules="[checkDateValid, checkMax, checkMin, checkRequire]"
|
|
48
48
|
@keyup="keyUpInput"
|
|
49
49
|
/>
|
|
50
50
|
</template>
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
<script lang="ts">
|
|
54
54
|
import { defineComponent } from 'vue';
|
|
55
55
|
import { VDatePicker } from 'vuetify/lib/components/VDatePicker';
|
|
56
|
-
import { defaultFormat as dateDefaultFormatter, convertDate } from '../../helpers/date';
|
|
56
|
+
import { defaultFormat as dateDefaultFormatter, convertDate, checkDateValid } from '../../helpers/date';
|
|
57
57
|
import { formatDatePickerHeader } from '../../helpers';
|
|
58
58
|
/**
|
|
59
59
|
* Componente de input com datepicker para data
|
|
@@ -110,37 +110,37 @@ export default defineComponent({
|
|
|
110
110
|
menuField: false,
|
|
111
111
|
dateField: this.value,
|
|
112
112
|
fieldRange: s,
|
|
113
|
+
checkDateValid: value => {
|
|
114
|
+
if(value.length > 0) {
|
|
115
|
+
const isValid = checkDateValid(value);
|
|
116
|
+
return isValid ? true : 'Data inválida';
|
|
117
|
+
}
|
|
118
|
+
return true;
|
|
119
|
+
},
|
|
113
120
|
checkRequire: value => {
|
|
114
121
|
return this.required ? !!value || value != '' || 'Campo obrigatório' : true;
|
|
115
122
|
},
|
|
116
123
|
checkMax: value => {
|
|
124
|
+
if(!this.required && value.length === 0) {
|
|
125
|
+
return true;
|
|
126
|
+
}
|
|
117
127
|
return this.max && new Date(convertDate(value)) > new Date(this.max)
|
|
118
128
|
? 'A data está fora do período permitido'
|
|
119
129
|
: true;
|
|
120
130
|
},
|
|
121
131
|
checkMin: value => {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
'pt-BR',
|
|
131
|
-
{
|
|
132
|
-
timeZone: 'America/Sao_Paulo',
|
|
132
|
+
if(!this.required && value.length === 0) {
|
|
133
|
+
return true;
|
|
134
|
+
}
|
|
135
|
+
if(this.min) {
|
|
136
|
+
const dateSelected = new Date(convertDate(value));
|
|
137
|
+
const dateMin = new Date(convertDate(this.min));
|
|
138
|
+
if(dateSelected.getTime() >= dateMin.getTime()){
|
|
139
|
+
return true;
|
|
133
140
|
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
return this.min &&
|
|
140
|
-
this.getUniversalDate(locatedSelectedDate) <
|
|
141
|
-
this.getUniversalDate(locatedMinDate)
|
|
142
|
-
? 'A data está fora do período permitido'
|
|
143
|
-
: true;
|
|
141
|
+
return 'A data está fora do período permitido';
|
|
142
|
+
}
|
|
143
|
+
return true;
|
|
144
144
|
},
|
|
145
145
|
};
|
|
146
146
|
},
|
package/src/helpers/date.js
CHANGED
|
@@ -12,3 +12,75 @@ export const convertDate = (data) => {
|
|
|
12
12
|
let newdate = data.split("/").reverse().join("-");
|
|
13
13
|
return newdate;
|
|
14
14
|
};
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
const checkLength = (value, length) => {
|
|
18
|
+
return parseInt(value.length, 10) === length;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const dateFormatting = (date) => {
|
|
22
|
+
if(date.includes('/')){
|
|
23
|
+
let dateSplit = date.split('/');
|
|
24
|
+
return {
|
|
25
|
+
day: dateSplit[0],
|
|
26
|
+
month: dateSplit[1],
|
|
27
|
+
year: dateSplit[2]
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
let dateSplit = date.split('-');
|
|
31
|
+
return {
|
|
32
|
+
day: dateSplit[2],
|
|
33
|
+
month: dateSplit[1],
|
|
34
|
+
year: dateSplit[0]
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const checkLeapYear = (year) => {
|
|
39
|
+
if (parseInt(year, 10) % 400 === 0){
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
if(parseInt(year, 10) % 4 === 0 && parseInt(year, 10) % 100 !== 0) {
|
|
43
|
+
return true;
|
|
44
|
+
}else{
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const getTotalDays = (month, isLeapYear) => {
|
|
50
|
+
const numberMonth = parseInt(month, 10);
|
|
51
|
+
if(numberMonth === 2) {
|
|
52
|
+
return isLeapYear ? 29 : 28;
|
|
53
|
+
}
|
|
54
|
+
const monthsWith31Days = [1, 3, 5, 7, 8, 10, 12];
|
|
55
|
+
return monthsWith31Days.includes(numberMonth) ? 31 : 30;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const checkDay = (day, totalDays) => {
|
|
59
|
+
if(parseInt(day, 10) > 0 && parseInt(day, 10) <= totalDays) {
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
return false;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const checkMonth = (month) => {
|
|
66
|
+
if(parseInt(month, 10) > 0 && parseInt(month, 10) <= 12) {
|
|
67
|
+
return true;
|
|
68
|
+
}
|
|
69
|
+
return false;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export const checkDateValid = (date) => {
|
|
73
|
+
if(!checkLength(date, 10)){
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
const {day, month, year} = dateFormatting(date);
|
|
77
|
+
if(!checkMonth(month)){
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
const isLeapYear = checkLeapYear(year);
|
|
81
|
+
const totalDays = getTotalDays(month, isLeapYear);
|
|
82
|
+
if(!checkDay(day, totalDays)){
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
return true;
|
|
86
|
+
};
|