nuxt-hs-ui 2.0.5 → 2.0.7
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/module.json +1 -1
- package/dist/runtime/components/form/datepicker.vue +1 -1
- package/dist/runtime/composables/use-hs-multi-lang.d.ts +8 -0
- package/dist/runtime/composables/use-hs-multi-lang.js +4 -1
- package/dist/runtime/utils/dayjs.d.ts +1 -1
- package/dist/runtime/utils/dayjs.js +1 -1
- package/package.json +1 -1
- package/dist/runtime/components/form/datepicker copy.vue +0 -770
package/dist/module.json
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
----------------------------------------------------------------------------- */
|
|
8
8
|
|
|
9
9
|
// [ node-modules ]
|
|
10
|
-
import dayjs from "dayjs";
|
|
10
|
+
import dayjs from "dayjs/esm/index";
|
|
11
11
|
import flatpickr from "flatpickr";
|
|
12
12
|
import monthSelectPlugin from "flatpickr/dist/plugins/monthSelect";
|
|
13
13
|
import { Japanese as ja } from "flatpickr/dist/l10n/ja";
|
|
@@ -16,6 +16,14 @@ export declare const useHsMultiLang: import("pinia").StoreDefinition<"HsMultiLan
|
|
|
16
16
|
isInit: boolean;
|
|
17
17
|
};
|
|
18
18
|
} & import("pinia").PiniaCustomStateProperties<StoreState>): string;
|
|
19
|
+
dateFormat(state: {
|
|
20
|
+
state: {
|
|
21
|
+
lang: string;
|
|
22
|
+
fallBack: string;
|
|
23
|
+
dateFormat: string;
|
|
24
|
+
isInit: boolean;
|
|
25
|
+
};
|
|
26
|
+
} & import("pinia").PiniaCustomStateProperties<StoreState>): string;
|
|
19
27
|
}, {
|
|
20
28
|
init(arg: {
|
|
21
29
|
lang?: string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import dayjs from "dayjs";
|
|
1
|
+
import dayjs from "dayjs/esm/index";
|
|
2
2
|
import ja from "dayjs/locale/ja.js";
|
|
3
3
|
import en from "dayjs/locale/en.js";
|
|
4
4
|
import { defineStore } from "pinia";
|
|
@@ -18,6 +18,9 @@ export const useHsMultiLang = defineStore("HsMultiLang", {
|
|
|
18
18
|
getters: {
|
|
19
19
|
lang(state) {
|
|
20
20
|
return state.state.lang;
|
|
21
|
+
},
|
|
22
|
+
dateFormat(state) {
|
|
23
|
+
return state.state.dateFormat;
|
|
21
24
|
}
|
|
22
25
|
},
|
|
23
26
|
// ----------------------------------------------------------------------------
|
package/package.json
CHANGED
|
@@ -1,770 +0,0 @@
|
|
|
1
|
-
<script setup lang="ts">
|
|
2
|
-
/* ----------------------------------------------------------------------------
|
|
3
|
-
// src\runtime\components\form\datepicker.vue
|
|
4
|
-
// ----------------------------------------------------------------------------
|
|
5
|
-
// Datepicker
|
|
6
|
-
// DatepickerDatepicker
|
|
7
|
-
----------------------------------------------------------------------------- */
|
|
8
|
-
|
|
9
|
-
// [ node-modules ]
|
|
10
|
-
import dayjs from "dayjs";
|
|
11
|
-
import flatpickr from "flatpickr";
|
|
12
|
-
import monthSelectPlugin from "flatpickr/dist/plugins/monthSelect";
|
|
13
|
-
import { Japanese as ja } from "flatpickr/dist/l10n/ja";
|
|
14
|
-
import { english as en } from "flatpickr/dist/l10n/default";
|
|
15
|
-
// [ vueuse ]
|
|
16
|
-
import { useMounted } from "@vueuse/core";
|
|
17
|
-
// [ NUXT ]
|
|
18
|
-
import {
|
|
19
|
-
reactive,
|
|
20
|
-
ref,
|
|
21
|
-
watch,
|
|
22
|
-
computed,
|
|
23
|
-
useId,
|
|
24
|
-
onMounted,
|
|
25
|
-
nextTick,
|
|
26
|
-
onUnmounted,
|
|
27
|
-
} from "#imports";
|
|
28
|
-
// [ utils ]
|
|
29
|
-
import type { ClassType } from "../../utils/class-style";
|
|
30
|
-
import { GetTimeShiftValue, Dayjs, DayjsInit } from "../../utils/dayjs";
|
|
31
|
-
// [ composables ]
|
|
32
|
-
import { useHsFocus } from "../../composables/use-hs-focus";
|
|
33
|
-
import { useHsToast } from "../../composables/use-hs-toast";
|
|
34
|
-
import { useHsMultiLang } from "../../composables/use-hs-multi-lang";
|
|
35
|
-
// [ Components ]
|
|
36
|
-
import InputFrame from "./input-frame.vue";
|
|
37
|
-
|
|
38
|
-
// ----------------------------------------------------------------------------
|
|
39
|
-
// ----------------------------------------------------------------------------
|
|
40
|
-
DayjsInit();
|
|
41
|
-
const hsFocus = useHsFocus();
|
|
42
|
-
const Toast = useHsToast();
|
|
43
|
-
const multiLang = useHsMultiLang();
|
|
44
|
-
// ----------------------------------------------------------------------------
|
|
45
|
-
// [ vueuse ]
|
|
46
|
-
const isMounted = useMounted();
|
|
47
|
-
// ----------------------------------------------------------------------------
|
|
48
|
-
// flatpickr
|
|
49
|
-
const MonthSelectPlugin: any = monthSelectPlugin;
|
|
50
|
-
const timeDateFormat = "YYYY-MM-DD HH:mm:ss.SSS";
|
|
51
|
-
const timeOutputDateFormat = "HH:mm:ss.SSS";
|
|
52
|
-
const timeShowDateFormat = "HH:mm";
|
|
53
|
-
// ----------------------------------------------------------------------------
|
|
54
|
-
// [ Props ]
|
|
55
|
-
type Props = {
|
|
56
|
-
// ----------------------------------------------------------------------------
|
|
57
|
-
// Input 種類別
|
|
58
|
-
textAlign?: "left" | "center" | "right";
|
|
59
|
-
mode?: "all" | "date" | "time" | "month";
|
|
60
|
-
/** mode=time の場合、[HH:mm:ss.SSS] に固定 */
|
|
61
|
-
dataFormat?: string;
|
|
62
|
-
/** mode=time の場合、[HH:mm] に固定 */
|
|
63
|
-
showFormat?: string;
|
|
64
|
-
minDate?: string | null;
|
|
65
|
-
maxDate?: string | null;
|
|
66
|
-
hideDeleteBtn?: boolean;
|
|
67
|
-
hideTodayBtn?: boolean;
|
|
68
|
-
disableMobile?: boolean;
|
|
69
|
-
hasShift?: boolean;
|
|
70
|
-
// ----------------------------------------------------------------------------
|
|
71
|
-
data: string | null;
|
|
72
|
-
diff?: string | null | undefined;
|
|
73
|
-
tabindex?: string | undefined;
|
|
74
|
-
// ----------------------------------------------------------------------------
|
|
75
|
-
class?: ClassType;
|
|
76
|
-
classHeader?: ClassType;
|
|
77
|
-
classInput?: ClassType;
|
|
78
|
-
// ----------------------------------------------------------------------------
|
|
79
|
-
// 状態
|
|
80
|
-
// focus?: boolean;
|
|
81
|
-
focusColor?: string;
|
|
82
|
-
// change?: boolean;
|
|
83
|
-
changeColor?: string;
|
|
84
|
-
error?: boolean;
|
|
85
|
-
errorColor?: string;
|
|
86
|
-
disabled?: boolean;
|
|
87
|
-
disabledColor?: string;
|
|
88
|
-
readonly?: boolean;
|
|
89
|
-
// ----------------------------------------------------------------------------
|
|
90
|
-
// 表示
|
|
91
|
-
label?: string;
|
|
92
|
-
// 表示-副情報
|
|
93
|
-
require?: boolean;
|
|
94
|
-
requireText?: string;
|
|
95
|
-
warn?: string;
|
|
96
|
-
warnTimeOut?: number;
|
|
97
|
-
// ----------------------------------------------------------------------------
|
|
98
|
-
// 設定
|
|
99
|
-
size?: "s" | "m" | "l";
|
|
100
|
-
// ----------------------------------------------------------------------------
|
|
101
|
-
uiText?: {
|
|
102
|
-
error: {
|
|
103
|
-
inputRangeTitle: string;
|
|
104
|
-
inputRangeMessage: string;
|
|
105
|
-
};
|
|
106
|
-
};
|
|
107
|
-
};
|
|
108
|
-
const props = withDefaults(defineProps<Props>(), {
|
|
109
|
-
// ----------------------------------------------------------------------------
|
|
110
|
-
// Input 種類別
|
|
111
|
-
textAlign: "left",
|
|
112
|
-
mode: "date",
|
|
113
|
-
dataFormat: "",
|
|
114
|
-
showFormat: "",
|
|
115
|
-
minDate: null,
|
|
116
|
-
maxDate: null,
|
|
117
|
-
hideDeleteBtn: false,
|
|
118
|
-
disableMobile: false,
|
|
119
|
-
hasShift: true,
|
|
120
|
-
// ----------------------------------------------------------------------------
|
|
121
|
-
diff: undefined,
|
|
122
|
-
tabindex: undefined,
|
|
123
|
-
// ----------------------------------------------------------------------------
|
|
124
|
-
class: "",
|
|
125
|
-
classHeader: "",
|
|
126
|
-
classInput: "",
|
|
127
|
-
// ----------------------------------------------------------------------------
|
|
128
|
-
// 状態
|
|
129
|
-
// focus: false,
|
|
130
|
-
focusColor: "shadow-[inset_0px_0px_1px_2px_#0d8ee4]",
|
|
131
|
-
// change: false,
|
|
132
|
-
changeColor: "shadow-[inset_0px_0px_1px_2px_#fd9831be]",
|
|
133
|
-
error: false,
|
|
134
|
-
errorColor: "shadow-[inset_0px_0px_1px_2px_#d80000dc]",
|
|
135
|
-
disabled: false,
|
|
136
|
-
disabledColor: "",
|
|
137
|
-
readonly: false,
|
|
138
|
-
// ----------------------------------------------------------------------------
|
|
139
|
-
// 表示
|
|
140
|
-
label: "",
|
|
141
|
-
// 表示-副情報
|
|
142
|
-
require: false,
|
|
143
|
-
requireText: "必須",
|
|
144
|
-
warn: "",
|
|
145
|
-
warnTimeOut: 300,
|
|
146
|
-
// ----------------------------------------------------------------------------
|
|
147
|
-
// 設定
|
|
148
|
-
size: "m",
|
|
149
|
-
// ----------------------------------------------------------------------------
|
|
150
|
-
uiText: () => {
|
|
151
|
-
return {
|
|
152
|
-
error: {
|
|
153
|
-
inputRangeTitle: "入力値エラー",
|
|
154
|
-
inputRangeMessage: "入力範囲外です",
|
|
155
|
-
},
|
|
156
|
-
};
|
|
157
|
-
},
|
|
158
|
-
});
|
|
159
|
-
// [ emit ]
|
|
160
|
-
// ----------------------------------------------------------------------------
|
|
161
|
-
// [ emit ]
|
|
162
|
-
type Emits = {
|
|
163
|
-
ref: [element: HTMLElement];
|
|
164
|
-
focus: [elm: HTMLElement];
|
|
165
|
-
blur: [elm: HTMLElement];
|
|
166
|
-
// ----------------------------
|
|
167
|
-
"update:data": [value: string | null];
|
|
168
|
-
"value-change": [after: string | null, before: string | null];
|
|
169
|
-
// ----------------------------
|
|
170
|
-
"reset-piceker-func": [func: any];
|
|
171
|
-
// ----------------------------
|
|
172
|
-
};
|
|
173
|
-
const emit = defineEmits<Emits>();
|
|
174
|
-
// ----------------------------------------------------------------------------
|
|
175
|
-
// [ getCurrentInstance ]
|
|
176
|
-
const uid = useId();
|
|
177
|
-
|
|
178
|
-
// ----------------------------------------------------------------------------
|
|
179
|
-
// [ reactive ]
|
|
180
|
-
|
|
181
|
-
interface State {
|
|
182
|
-
picker: any;
|
|
183
|
-
// FormControl値
|
|
184
|
-
date: Date | null;
|
|
185
|
-
// text: string;
|
|
186
|
-
option: any;
|
|
187
|
-
}
|
|
188
|
-
const state = reactive<State>({
|
|
189
|
-
// text: '',
|
|
190
|
-
picker: null,
|
|
191
|
-
date: null,
|
|
192
|
-
option: {
|
|
193
|
-
dateFormat: "Z",
|
|
194
|
-
locale: ja,
|
|
195
|
-
time_24hr: true,
|
|
196
|
-
minDate: undefined,
|
|
197
|
-
maxDate: undefined,
|
|
198
|
-
plugins: [],
|
|
199
|
-
},
|
|
200
|
-
});
|
|
201
|
-
// ----------------------------------------------------------------------------
|
|
202
|
-
|
|
203
|
-
onMounted(() => {
|
|
204
|
-
state.option.maxDate =
|
|
205
|
-
dayjs(props.maxDate).isValid() === true
|
|
206
|
-
? dayjs(props.maxDate).toISOString()
|
|
207
|
-
: undefined;
|
|
208
|
-
state.option.minDate =
|
|
209
|
-
dayjs(props.minDate).isValid() === true
|
|
210
|
-
? dayjs(props.minDate).toISOString()
|
|
211
|
-
: undefined;
|
|
212
|
-
});
|
|
213
|
-
const shiftM = GetTimeShiftValue(Dayjs());
|
|
214
|
-
const getShiftDayjs = (date: any) => {
|
|
215
|
-
if (props.hasShift && shiftM !== 0) {
|
|
216
|
-
return dayjs(date).subtract(shiftM, "minute");
|
|
217
|
-
}
|
|
218
|
-
return dayjs(date);
|
|
219
|
-
};
|
|
220
|
-
|
|
221
|
-
const inputBoxClass = computed(() => {
|
|
222
|
-
if (props.textAlign === "left") {
|
|
223
|
-
return "display-left";
|
|
224
|
-
} else if (props.textAlign === "center") {
|
|
225
|
-
return "display-center";
|
|
226
|
-
} else {
|
|
227
|
-
return "display-right";
|
|
228
|
-
}
|
|
229
|
-
});
|
|
230
|
-
const displayText = computed(() => {
|
|
231
|
-
const lang = multiLang.state.lang;
|
|
232
|
-
dayjs.locale(lang);
|
|
233
|
-
if (props.data === null) {
|
|
234
|
-
return "";
|
|
235
|
-
} else if (props.mode === "time") {
|
|
236
|
-
return getShiftDayjs(dayjs().format("YYYY-MM-DD ") + props.data).format(
|
|
237
|
-
timeShowDateFormat
|
|
238
|
-
);
|
|
239
|
-
} else {
|
|
240
|
-
return getShiftDayjs(props.data).format(props.showFormat);
|
|
241
|
-
}
|
|
242
|
-
});
|
|
243
|
-
|
|
244
|
-
// ----------------------------------------------------------------------------
|
|
245
|
-
watch(
|
|
246
|
-
computed(() => {
|
|
247
|
-
return [props.minDate, props.maxDate, multiLang.state.lang];
|
|
248
|
-
}),
|
|
249
|
-
() => {
|
|
250
|
-
// console.log('computed', props.minDate, props.maxDate, isMounted.value);
|
|
251
|
-
if (!isMounted.value) return;
|
|
252
|
-
setTimeout(() => {
|
|
253
|
-
resetPicekr();
|
|
254
|
-
}, 1);
|
|
255
|
-
}
|
|
256
|
-
);
|
|
257
|
-
|
|
258
|
-
const checkDate = (date: any) => {
|
|
259
|
-
// console.log(props.minDate);
|
|
260
|
-
const d = getShiftDayjs(date);
|
|
261
|
-
if (props.minDate !== "" && d.isBefore(props.minDate)) {
|
|
262
|
-
// console.log('最小日付を下回っています', props.data, props.minDate);
|
|
263
|
-
return false;
|
|
264
|
-
} else if (props.maxDate !== "" && d.isAfter(props.maxDate)) {
|
|
265
|
-
// console.log('最大日付を下回っています', props.data, props.maxDate);
|
|
266
|
-
return false;
|
|
267
|
-
}
|
|
268
|
-
return true;
|
|
269
|
-
};
|
|
270
|
-
|
|
271
|
-
const keyDown = (event: any) => {
|
|
272
|
-
const before = props.data;
|
|
273
|
-
// console.log('keyDown', state.picker);
|
|
274
|
-
if (event.key === "Enter") {
|
|
275
|
-
datePickerToday();
|
|
276
|
-
return;
|
|
277
|
-
}
|
|
278
|
-
if (event.key === "Backspace") {
|
|
279
|
-
iconEventDelete();
|
|
280
|
-
return;
|
|
281
|
-
}
|
|
282
|
-
let move = 0;
|
|
283
|
-
if (event.key === "ArrowLeft" || event.key === "ArrowUp") {
|
|
284
|
-
move--;
|
|
285
|
-
}
|
|
286
|
-
if (event.key === "ArrowRight" || event.key === "ArrowDown") {
|
|
287
|
-
move++;
|
|
288
|
-
}
|
|
289
|
-
if (event.key === "ArrowUp" || event.key === "ArrowDown") {
|
|
290
|
-
// Flatpickerにフォーカスを奪われるキーイベントはフォーカスを取り戻す予約
|
|
291
|
-
setTimeout(() => {
|
|
292
|
-
// console.log('フォーカス戻す');
|
|
293
|
-
if (inputElement.value != null) {
|
|
294
|
-
inputElement.value.focus();
|
|
295
|
-
}
|
|
296
|
-
}, 150);
|
|
297
|
-
}
|
|
298
|
-
if (move !== 0) {
|
|
299
|
-
let m =
|
|
300
|
-
props.data == null ? getShiftDayjs(dayjs()) : getShiftDayjs(props.data);
|
|
301
|
-
if (move < 0) {
|
|
302
|
-
m = m.subtract(1, "d");
|
|
303
|
-
} else {
|
|
304
|
-
m = m.add(1, "d");
|
|
305
|
-
}
|
|
306
|
-
if (props.data !== "") {
|
|
307
|
-
if (checkDate(m) === false) {
|
|
308
|
-
// console.log('行き過ぎ');
|
|
309
|
-
return false;
|
|
310
|
-
}
|
|
311
|
-
} else if (move < 0) {
|
|
312
|
-
m = getShiftDayjs(props.maxDate).subtract(1, "d");
|
|
313
|
-
} else {
|
|
314
|
-
m = getShiftDayjs(props.minDate).add(1, "d");
|
|
315
|
-
}
|
|
316
|
-
emit("update:data", m.format(props.dataFormat));
|
|
317
|
-
nextTick(() => {
|
|
318
|
-
emit("value-change", m.format(props.dataFormat), before);
|
|
319
|
-
});
|
|
320
|
-
return false;
|
|
321
|
-
}
|
|
322
|
-
};
|
|
323
|
-
|
|
324
|
-
// ----------------------------------------------------------------------------
|
|
325
|
-
// [ flatpicker関連 ]
|
|
326
|
-
const initFlatPickerOption = () => {
|
|
327
|
-
if (props.mode === "all" || props.mode === "time") {
|
|
328
|
-
state.option.enableTime = true;
|
|
329
|
-
if (props.mode === "time") {
|
|
330
|
-
state.option.noCalendar = true;
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
if (props.mode === "month") {
|
|
334
|
-
state.option.disableMobile = true;
|
|
335
|
-
}
|
|
336
|
-
if (props.disableMobile) {
|
|
337
|
-
state.option.disableMobile = true;
|
|
338
|
-
}
|
|
339
|
-
if (props.mode === "month") {
|
|
340
|
-
state.option.plugins = [
|
|
341
|
-
new MonthSelectPlugin({
|
|
342
|
-
shorthand: true, // デフォルトはfalse
|
|
343
|
-
dateFormat: "m.y", // デフォルトは"F Y"
|
|
344
|
-
altFormat: "F Y", // デフォルトは"F Y"
|
|
345
|
-
theme: "dark", // デフォルトは"light"
|
|
346
|
-
}),
|
|
347
|
-
];
|
|
348
|
-
}
|
|
349
|
-
};
|
|
350
|
-
|
|
351
|
-
const onOpen = () => {
|
|
352
|
-
focusState.isOpenFlatpickr = true;
|
|
353
|
-
};
|
|
354
|
-
|
|
355
|
-
const onClose = () => {
|
|
356
|
-
focusState.isOpenFlatpickr = false;
|
|
357
|
-
focusState.isClosingFlatpickr = true;
|
|
358
|
-
setTimeout(() => {
|
|
359
|
-
focusState.isClosingFlatpickr = false;
|
|
360
|
-
}, 200);
|
|
361
|
-
};
|
|
362
|
-
|
|
363
|
-
const onChange = (selectedDates: any) => {
|
|
364
|
-
// console.log('onChange');
|
|
365
|
-
let value = null;
|
|
366
|
-
if (selectedDates.length === 0) {
|
|
367
|
-
value = null;
|
|
368
|
-
} else {
|
|
369
|
-
const d = selectedDates[0];
|
|
370
|
-
if (d == null) {
|
|
371
|
-
value = null;
|
|
372
|
-
} else {
|
|
373
|
-
value = d;
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
updateValue(value);
|
|
377
|
-
};
|
|
378
|
-
|
|
379
|
-
const generateFlatPickerOption = () => {
|
|
380
|
-
// console.log('generatePicker', elmInput.value);
|
|
381
|
-
if (inputElement.value != null) {
|
|
382
|
-
dayjs.locale(multiLang.state.lang);
|
|
383
|
-
switch (multiLang.state.lang) {
|
|
384
|
-
case "ja":
|
|
385
|
-
state.option.locale = ja;
|
|
386
|
-
break;
|
|
387
|
-
case "en":
|
|
388
|
-
state.option.locale = en;
|
|
389
|
-
break;
|
|
390
|
-
default:
|
|
391
|
-
state.option.locale = en;
|
|
392
|
-
break;
|
|
393
|
-
}
|
|
394
|
-
state.picker = flatpickr(inputElement.value, state.option);
|
|
395
|
-
state.picker.config.onChange.push(onChange);
|
|
396
|
-
state.picker.config.onOpen.push(onOpen);
|
|
397
|
-
state.picker.config.onClose.push(onClose);
|
|
398
|
-
setValue();
|
|
399
|
-
}
|
|
400
|
-
};
|
|
401
|
-
const flag = ref(false);
|
|
402
|
-
|
|
403
|
-
const resetPicekr = () => {
|
|
404
|
-
if (flag.value) return;
|
|
405
|
-
try {
|
|
406
|
-
flag.value = true;
|
|
407
|
-
state.picker.destroy();
|
|
408
|
-
state.picker = false;
|
|
409
|
-
focusState.isOpenFlatpickr = false;
|
|
410
|
-
dayjs.locale(multiLang.state.lang);
|
|
411
|
-
if (props.minDate !== null) {
|
|
412
|
-
state.option.minDate =
|
|
413
|
-
dayjs(props.minDate).isValid() === true
|
|
414
|
-
? dayjs(props.minDate).toISOString()
|
|
415
|
-
: undefined;
|
|
416
|
-
} else {
|
|
417
|
-
state.option.minDate = null;
|
|
418
|
-
}
|
|
419
|
-
if (props.maxDate !== null) {
|
|
420
|
-
state.option.maxDate =
|
|
421
|
-
dayjs(props.maxDate).isValid() === true
|
|
422
|
-
? dayjs(props.maxDate).toISOString()
|
|
423
|
-
: undefined;
|
|
424
|
-
} else {
|
|
425
|
-
state.option.maxDate = null;
|
|
426
|
-
}
|
|
427
|
-
generateFlatPickerOption();
|
|
428
|
-
} catch (error) {
|
|
429
|
-
console.error("resetPicekr()", error);
|
|
430
|
-
} finally {
|
|
431
|
-
flag.value = false;
|
|
432
|
-
}
|
|
433
|
-
};
|
|
434
|
-
emit("reset-piceker-func", resetPicekr);
|
|
435
|
-
watch(
|
|
436
|
-
() => props.data,
|
|
437
|
-
() => {
|
|
438
|
-
setValue();
|
|
439
|
-
}
|
|
440
|
-
);
|
|
441
|
-
|
|
442
|
-
const setValue = () => {
|
|
443
|
-
// console.log('setValue');
|
|
444
|
-
try {
|
|
445
|
-
if (props.data == null) {
|
|
446
|
-
state.picker.setDate(null);
|
|
447
|
-
state.date = null;
|
|
448
|
-
return;
|
|
449
|
-
}
|
|
450
|
-
const date =
|
|
451
|
-
props.mode === "time"
|
|
452
|
-
? dayjs().format("YYYY-MM-DD ") + props.data
|
|
453
|
-
: props.data;
|
|
454
|
-
const d = getShiftDayjs(date);
|
|
455
|
-
// console.log('setValue', date);
|
|
456
|
-
if (d.isValid() === true) {
|
|
457
|
-
if (checkDate(props.data) === true) {
|
|
458
|
-
state.date = d.toDate();
|
|
459
|
-
state.picker.setDate(state.date);
|
|
460
|
-
return;
|
|
461
|
-
}
|
|
462
|
-
}
|
|
463
|
-
throw new Error("変換失敗");
|
|
464
|
-
} catch (err) {
|
|
465
|
-
console.error(err);
|
|
466
|
-
state.picker.setDate(null);
|
|
467
|
-
state.date = null;
|
|
468
|
-
updateValue(null);
|
|
469
|
-
}
|
|
470
|
-
};
|
|
471
|
-
// アイコン系イベント
|
|
472
|
-
const datePickerToggle = () => {
|
|
473
|
-
if (props.readonly === true) return;
|
|
474
|
-
if (props.disabled === true) return;
|
|
475
|
-
if (state.picker === null) return;
|
|
476
|
-
if (focusState.isClosingFlatpickr) return;
|
|
477
|
-
hsFocus.state.id = uid;
|
|
478
|
-
state.picker.open();
|
|
479
|
-
};
|
|
480
|
-
|
|
481
|
-
const datePickerToday = () => {
|
|
482
|
-
if (props.readonly === true) return;
|
|
483
|
-
if (props.disabled === true) return;
|
|
484
|
-
if (state.date !== null) return;
|
|
485
|
-
let inputValue = dayjs();
|
|
486
|
-
if (props.mode === "month") {
|
|
487
|
-
inputValue = inputValue.startOf("month");
|
|
488
|
-
}
|
|
489
|
-
const d = getShiftDayjs(inputValue);
|
|
490
|
-
if (checkDate(d.format("YYYY-MM-DD")) === false) {
|
|
491
|
-
Toast.Warning(
|
|
492
|
-
props.uiText.error.inputRangeMessage,
|
|
493
|
-
props.uiText.error.inputRangeTitle,
|
|
494
|
-
props.warnTimeOut
|
|
495
|
-
);
|
|
496
|
-
return;
|
|
497
|
-
}
|
|
498
|
-
if (props.mode === "time") {
|
|
499
|
-
updateValue(inputValue.format(timeDateFormat));
|
|
500
|
-
} else {
|
|
501
|
-
updateValue(inputValue.format(props.dataFormat));
|
|
502
|
-
}
|
|
503
|
-
};
|
|
504
|
-
|
|
505
|
-
const updateValue = async (text: string | null) => {
|
|
506
|
-
// console.log('updateValue', text);
|
|
507
|
-
const before = props.data;
|
|
508
|
-
if (text === null || text.length === 0) {
|
|
509
|
-
emit("update:data", null);
|
|
510
|
-
await nextTick();
|
|
511
|
-
emit("value-change", null, before);
|
|
512
|
-
return;
|
|
513
|
-
}
|
|
514
|
-
if (props.mode === "all") {
|
|
515
|
-
emit("update:data", dayjs(text).format(props.dataFormat));
|
|
516
|
-
nextTick(() => {
|
|
517
|
-
emit("value-change", dayjs(text).format(props.dataFormat), before);
|
|
518
|
-
});
|
|
519
|
-
} else if (props.mode === "time") {
|
|
520
|
-
emit("update:data", dayjs(text).format(timeOutputDateFormat));
|
|
521
|
-
nextTick(() => {
|
|
522
|
-
emit("value-change", dayjs(text).format(timeOutputDateFormat), before);
|
|
523
|
-
});
|
|
524
|
-
} else {
|
|
525
|
-
// 時間情報を削除する
|
|
526
|
-
emit(
|
|
527
|
-
"update:data",
|
|
528
|
-
dayjs(dayjs(text).format("YYYY-MM-DD")).format(props.dataFormat)
|
|
529
|
-
);
|
|
530
|
-
nextTick(() => {
|
|
531
|
-
emit(
|
|
532
|
-
"value-change",
|
|
533
|
-
dayjs(dayjs(text).format("YYYY-MM-DD")).format(props.dataFormat),
|
|
534
|
-
before
|
|
535
|
-
);
|
|
536
|
-
});
|
|
537
|
-
}
|
|
538
|
-
};
|
|
539
|
-
|
|
540
|
-
const iconEventDelete = () => {
|
|
541
|
-
const before = props.data;
|
|
542
|
-
if (props.readonly === true) return;
|
|
543
|
-
if (props.disabled === true) return;
|
|
544
|
-
if (state.date != null) {
|
|
545
|
-
emit("update:data", null);
|
|
546
|
-
nextTick(() => {
|
|
547
|
-
emit("value-change", null, before);
|
|
548
|
-
});
|
|
549
|
-
}
|
|
550
|
-
};
|
|
551
|
-
|
|
552
|
-
// [ ref ]
|
|
553
|
-
const inputElement = ref();
|
|
554
|
-
onMounted(() => {
|
|
555
|
-
emit("ref", inputElement.value as HTMLInputElement);
|
|
556
|
-
});
|
|
557
|
-
|
|
558
|
-
const setRef = (elm: any) => {
|
|
559
|
-
inputElement.value = elm;
|
|
560
|
-
emit("ref", elm);
|
|
561
|
-
};
|
|
562
|
-
|
|
563
|
-
// [ focus, blur ]
|
|
564
|
-
|
|
565
|
-
interface FocusState {
|
|
566
|
-
isOpenFlatpickr: boolean;
|
|
567
|
-
isClosingFlatpickr: boolean;
|
|
568
|
-
}
|
|
569
|
-
|
|
570
|
-
const focusState = reactive<FocusState>({
|
|
571
|
-
isOpenFlatpickr: false,
|
|
572
|
-
isClosingFlatpickr: false,
|
|
573
|
-
});
|
|
574
|
-
|
|
575
|
-
/**
|
|
576
|
-
* コントロールのFocus判定
|
|
577
|
-
*/
|
|
578
|
-
const computedActivate = computed(() => {
|
|
579
|
-
if (props.disabled === true) return false;
|
|
580
|
-
if (props.readonly === true) return false;
|
|
581
|
-
if (hsFocus.state.id !== uid) return false;
|
|
582
|
-
if (focusState.isOpenFlatpickr) return true;
|
|
583
|
-
return false;
|
|
584
|
-
});
|
|
585
|
-
|
|
586
|
-
/**
|
|
587
|
-
* focus, blur イベント
|
|
588
|
-
*/
|
|
589
|
-
watch(computedActivate, (value) => {
|
|
590
|
-
if (value === true) {
|
|
591
|
-
// クリックでの遷移の場合に
|
|
592
|
-
// 一つ前のコントロールのblurイベントよりも早くfocusが発生しないようにする対策で10ミリ秒処理をずらす
|
|
593
|
-
setTimeout(() => {
|
|
594
|
-
emit("focus", inputElement.value);
|
|
595
|
-
}, 10);
|
|
596
|
-
} else {
|
|
597
|
-
emit("blur", inputElement.value);
|
|
598
|
-
}
|
|
599
|
-
});
|
|
600
|
-
|
|
601
|
-
onMounted(() => {
|
|
602
|
-
initFlatPickerOption();
|
|
603
|
-
generateFlatPickerOption();
|
|
604
|
-
});
|
|
605
|
-
onUnmounted(() => {
|
|
606
|
-
if (state.picker != null) {
|
|
607
|
-
state.picker.destroy();
|
|
608
|
-
state.picker = null;
|
|
609
|
-
}
|
|
610
|
-
});
|
|
611
|
-
const tabindex = computed(() => {
|
|
612
|
-
if (props.disabled === true) return -1;
|
|
613
|
-
return props.tabindex;
|
|
614
|
-
});
|
|
615
|
-
|
|
616
|
-
// 更新の有無判定
|
|
617
|
-
const isChangeData = computed(() => {
|
|
618
|
-
if (props.diff === undefined) return false;
|
|
619
|
-
if (props.diff === null && props.data === "") return false;
|
|
620
|
-
if (props.diff === "" && props.data === null) return false;
|
|
621
|
-
if (props.diff !== props.data) return true;
|
|
622
|
-
return false;
|
|
623
|
-
});
|
|
624
|
-
|
|
625
|
-
// ---------------------------------------------------------------------------------
|
|
626
|
-
</script>
|
|
627
|
-
|
|
628
|
-
<template>
|
|
629
|
-
<InputFrame
|
|
630
|
-
:class="props.class"
|
|
631
|
-
:class-header="props.classHeader"
|
|
632
|
-
:class-input="[props.classInput]"
|
|
633
|
-
:focus="computedActivate"
|
|
634
|
-
:focus-color="props.focusColor"
|
|
635
|
-
:change="isChangeData"
|
|
636
|
-
:change-color="props.changeColor"
|
|
637
|
-
:error="props.error"
|
|
638
|
-
:error-color="props.errorColor"
|
|
639
|
-
:disabled="props.disabled"
|
|
640
|
-
:disabled-color="props.disabledColor"
|
|
641
|
-
:readonly="props.readonly"
|
|
642
|
-
:label="props.label"
|
|
643
|
-
:require="props.require"
|
|
644
|
-
:require-text="props.requireText"
|
|
645
|
-
:warn="props.warn"
|
|
646
|
-
:warn-time-out="props.warnTimeOut"
|
|
647
|
-
:size="props.size"
|
|
648
|
-
>
|
|
649
|
-
<template v-if="!props.readonly" #left-icons="{ disabled: iconDisabled }">
|
|
650
|
-
<div
|
|
651
|
-
:class="
|
|
652
|
-
!iconDisabled
|
|
653
|
-
? 'cursor-pointer hover:bg-accent1/[0.1] active:bg-accent1/[0.2]'
|
|
654
|
-
: ''
|
|
655
|
-
"
|
|
656
|
-
@click="datePickerToggle()"
|
|
657
|
-
>
|
|
658
|
-
<i
|
|
659
|
-
:class="
|
|
660
|
-
props.mode === 'time'
|
|
661
|
-
? 'fa-regular fa-clock'
|
|
662
|
-
: 'fa-solid fa-calendar-days'
|
|
663
|
-
"
|
|
664
|
-
></i>
|
|
665
|
-
</div>
|
|
666
|
-
</template>
|
|
667
|
-
<div
|
|
668
|
-
class="nac-c-input-p"
|
|
669
|
-
:class="[
|
|
670
|
-
{ disabled: props.disabled, readonly: props.readonly },
|
|
671
|
-
inputBoxClass,
|
|
672
|
-
]"
|
|
673
|
-
@click="datePickerToggle()"
|
|
674
|
-
>
|
|
675
|
-
<input
|
|
676
|
-
:ref="(e) => setRef(e)"
|
|
677
|
-
type="text"
|
|
678
|
-
class="flatpickr-body"
|
|
679
|
-
:disabled="props.disabled"
|
|
680
|
-
:tabindex="tabindex"
|
|
681
|
-
@keydown="keyDown"
|
|
682
|
-
/>
|
|
683
|
-
<span>{{ displayText }}</span>
|
|
684
|
-
<span
|
|
685
|
-
v-if="
|
|
686
|
-
props.data === null &&
|
|
687
|
-
!props.hideTodayBtn &&
|
|
688
|
-
!props.readonly &&
|
|
689
|
-
!props.disabled
|
|
690
|
-
"
|
|
691
|
-
class="today"
|
|
692
|
-
@click.stop="datePickerToday()"
|
|
693
|
-
>
|
|
694
|
-
{{ props.mode === "time" ? "Now" : "Today" }}
|
|
695
|
-
</span>
|
|
696
|
-
</div>
|
|
697
|
-
<template
|
|
698
|
-
v-if="!props.hideDeleteBtn && !props.readonly"
|
|
699
|
-
#right-icons="{ disabled: iconDisabled }"
|
|
700
|
-
>
|
|
701
|
-
<div
|
|
702
|
-
:class="
|
|
703
|
-
!iconDisabled
|
|
704
|
-
? 'text-error cursor-pointer hover:bg-error/[0.1] active:bg-error/[0.2]'
|
|
705
|
-
: ''
|
|
706
|
-
"
|
|
707
|
-
@click="iconEventDelete()"
|
|
708
|
-
>
|
|
709
|
-
<i class="fa-solid fa-delete-left"></i>
|
|
710
|
-
</div>
|
|
711
|
-
</template>
|
|
712
|
-
</InputFrame>
|
|
713
|
-
</template>
|
|
714
|
-
|
|
715
|
-
<style scoped>
|
|
716
|
-
.nac-c-input-p {
|
|
717
|
-
width: 100%;
|
|
718
|
-
height: 100%;
|
|
719
|
-
padding: 0 4px;
|
|
720
|
-
}
|
|
721
|
-
.nac-c-input-p:not(.readonly) {
|
|
722
|
-
cursor: pointer;
|
|
723
|
-
}
|
|
724
|
-
.nac-c-input-p .today {
|
|
725
|
-
margin: 0 0 0 4px;
|
|
726
|
-
border-radius: 4px;
|
|
727
|
-
border: solid 1px #f68708;
|
|
728
|
-
background-color: rgb(255, 246, 237);
|
|
729
|
-
color: #e26f2c;
|
|
730
|
-
font-size: 12px;
|
|
731
|
-
padding: 1px 4px;
|
|
732
|
-
}
|
|
733
|
-
.nac-c-input-p .flatpickr-body {
|
|
734
|
-
position: absolute;
|
|
735
|
-
opacity: 0 !important;
|
|
736
|
-
top: 0px;
|
|
737
|
-
height: 40px;
|
|
738
|
-
height: 100%;
|
|
739
|
-
width: 40px;
|
|
740
|
-
left: 0;
|
|
741
|
-
z-index: -1;
|
|
742
|
-
pointer-events: none;
|
|
743
|
-
}
|
|
744
|
-
|
|
745
|
-
:deep(.flatpickr-mobile) {
|
|
746
|
-
position: absolute;
|
|
747
|
-
opacity: 0;
|
|
748
|
-
}
|
|
749
|
-
|
|
750
|
-
.nac-c-input-p {
|
|
751
|
-
display: flex;
|
|
752
|
-
align-items: center;
|
|
753
|
-
}
|
|
754
|
-
.nac-c-input-p.display-left {
|
|
755
|
-
justify-content: flex-start;
|
|
756
|
-
}
|
|
757
|
-
.nac-c-input-p.display-center {
|
|
758
|
-
justify-content: center;
|
|
759
|
-
}
|
|
760
|
-
.nac-c-input-p.display-right {
|
|
761
|
-
justify-content: flex-end;
|
|
762
|
-
}
|
|
763
|
-
|
|
764
|
-
.disabled .nac-c-input-p {
|
|
765
|
-
cursor: default;
|
|
766
|
-
}
|
|
767
|
-
.disabled .nac-c-input-p .today {
|
|
768
|
-
display: none;
|
|
769
|
-
}
|
|
770
|
-
</style>
|